&&, ||, &, |, &=, |=

This commit is contained in:
uan
2026-02-07 16:11:00 +01:00
parent 9d26256023
commit 005828cec2
4 changed files with 26 additions and 16 deletions

18
lexer.v
View File

@@ -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++
}