Skip to content

Commit b9080f8

Browse files
committed
Fix issue parsing vendor/stb/image with the core:odin/parser parser
1 parent 757c243 commit b9080f8

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

core/odin/parser/parser.odin

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
23072307
open := expect_token(p, .Open_Paren)
23082308
p.expr_level += 1
23092309
expr := parse_expr(p, false)
2310+
skip_possible_newline(p)
23102311
p.expr_level -= 1
23112312
close := expect_token(p, .Close_Paren)
23122313

@@ -3526,7 +3527,9 @@ parse_binary_expr :: proc(p: ^Parser, lhs: bool, prec_in: int) -> ^ast.Expr {
35263527
case .When:
35273528
x := expr
35283529
cond := parse_expr(p, lhs)
3530+
skip_possible_newline(p)
35293531
else_tok := expect_token(p, .Else)
3532+
skip_possible_newline(p)
35303533
y := parse_expr(p, lhs)
35313534
te := ast.new(ast.Ternary_When_Expr, expr.pos, end_pos(p.prev_tok))
35323535
te.x = x
@@ -3780,10 +3783,6 @@ parse_import_decl :: proc(p: ^Parser, kind := Import_Decl_Kind.Standard) -> ^ast
37803783
import_name.pos = p.curr_tok.pos
37813784
}
37823785

3783-
if !is_using && is_blank_ident(import_name) {
3784-
error(p, import_name.pos, "illegal import name: '_'")
3785-
}
3786-
37873786
path := expect_token_after(p, .String, "import")
37883787

37893788
decl := ast.new(ast.Import_Decl, tok.pos, end_pos(path))

tests/core/odin/test_parser.odin

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,31 @@ Foo :: bit_field uint {
6666
ok := parser.parse_file(&p, &file)
6767
testing.expect(t, ok, "bad parse")
6868
}
69+
70+
@test
71+
test_parse_parser :: proc(t: ^testing.T) {
72+
context.allocator = context.temp_allocator
73+
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
74+
75+
pkg, ok := parser.parse_package_from_path(ODIN_ROOT + "core/odin/parser")
76+
77+
testing.expect(t, ok, "parser.parse_package_from_path failed")
78+
79+
for key, value in pkg.files {
80+
testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
81+
}
82+
}
83+
84+
@test
85+
test_parse_stb_image :: proc(t: ^testing.T) {
86+
context.allocator = context.temp_allocator
87+
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
88+
89+
pkg, ok := parser.parse_package_from_path(ODIN_ROOT + "vendor/stb/image")
90+
91+
testing.expect(t, ok, "parser.parse_package_from_path failed")
92+
93+
for key, value in pkg.files {
94+
testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
95+
}
96+
}

0 commit comments

Comments
 (0)