Skip to content

Commit 4bef32b

Browse files
committed
Fix clash between format and call_expression
Also allows parsing `foo()` as a standalone statement, which could be a compiler extension or preprocessor macro
1 parent 1f29192 commit 4bef32b

File tree

4 files changed

+581035
-578459
lines changed

4 files changed

+581035
-578459
lines changed

grammar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,8 @@ module.exports = grammar({
10861086
$.coarray_statement,
10871087
$.coarray_team_statement,
10881088
$.coarray_critical_statement,
1089+
// Not strictly valid, but can catch extensions and preprocessor macros
1090+
$.call_expression,
10891091
),
10901092

10911093
statement_label: $ => prec(1, alias($._integer_literal, 'statement_label')),
@@ -1569,12 +1571,12 @@ module.exports = grammar({
15691571
optional($._block_label)
15701572
),
15711573

1572-
format_statement: $ => seq(
1574+
format_statement: $ => prec.dynamic(PREC.CALL, seq(
15731575
caseInsensitive('format'),
15741576
'(',
15751577
alias($._transfer_items, $.transfer_items),
15761578
')'
1577-
),
1579+
)),
15781580

15791581
_transfer_item: $ => choice(
15801582
$.string_literal,

src/grammar.json

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13152,6 +13152,10 @@
1315213152
{
1315313153
"type": "SYMBOL",
1315413154
"name": "coarray_critical_statement"
13155+
},
13156+
{
13157+
"type": "SYMBOL",
13158+
"name": "call_expression"
1315513159
}
1315613160
]
1315713161
},
@@ -16474,35 +16478,39 @@
1647416478
]
1647516479
},
1647616480
"format_statement": {
16477-
"type": "SEQ",
16478-
"members": [
16479-
{
16480-
"type": "ALIAS",
16481-
"content": {
16482-
"type": "PATTERN",
16483-
"value": "[fF][oO][rR][mM][aA][tT]"
16481+
"type": "PREC_DYNAMIC",
16482+
"value": 80,
16483+
"content": {
16484+
"type": "SEQ",
16485+
"members": [
16486+
{
16487+
"type": "ALIAS",
16488+
"content": {
16489+
"type": "PATTERN",
16490+
"value": "[fF][oO][rR][mM][aA][tT]"
16491+
},
16492+
"named": false,
16493+
"value": "format"
1648416494
},
16485-
"named": false,
16486-
"value": "format"
16487-
},
16488-
{
16489-
"type": "STRING",
16490-
"value": "("
16491-
},
16492-
{
16493-
"type": "ALIAS",
16494-
"content": {
16495-
"type": "SYMBOL",
16496-
"name": "_transfer_items"
16495+
{
16496+
"type": "STRING",
16497+
"value": "("
1649716498
},
16498-
"named": true,
16499-
"value": "transfer_items"
16500-
},
16501-
{
16502-
"type": "STRING",
16503-
"value": ")"
16504-
}
16505-
]
16499+
{
16500+
"type": "ALIAS",
16501+
"content": {
16502+
"type": "SYMBOL",
16503+
"name": "_transfer_items"
16504+
},
16505+
"named": true,
16506+
"value": "transfer_items"
16507+
},
16508+
{
16509+
"type": "STRING",
16510+
"value": ")"
16511+
}
16512+
]
16513+
}
1650616514
},
1650716515
"_transfer_item": {
1650816516
"type": "CHOICE",
@@ -20934,6 +20942,15 @@
2093420942
"named": false,
2093520943
"value": "fail"
2093620944
},
20945+
{
20946+
"type": "ALIAS",
20947+
"content": {
20948+
"type": "PATTERN",
20949+
"value": "[fF][lL][uU][sS][hH]"
20950+
},
20951+
"named": false,
20952+
"value": "flush"
20953+
},
2093720954
{
2093820955
"type": "ALIAS",
2093920956
"content": {
@@ -21251,6 +21268,15 @@
2125121268
"named": false,
2125221269
"value": "value"
2125321270
},
21271+
{
21272+
"type": "ALIAS",
21273+
"content": {
21274+
"type": "PATTERN",
21275+
"value": "[wW][aA][iI][tT]"
21276+
},
21277+
"named": false,
21278+
"value": "wait"
21279+
},
2125421280
{
2125521281
"type": "PREC",
2125621282
"value": -1,
@@ -21405,6 +21431,10 @@
2140521431
"arithmetic_if_statement",
2140621432
"_block_if_statement",
2140721433
"identifier"
21434+
],
21435+
[
21436+
"file_position_statement",
21437+
"identifier"
2140821438
]
2140921439
],
2141021440
"precedences": [],

0 commit comments

Comments
 (0)