Skip to content

Commit

Permalink
Allow enums to use heredocs and double quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jan 6, 2024
1 parent 2f791d9 commit ea40b7b
Show file tree
Hide file tree
Showing 8 changed files with 36,794 additions and 36,732 deletions.
2 changes: 1 addition & 1 deletion common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,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', choice($._string, $.integer)))),
$._semicolon,
),

Expand Down
16 changes: 8 additions & 8 deletions common/test/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class B {
name: (name)
parameters: (formal_parameters
(simple_parameter
attributes: (attribute_list
attributes: (attribute_list
(attribute_group (attribute (name)))
)
name: (variable_name (name))
Expand Down Expand Up @@ -651,8 +651,10 @@ enum Suit: string
{
case Hearts = 'H';
case Diamonds;
case Clubs = 'C';
case Spades = 'S';
case Clubs = "C";
case Spades = <<<TXT
S
TXT;

// Fulfills the interface contract.
public function color(): string {
Expand Down Expand Up @@ -688,14 +690,12 @@ enum Suit: string
(enum_declaration
(name)
(primitive_type)
(enum_declaration_list
(enum_declaration_list
(enum_case (name) (string (string_value)))
(enum_case (name))
(enum_case (name) (string (string_value)))
(enum_case (name) (string (string_value)))

(enum_case (name) (encapsed_string (string_value)))
(enum_case (name) (heredoc (heredoc_start) (heredoc_body (string_value)) (heredoc_end)))
(comment)

(method_declaration
(visibility_modifier)
(name)
Expand Down
2 changes: 1 addition & 1 deletion php/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@
"members": [
{
"type": "SYMBOL",
"name": "string"
"name": "_string"
},
{
"type": "SYMBOL",
Expand Down
12 changes: 12 additions & 0 deletions php/src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1833,10 +1833,22 @@
"multiple": false,
"required": false,
"types": [
{
"type": "encapsed_string",
"named": true
},
{
"type": "heredoc",
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "nowdoc",
"named": true
},
{
"type": "string",
"named": true
Expand Down
Loading

0 comments on commit ea40b7b

Please sign in to comment.