Skip to content

Commit 1ea74a6

Browse files
authored
Merge pull request #224 from calebdw/fix_comment_again
fix: comment precedence (again)
2 parents 710754c + cf38b7f commit 1ea74a6

File tree

8 files changed

+61658
-61690
lines changed

8 files changed

+61658
-61690
lines changed

common/define-grammar.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ module.exports = function defineGrammar(dialect) {
148148

149149
text: _ => repeat1(choice(
150150
token(prec(-1, /</)),
151-
/[^\s<][^<]*/,
151+
token(prec(1, /[^\s<][^<]*/)),
152152
)),
153153

154154
_statement: $ => choice(
@@ -1553,7 +1553,7 @@ module.exports = function defineGrammar(dialect) {
15531553
keyword('static'),
15541554
),
15551555

1556-
comment: _ => token(prec(-1, choice(
1556+
comment: _ => token(choice(
15571557
seq(
15581558
choice('//', /#[^?\[?\r?\n]/),
15591559
repeat(/[^?\r?\n]|\?[^>\r\n]/),
@@ -1565,7 +1565,7 @@ module.exports = function defineGrammar(dialect) {
15651565
/[^*]*\*+([^/*][^*]*\*+)*/,
15661566
'/',
15671567
),
1568-
))),
1568+
)),
15691569

15701570
_semicolon: $ => choice($._automatic_semicolon, ';'),
15711571
},

common/test/corpus/bugs.txt

+23-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ foo(void: null);
164164
function: (name)
165165
arguments: (arguments (argument name: (name) (null))))))
166166

167-
168167
=========================================
169168
#221: Error when closing tag is in a string
170169
=========================================
@@ -209,3 +208,26 @@ $foo = '?>';
209208
(assignment_expression
210209
left: (variable_name (name))
211210
right: (string (string_value)))))
211+
212+
=========================================
213+
#223: Error with comment inside binary expression
214+
=========================================
215+
216+
<?php
217+
if (
218+
true
219+
// this is a comment
220+
|| false
221+
) {}
222+
223+
---
224+
225+
(program
226+
(php_tag)
227+
(if_statement
228+
condition: (parenthesized_expression
229+
(binary_expression
230+
left: (boolean)
231+
(comment)
232+
right: (boolean)))
233+
body: (compound_statement)))

common/test/corpus/string.txt

+2
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ okay to do';
455455
'#valid regexp#';
456456
'hello#world';
457457
'hello//world';
458+
'//hello world';
458459
'/*valid regexp*/';
459460
'/*valid regexp';
460461

@@ -474,6 +475,7 @@ okay to do';
474475
(expression_statement (string (string_value)))
475476
(expression_statement (string (string_value)))
476477
(expression_statement (string (string_value)))
478+
(expression_statement (string (string_value)))
477479
(expression_statement (string (string_value))))
478480

479481
=========================================

common/test/highlight/literals.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
OMG;
77
// <- string
88

9-
echo true, TRUE, false, FALSE
9+
echo true, TRUE, false, FALSE;
1010
// ^ constant.builtin
1111
// ^ constant.builtin
1212
// ^ constant.builtin
1313
// ^ constant.builtin
1414

15-
echo PI_314
15+
echo PI_314;
1616
// ^ constant
1717

18-
echo __DIR__
19-
// ^ constant.builtin
18+
echo __DIR__;
19+
// ^ constant.builtin

php/src/grammar.json

+66-63
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@
9898
}
9999
},
100100
{
101-
"type": "PATTERN",
102-
"value": "[^\\s<][^<]*"
101+
"type": "TOKEN",
102+
"content": {
103+
"type": "PREC",
104+
"value": 1,
105+
"content": {
106+
"type": "PATTERN",
107+
"value": "[^\\s<][^<]*"
108+
}
109+
}
103110
}
104111
]
105112
}
@@ -8980,71 +8987,67 @@
89808987
"comment": {
89818988
"type": "TOKEN",
89828989
"content": {
8983-
"type": "PREC",
8984-
"value": -1,
8985-
"content": {
8986-
"type": "CHOICE",
8987-
"members": [
8988-
{
8989-
"type": "SEQ",
8990-
"members": [
8991-
{
8992-
"type": "CHOICE",
8993-
"members": [
8994-
{
8995-
"type": "STRING",
8996-
"value": "//"
8997-
},
8998-
{
8999-
"type": "PATTERN",
9000-
"value": "#[^?\\[?\\r?\\n]"
9001-
}
9002-
]
9003-
},
9004-
{
9005-
"type": "REPEAT",
9006-
"content": {
8990+
"type": "CHOICE",
8991+
"members": [
8992+
{
8993+
"type": "SEQ",
8994+
"members": [
8995+
{
8996+
"type": "CHOICE",
8997+
"members": [
8998+
{
8999+
"type": "STRING",
9000+
"value": "//"
9001+
},
9002+
{
90079003
"type": "PATTERN",
9008-
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
9004+
"value": "#[^?\\[?\\r?\\n]"
90099005
}
9010-
},
9011-
{
9012-
"type": "CHOICE",
9013-
"members": [
9014-
{
9015-
"type": "PATTERN",
9016-
"value": "\\?\\r?\\n"
9017-
},
9018-
{
9019-
"type": "BLANK"
9020-
}
9021-
]
9022-
}
9023-
]
9024-
},
9025-
{
9026-
"type": "STRING",
9027-
"value": "#"
9028-
},
9029-
{
9030-
"type": "SEQ",
9031-
"members": [
9032-
{
9033-
"type": "STRING",
9034-
"value": "/*"
9035-
},
9036-
{
9006+
]
9007+
},
9008+
{
9009+
"type": "REPEAT",
9010+
"content": {
90379011
"type": "PATTERN",
9038-
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
9039-
},
9040-
{
9041-
"type": "STRING",
9042-
"value": "/"
9012+
"value": "[^?\\r?\\n]|\\?[^>\\r\\n]"
90439013
}
9044-
]
9045-
}
9046-
]
9047-
}
9014+
},
9015+
{
9016+
"type": "CHOICE",
9017+
"members": [
9018+
{
9019+
"type": "PATTERN",
9020+
"value": "\\?\\r?\\n"
9021+
},
9022+
{
9023+
"type": "BLANK"
9024+
}
9025+
]
9026+
}
9027+
]
9028+
},
9029+
{
9030+
"type": "STRING",
9031+
"value": "#"
9032+
},
9033+
{
9034+
"type": "SEQ",
9035+
"members": [
9036+
{
9037+
"type": "STRING",
9038+
"value": "/*"
9039+
},
9040+
{
9041+
"type": "PATTERN",
9042+
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
9043+
},
9044+
{
9045+
"type": "STRING",
9046+
"value": "/"
9047+
}
9048+
]
9049+
}
9050+
]
90489051
}
90499052
},
90509053
"_semicolon": {

0 commit comments

Comments
 (0)