Skip to content

Commit

Permalink
feat: parse printf-like format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
fargiolas committed Apr 20, 2024
1 parent 1aafaff commit fecec92
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1281,12 +1281,21 @@ module.exports = grammar({
string_literal: $ => seq(
choice('L"', 'u"', 'U"', 'u8"', '"'),
repeat(choice(
alias(token.immediate(prec(1, /[^\\"\n]+/)), $.string_content),
alias(token.immediate(prec(1, /[^\\"\n\\%]+/)), $.string_content),
alias(token.immediate(/%/), $.string_content),
$.escape_sequence,
$.format_string,
)),
'"',
),

format_string: ($) => token.immediate(seq(
'%',
optional(/[#0-\\ +\\']*/),
optional(/[\d]*[\\.]*[\d]*/),
optional(/(hh|h|l|ll|j|t|z|q|G|L)?/),
/[diouxXDOUeEfFgGaACcSspn%]/)),

escape_sequence: _ => token(prec(1, seq(
'\\',
choice(
Expand Down

0 comments on commit fecec92

Please sign in to comment.