Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= <inaki.amatria@appentra.com>
Date: Wed, 25 Jun 2025 15:37:31 +0200
Subject: Allow `identifier`s in `data_value`'s `repeat`s

As seen in
https://github.com/llvm/llvm-project/blob/llvmorg-20.1.6/flang/lib/Parser/Fortran-parsers.cpp#L913-L915.
---
grammar.js | 4 +++-
test/corpus/statements.txt | 12 ++++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/grammar.js b/grammar.js
index 80bc23a..6e79004 100644
--- a/grammar.js
+++ b/grammar.js
@@ -1273,7 +1273,9 @@ module.exports = grammar({
data_value: $ => seq(
'/',
commaSep1(seq(
- optional(prec(1, seq(field('repeat', $.number_literal), '*'))),
+ optional(prec(1,
+ seq(field('repeat', choice($.number_literal, $.identifier)), '*')
+ )),
choice(
$.number_literal,
$.complex_literal,
diff --git a/test/corpus/statements.txt b/test/corpus/statements.txt
index 7948402..41a00f8 100644
--- a/test/corpus/statements.txt
+++ b/test/corpus/statements.txt
@@ -2842,6 +2842,7 @@ program test
DATA array(:, N) / &
54.45_fp, 200.01_fp /
DATA complex_array / ( 0, 1 ), ( 1, 0 ) /
+ DATA foo / 3 * 0.0, 4 * bar, 1.0, 2.0 /
data params/ param1, param2/

! This is awful, but this makes sure the specification part has
@@ -2949,6 +2950,17 @@ end program test
(number_literal)
(number_literal)))))
(end_of_statement)
+ (data_statement
+ (data_set
+ (identifier)
+ (data_value
+ (number_literal)
+ (number_literal)
+ (number_literal)
+ (identifier)
+ (number_literal)
+ (number_literal))))
+ (end_of_statement)
(data_statement
(data_set
(identifier)
4 changes: 3 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,9 @@ module.exports = grammar({
data_value: $ => seq(
'/',
commaSep1(seq(
optional(prec(1, seq(field('repeat', $.number_literal), '*'))),
optional(prec(1,
seq(field('repeat', choice($.number_literal, $.identifier)), '*')
)),
choice(
$.number_literal,
$.complex_literal,
Expand Down
26 changes: 22 additions & 4 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -14088,8 +14088,17 @@
"type": "FIELD",
"name": "repeat",
"content": {
"type": "SYMBOL",
"name": "number_literal"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "number_literal"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
},
{
Expand Down Expand Up @@ -14168,8 +14177,17 @@
"type": "FIELD",
"name": "repeat",
"content": {
"type": "SYMBOL",
"name": "number_literal"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "number_literal"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
},
{
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,10 @@
"multiple": true,
"required": false,
"types": [
{
"type": "identifier",
"named": true
},
{
"type": "number_literal",
"named": true
Expand Down
8 changes: 4 additions & 4 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -719287,7 +719287,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[sym_string_literal] = STATE(7461),
[sym_coarray_expression] = STATE(5978),
[sym_conditional_expression] = STATE(5978),
[sym_identifier] = STATE(7461),
[sym_identifier] = STATE(7462),
[anon_sym_LPAREN2] = ACTIONS(17),
[anon_sym_PLUS] = ACTIONS(19),
[anon_sym_DASH] = ACTIONS(19),
Expand Down Expand Up @@ -726047,7 +726047,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[sym_string_literal] = STATE(7099),
[sym_coarray_expression] = STATE(5978),
[sym_conditional_expression] = STATE(5978),
[sym_identifier] = STATE(7099),
[sym_identifier] = STATE(7100),
[anon_sym_LPAREN2] = ACTIONS(17),
[anon_sym_PLUS] = ACTIONS(19),
[anon_sym_DASH] = ACTIONS(19),
Expand Down Expand Up @@ -728023,7 +728023,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[sym_string_literal] = STATE(7426),
[sym_coarray_expression] = STATE(5978),
[sym_conditional_expression] = STATE(5978),
[sym_identifier] = STATE(7426),
[sym_identifier] = STATE(7427),
[anon_sym_LPAREN2] = ACTIONS(17),
[anon_sym_PLUS] = ACTIONS(19),
[anon_sym_DASH] = ACTIONS(19),
Expand Down Expand Up @@ -728959,7 +728959,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = {
[sym_string_literal] = STATE(7092),
[sym_coarray_expression] = STATE(5978),
[sym_conditional_expression] = STATE(5978),
[sym_identifier] = STATE(7092),
[sym_identifier] = STATE(7093),
[anon_sym_LPAREN2] = ACTIONS(17),
[anon_sym_PLUS] = ACTIONS(19),
[anon_sym_DASH] = ACTIONS(19),
Expand Down
12 changes: 12 additions & 0 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,7 @@ program test
DATA array(:, N) / &
54.45_fp, 200.01_fp /
DATA complex_array / ( 0, 1 ), ( 1, 0 ) /
DATA foo / 3 * 0.0, 4 * bar, 1.0, 2.0 /
data params/ param1, param2/

! This is awful, but this makes sure the specification part has
Expand Down Expand Up @@ -2949,6 +2950,17 @@ end program test
(number_literal)
(number_literal)))))
(end_of_statement)
(data_statement
(data_set
(identifier)
(data_value
(number_literal)
(number_literal)
(number_literal)
(identifier)
(number_literal)
(number_literal))))
(end_of_statement)
(data_statement
(data_set
(identifier)
Expand Down
Loading