This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Handle PERLIO= and document a bit.
[perl5.git] / regexp.h
CommitLineData
a0d0e21e 1/* regexp.h
d6376244 2 *
4c79ee7a 3 * Copyright (c) 1997-2003, Larry Wall
d6376244
JH
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
a0d0e21e
LW
8 */
9
378cc40b
LW
10/*
11 * Definitions etc. for regexp(3) routines.
12 *
13 * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
14 * not the System V one.
15 */
16
378cc40b 17
c277df42
IZ
18struct regnode {
19 U8 flags;
20 U8 type;
21 U16 next_off;
22};
23
24typedef struct regnode regnode;
25
cad2e5aa 26struct reg_substr_data;
2779dcf1 27
0ee3c8d0
JH
28struct reg_data;
29
378cc40b 30typedef struct regexp {
cf93c79d
IZ
31 I32 *startp;
32 I32 *endp;
c277df42 33 regnode *regstclass;
2779dcf1 34 struct reg_substr_data *substrs;
cf93c79d 35 char *precomp; /* pre-compilation regular expression */
c277df42 36 struct reg_data *data; /* Additional data. */
cf93c79d
IZ
37 char *subbeg; /* saved or original string
38 so \digit works forever. */
ed252734
NC
39#ifdef PERL_COPY_ON_WRITE
40 SV *saved_copy; /* If non-NULL, SV which is COW from original */
41#endif
fac92740 42 U32 *offsets; /* offset annotations 20001228 MJD */
cf93c79d
IZ
43 I32 sublen; /* Length of string pointed by subbeg */
44 I32 refcnt;
45 I32 minlen; /* mininum possible length of $& */
46 I32 prelen; /* length of precomp */
47 U32 nparens; /* number of parentheses */
48 U32 lastparen; /* last paren matched */
a01268b5 49 U32 lastcloseparen; /* last paren matched */
cf93c79d
IZ
50 U32 reganch; /* Internal use only +
51 Tainted information used by regexec? */
c277df42 52 regnode program[1]; /* Unwarranted chumminess with compiler. */
378cc40b
LW
53} regexp;
54
cad2e5aa
JH
55#define ROPT_ANCH (ROPT_ANCH_BOL|ROPT_ANCH_MBOL|ROPT_ANCH_GPOS|ROPT_ANCH_SBOL)
56#define ROPT_ANCH_SINGLE (ROPT_ANCH_SBOL|ROPT_ANCH_GPOS)
a0ed51b3
LW
57#define ROPT_ANCH_BOL 0x00001
58#define ROPT_ANCH_MBOL 0x00002
cad2e5aa
JH
59#define ROPT_ANCH_SBOL 0x00004
60#define ROPT_ANCH_GPOS 0x00008
61#define ROPT_SKIP 0x00010
62#define ROPT_IMPLICIT 0x00020 /* Converted .* to ^.* */
63#define ROPT_NOSCAN 0x00040 /* Check-string always at start. */
64#define ROPT_GPOS_SEEN 0x00080
65#define ROPT_CHECK_ALL 0x00100
66#define ROPT_LOOKBEHIND_SEEN 0x00200
67#define ROPT_EVAL_SEEN 0x00400
cce850e4
JH
68#define ROPT_CANY_SEEN 0x00800
69#define ROPT_SANY_SEEN ROPT_CANY_SEEN /* src bckwrd cmpt */
a0ed51b3 70
8782bef2 71/* 0xf800 of reganch is used by PMf_COMPILETIME */
c277df42 72
a0ed51b3
LW
73#define ROPT_UTF8 0x10000
74#define ROPT_NAUGHTY 0x20000 /* how exponential is this pattern? */
cf93c79d 75#define ROPT_COPY_DONE 0x40000 /* subbeg is a copy of the string */
bc9a0d2c 76#define ROPT_TAINTED_SEEN 0x80000
a30b2f1f 77#define ROPT_MATCH_UTF8 0x10000000 /* subbeg is utf-8 */
a0ed51b3 78
cad2e5aa
JH
79#define RE_USE_INTUIT_NOML 0x0100000 /* Best to intuit before matching */
80#define RE_USE_INTUIT_ML 0x0200000
81#define REINT_AUTORITATIVE_NOML 0x0400000 /* Can trust a positive answer */
82#define REINT_AUTORITATIVE_ML 0x0800000
83#define REINT_ONCE_NOML 0x1000000 /* Intuit can succed once only. */
84#define REINT_ONCE_ML 0x2000000
85#define RE_INTUIT_ONECHAR 0x4000000
86#define RE_INTUIT_TAIL 0x8000000
87
88#define RE_USE_INTUIT (RE_USE_INTUIT_NOML|RE_USE_INTUIT_ML)
89#define REINT_AUTORITATIVE (REINT_AUTORITATIVE_NOML|REINT_AUTORITATIVE_ML)
90#define REINT_ONCE (REINT_ONCE_NOML|REINT_ONCE_ML)
91
c277df42 92#define RX_MATCH_TAINTED(prog) ((prog)->reganch & ROPT_TAINTED_SEEN)
72311751
GS
93#define RX_MATCH_TAINTED_on(prog) ((prog)->reganch |= ROPT_TAINTED_SEEN)
94#define RX_MATCH_TAINTED_off(prog) ((prog)->reganch &= ~ROPT_TAINTED_SEEN)
95#define RX_MATCH_TAINTED_set(prog, t) ((t) \
96 ? RX_MATCH_TAINTED_on(prog) \
97 : RX_MATCH_TAINTED_off(prog))
c277df42 98
cf93c79d
IZ
99#define RX_MATCH_COPIED(prog) ((prog)->reganch & ROPT_COPY_DONE)
100#define RX_MATCH_COPIED_on(prog) ((prog)->reganch |= ROPT_COPY_DONE)
101#define RX_MATCH_COPIED_off(prog) ((prog)->reganch &= ~ROPT_COPY_DONE)
102#define RX_MATCH_COPIED_set(prog,t) ((t) \
103 ? RX_MATCH_COPIED_on(prog) \
104 : RX_MATCH_COPIED_off(prog))
105
ed252734
NC
106#ifdef PERL_COPY_ON_WRITE
107#define RX_MATCH_COPY_FREE(rx) \
108 STMT_START {if (rx->saved_copy) { \
109 SV_CHECK_THINKFIRST_COW_DROP(rx->saved_copy); \
110 } \
111 if (RX_MATCH_COPIED(rx)) { \
112 Safefree(rx->subbeg); \
113 RX_MATCH_COPIED_off(rx); \
114 }} STMT_END
115#else
116#define RX_MATCH_COPY_FREE(rx) \
117 STMT_START {if (RX_MATCH_COPIED(rx)) { \
118 Safefree(rx->subbeg); \
119 RX_MATCH_COPIED_off(rx); \
120 }} STMT_END
121#endif
122
a30b2f1f
RGS
123#define RX_MATCH_UTF8(prog) ((prog)->reganch & ROPT_MATCH_UTF8)
124#define RX_MATCH_UTF8_on(prog) ((prog)->reganch |= ROPT_MATCH_UTF8)
125#define RX_MATCH_UTF8_off(prog) ((prog)->reganch &= ~ROPT_MATCH_UTF8)
126#define RX_MATCH_UTF8_set(prog, t) ((t) \
127 ? (RX_MATCH_UTF8_on(prog), (PL_reg_match_utf8 = 1)) \
128 : (RX_MATCH_UTF8_off(prog), (PL_reg_match_utf8 = 0)))
129
cad2e5aa
JH
130#define REXEC_COPY_STR 0x01 /* Need to copy the string. */
131#define REXEC_CHECKED 0x02 /* check_substr already checked. */
132#define REXEC_SCREAM 0x04 /* use scream table. */
133#define REXEC_IGNOREPOS 0x08 /* \G matches at start. */
cf93c79d 134#define REXEC_NOT_FIRST 0x10 /* This is another iteration of //g. */
cad2e5aa 135#define REXEC_ML 0x20 /* $* was set. */
c277df42 136
155aba94 137#define ReREFCNT_inc(re) ((void)(re && re->refcnt++), re)
cad2e5aa 138#define ReREFCNT_dec(re) CALLREGFREE(aTHX_ re)
cf93c79d
IZ
139
140#define FBMcf_TAIL_DOLLAR 1
cad2e5aa
JH
141#define FBMcf_TAIL_DOLLARM 2
142#define FBMcf_TAIL_Z 4
143#define FBMcf_TAIL_z 8
144#define FBMcf_TAIL (FBMcf_TAIL_DOLLAR|FBMcf_TAIL_DOLLARM|FBMcf_TAIL_Z|FBMcf_TAIL_z)
cf93c79d
IZ
145
146#define FBMrf_MULTILINE 1
cad2e5aa
JH
147
148struct re_scream_pos_data_s;