Skip to content

Commit

Permalink
fix: improve concatenated_string
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Feb 13, 2024
1 parent ecdd500 commit 8278ca9
Show file tree
Hide file tree
Showing 4 changed files with 68,089 additions and 67,613 deletions.
21 changes: 15 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,16 +911,20 @@ module.exports = grammar({
$.compound_literal_expression,
$.identifier,
$.number_literal,
$.string_literal,
$._string,
$.true,
$.false,
$.null,
$.concatenated_string,
$.char_literal,
$.parenthesized_expression,
$.gnu_asm_expression,
),

_string: $ => prec.left(choice(
$.string_literal,
$.concatenated_string,
)),

comma_expression: $ => seq(
field('left', $._expression),
',',
Expand Down Expand Up @@ -1070,7 +1074,7 @@ module.exports = grammar({
choice('asm', '__asm__'),
repeat($.gnu_asm_qualifier),
'(',
field('assembly_code', choice($.string_literal, $.concatenated_string)),
field('assembly_code', $._string),
optional(seq(
field('output_operands', $.gnu_asm_output_operand_list),
optional(seq(
Expand Down Expand Up @@ -1232,10 +1236,15 @@ module.exports = grammar({
'\'',
),

// Must concatenate at least 2 nodes, one of which must be a string_literal.
// Identifier is added to parse macros that are strings, like PRIu64.
concatenated_string: $ => prec.right(seq(
choice($.identifier, $.string_literal),
$.string_literal,
repeat(choice($.string_literal, $.identifier)), // Identifier is added to parse macros that are strings, like PRIu64
choice(
seq($.identifier, $.string_literal),
seq($.string_literal, $.string_literal),
seq($.string_literal, $.identifier),
),
repeat(choice($.string_literal, $.identifier))
)),

string_literal: $ => seq(
Expand Down
79 changes: 55 additions & 24 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8278ca9

Please sign in to comment.