mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 16:07:01 +00:00
Code split
This commit is contained in:
+3
-67
@@ -1,70 +1,6 @@
|
||||
// lexer.v — tokenizer for the VuurRaaf source language (.vr).
|
||||
module compiler
|
||||
|
||||
pub enum TokKind {
|
||||
eof
|
||||
ident
|
||||
int_lit
|
||||
str_lit
|
||||
lparen
|
||||
rparen
|
||||
lbrace
|
||||
rbrace
|
||||
lbracket
|
||||
rbracket
|
||||
comma
|
||||
dot
|
||||
colon
|
||||
plus
|
||||
minus
|
||||
star
|
||||
slash
|
||||
percent
|
||||
eq_eq
|
||||
not_eq
|
||||
lt
|
||||
le
|
||||
gt
|
||||
ge
|
||||
assign
|
||||
plus_eq
|
||||
minus_eq
|
||||
star_eq
|
||||
slash_eq
|
||||
dotdot
|
||||
dotdotdot
|
||||
kw_fn
|
||||
kw_struct
|
||||
kw_let
|
||||
kw_if
|
||||
kw_else
|
||||
kw_while
|
||||
kw_for
|
||||
kw_in
|
||||
kw_match
|
||||
kw_break
|
||||
kw_continue
|
||||
kw_return
|
||||
kw_true
|
||||
kw_false
|
||||
kw_and
|
||||
kw_or
|
||||
kw_not
|
||||
kw_print
|
||||
kw_println
|
||||
kw_assert
|
||||
kw_import
|
||||
kw_enum
|
||||
kw_const
|
||||
}
|
||||
|
||||
pub struct Tok {
|
||||
pub:
|
||||
kind TokKind
|
||||
lit string
|
||||
line int
|
||||
}
|
||||
|
||||
pub fn tokenize(src string) ![]Tok {
|
||||
mut l := Lexer{ src: src }
|
||||
mut toks := []Tok{}
|
||||
@@ -242,7 +178,7 @@ fn (mut l Lexer) next() !Tok {
|
||||
}
|
||||
return Tok{ kind: .gt, lit: '>', line: line }
|
||||
}
|
||||
`"` {
|
||||
`\"` {
|
||||
return l.lex_string(line)!
|
||||
}
|
||||
`0`...`9` {
|
||||
@@ -310,7 +246,7 @@ fn (mut l Lexer) lex_string(line int) !Tok {
|
||||
mut s := ''
|
||||
for l.pos < l.src.len {
|
||||
c := l.advance()
|
||||
if c == `"` {
|
||||
if c == `\"` {
|
||||
return Tok{ kind: .str_lit, lit: s, line: line }
|
||||
}
|
||||
if c == `\\` {
|
||||
@@ -325,7 +261,7 @@ fn (mut l Lexer) lex_string(line int) !Tok {
|
||||
`t` {
|
||||
s += '\t'
|
||||
}
|
||||
`"` {
|
||||
`\"` {
|
||||
s += '"'
|
||||
}
|
||||
`\\` {
|
||||
|
||||
Reference in New Issue
Block a user