Skip to content

Commit

Permalink
fix: correctly parse regex literals
Browse files Browse the repository at this point in the history
  • Loading branch information
MXfive committed Sep 6, 2024
1 parent 6bf0466 commit eced5b2
Show file tree
Hide file tree
Showing 4 changed files with 2,237 additions and 3,652 deletions.
24 changes: 17 additions & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,25 @@ module.exports = grammar({
choice('m', 'h', 'd')
),

regex_literal: _ => token(seq(
regex_literal: _ => seq(
'/',
/[^/\\\*]/,
repeat(choice(
/[^/\\]/,
seq('\\', /./)
token.immediate(prec(-1,
repeat1(choice(
seq(
'[',
repeat(choice(
seq('\\', /./), // escaped character
/[^\]\n\\]/, // any character besides ']' or '\n'
)),
']',
), // square-bracket-delimited character class
seq('\\', /./), // escaped character
/[^/\\\[\n]/, // any character besides '[', '\', '/', '\n'
)),
)),
'/'
)),
token.immediate(prec(1, '/')),
),


boolean_literal: _ => choice('true', 'false'),

Expand Down
125 changes: 85 additions & 40 deletions src/grammar.json

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

9 changes: 5 additions & 4 deletions src/node-types.json

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

Loading

0 comments on commit eced5b2

Please sign in to comment.