Skip to content

Commit

Permalink
Merge pull request #224 from calebdw/fix_comment_again
Browse files Browse the repository at this point in the history
fix: comment precedence (again)
  • Loading branch information
calebdw authored Feb 25, 2024
2 parents 710754c + cf38b7f commit 1ea74a6
Show file tree
Hide file tree
Showing 8 changed files with 61,658 additions and 61,690 deletions.
6 changes: 3 additions & 3 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module.exports = function defineGrammar(dialect) {

text: _ => repeat1(choice(
token(prec(-1, /</)),
/[^\s<][^<]*/,
token(prec(1, /[^\s<][^<]*/)),
)),

_statement: $ => choice(
Expand Down Expand Up @@ -1553,7 +1553,7 @@ module.exports = function defineGrammar(dialect) {
keyword('static'),
),

comment: _ => token(prec(-1, choice(
comment: _ => token(choice(
seq(
choice('//', /#[^?\[?\r?\n]/),
repeat(/[^?\r?\n]|\?[^>\r\n]/),
Expand All @@ -1565,7 +1565,7 @@ module.exports = function defineGrammar(dialect) {
/[^*]*\*+([^/*][^*]*\*+)*/,
'/',
),
))),
)),

_semicolon: $ => choice($._automatic_semicolon, ';'),
},
Expand Down
24 changes: 23 additions & 1 deletion common/test/corpus/bugs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ foo(void: null);
function: (name)
arguments: (arguments (argument name: (name) (null))))))


=========================================
#221: Error when closing tag is in a string
=========================================
Expand Down Expand Up @@ -209,3 +208,26 @@ $foo = '?>';
(assignment_expression
left: (variable_name (name))
right: (string (string_value)))))

=========================================
#223: Error with comment inside binary expression
=========================================

<?php
if (
true
// this is a comment
|| false
) {}

---

(program
(php_tag)
(if_statement
condition: (parenthesized_expression
(binary_expression
left: (boolean)
(comment)
right: (boolean)))
body: (compound_statement)))
2 changes: 2 additions & 0 deletions common/test/corpus/string.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ okay to do';
'#valid regexp#';
'hello#world';
'hello//world';
'//hello world';
'/*valid regexp*/';
'/*valid regexp';

Expand All @@ -474,6 +475,7 @@ okay to do';
(expression_statement (string (string_value)))
(expression_statement (string (string_value)))
(expression_statement (string (string_value)))
(expression_statement (string (string_value)))
(expression_statement (string (string_value))))

=========================================
Expand Down
8 changes: 4 additions & 4 deletions common/test/highlight/literals.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
OMG;
// <- string

echo true, TRUE, false, FALSE
echo true, TRUE, false, FALSE;
// ^ constant.builtin
// ^ constant.builtin
// ^ constant.builtin
// ^ constant.builtin

echo PI_314
echo PI_314;
// ^ constant

echo __DIR__
// ^ constant.builtin
echo __DIR__;
// ^ constant.builtin
129 changes: 66 additions & 63 deletions php/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@
}
},
{
"type": "PATTERN",
"value": "[^\\s<][^<]*"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[^\\s<][^<]*"
}
}
}
]
}
Expand Down Expand Up @@ -8980,71 +8987,67 @@
"comment": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "//"
},
{
"type": "PATTERN",
"value": "#[^?\\[?\\r?\\n]"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "//"
},
{
"type": "PATTERN",
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
"value": "#[^?\\[?\\r?\\n]"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\?\\r?\\n"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": "#"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "/*"
},
{
]
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
},
{
"type": "STRING",
"value": "/"
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\?\\r?\\n"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": "#"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "/*"
},
{
"type": "PATTERN",
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
},
{
"type": "STRING",
"value": "/"
}
]
}
]
}
},
"_semicolon": {
Expand Down
Loading

0 comments on commit 1ea74a6

Please sign in to comment.