Skip to content

Commit 34f89db

Browse files
committed
fix: comment precedence
1 parent 5a779d3 commit 34f89db

File tree

7 files changed

+24855
-25010
lines changed

7 files changed

+24855
-25010
lines changed

common/define-grammar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ module.exports = function defineGrammar(dialect) {
13351335
'\'',
13361336
),
13371337

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

13401340
heredoc_body: $ => seq($._new_line,
13411341
repeat1(prec.right(
@@ -1523,7 +1523,7 @@ module.exports = function defineGrammar(dialect) {
15231523
keyword('static'),
15241524
),
15251525

1526-
comment: _ => token(choice(
1526+
comment: _ => token(prec(-1, choice(
15271527
seq(
15281528
choice('//', /#[^?\[?\r?\n]/),
15291529
repeat(/[^?\r?\n]|\?[^>\r\n]/),
@@ -1535,7 +1535,7 @@ module.exports = function defineGrammar(dialect) {
15351535
/[^*]*\*+([^/*][^*]*\*+)*/,
15361536
'/',
15371537
),
1538-
)),
1538+
))),
15391539

15401540
_semicolon: $ => choice($._automatic_semicolon, ';'),
15411541
},

common/test/corpus/bugs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ var_dump(self);
6464
)
6565
)
6666
)
67-
)
67+
)

php/src/grammar.json

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7274,14 +7274,10 @@
72747274
"string_value": {
72757275
"type": "TOKEN",
72767276
"content": {
7277-
"type": "PREC",
7278-
"value": 1,
7277+
"type": "REPEAT1",
72797278
"content": {
7280-
"type": "REPEAT1",
7281-
"content": {
7282-
"type": "PATTERN",
7283-
"value": "\\\\'|\\\\\\\\|\\\\?[^'\\\\]"
7284-
}
7279+
"type": "PATTERN",
7280+
"value": "\\\\'|\\\\\\\\|\\\\?[^'\\\\]"
72857281
}
72867282
}
72877283
},
@@ -8932,67 +8928,71 @@
89328928
"comment": {
89338929
"type": "TOKEN",
89348930
"content": {
8935-
"type": "CHOICE",
8936-
"members": [
8937-
{
8938-
"type": "SEQ",
8939-
"members": [
8940-
{
8941-
"type": "CHOICE",
8942-
"members": [
8943-
{
8944-
"type": "STRING",
8945-
"value": "//"
8946-
},
8947-
{
8931+
"type": "PREC",
8932+
"value": -1,
8933+
"content": {
8934+
"type": "CHOICE",
8935+
"members": [
8936+
{
8937+
"type": "SEQ",
8938+
"members": [
8939+
{
8940+
"type": "CHOICE",
8941+
"members": [
8942+
{
8943+
"type": "STRING",
8944+
"value": "//"
8945+
},
8946+
{
8947+
"type": "PATTERN",
8948+
"value": "#[^?\\[?\\r?\\n]"
8949+
}
8950+
]
8951+
},
8952+
{
8953+
"type": "REPEAT",
8954+
"content": {
89488955
"type": "PATTERN",
8949-
"value": "#[^?\\[?\\r?\\n]"
8956+
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
89508957
}
8951-
]
8952-
},
8953-
{
8954-
"type": "REPEAT",
8955-
"content": {
8958+
},
8959+
{
8960+
"type": "CHOICE",
8961+
"members": [
8962+
{
8963+
"type": "PATTERN",
8964+
"value": "\\?\\r?\\n"
8965+
},
8966+
{
8967+
"type": "BLANK"
8968+
}
8969+
]
8970+
}
8971+
]
8972+
},
8973+
{
8974+
"type": "STRING",
8975+
"value": "#"
8976+
},
8977+
{
8978+
"type": "SEQ",
8979+
"members": [
8980+
{
8981+
"type": "STRING",
8982+
"value": "/*"
8983+
},
8984+
{
89568985
"type": "PATTERN",
8957-
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
8986+
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
8987+
},
8988+
{
8989+
"type": "STRING",
8990+
"value": "/"
89588991
}
8959-
},
8960-
{
8961-
"type": "CHOICE",
8962-
"members": [
8963-
{
8964-
"type": "PATTERN",
8965-
"value": "\\?\\r?\\n"
8966-
},
8967-
{
8968-
"type": "BLANK"
8969-
}
8970-
]
8971-
}
8972-
]
8973-
},
8974-
{
8975-
"type": "STRING",
8976-
"value": "#"
8977-
},
8978-
{
8979-
"type": "SEQ",
8980-
"members": [
8981-
{
8982-
"type": "STRING",
8983-
"value": "/*"
8984-
},
8985-
{
8986-
"type": "PATTERN",
8987-
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
8988-
},
8989-
{
8990-
"type": "STRING",
8991-
"value": "/"
8992-
}
8993-
]
8994-
}
8995-
]
8992+
]
8993+
}
8994+
]
8995+
}
89968996
}
89978997
},
89988998
"_semicolon": {

0 commit comments

Comments
 (0)