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