diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-11-02 12:45:37 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-02 12:45:37 +0000 |
| commit | 5d609d402fb685c9eaeaebe33b0fb73879d9ea4e (patch) | |
| tree | 1a903594ff9a0c08a2385340c694ec52b02700fc | |
| parent | ade189008b5d2df9e4ec39730459c3453aa2e6b6 (diff) | |
| parent | e2b276f3ea2b00640a028c5455c283aa45261908 (diff) | |
Merge pull request #5867 from BradLewis/empty-selector-fields
Parse empty idents after selector as a selector expr with an empty field
| -rw-r--r-- | core/odin/parser/parser.odin | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 7ebe275ed..9ce484a10 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -3210,6 +3210,17 @@ parse_call_expr :: proc(p: ^Parser, operand: ^ast.Expr) -> ^ast.Expr { return ce } +empty_selector_expr :: proc(tok: tokenizer.Token, operand: ^ast.Expr) -> ^ast.Selector_Expr { + field := ast.new(ast.Ident, tok.pos, end_pos(tok)) + field.name = "" + + sel := ast.new(ast.Selector_Expr, operand.pos, field) + sel.expr = operand + sel.op = tok + sel.field = field + + return sel +} parse_atom_expr :: proc(p: ^Parser, value: ^ast.Expr, lhs: bool) -> (operand: ^ast.Expr) { operand = value @@ -3343,8 +3354,7 @@ parse_atom_expr :: proc(p: ^Parser, value: ^ast.Expr, lhs: bool) -> (operand: ^a case: error(p, p.curr_tok.pos, "expected a selector") - advance_token(p) - operand = ast.new(ast.Bad_Expr, operand.pos, end_pos(tok)) + operand = empty_selector_expr(tok, operand) } case .Arrow_Right: @@ -3361,8 +3371,7 @@ parse_atom_expr :: proc(p: ^Parser, value: ^ast.Expr, lhs: bool) -> (operand: ^a operand = sel case: error(p, p.curr_tok.pos, "expected a selector") - advance_token(p) - operand = ast.new(ast.Bad_Expr, operand.pos, end_pos(tok)) + operand = empty_selector_expr(tok, operand) } case .Pointer: |