Skip to content

Commit

Permalink
fix: allow expressions in enum values
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Oct 15, 2024
1 parent 69af07e commit d58d957
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ module.exports = function defineGrammar(dialect) {
optional(field('attributes', $.attribute_list)),
keyword('case'),
field('name', $.name),
optional(seq('=', field('value', choice($._string, $.integer)))),
optional(seq('=', field('value', $.expression))),
$._semicolon,
),

Expand Down
40 changes: 39 additions & 1 deletion test/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,18 @@ enum Suit: string
}
}

enum D: int
{
case Minus_1 = -1;
case Zero = 0;
case Plus_1 = +1;
}

enum E: string
{
case StringConcat = 'Hello ' . "World";
}

---

(program
Expand Down Expand Up @@ -944,4 +956,30 @@ enum Suit: string
(name)
(name)))
(string
(string_content)))))))))))
(string_content))))))))))
(enum_declaration
(name)
(primitive_type)
(enum_declaration_list
(enum_case
(name)
(unary_op_expression
(integer)))
(enum_case
(name)
(integer))
(enum_case
(name)
(unary_op_expression
(integer)))))
(enum_declaration
(name)
(primitive_type)
(enum_declaration_list
(enum_case
(name)
(binary_expression
(string
(string_content))
(encapsed_string
(string_content)))))))

0 comments on commit d58d957

Please sign in to comment.