diff --git a/codee/patches/0019-Allow-identifier-s-in-data_value-s-repeat-s.patch b/codee/patches/0019-Allow-identifier-s-in-data_value-s-repeat-s.patch new file mode 100644 index 0000000..d44c574 --- /dev/null +++ b/codee/patches/0019-Allow-identifier-s-in-data_value-s-repeat-s.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?I=C3=B1aki=20Amatria=20Barral?= +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) 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/src/grammar.json b/src/grammar.json index e11c5f4..e5963d1 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -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" + } + ] } }, { @@ -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" + } + ] } }, { diff --git a/src/node-types.json b/src/node-types.json index f41d4b4..5f7d055 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -2063,6 +2063,10 @@ "multiple": true, "required": false, "types": [ + { + "type": "identifier", + "named": true + }, { "type": "number_literal", "named": true diff --git a/src/parser.c b/src/parser.c index 34fcca2..588e46a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -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), @@ -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), @@ -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), @@ -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), 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)