Skip to content

Commit

Permalink
Merge pull request #2789 from fabiansperber/fix-odin-parser
Browse files Browse the repository at this point in the history
Fix issues with core:odin parser
  • Loading branch information
gingerBill authored Sep 14, 2023
2 parents ed3a9ae + 886d0de commit d928f42
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
28 changes: 25 additions & 3 deletions core/odin/ast/ast.odin
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,27 @@ unparen_expr :: proc(expr: ^Expr) -> (val: ^Expr) {
return
}

strip_or_return_expr :: proc(expr: ^Expr) -> (val: ^Expr) {
val = expr
if expr == nil {
return
}
for {
inner: ^Expr
#partial switch e in val.derived {
case ^Or_Return_Expr:
inner = e.expr
case ^Paren_Expr:
inner = e.expr
}
if inner == nil {
break
}
val = inner
}
return
}

Field_Flags :: distinct bit_set[Field_Flag]

Field_Flag :: enum {
Expand All @@ -563,7 +584,7 @@ Field_Flag :: enum {
Using,
No_Alias,
C_Vararg,
Auto_Cast,
Const,
Any_Int,
Subtype,
By_Ptr,
Expand All @@ -582,7 +603,7 @@ field_flag_strings := [Field_Flag]string{
.Using = "using",
.No_Alias = "#no_alias",
.C_Vararg = "#c_vararg",
.Auto_Cast = "auto_cast",
.Const = "#const",
.Any_Int = "#any_int",
.Subtype = "#subtype",
.By_Ptr = "#by_ptr",
Expand All @@ -596,6 +617,7 @@ field_flag_strings := [Field_Flag]string{
field_hash_flag_strings := []struct{key: string, flag: Field_Flag}{
{"no_alias", .No_Alias},
{"c_vararg", .C_Vararg},
{"const", .Const},
{"any_int", .Any_Int},
{"subtype", .Subtype},
{"by_ptr", .By_Ptr},
Expand All @@ -616,7 +638,7 @@ Field_Flags_Signature :: Field_Flags{
.Using,
.No_Alias,
.C_Vararg,
.Auto_Cast,
.Const,
.Any_Int,
.By_Ptr,
.Default_Parameters,
Expand Down
5 changes: 1 addition & 4 deletions core/odin/parser/parser.odin
Original file line number Diff line number Diff line change
Expand Up @@ -1666,9 +1666,6 @@ is_token_field_prefix :: proc(p: ^Parser) -> ast.Field_Flag {
case .Using:
advance_token(p)
return .Using
case .Auto_Cast:
advance_token(p)
return .Auto_Cast
case .Hash:
tok: tokenizer.Token
advance_token(p)
Expand Down Expand Up @@ -2153,7 +2150,7 @@ parse_inlining_operand :: proc(p: ^Parser, lhs: bool, tok: tokenizer.Token) -> ^
}
}

#partial switch e in ast.unparen_expr(expr).derived_expr {
#partial switch e in ast.strip_or_return_expr(expr).derived_expr {
case ^ast.Proc_Lit:
if e.inlining != .None && e.inlining != pi {
error(p, expr.pos, "both 'inline' and 'no_inline' cannot be applied to a procedure literal")
Expand Down

0 comments on commit d928f42

Please sign in to comment.