Skip to content

Commit

Permalink
Fixes bugs in nowdoc implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cfroystad committed Jun 21, 2022
1 parent 363cd0d commit 3b2af70
Show file tree
Hide file tree
Showing 5 changed files with 60,056 additions and 59,635 deletions.
17 changes: 13 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1322,9 +1322,9 @@ module.exports = grammar({
nowdoc_body: $ => seq($._new_line,
choice(
repeat1(
$.nowdoc_string,
$.nowdoc_string
),
"",
alias("", $.nowdoc_string)
)
),

Expand All @@ -1333,8 +1333,17 @@ module.exports = grammar({
"'",
field('identifier', $.heredoc_start),
token.immediate("'"),
field('value', $.nowdoc_body),
seq($._new_line, field('end_tag', $.heredoc_end)),
choice(
seq(
field('value', $.nowdoc_body),
$._new_line,
field('end_tag', $.heredoc_end),
),
seq(
field('value', optional($.nowdoc_body)),
field('end_tag', $.heredoc_end),
)
),
),

boolean: $ => /[Tt][Rr][Uu][Ee]|[Ff][Aa][Ll][Ss][Ee]/,
Expand Down
77 changes: 58 additions & 19 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7297,8 +7297,13 @@
}
},
{
"type": "STRING",
"value": ""
"type": "ALIAS",
"content": {
"type": "STRING",
"value": ""
},
"named": true,
"value": "nowdoc_string"
}
]
}
Expand Down Expand Up @@ -7334,27 +7339,61 @@
}
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "nowdoc_body"
}
},
{
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_new_line"
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "nowdoc_body"
}
},
{
"type": "SYMBOL",
"name": "_new_line"
},
{
"type": "FIELD",
"name": "end_tag",
"content": {
"type": "SYMBOL",
"name": "heredoc_end"
}
}
]
},
{
"type": "FIELD",
"name": "end_tag",
"content": {
"type": "SYMBOL",
"name": "heredoc_end"
}
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "value",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "nowdoc_body"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "end_tag",
"content": {
"type": "SYMBOL",
"name": "heredoc_end"
}
}
]
}
]
}
Expand Down
8 changes: 2 additions & 6 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -3205,7 +3205,7 @@
},
"value": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "nowdoc_body",
Expand All @@ -3221,7 +3221,7 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "nowdoc_string",
Expand Down Expand Up @@ -4917,10 +4917,6 @@
]
}
},
{
"type": "",
"named": false
},
{
"type": "!",
"named": false
Expand Down
Loading

0 comments on commit 3b2af70

Please sign in to comment.