&&, ||, &, |, &=, |=
This commit is contained in:
18
lexer.v
18
lexer.v
@@ -26,6 +26,10 @@ enum TokenType as u8 {
|
||||
star
|
||||
slash
|
||||
percent
|
||||
and
|
||||
or
|
||||
and_and
|
||||
or_or
|
||||
equals
|
||||
less
|
||||
greater
|
||||
@@ -38,6 +42,8 @@ enum TokenType as u8 {
|
||||
star_eq
|
||||
slash_eq
|
||||
percent_eq
|
||||
and_eq
|
||||
or_eq
|
||||
increment
|
||||
decrement
|
||||
lparen
|
||||
@@ -94,6 +100,12 @@ fn toktype_from_delimiter(delimiter string) TokenType {
|
||||
'%=' {.percent_eq}
|
||||
'++' {.increment}
|
||||
'--' {.decrement}
|
||||
'&' {.and}
|
||||
'&&' {.and_and}
|
||||
'|' {.or}
|
||||
'||' {.or_or}
|
||||
'&=' {.and_eq}
|
||||
'|=' {.or_eq}
|
||||
else {.unknown}
|
||||
}
|
||||
}
|
||||
@@ -120,8 +132,8 @@ fn toktype_from_kw(kw string) TokenType {
|
||||
|
||||
fn is_delimiter(c u8, is_inside_number bool) bool {
|
||||
valid_chars := match is_inside_number {
|
||||
true {" #+-*/,;:%<>()[]{}=\n\""}
|
||||
false {". #+-*/,;:%<>()[]{}=\n\""}
|
||||
true {" #+-*/,;:%<>()[]{}=|&!\n\""}
|
||||
false {". #+-*/,;:%<>()[]{}=|&!\n\""}
|
||||
}
|
||||
return valid_chars.contains(c.ascii_str())
|
||||
}
|
||||
@@ -190,7 +202,7 @@ fn lex(input string) ?[]Token {
|
||||
mut tok_str := input[right].ascii_str()
|
||||
if right + 1 < input.len {
|
||||
combined := input.substr(right, right + 2)
|
||||
if combined in ['==', '>=', '<=', '!=', '+=', '-=', '*=', '/=', '%=', '++', '--'] {
|
||||
if combined in ['==', '>=', '<=', '!=', '+=', '-=', '*=', '/=', '%=', '++', '--', '||', '&&', '&=', '|='] {
|
||||
tok_str = combined
|
||||
right++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user