Skip to content

Commit

Permalink
fix: comment precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Jan 6, 2024
1 parent 2f791d9 commit 7e5617c
Show file tree
Hide file tree
Showing 4 changed files with 12,640 additions and 12,697 deletions.
6 changes: 3 additions & 3 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ module.exports = function defineGrammar(dialect) {
'\'',
),

string_value: _ => token(prec(1, repeat1(/\\'|\\\\|\\?[^'\\]/))), // prec(1, ...) is needed to avoid conflict with $.comment
string_value: _ => token(repeat1(/\\'|\\\\|\\?[^'\\]/)),

heredoc_body: $ => seq($._new_line,
repeat1(prec.right(
Expand Down Expand Up @@ -1512,7 +1512,7 @@ module.exports = function defineGrammar(dialect) {
keyword('static'),
),

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

_semicolon: $ => choice($._automatic_semicolon, ';'),
},
Expand Down
128 changes: 64 additions & 64 deletions php/src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7181,14 +7181,10 @@
"string_value": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"type": "REPEAT1",
"content": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "\\\\'|\\\\\\\\|\\\\?[^'\\\\]"
}
"type": "PATTERN",
"value": "\\\\'|\\\\\\\\|\\\\?[^'\\\\]"
}
}
},
Expand Down Expand Up @@ -8839,67 +8835,71 @@
"comment": {
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "//"
},
{
"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": "PATTERN",
"value": "#[^?\\[?\\r?\\n]"
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
}
]
},
{
"type": "REPEAT",
"content": {
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\?\\r?\\n"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": "#"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "/*"
},
{
"type": "PATTERN",
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
},
{
"type": "STRING",
"value": "/"
}
},
{
"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 7e5617c

Please sign in to comment.