Skip to content

Commit

Permalink
Fixes bugs in heredoc implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cfroystad committed Jun 9, 2022
1 parent 56af3f2 commit 1e03dc3
Show file tree
Hide file tree
Showing 5 changed files with 58,915 additions and 58,675 deletions.
15 changes: 12 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ module.exports = grammar({
alias('\\u', $.string_value),
alias("'", $.string_value), // Needed to avoid the edge case "$b'" from breaking parsing by trying to apply the $.string rule for some reason
alias('<?', $.string_value),
alias(token(prec(1, '?>')), $.string_value)
alias(token(prec(1, '?>')), $.string_value),
),
),

Expand Down Expand Up @@ -1304,8 +1304,17 @@ module.exports = grammar({
$.heredoc_start,
seq('"', $.heredoc_start, token.immediate('"'))
)),
field('value', optional($.heredoc_body)),
seq($._new_line, field('end_tag', $.heredoc_end)),
choice(
seq(
field('value', $.heredoc_body),
$._new_line,
field('end_tag', $.heredoc_end),
),
seq(
field('value', optional($.heredoc_body)),
field('end_tag', $.heredoc_end),
)
),
),

_new_line: $ => token(/\r?\n/),
Expand Down
76 changes: 51 additions & 25 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7200,35 +7200,61 @@
}
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "heredoc_body"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_new_line"
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "heredoc_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": "heredoc_body"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "end_tag",
"content": {
"type": "SYMBOL",
"name": "heredoc_end"
}
}
]
}
]
}
Expand Down
Loading

0 comments on commit 1e03dc3

Please sign in to comment.