-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree-sitter-regex.ebnf
120 lines (85 loc) · 2.14 KB
/
tree-sitter-regex.ebnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//
// From tree-sitter-regex/src/grammar.json
//
//
// EBNF to generate railroad diagram at
// (IPV6) https://www.bottlecaps.de/rr/ui
// (IPV4) https://rr.red-dove.com/ui
//
pattern ::=
alternation
| term
alternation ::=
term? ( '|' term? )+
term ::=
( ( start_assertion | end_assertion | boundary_assertion | non_boundary_assertion | lookaround_assertion | pattern_character | character_class | any_character | decimal_escape | character_class_escape | _character_escape | backreference_escape | anonymous_capturing_group | named_capturing_group | non_capturing_group ) ( zero_or_more | one_or_more | optional | count_quantifier )? )+
any_character ::=
'.'
start_assertion ::=
'^'
end_assertion ::=
'$'
boundary_assertion ::=
'\b'
non_boundary_assertion ::=
'\B'
lookaround_assertion ::=
_lookahead_assertion
| _lookbehind_assertion
_lookahead_assertion ::=
'(?' ( '=' | '!' ) pattern ')'
_lookbehind_assertion ::=
'(?<' ( '=' | '!' ) pattern ')'
pattern_character ::=
[^\^\$\.\*\+\?\(\)#x5B#x5D\|#x0D?#x0A]
character_class ::=
'[' '^'? ( class_range | _class_atom )* ']'
class_range ::=
_class_atom '-' _class_atom
_class_atom ::=
'-'
| class_character
| '\-'
| character_class_escape
| _character_escape
class_character ::=
[^\#x5D#x2D-]
anonymous_capturing_group ::=
'(' pattern ')'
named_capturing_group ::=
'(?<' group_name '>' pattern ')'
non_capturing_group ::=
'(?:' pattern ')'
zero_or_more ::=
'*' '?'?
one_or_more ::=
'+' '?'?
optional ::=
'?' '?'?
count_quantifier ::=
'{' decimal_digits ( ',' decimal_digits )? '}' '?'?
backreference_escape ::=
'\k' group_name
decimal_escape ::=
'\'[1-9][0-9]*
character_class_escape ::=
'\'[dDsSwW]
| '\'[pP] '{' unicode_property_value_expression '}'
unicode_property_value_expression ::=
( unicode_property '=' )? unicode_property
unicode_property ::=
[a-zA-Z_0-9]+
_character_escape ::=
control_escape
| control_letter_escape
| identity_escape
control_escape ::=
'\'[bfnrtv0]
control_letter_escape ::=
'\c'[a-zA-Z]
identity_escape ::=
( '\\' [^kdDsSpPwWbfnrtv0-9] )
group_name ::=
[A-Za-z0-9]+
decimal_digits ::=
[0-9]+