Fix issue parsing vendor/stb/image with the core:odin/parser parser

This commit is contained in:
Brad Lewis
2025-06-18 21:45:15 -04:00
parent 757c243aaf
commit fc58158fb7
2 changed files with 30 additions and 4 deletions

View File

@@ -2307,6 +2307,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
open := expect_token(p, .Open_Paren)
p.expr_level += 1
expr := parse_expr(p, false)
skip_possible_newline(p)
p.expr_level -= 1
close := expect_token(p, .Close_Paren)
@@ -3526,6 +3527,7 @@ parse_binary_expr :: proc(p: ^Parser, lhs: bool, prec_in: int) -> ^ast.Expr {
case .When:
x := expr
cond := parse_expr(p, lhs)
skip_possible_newline(p)
else_tok := expect_token(p, .Else)
y := parse_expr(p, lhs)
te := ast.new(ast.Ternary_When_Expr, expr.pos, end_pos(p.prev_tok))
@@ -3780,10 +3782,6 @@ parse_import_decl :: proc(p: ^Parser, kind := Import_Decl_Kind.Standard) -> ^ast
import_name.pos = p.curr_tok.pos
}
if !is_using && is_blank_ident(import_name) {
error(p, import_name.pos, "illegal import name: '_'")
}
path := expect_token_after(p, .String, "import")
decl := ast.new(ast.Import_Decl, tok.pos, end_pos(path))

View File

@@ -66,3 +66,31 @@ Foo :: bit_field uint {
ok := parser.parse_file(&p, &file)
testing.expect(t, ok, "bad parse")
}
@test
test_parse_parser :: proc(t: ^testing.T) {
context.allocator = context.temp_allocator
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
pkg, ok := parser.parse_package_from_path(ODIN_ROOT + "core/odin/parser")
testing.expect(t, ok, "parser.parse_package_from_path failed")
for key, value in pkg.files {
testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
}
}
@test
test_parse_stb_image :: proc(t: ^testing.T) {
context.allocator = context.temp_allocator
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
pkg, ok := parser.parse_package_from_path(ODIN_ROOT + "vendor/stb/image")
testing.expect(t, ok, "parser.parse_package_from_path failed")
for key, value in pkg.files {
testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
}
}