Skip to content

Commit

Permalink
Improve string parsing
Browse files Browse the repository at this point in the history
Single and double quoted strings are now parsed as different entities.
This lays the ground for different escape sequences in both types of
strings.  Also it will allow the detection of questionable language
elements like non-working interpolation in a single quoted string.
  • Loading branch information
smoeding committed Jun 17, 2024
1 parent e6a9737 commit b52d643
Show file tree
Hide file tree
Showing 30 changed files with 50,244 additions and 49,010 deletions.
23 changes: 17 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ module.exports = grammar({
externals: $ => [
$.qmark,
$.selbrace,
$._fixed_string,
$._expandable_string,
$._sq_string,
$._dq_string,
$._heredoc_start,
$._heredoc_body,
$._heredoc_end,
Expand Down Expand Up @@ -602,11 +602,22 @@ module.exports = grammar({

// Literals (dynamic and static)

_quotedtext: $ => choice($.string, $.heredoc),
_quotedtext: $ => choice(
$.single_quoted_string,
$.double_quoted_string,
$.heredoc
),

single_quoted_string: $ => seq(
"'",
repeat($._sq_string),
"'",
),

string: $ => choice(
seq("'", repeat($._fixed_string), "'"),
seq('"', repeat(choice($._expandable_string, $.interpolation, $.escape_sequence)), '"'),
double_quoted_string: $ => seq(
'"',
repeat(choice($._dq_string, $.interpolation, $.escape_sequence)),
'"',
),

heredoc: $ => seq(
Expand Down
Loading

0 comments on commit b52d643

Please sign in to comment.