Fixes bugs in nowdoc implementation

pull/315/head
Christian Frøystad 2022-06-21 12:13:51 +07:00
parent 363cd0d05f
commit 3b2af709a9
5 changed files with 60056 additions and 59635 deletions

@ -1322,9 +1322,9 @@ module.exports = grammar({
nowdoc_body: $ => seq($._new_line,
choice(
repeat1(
$.nowdoc_string,
$.nowdoc_string
),
"",
alias("", $.nowdoc_string)
)
),
@ -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]/,

77
src/grammar.json vendored

@ -7297,8 +7297,13 @@
}
},
{
"type": "STRING",
"value": ""
"type": "ALIAS",
"content": {
"type": "STRING",
"value": ""
},
"named": true,
"value": "nowdoc_string"
}
]
}
@ -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"
}
}
]
}
]
}

@ -3205,7 +3205,7 @@
},
"value": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "nowdoc_body",
@ -3221,7 +3221,7 @@
"fields": {},
"children": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "nowdoc_string",
@ -4917,10 +4917,6 @@
]
}
},
{
"type": "",
"named": false
},
{
"type": "!",
"named": false

119463
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -974,6 +974,49 @@ Nowdocs
<?php echo phpversion().PHP_SAPI;
PHP;
<<< 'EOF'
EOF;
<<< 'EOF'
EOF;
<<< 'EOF'
EOF;
<<< 'EOF'
\x0b, \x0c or \x0d
EOF;
<<< 'EOF'
\x0b
EOF;
<<< 'EOF'
\x0c
EOF;
<<< 'EOF'
\x0d
EOF;
<<< 'EOF'
This is a test
with multiple
lines
EOF;
<<< 'EOF'
b'asdfasdf'
EOF;
<<< 'EOF'
$this->atlas?->go();
EOF;
---
(program
@ -987,6 +1030,89 @@ PHP;
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
value: (nowdoc_body
(nowdoc_string)
)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
value: (nowdoc_body
(nowdoc_string)
)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
value: (nowdoc_body
(nowdoc_string)
)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
value: (nowdoc_body
(nowdoc_string)
)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
value: (nowdoc_body
(nowdoc_string)
(nowdoc_string)
(nowdoc_string)
)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
value: (nowdoc_body
(nowdoc_string)
)
end_tag: (heredoc_end)
)
)
(expression_statement
(nowdoc
identifier: (heredoc_start)
value: (nowdoc_body
(nowdoc_string)
)
end_tag: (heredoc_end)
)
)
)