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": [],

src/node-types.json

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@
527527
"type": "block_label_start_expression",
528528
"named": true
529529
},
530+
{
531+
"type": "call_expression",
532+
"named": true
533+
},
530534
{
531535
"type": "close_statement",
532536
"named": true
@@ -1040,6 +1044,10 @@
10401044
"type": "block_label_start_expression",
10411045
"named": true
10421046
},
1047+
{
1048+
"type": "call_expression",
1049+
"named": true
1050+
},
10431051
{
10441052
"type": "close_statement",
10451053
"named": true
@@ -1571,6 +1579,10 @@
15711579
"type": "block_label",
15721580
"named": true
15731581
},
1582+
{
1583+
"type": "call_expression",
1584+
"named": true
1585+
},
15741586
{
15751587
"type": "case_value_range_list",
15761588
"named": true
@@ -1964,6 +1976,10 @@
19641976
"type": "block_label_start_expression",
19651977
"named": true
19661978
},
1979+
{
1980+
"type": "call_expression",
1981+
"named": true
1982+
},
19671983
{
19681984
"type": "close_statement",
19691985
"named": true
@@ -2458,6 +2474,10 @@
24582474
"type": "block_label_start_expression",
24592475
"named": true
24602476
},
2477+
{
2478+
"type": "call_expression",
2479+
"named": true
2480+
},
24612481
{
24622482
"type": "close_statement",
24632483
"named": true
@@ -4164,6 +4184,10 @@
41644184
"type": "block_label_start_expression",
41654185
"named": true
41664186
},
4187+
{
4188+
"type": "call_expression",
4189+
"named": true
4190+
},
41674191
{
41684192
"type": "close_statement",
41694193
"named": true
@@ -4364,6 +4388,10 @@
43644388
"type": "block_label",
43654389
"named": true
43664390
},
4391+
{
4392+
"type": "call_expression",
4393+
"named": true
4394+
},
43674395
{
43684396
"type": "close_statement",
43694397
"named": true
@@ -4543,6 +4571,10 @@
45434571
"type": "block_label",
45444572
"named": true
45454573
},
4574+
{
4575+
"type": "call_expression",
4576+
"named": true
4577+
},
45464578
{
45474579
"type": "close_statement",
45484580
"named": true
@@ -4726,6 +4758,10 @@
47264758
"type": "block_label",
47274759
"named": true
47284760
},
4761+
{
4762+
"type": "call_expression",
4763+
"named": true
4764+
},
47294765
{
47304766
"type": "close_statement",
47314767
"named": true
@@ -5538,6 +5574,10 @@
55385574
"type": "block_label_start_expression",
55395575
"named": true
55405576
},
5577+
{
5578+
"type": "call_expression",
5579+
"named": true
5580+
},
55415581
{
55425582
"type": "close_statement",
55435583
"named": true
@@ -5787,6 +5827,10 @@
57875827
"type": "block_construct",
57885828
"named": true
57895829
},
5830+
{
5831+
"type": "call_expression",
5832+
"named": true
5833+
},
57905834
{
57915835
"type": "close_statement",
57925836
"named": true
@@ -6140,6 +6184,10 @@
61406184
"type": "block_label_start_expression",
61416185
"named": true
61426186
},
6187+
{
6188+
"type": "call_expression",
6189+
"named": true
6190+
},
61436191
{
61446192
"type": "close_statement",
61456193
"named": true
@@ -7898,6 +7946,10 @@
78987946
"type": "block_construct",
78997947
"named": true
79007948
},
7949+
{
7950+
"type": "call_expression",
7951+
"named": true
7952+
},
79017953
{
79027954
"type": "close_statement",
79037955
"named": true
@@ -9083,6 +9135,10 @@
90839135
"type": "block_data",
90849136
"named": true
90859137
},
9138+
{
9139+
"type": "call_expression",
9140+
"named": true
9141+
},
90869142
{
90879143
"type": "case_statement",
90889144
"named": true
@@ -9407,6 +9463,10 @@
94079463
"type": "block_data",
94089464
"named": true
94099465
},
9466+
{
9467+
"type": "call_expression",
9468+
"named": true
9469+
},
94109470
{
94119471
"type": "case_statement",
94129472
"named": true
@@ -9702,6 +9762,10 @@
97029762
"type": "block_data",
97039763
"named": true
97049764
},
9765+
{
9766+
"type": "call_expression",
9767+
"named": true
9768+
},
97059769
{
97069770
"type": "case_statement",
97079771
"named": true
@@ -10090,6 +10154,10 @@
1009010154
"type": "block_data",
1009110155
"named": true
1009210156
},
10157+
{
10158+
"type": "call_expression",
10159+
"named": true
10160+
},
1009310161
{
1009410162
"type": "case_statement",
1009510163
"named": true
@@ -10414,6 +10482,10 @@
1041410482
"type": "block_data",
1041510483
"named": true
1041610484
},
10485+
{
10486+
"type": "call_expression",
10487+
"named": true
10488+
},
1041710489
{
1041810490
"type": "case_statement",
1041910491
"named": true
@@ -10886,6 +10958,10 @@
1088610958
"type": "block_construct",
1088710959
"named": true
1088810960
},
10961+
{
10962+
"type": "call_expression",
10963+
"named": true
10964+
},
1088910965
{
1089010966
"type": "close_statement",
1089110967
"named": true
@@ -11187,6 +11263,10 @@
1118711263
"type": "block_label",
1118811264
"named": true
1118911265
},
11266+
{
11267+
"type": "call_expression",
11268+
"named": true
11269+
},
1119011270
{
1119111271
"type": "case_value_range_list",
1119211272
"named": true
@@ -12373,6 +12453,10 @@
1237312453
"type": "block_construct",
1237412454
"named": true
1237512455
},
12456+
{
12457+
"type": "call_expression",
12458+
"named": true
12459+
},
1237612460
{
1237712461
"type": "close_statement",
1237812462
"named": true
@@ -13029,6 +13113,10 @@
1302913113
"type": "block_label",
1303013114
"named": true
1303113115
},
13116+
{
13117+
"type": "call_expression",
13118+
"named": true
13119+
},
1303213120
{
1303313121
"type": "close_statement",
1303413122
"named": true
@@ -13559,6 +13647,10 @@
1355913647
"type": "block_label_start_expression",
1356013648
"named": true
1356113649
},
13650+
{
13651+
"type": "call_expression",
13652+
"named": true
13653+
},
1356213654
{
1356313655
"type": "close_statement",
1356413656
"named": true

0 commit comments

Comments
 (0)