mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 16:07:01 +00:00
More buildins and vscode exstention <CO-AUthored, ai>
This commit is contained in:
@@ -220,6 +220,11 @@ fn (mut l Lexer) next() !Tok {
|
||||
return l.lex_number(line, col)
|
||||
}
|
||||
else {
|
||||
// r"..." raw strings (no escape processing) — handy for regex
|
||||
// patterns like r"\d+" that would otherwise need double escaping
|
||||
if c == `r` && l.peek2() == `\"` {
|
||||
return l.lex_raw_string(line, col)!
|
||||
}
|
||||
if (c >= `a` && c <= `z`) || (c >= `A` && c <= `Z`) || c == `_` {
|
||||
return l.lex_ident(line, col)
|
||||
}
|
||||
@@ -310,6 +315,21 @@ fn (mut l Lexer) lex_ident(line int, col int) Tok {
|
||||
return Tok{ kind: kind, lit: lit, line: line, col: col }
|
||||
}
|
||||
|
||||
// lex_raw_string reads an r"..." string verbatim: backslashes, quotes and
|
||||
// ${...} sequences are all kept literally, so regex patterns pass through
|
||||
// untouched. The token is a plain str_lit whose content is the raw text.
|
||||
fn (mut l Lexer) lex_raw_string(line int, col int) !Tok {
|
||||
l.advance() // 'r'
|
||||
l.advance() // opening quote
|
||||
start := l.pos
|
||||
for l.pos < l.src.len {
|
||||
if l.advance() == `\"` {
|
||||
return Tok{ kind: .str_lit, lit: l.src[start..l.pos - 1], line: line, col: col }
|
||||
}
|
||||
}
|
||||
return error('unterminated raw string at line ${line}, col ${col}')
|
||||
}
|
||||
|
||||
fn (mut l Lexer) lex_string(line int, col int) !Tok {
|
||||
l.advance() // opening quote
|
||||
mut s := ''
|
||||
|
||||
Reference in New Issue
Block a user