Skip to content

Commit f74b907

Browse files
committed
fix: improve concatenated_string
1 parent ecdd500 commit f74b907

File tree

4 files changed

+68089
-67613
lines changed

4 files changed

+68089
-67613
lines changed

grammar.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -911,16 +911,20 @@ module.exports = grammar({
911911
$.compound_literal_expression,
912912
$.identifier,
913913
$.number_literal,
914-
$.string_literal,
914+
$._string,
915915
$.true,
916916
$.false,
917917
$.null,
918-
$.concatenated_string,
919918
$.char_literal,
920919
$.parenthesized_expression,
921920
$.gnu_asm_expression,
922921
),
923922

923+
_string: $ => prec.left(choice(
924+
$.string_literal,
925+
$.concatenated_string,
926+
)),
927+
924928
comma_expression: $ => seq(
925929
field('left', $._expression),
926930
',',
@@ -1070,7 +1074,7 @@ module.exports = grammar({
10701074
choice('asm', '__asm__'),
10711075
repeat($.gnu_asm_qualifier),
10721076
'(',
1073-
field('assembly_code', choice($.string_literal, $.concatenated_string)),
1077+
field('assembly_code', $._string),
10741078
optional(seq(
10751079
field('output_operands', $.gnu_asm_output_operand_list),
10761080
optional(seq(
@@ -1232,10 +1236,15 @@ module.exports = grammar({
12321236
'\'',
12331237
),
12341238

1239+
// Must concatenate at least 2 nodes, one of which must be a string_literal.
1240+
// Identifier is added to parse macros that are strings, like PRIu64.
12351241
concatenated_string: $ => prec.right(seq(
1236-
choice($.identifier, $.string_literal),
1237-
$.string_literal,
1238-
repeat(choice($.string_literal, $.identifier)), // Identifier is added to parse macros that are strings, like PRIu64
1242+
choice(
1243+
seq($.identifier, $.string_literal),
1244+
seq($.string_literal, $.string_literal),
1245+
seq($.string_literal, $.identifier),
1246+
),
1247+
repeat(choice($.string_literal, $.identifier)),
12391248
)),
12401249

12411250
string_literal: $ => seq(

src/grammar.json

+55-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)