booleans, comparisons, and if/else

This commit is contained in:
2026-06-21 20:20:55 +02:00
parent 19e9fbdd4b
commit c90ada608e
13 changed files with 1064 additions and 518 deletions
+41 -1
View File
@@ -23,7 +23,14 @@ keyword_kind :: proc(text: string) -> token.Kind {
case "mut": return .Keyword_Mut
case "none": return .Keyword_None
case "orelse": return .Keyword_Orelse
case "and": return .Keyword_And
case "or": return .Keyword_Or
case "if": return .Keyword_If
case "else": return .Keyword_Else
case "true": return .Keyword_True
case "false": return .Keyword_False
case "void": return .Keyword_Void
case "bool": return .Keyword_Bool
case "int": return .Keyword_Int
case "i8": return .Keyword_I8
case "i16": return .Keyword_I16
@@ -106,8 +113,41 @@ lex :: proc(
append_token(&stream, source_file, .Invalid, start, cursor, diagnostic=id)
}
case '=':
append_token(&stream, source_file, .Equal, cursor, cursor+1)
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Equal_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Equal, start, cursor)
}
case '!':
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Bang_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Bang, start, cursor)
}
case '<':
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Less_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Less, start, cursor)
}
case '>':
start := cursor
cursor += 1
if cursor < len(bytes) && bytes[cursor] == '=' {
cursor += 1
append_token(&stream, source_file, .Greater_Equal, start, cursor)
} else {
append_token(&stream, source_file, .Greater, start, cursor)
}
case '+':
append_token(&stream, source_file, .Plus, cursor, cursor+1)
cursor += 1