blob: 0fc8fc521af13a529a2afd7b2c32a0da96cf769c (
plain)
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
package syntax
//go:generate stringer -type=Operation -trimprefix=Op
const (
OpNone Operation = iota
// OpConcat is a concatenation of ops.
// Examples: `xy` `abc\d` ``
// Args - concatenated ops
//
// As a special case, OpConcat with 0 Args is used for "empty"
// set of operations.
OpConcat
// OpDot is a '.' wildcard.
OpDot
// OpAlt is x|y alternation of ops.
// Examples: `a|bc` `x(.*?)|y(.*?)`
// Args - union-connected regexp branches
OpAlt
// OpStar is a shorthand for {0,} repetition.
// Examples: `x*`
// Args[0] - repeated expression
OpStar
// OpPlus is a shorthand for {1,} repetition.
// Examples: `x+`
// Args[0] - repeated expression
OpPlus
// OpQuestion is a shorthand for {0,1} repetition.
// Examples: `x?`
// Args[0] - repeated expression
OpQuestion
// OpNonGreedy makes its operand quantifier non-greedy.
// Examples: `x??` `x*?` `x+?`
// Args[0] - quantified expression
OpNonGreedy
// OpPossessive makes its operand quantifier possessive.
// Examples: `x?+` `x*+` `x++`
// Args[0] - quantified expression
OpPossessive
// OpCaret is ^ anchor.
OpCaret
// OpDollar is $ anchor.
OpDollar
// OpLiteral is a collection of consecutive chars.
// Examples: `ab` `10x`
// Args - enclosed characters (OpChar)
OpLiteral
// OpChar is a single literal pattern character.
// Examples: `a` `6` `ф`
OpChar
// OpString is an artificial element that is used in other expressions.
OpString
// OpQuote is a \Q...\E enclosed literal.
// Examples: `\Q.?\E` `\Q?q[]=1`
// FormQuoteUnclosed: `\Qabc`
// Args[0] - literal value (OpString)
OpQuote
// OpEscapeChar is a single char escape.
// Examples: `\d` `\a` `\n`
// Args[0] - escaped value (OpString)
OpEscapeChar
// OpEscapeMeta is an escaped meta char.
// Examples: `\(` `\[` `\+`
// Args[0] - escaped value (OpString)
OpEscapeMeta
// OpEscapeOctal is an octal char code escape (up to 3 digits).
// Examples: `\123` `\12`
// Args[0] - escaped value (OpString)
OpEscapeOctal
// OpEscapeHex is a hex char code escape.
// Examples: `\x7F` `\xF7`
// FormEscapeHexFull examples: `\x{10FFFF}` `\x{F}`.
// Args[0] - escaped value (OpString)
OpEscapeHex
// OpEscapeUni is a Unicode char class escape.
// Examples: `\pS` `\pL` `\PL`
// FormEscapeUniFull examples: `\p{Greek}` `\p{Symbol}` `\p{^L}`
// Args[0] - escaped value (OpString)
OpEscapeUni
// OpCharClass is a char class enclosed in [].
// Examples: `[abc]` `[a-z0-9\]]`
// Args - char class elements (can include OpCharRange and OpPosixClass)
OpCharClass
// OpNegCharClass is a negated char class enclosed in [].
// Examples: `[^abc]` `[^a-z0-9\]]`
// Args - char class elements (can include OpCharRange and OpPosixClass)
OpNegCharClass
// OpCharRange is an inclusive char range inside a char class.
// Examples: `0-9` `A-Z`
// Args[0] - range lower bound
// Args[1] - range upper bound
OpCharRange
// OpPosixClass is a named ASCII char set inside a char class.
// Examples: `[:alpha:]` `[:blank:]`
OpPosixClass
// OpRepeat is a {min,max} repetition quantifier.
// Examples: `x{5}` `x{min,max}` `x{min,}`
// Args[0] - repeated expression
// Args[1] - repeat count (OpString)
OpRepeat
// OpCapture is `(re)` capturing group.
// Examples: `(abc)` `(x|y)`
// Args[0] - enclosed expression
OpCapture
// OpNamedCapture is `(?P<name>re)` capturing group.
// Examples: `(?P<foo>abc)` `(?P<name>x|y)`
// FormNamedCaptureAngle examples: `(?<foo>abc)` `(?<name>x|y)`
// FormNamedCaptureQuote examples: `(?'foo'abc)` `(?'name'x|y)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
// Args[1] - group name (OpString)
OpNamedCapture
// OpGroup is `(?:re)` non-capturing group.
// Examples: `(?:abc)` `(?:x|y)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
OpGroup
// OpGroupWithFlags is `(?flags:re)` non-capturing group.
// Examples: `(?i:abc)` `(?i:x|y)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
// Args[1] - flags (OpString)
OpGroupWithFlags
// OpAtomicGroup is `(?>re)` non-capturing group without backtracking.
// Examples: `(?>foo)` `(?>)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
OpAtomicGroup
// OpPositiveLookahead is `(?=re)` asserts that following text matches re.
// Examples: `(?=foo)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
OpPositiveLookahead
// OpNegativeLookahead is `(?!re)` asserts that following text doesn't match re.
// Examples: `(?!foo)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
OpNegativeLookahead
// OpPositiveLookbehind is `(?<=re)` asserts that preceding text matches re.
// Examples: `(?<=foo)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
OpPositiveLookbehind
// OpNegativeLookbehind is `(?=re)` asserts that preceding text doesn't match re.
// Examples: `(?<!foo)`
// Args[0] - enclosed expression (OpConcat with 0 args for empty group)
OpNegativeLookbehind
// OpFlagOnlyGroup is `(?flags)` form that affects current group flags.
// Examples: `(?i)` `(?i-m)` `(?-im)`
// Args[0] - flags (OpString)
OpFlagOnlyGroup
// OpComment is a group-like regexp comment expression.
// Examples: `(?#text)` `(?#)`
OpComment
// OpNone2 is a sentinel value that is never part of the AST.
// OpNone and OpNone2 can be used to cover all ops in a range.
OpNone2
)
const (
FormDefault Form = iota
FormEscapeHexFull
FormEscapeUniFull
FormNamedCaptureAngle
FormNamedCaptureQuote
FormQuoteUnclosed
)
|