This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / regexp.h
CommitLineData
a0d0e21e 1/* regexp.h
d6376244 2 *
e6906430
JH
3 * Copyright (C) 1993, 1994, 1996, 1997, 1999, 2000, 2001, 2003,
4 * by Larry Wall and others
d6376244
JH
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
a0d0e21e
LW
9 */
10
378cc40b
LW
11/*
12 * Definitions etc. for regexp(3) routines.
13 *
14 * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
15 * not the System V one.
16 */
17
378cc40b 18
c277df42
IZ
19struct regnode {
20 U8 flags;
21 U8 type;
22 U16 next_off;
23};
24
25typedef struct regnode regnode;
26
cad2e5aa 27struct reg_substr_data;
2779dcf1 28
0ee3c8d0
JH
29struct reg_data;
30
378cc40b 31typedef struct regexp {
cf93c79d
IZ
32 I32 *startp;
33 I32 *endp;
c277df42 34 regnode *regstclass;
2779dcf1 35 struct reg_substr_data *substrs;
cf93c79d 36 char *precomp; /* pre-compilation regular expression */
c277df42 37 struct reg_data *data; /* Additional data. */
cf93c79d
IZ
38 char *subbeg; /* saved or original string
39 so \digit works forever. */
fac92740 40 U32 *offsets; /* offset annotations 20001228 MJD */
cf93c79d
IZ
41 I32 sublen; /* Length of string pointed by subbeg */
42 I32 refcnt;
43 I32 minlen; /* mininum possible length of $& */
44 I32 prelen; /* length of precomp */
45 U32 nparens; /* number of parentheses */
46 U32 lastparen; /* last paren matched */
a01268b5 47 U32 lastcloseparen; /* last paren matched */
cf93c79d
IZ
48 U32 reganch; /* Internal use only +
49 Tainted information used by regexec? */
c277df42 50 regnode program[1]; /* Unwarranted chumminess with compiler. */
378cc40b
LW
51} regexp;
52
cad2e5aa
JH
53#define ROPT_ANCH (ROPT_ANCH_BOL|ROPT_ANCH_MBOL|ROPT_ANCH_GPOS|ROPT_ANCH_SBOL)
54#define ROPT_ANCH_SINGLE (ROPT_ANCH_SBOL|ROPT_ANCH_GPOS)
a0ed51b3
LW
55#define ROPT_ANCH_BOL 0x00001
56#define ROPT_ANCH_MBOL 0x00002
cad2e5aa
JH
57#define ROPT_ANCH_SBOL 0x00004
58#define ROPT_ANCH_GPOS 0x00008
59#define ROPT_SKIP 0x00010
60#define ROPT_IMPLICIT 0x00020 /* Converted .* to ^.* */
61#define ROPT_NOSCAN 0x00040 /* Check-string always at start. */
62#define ROPT_GPOS_SEEN 0x00080
63#define ROPT_CHECK_ALL 0x00100
64#define ROPT_LOOKBEHIND_SEEN 0x00200
65#define ROPT_EVAL_SEEN 0x00400
cce850e4
JH
66#define ROPT_CANY_SEEN 0x00800
67#define ROPT_SANY_SEEN ROPT_CANY_SEEN /* src bckwrd cmpt */
a0ed51b3 68
8782bef2 69/* 0xf800 of reganch is used by PMf_COMPILETIME */
c277df42 70
a0ed51b3
LW
71#define ROPT_UTF8 0x10000
72#define ROPT_NAUGHTY 0x20000 /* how exponential is this pattern? */
cf93c79d 73#define ROPT_COPY_DONE 0x40000 /* subbeg is a copy of the string */
bc9a0d2c 74#define ROPT_TAINTED_SEEN 0x80000
2ea5368e 75#define ROPT_MATCH_UTF8 0x10000000 /* subbeg is utf-8 */
a0ed51b3 76
cad2e5aa
JH
77#define RE_USE_INTUIT_NOML 0x0100000 /* Best to intuit before matching */
78#define RE_USE_INTUIT_ML 0x0200000
79#define REINT_AUTORITATIVE_NOML 0x0400000 /* Can trust a positive answer */
80#define REINT_AUTORITATIVE_ML 0x0800000
81#define REINT_ONCE_NOML 0x1000000 /* Intuit can succed once only. */
82#define REINT_ONCE_ML 0x2000000
83#define RE_INTUIT_ONECHAR 0x4000000
84#define RE_INTUIT_TAIL 0x8000000
85
86#define RE_USE_INTUIT (RE_USE_INTUIT_NOML|RE_USE_INTUIT_ML)
87#define REINT_AUTORITATIVE (REINT_AUTORITATIVE_NOML|REINT_AUTORITATIVE_ML)
88#define REINT_ONCE (REINT_ONCE_NOML|REINT_ONCE_ML)
89
c277df42 90#define RX_MATCH_TAINTED(prog) ((prog)->reganch & ROPT_TAINTED_SEEN)
72311751
GS
91#define RX_MATCH_TAINTED_on(prog) ((prog)->reganch |= ROPT_TAINTED_SEEN)
92#define RX_MATCH_TAINTED_off(prog) ((prog)->reganch &= ~ROPT_TAINTED_SEEN)
93#define RX_MATCH_TAINTED_set(prog, t) ((t) \
94 ? RX_MATCH_TAINTED_on(prog) \
95 : RX_MATCH_TAINTED_off(prog))
c277df42 96
cf93c79d
IZ
97#define RX_MATCH_COPIED(prog) ((prog)->reganch & ROPT_COPY_DONE)
98#define RX_MATCH_COPIED_on(prog) ((prog)->reganch |= ROPT_COPY_DONE)
99#define RX_MATCH_COPIED_off(prog) ((prog)->reganch &= ~ROPT_COPY_DONE)
100#define RX_MATCH_COPIED_set(prog,t) ((t) \
101 ? RX_MATCH_COPIED_on(prog) \
102 : RX_MATCH_COPIED_off(prog))
103
2ea5368e
JH
104#define RX_MATCH_UTF8(prog) ((prog)->reganch & ROPT_MATCH_UTF8)
105#define RX_MATCH_UTF8_on(prog) ((prog)->reganch |= ROPT_MATCH_UTF8)
106#define RX_MATCH_UTF8_off(prog) ((prog)->reganch &= ~ROPT_MATCH_UTF8)
107#define RX_MATCH_UTF8_set(prog, t) ((t) \
108 ? (RX_MATCH_UTF8_on(prog), (PL_reg_match_utf8 = 1)) \
109 : (RX_MATCH_UTF8_off(prog), (PL_reg_match_utf8 = 0)))
110
cad2e5aa
JH
111#define REXEC_COPY_STR 0x01 /* Need to copy the string. */
112#define REXEC_CHECKED 0x02 /* check_substr already checked. */
113#define REXEC_SCREAM 0x04 /* use scream table. */
114#define REXEC_IGNOREPOS 0x08 /* \G matches at start. */
cf93c79d 115#define REXEC_NOT_FIRST 0x10 /* This is another iteration of //g. */
cad2e5aa 116#define REXEC_ML 0x20 /* $* was set. */
c277df42 117
155aba94 118#define ReREFCNT_inc(re) ((void)(re && re->refcnt++), re)
cad2e5aa 119#define ReREFCNT_dec(re) CALLREGFREE(aTHX_ re)
cf93c79d
IZ
120
121#define FBMcf_TAIL_DOLLAR 1
cad2e5aa
JH
122#define FBMcf_TAIL_DOLLARM 2
123#define FBMcf_TAIL_Z 4
124#define FBMcf_TAIL_z 8
125#define FBMcf_TAIL (FBMcf_TAIL_DOLLAR|FBMcf_TAIL_DOLLARM|FBMcf_TAIL_Z|FBMcf_TAIL_z)
cf93c79d
IZ
126
127#define FBMrf_MULTILINE 1
cad2e5aa
JH
128
129struct re_scream_pos_data_s;
4c49a5e0
NC
130
131struct re_save_state {
132 U32 re_state_reg_flags; /* from regexec.c */
133 char *re_state_bostr;
134 char *re_state_reginput; /* String-input pointer. */
135 char *re_state_regbol; /* Beginning of input, for ^ check. */
136 char *re_state_regeol; /* End of input, for $ check. */
137 I32 *re_state_regstartp; /* Pointer to startp array. */
138 I32 *re_state_regendp; /* Ditto for endp. */
139 U32 *re_state_reglastparen; /* Similarly for lastparen. */
140 U32 *re_state_reglastcloseparen; /* Similarly for lastcloseparen. */
141 char *re_state_regtill; /* How far we are required to go. */
142 char **re_state_reg_start_tmp; /* from regexec.c */
143 U32 re_state_reg_start_tmpl; /* from regexec.c */
144 I32 re_state_reg_eval_set; /* from regexec.c */
145 I32 re_state_regnarrate; /* from regexec.c */
146 int re_state_regindent; /* from regexec.c */
147 struct re_cc_state *re_state_reg_call_cc; /* from regexec.c */
148 regexp *re_state_reg_re; /* from regexec.c */
149 char *re_state_reg_ganch; /* from regexec.c */
150 SV *re_state_reg_sv; /* from regexec.c */
151 bool re_state_reg_match_utf8; /* from regexec.c */
152 MAGIC *re_state_reg_magic; /* from regexec.c */
153 I32 re_state_reg_oldpos; /* from regexec.c */
154 PMOP *re_state_reg_oldcurpm; /* from regexec.c */
155 PMOP *re_state_reg_curpm; /* from regexec.c */
156 char *re_state_reg_oldsaved; /* old saved substr during match */
157 STRLEN re_state_reg_oldsavedlen; /* old length of saved substr during match */
158 I32 re_state_reg_maxiter; /* max wait until caching pos */
159 I32 re_state_reg_leftiter; /* wait until caching pos */
160 char *re_state_reg_poscache; /* cache of pos of WHILEM */
161 STRLEN re_state_reg_poscache_size; /* size of pos cache of WHILEM */
162 I32 re_state_regsize; /* from regexec.c */
163 char *re_state_reg_starttry; /* from regexec.c */
164
165 struct reg_data *re_state_regdata; /* from regexec.c renamed was data */
166 regnode *re_state_regprogram; /* from regexec.c */
167 struct curcur *re_state_regcc; /* from regexec.c */
168 char *re_state_regprecomp; /* uncompiled string. */
169 I32 re_state_regnpar; /* () count. */
170};
171
172#define SAVESTACK_ALLOC_FOR_RE_SAVE_STATE \
173 (1 + ((sizeof(struct re_save_state) - 1) / sizeof(*PL_savestack)))
174/*
175 * Local variables:
176 * c-indentation-style: bsd
177 * c-basic-offset: 4
178 * indent-tabs-mode: t
179 * End:
180 *
181 * ex: set ts=8 sts=4 sw=4 noet:
182 */