Skip to content

Commit

Permalink
Slightly better capture_group_conditional error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RedCMD committed Apr 27, 2024
1 parent 73d0ec0 commit 7b09af5
Show file tree
Hide file tree
Showing 4 changed files with 15,747 additions and 17,998 deletions.
89 changes: 49 additions & 40 deletions src/tree-sitter/tree-sitter-regex/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,72 +230,81 @@ module.exports = grammar({
')',
),
capture_group_conditional: $ => seq(
'(?(',
choice(
$.capture_group_conditional_name,
repeat($._expression),
),
')',
$.capture_group_condition,
repeat($._expression),
optional('|'),
repeat($._expression),
')',
),
capture_group_conditional_extended: $ => seq(
capture_group_condition: $ => seq( // Because TS can only insert missing nodes at the end of a node
'(?(',
choice(
$.capture_group_conditional_name,
repeat($._expression_extended),
alias(
$.capture_group_conditional_name,
$.name,
),
repeat($._expression),
),
')',
),
capture_group_conditional_extended: $ => seq(
$.capture_group_condition_extended,
repeat($._expression_extended),
optional('|'),
repeat($._expression_extended),
')',
),
capture_group_conditional_name: $ => alias(
capture_group_condition_extended: $ => seq( // Because TS can only insert missing nodes at the end of a node
'(?(',
choice(
alias(
$.capture_group_conditional_name,
$.name,
),
repeat($._expression_extended),
),
')',
),
capture_group_conditional_name: $ => choice(
seq(
'<',
seq(
'<',
seq(
token(
choice(
seq(
optional(choice('+', '-')),
repeat('0'),
/[1-9]/,
repeat(/[0-9]/),
),
seq(
/[a-zA-Z_]/,
repeat(/\w/),
),
token(
choice(
seq(
optional(choice('+', '-')),
repeat('0'),
/[1-9]/,
repeat(/[0-9]/),
),
),
optional(
seq(
optional(choice('-', '+')),
repeat1(/[0-9]/),
/[a-zA-Z_]/,
repeat(/\w/),
),
),
),
'>'
),
seq(
"'",
choice(
/[+-]?[1-9]\d*/,
/[a-zA-Z_]\w*/,
optional(
seq(
optional(choice('-', '+')),
repeat1(/[0-9]/),
),
),
optional(/[+-]\d+/),
"'"
),
seq(
'>'
),
seq(
"'",
choice(
/[+-]?[1-9]\d*/,
optional(/[+-]\d+/),
/[a-zA-Z_]\w*/,
),
optional(/[+-]\d+/),
"'"
),
seq(
/[+-]?[1-9]\d*/,
optional(/[+-]\d+/),
),
$.name,
),
comment_group: $ => seq(
'(?#',
Expand Down
Loading

0 comments on commit 7b09af5

Please sign in to comment.