xref: /openbsd-src/gnu/usr.bin/perl/regcomp.sym (revision e068048151d29f2562a32185e21a8ba885482260)
1# regcomp.sym
2#
3# File has two sections, divided by a line of dashes '-'.
4#
5# Lines beginning with # are ignored, except for those that start with #*
6# which are included in pod/perldebguts.pod.  # within a line may be part
7# of a description.
8#
9# First section is for regops, second section is for regmatch-states
10#
11# Note that the order in this file is important.
12#
13# Format for first section:
14# NAME \s+ TYPE, arg-description [struct regnode suffix] [flags] [longjump] ; DESCRIPTION
15#   arg-description is currently unused
16#   suffix is appended to 'struct_regnode_' giving which one to use.  If empty,
17#       it means plain 'struct regnode'.  If the regnode is a string one, this
18#       should instead refer to the base regnode, without the char[1] element
19#       of the structure
20#   flag <S> means is REGNODE_SIMPLE; flag <V> means is REGNODE_VARIES; <.> is
21#       a placeholder
22#   longjump is 1 if the (first) argument holds the next offset (instead of the
23#       usual 'next_offset' field
24#
25# run perl regen.pl after editing this file
26
27#                             +- suffix of which struct regnode to use e.g.,
28#                             | +- flags  (S or V)               struct regnode_1
29#                         un- | | +- longjmp (0, blank, or 1)  blank means 0
30# Name        Type       used | | | ; comment
31# --------------------------------------------------------------------------
32# IFMATCH     BRANCHJ,    off 1 . 1 ; Succeeds if the following matches.
33# UNLESSM     BRANCHJ,    off 1 . 1 ; Fails if the following matches.
34# SUSPEND     BRANCHJ,    off 1 V 1 ; "Independent" sub-RE.
35# IFTHEN      BRANCHJ,    off 1 V 1 ; Switch, should be preceded by switcher.
36# GROUPP      GROUPP,     num 1     ; Whether the group matched.
37#
38# If we were to start running out of regnodes, many of the ones that are
39# complements could be combined with their non-complement mates.  For example,
40# POSIXU could have the flags field have the bottom bit mean do we complement
41# or not, and the type be shifted left 1 bit.  Then all that would be needed to
42# extract which to do is a mask for the complement bit, and a right shift for
43# the other, an inconsequential increase in instructions.  It might actually be
44# clearer and slightly faster given the case statement and assignment are
45# removed.  Note that not everything could be collapsed: NPOSIXA, for example,
46# would require special handling for performance.
47
48
49#* Exit points
50
51END         END,        no        ; End of program.
52SUCCEED     END,        no        ; Return from a subroutine, basically.
53
54#* Line Start Anchors:
55#Note flags field for SBOL indicates if it is a /^/ or a /\A/
56SBOL        BOL,        no        ; Match "" at beginning of line: /^/, /\A/
57MBOL        BOL,        no        ; Same, assuming multiline: /^/m
58
59#* Line End Anchors:
60SEOL        EOL,        no        ; Match "" at end of line: /$/
61MEOL        EOL,        no        ; Same, assuming multiline: /$/m
62EOS         EOL,        no        ; Match "" at end of string: /\z/
63
64#* Match Start Anchors:
65GPOS        GPOS,       no        ; Matches where last m//g left off.
66
67#* Word Boundary Opcodes:
68# The regops that have varieties that vary depending on the character set regex
69# modifiers have to ordered thusly: /d, /l, /u, /a, /aa.  This is because code
70# in regcomp.c uses the enum value of the modifier as an offset from the /d
71# version.  The complements must come after the non-complements.
72# BOUND, POSIX and their complements are affected, as well as EXACTF.
73BOUND       BOUND,      no        ; Like BOUNDA for non-utf8, otherwise like BOUNDU
74BOUNDL      BOUND,      no        ; Like BOUND/BOUNDU, but \w and \W are defined by current locale
75BOUNDU      BOUND,      no        ; Match "" at any boundary of a given type using /u rules.
76BOUNDA      BOUND,      no        ; Match "" at any boundary between \w\W or \W\w, where \w is [_a-zA-Z0-9]
77# All NBOUND nodes are required by code in regexec.c to be greater than all BOUND ones
78NBOUND      NBOUND,     no        ; Like NBOUNDA for non-utf8, otherwise like BOUNDU
79NBOUNDL     NBOUND,     no        ; Like NBOUND/NBOUNDU, but \w and \W are defined by current locale
80NBOUNDU     NBOUND,     no        ; Match "" at any non-boundary of a given type using using /u rules.
81NBOUNDA     NBOUND,     no        ; Match "" betweeen any \w\w or \W\W, where \w is [_a-zA-Z0-9]
82
83#* [Special] alternatives:
84REG_ANY     REG_ANY,    no 0 S    ; Match any one character (except newline).
85SANY        REG_ANY,    no 0 S    ; Match any one character.
86ANYOF       ANYOF,      sv charclass S    ; Match character in (or not in) this class, single char match only
87ANYOFD      ANYOF,      sv charclass S    ; Like ANYOF, but /d is in effect
88ANYOFL      ANYOF,      sv charclass S    ; Like ANYOF, but /l is in effect
89ANYOFPOSIXL ANYOF,      sv charclass_posixl S    ; Like ANYOFL, but matches [[:posix:]] classes
90
91# Must be sequential
92ANYOFH      ANYOFH,     sv 1 S    ; Like ANYOF, but only has "High" matches, none in the bitmap; the flags field contains the lowest matchable UTF-8 start byte
93ANYOFHb     ANYOFH,     sv 1 S    ; Like ANYOFH, but all matches share the same UTF-8 start byte, given in the flags field
94ANYOFHr     ANYOFH,     sv 1 S    ; Like ANYOFH, but the flags field contains packed bounds for all matchable UTF-8 start bytes.
95ANYOFHs     ANYOFH,     sv:str 1 S    ; Like ANYOFHb, but has a string field that gives the leading matchable UTF-8 bytes; flags field is len
96ANYOFR      ANYOFR,     packed 1  S  ; Matches any character in the range given by its packed args: upper 12 bits is the max delta from the base lower 20; the flags field contains the lowest matchable UTF-8 start byte
97ANYOFRb     ANYOFR,     packed 1  S ; Like ANYOFR, but all matches share the same UTF-8 start byte, given in the flags field
98# There is no ANYOFRr because khw doesn't think there are likely to be
99# real-world cases where such a large range is used.
100#
101# And khw doesn't believe an ANYOFRs (which would behave like ANYOFHs) is
102# actually worth it.  On two-byte UTF-8, the first byte alone is all we need,
103# and ANYOFR already does that.  And we don't consider non-Unicode code points
104# or EBCDIC for performance decisions.  If we had it, we would be comparing the
105# strings, and if they are equal convert to UV and then test to see if it is in
106# the range.  The fast DFA we now use to do the conversion is slower than
107# comparing the strings, but not by much, and negligible in 2 or 3 byte
108# operations.  (We don't have to compare the final byte as it has to be
109# different or else this wouldn't be a range.)  So we might as well displense
110# with the comparisons that ANYOFRs would do, and go directly to do the
111# conversion .
112
113ANYOFHbbm   ANYOFHbbm   none bbm S ; Like ANYOFHb, but only for 2-byte UTF-8 characters; uses a bitmap to match the continuation byte
114
115ANYOFM      ANYOFM,     byte 1 S  ; Like ANYOF, but matches an invariant byte as determined by the mask and arg
116NANYOFM     ANYOFM,     byte 1 S  ; complement of ANYOFM
117
118#* POSIX Character Classes:
119# Order of the below is important.  See ordering comment above.
120POSIXD      POSIXD,     none 0 S   ; Some [[:class:]] under /d; the FLAGS field gives which one
121POSIXL      POSIXD,     none 0 S   ; Some [[:class:]] under /l; the FLAGS field gives which one
122POSIXU      POSIXD,     none 0 S   ; Some [[:class:]] under /u; the FLAGS field gives which one
123POSIXA      POSIXD,     none 0 S   ; Some [[:class:]] under /a; the FLAGS field gives which one
124NPOSIXD     NPOSIXD,    none 0 S   ; complement of POSIXD, [[:^class:]]
125NPOSIXL     NPOSIXD,    none 0 S   ; complement of POSIXL, [[:^class:]]
126NPOSIXU     NPOSIXD,    none 0 S   ; complement of POSIXU, [[:^class:]]
127NPOSIXA     NPOSIXD,    none 0 S   ; complement of POSIXA, [[:^class:]]
128# End of order is important
129
130CLUMP       CLUMP,      no 0 V    ; Match any extended grapheme cluster sequence
131
132#* Alternation
133
134#* BRANCH        The set of branches constituting a single choice are
135#*               hooked together with their "next" pointers, since
136#*               precedence prevents anything being concatenated to
137#*               any individual branch.  The "next" pointer of the last
138#*               BRANCH in a choice points to the thing following the
139#*               whole choice.  This is also where the final "next"
140#*               pointer of each individual branch points; each branch
141#*               starts with the operand node of a BRANCH node.
142#*
143BRANCH      BRANCH,     node 1 V  ; Match this alternative, or the next...
144
145#*Literals
146# NOTE: the relative ordering of these types is important do not change it
147# By convention, folding nodes begin with EXACTF; A digit 8 is in the name if
148# and only if it it requires a UTF-8 target string in order to successfully
149# match.
150
151EXACT       EXACT,      str       ; Match this string (flags field is the length).
152
153#* In a long string node, the U32 argument is the length, and is
154#* immediately followed by the string.
155LEXACT      EXACT,  len:str 1; Match this long string (preceded by length; flags unused).
156EXACTL      EXACT,      str       ; Like EXACT, but /l is in effect (used so locale-related warnings can be checked for)
157EXACTF      EXACT,      str       ; Like EXACT, but match using /id rules; (string not UTF-8, ASCII folded; non-ASCII not)
158EXACTFL     EXACT,      str       ; Like EXACT, but match using /il rules; (string not likely to be folded)
159EXACTFU     EXACT,      str	  ; Like EXACT, but match using /iu rules; (string folded)
160
161# The reason MICRO and SHARP S aren't folded in non-UTF8 patterns is because
162# they would fold to something that requires UTF-8.  SHARP S would normally
163# fold to 'ss', but because of /aa, it instead folds to a pair of LATIN SMALL
164# LETTER LONG S characters (U+017F)
165EXACTFAA    EXACT,      str	  ; Like EXACT, but match using /iaa rules; (string folded except MICRO in non-UTF8 patterns; doesn't contain SHARP S unless UTF-8; folded length <= unfolded)
166# must immediately follow EXACTFAA
167EXACTFAA_NO_TRIE  EXACT, str	  ; Like EXACTFAA, (string not UTF-8, folded except: MICRO, SHARP S; folded length <= unfolded, not currently trie-able)
168
169# End of important relative ordering.
170
171EXACTFUP    EXACT,      str	  ; Like EXACT, but match using /iu rules; (string not UTF-8, folded except MICRO: hence Problematic)
172# In order for a non-UTF-8 EXACTFAA to think the pattern is pre-folded when
173# matching a UTF-8 target string, there would have to be something like an
174# EXACTFAA_MICRO which would not be considered pre-folded for UTF-8 targets,
175# since the fold of the MICRO SIGN would not be done, and would be
176# representable in the UTF-8 target string.
177
178EXACTFLU8   EXACT,      str	  ; Like EXACTFU, but use /il, UTF-8, (string is folded, and everything in it is above 255
179EXACT_REQ8   EXACT,      str      ; Like EXACT, but only UTF-8 encoded targets can match
180LEXACT_REQ8  EXACT,  len:str 1    ; Like LEXACT, but only UTF-8 encoded targets can match
181EXACTFU_REQ8 EXACT,    str        ; Like EXACTFU, but only UTF-8 encoded targets can match
182# One could add EXACTFAA8 and something that has the same effect for /l,
183# but these would be extremely uncommon
184
185EXACTFU_S_EDGE EXACT,   str       ; /di rules, but nothing in it precludes /ui, except begins and/or ends with [Ss]; (string not UTF-8; compile-time only)
186
187#*New charclass like patterns
188LNBREAK     LNBREAK,    none      ; generic newline pattern
189
190#*Trie Related
191
192#* Behave the same as A|LIST|OF|WORDS would. The '..C' variants
193#* have inline charclass data (ascii only), the 'C' store it in the
194#* structure.
195# NOTE: the relative order of the TRIE-like regops  is significant
196
197TRIE        TRIE,       trie 1    ; Match many EXACT(F[ALU]?)? at once. flags==type
198TRIEC       TRIE,trie charclass   ; Same as TRIE, but with embedded charclass data
199
200# For start classes, contains an added fail table.
201AHOCORASICK     TRIE,   trie 1    ; Aho Corasick stclass. flags==type
202AHOCORASICKC    TRIE,trie charclass   ; Same as AHOCORASICK, but with embedded charclass data
203
204#*Do nothing types
205
206NOTHING     NOTHING,    no        ; Match empty string.
207#*A variant of above which delimits a group, thus stops optimizations
208TAIL        NOTHING,    no        ; Match empty string. Can jump here from outside.
209
210#*Loops
211
212#* STAR,PLUS    '?', and complex '*' and '+', are implemented as
213#*               circular BRANCH structures.  Simple cases
214#*               (one character per match) are implemented with STAR
215#*               and PLUS for speed and to minimize recursive plunges.
216#*
217STAR        STAR,       node 0 V  ; Match this (simple) thing 0 or more times: /A{0,}B/ where A is width 1 char
218PLUS        PLUS,       node 0 V  ; Match this (simple) thing 1 or more times: /A{1,}B/ where A is width 1 char
219
220CURLY       CURLY,      sv 3 V    ; Match this (simple) thing {n,m} times: /A{m,n}B/ where A is width 1 char
221CURLYN      CURLY,      no 3 V    ; Capture next-after-this simple thing: /(A){m,n}B/ where A is width 1 char
222CURLYM      CURLY,      no 3 V    ; Capture this medium-complex thing {n,m} times: /(A){m,n}B/ where A is fixed-length
223CURLYX      CURLY,      sv 3 V    ; Match/Capture this complex thing {n,m} times.
224
225#*This terminator creates a loop structure for CURLYX
226WHILEM      WHILEM,     no 0 V    ; Do curly processing and see if rest matches.
227
228#*Buffer related
229
230#*OPEN,CLOSE,GROUPP     ...are numbered at compile time.
231OPEN        OPEN,       num 1     ; Mark this point in input as start of #n.
232CLOSE       CLOSE,      num 1     ; Close corresponding OPEN of #n.
233SROPEN      SROPEN,     none      ; Same as OPEN, but for script run
234SRCLOSE     SRCLOSE,    none      ; Close preceding SROPEN
235
236REF         REF,        num 2 V   ; Match some already matched string
237REFF        REF,        num 2 V   ; Match already matched string, using /di rules.
238REFFL       REF,        num 2 V   ; Match already matched string, using /li rules.
239# N?REFF[AU] could have been implemented using the FLAGS field of the
240# regnode, but by having a separate node type, we can use the existing switch
241# statement to avoid some tests
242REFFU       REF,        num 2 V   ; Match already matched string, usng /ui.
243REFFA       REF,        num 2 V   ; Match already matched string, using /aai rules.
244
245#*Named references.  Code in regcomp.c assumes that these all are after
246#*the numbered references
247REFN        REF,        no-sv 2 V ; Match some already matched string
248REFFN       REF,        no-sv 2 V ; Match already matched string, using /di rules.
249REFFLN      REF,        no-sv 2 V ; Match already matched string, using /li rules.
250REFFUN      REF,        num   2 V ; Match already matched string, using /ui rules.
251REFFAN      REF,        num   2 V ; Match already matched string, using /aai rules.
252
253#*Support for long RE
254LONGJMP     LONGJMP,    off 1 . 1 ; Jump far away.
255BRANCHJ     BRANCHJ,    off 2 V 1 ; BRANCH with long offset.
256
257#*Special Case Regops
258IFMATCH     BRANCHJ,    off 1 . 1 ; Succeeds if the following matches; non-zero flags "f", next_off "o" means lookbehind assertion starting "f..(f-o)" characters before current
259UNLESSM     BRANCHJ,    off 1 . 1 ; Fails if the following matches; non-zero flags "f", next_off "o" means lookbehind assertion starting "f..(f-o)" characters before current
260SUSPEND     BRANCHJ,    off 1 V 1 ; "Independent" sub-RE.
261IFTHEN      BRANCHJ,    off 1 V 1 ; Switch, should be preceded by switcher.
262GROUPP      GROUPP,     num 1     ; Whether the group matched.
263
264#*The heavy worker
265
266EVAL        EVAL,       evl/flags 2 ; Execute some Perl code.
267
268#*Modifiers
269
270MINMOD      MINMOD,     no        ; Next operator is not greedy.
271LOGICAL     LOGICAL,    no        ; Next opcode should set the flag only.
272
273#*This is not used yet
274RENUM       BRANCHJ,    off 1 . 1 ; Group with independently numbered parens.
275
276#*Regex Subroutines
277GOSUB       GOSUB,      num/ofs 2    ; recurse to paren arg1 at (signed) ofs arg2
278
279#*Special conditionals
280GROUPPN     GROUPPN,    no-sv 1   ; Whether the group matched.
281INSUBP      INSUBP,     num 1     ; Whether we are in a specific recurse.
282DEFINEP     DEFINEP,    none 1    ; Never execute directly.
283
284#*Backtracking Verbs
285ENDLIKE     ENDLIKE,    none      ; Used only for the type field of verbs
286OPFAIL      ENDLIKE,    no-sv 1   ; Same as (?!), but with verb arg
287ACCEPT      ENDLIKE,    no-sv/num 2   ; Accepts the current matched string, with verbar
288
289#*Verbs With Arguments
290VERB        VERB,       no-sv 1   ; Used only for the type field of verbs
291PRUNE       VERB,       no-sv 1   ; Pattern fails at this startpoint if no-backtracking through this
292MARKPOINT   VERB,       no-sv 1   ; Push the current location for rollback by cut.
293SKIP        VERB,       no-sv 1   ; On failure skip forward (to the mark) before retrying
294COMMIT      VERB,       no-sv 1   ; Pattern fails outright if backtracking through this
295CUTGROUP    VERB,       no-sv 1   ; On failure go to the next alternation in the group
296
297#*Control what to keep in $&.
298KEEPS       KEEPS,      no        ; $& begins here.
299
300#*Validate that lookbehind IFMATCH and UNLESSM end at the right place
301LOOKBEHIND_END   END,        no        ; Return from lookbehind (IFMATCH/UNLESSM) and validate position
302
303# NEW STUFF SOMEWHERE ABOVE THIS LINE.  Stuff that regexec.c: find_byclass()
304# and regrepeat() use should go way above, near LNBREAK to allow a more compact
305# jump table to be generated for their switch() statements
306
307################################################################################
308
309#*SPECIAL  REGOPS
310
311#* This is not really a node, but an optimized away piece of a "long"
312#* node.  To simplify debugging output, we mark it as if it were a node
313OPTIMIZED   NOTHING,    off       ; Placeholder for dump.
314
315#* Special opcode with the property that no opcode in a compiled program
316#* will ever be of this type. Thus it can be used as a flag value that
317#* no other opcode has been seen. END is used similarly, in that an END
318#* node cant be optimized. So END implies "unoptimizable" and PSEUDO
319#* mean "not seen anything to optimize yet".
320PSEUDO      PSEUDO,     off       ; Pseudo opcode for internal use.
321
322REGEX_SET   REGEX_SET,  depth p S ; Regex set, temporary node used in pre-optimization compilation
323
324-------------------------------------------------------------------------------
325# Format for second section:
326# REGOP \t typelist [ \t typelist]
327# typelist= namelist
328#         = namelist:FAIL
329#         = name:count
330
331# Anything below is a state
332#
333#
334TRIE            next:FAIL
335EVAL            B,postponed_AB:FAIL
336CURLYX          end:FAIL
337WHILEM          A_pre,A_min,A_max,B_min,B_max:FAIL
338BRANCH          next:FAIL
339CURLYM          A,B:FAIL
340IFMATCH         A:FAIL
341CURLY           B_min,B_max:FAIL
342COMMIT          next:FAIL
343MARKPOINT       next:FAIL
344SKIP            next:FAIL
345CUTGROUP        next:FAIL
346KEEPS           next:FAIL
347REF             next:FAIL
348