diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-18 21:45:15 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-06-22 09:42:33 -0400 |
| commit | fc58158fb76ea76c59454b3d201dfac182a61e73 (patch) | |
| tree | 87e87cccb9f5cb501e13b7a7f4d3b34097176064 | |
| parent | 757c243aaf73e8bc75dbe592817d56794f0ee5ca (diff) | |
Fix issue parsing `vendor/stb/image` with the `core:odin/parser` parser
| -rw-r--r-- | core/odin/parser/parser.odin | 6 | ||||
| -rw-r--r-- | tests/core/odin/test_parser.odin | 28 |
2 files changed, 30 insertions, 4 deletions
diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 7f1f4ca87..762410415 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -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)) diff --git a/tests/core/odin/test_parser.odin b/tests/core/odin/test_parser.odin index b4310104f..cc180f9af 100644 --- a/tests/core/odin/test_parser.odin +++ b/tests/core/odin/test_parser.odin @@ -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) + } +} |