Skip to content

Commit

Permalink
feat: alternative syntax for named groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ValdezFOmar authored and amaanq committed Nov 10, 2024
1 parent 7ba126f commit 9b46e66
Show file tree
Hide file tree
Showing 6 changed files with 1,746 additions and 1,447 deletions.
5 changes: 4 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = grammar({
$.character_class_escape,
$._character_escape,
$.backreference_escape,
$.named_group_backreference,
$.anonymous_capturing_group,
$.named_capturing_group,
$.non_capturing_group,
Expand Down Expand Up @@ -150,7 +151,7 @@ module.exports = grammar({

anonymous_capturing_group: $ => seq('(', $.pattern, ')'),

named_capturing_group: $ => seq('(?<', $.group_name, '>', $.pattern, ')'),
named_capturing_group: $ => seq(choice('(?<', '(?P<'), $.group_name, '>', $.pattern, ')'),

non_capturing_group: $ => seq('(?:', $.pattern, ')'),

Expand Down Expand Up @@ -184,6 +185,8 @@ module.exports = grammar({

backreference_escape: $ => seq('\\k', '<', $.group_name, '>'),

named_group_backreference: $ => seq('(?P=', $.group_name, ')'),

decimal_escape: _ => /\\[1-9][0-9]*/,

character_class_escape: $ => choice(
Expand Down
2 changes: 2 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"(?"
"(?:"
"(?<"
"(?P<"
"(?P="
">"
"["
"]"
Expand Down
34 changes: 32 additions & 2 deletions src/grammar.json

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

27 changes: 27 additions & 0 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 9b46e66

Please sign in to comment.