Skip to content

Commit 5d609d4

Browse files
authored
Merge pull request odin-lang#5867 from BradLewis/empty-selector-fields
Parse empty idents after selector as a selector expr with an empty field
2 parents ade1890 + e2b276f commit 5d609d4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

core/odin/parser/parser.odin

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3210,6 +3210,17 @@ parse_call_expr :: proc(p: ^Parser, operand: ^ast.Expr) -> ^ast.Expr {
32103210
return ce
32113211
}
32123212

3213+
empty_selector_expr :: proc(tok: tokenizer.Token, operand: ^ast.Expr) -> ^ast.Selector_Expr {
3214+
field := ast.new(ast.Ident, tok.pos, end_pos(tok))
3215+
field.name = ""
3216+
3217+
sel := ast.new(ast.Selector_Expr, operand.pos, field)
3218+
sel.expr = operand
3219+
sel.op = tok
3220+
sel.field = field
3221+
3222+
return sel
3223+
}
32133224

32143225
parse_atom_expr :: proc(p: ^Parser, value: ^ast.Expr, lhs: bool) -> (operand: ^ast.Expr) {
32153226
operand = value
@@ -3343,8 +3354,7 @@ parse_atom_expr :: proc(p: ^Parser, value: ^ast.Expr, lhs: bool) -> (operand: ^a
33433354

33443355
case:
33453356
error(p, p.curr_tok.pos, "expected a selector")
3346-
advance_token(p)
3347-
operand = ast.new(ast.Bad_Expr, operand.pos, end_pos(tok))
3357+
operand = empty_selector_expr(tok, operand)
33483358
}
33493359

33503360
case .Arrow_Right:
@@ -3361,8 +3371,7 @@ parse_atom_expr :: proc(p: ^Parser, value: ^ast.Expr, lhs: bool) -> (operand: ^a
33613371
operand = sel
33623372
case:
33633373
error(p, p.curr_tok.pos, "expected a selector")
3364-
advance_token(p)
3365-
operand = ast.new(ast.Bad_Expr, operand.pos, end_pos(tok))
3374+
operand = empty_selector_expr(tok, operand)
33663375
}
33673376

33683377
case .Pointer:

0 commit comments

Comments
 (0)