blob: 55b4722b8b274e009591169683551ee3a5ed19e3 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
4 *
5 * This is NOT the original regular expression code as written by Henry
6 * Spencer. This code has been modified specifically for use with Vim, and
7 * should not be used apart from compiling Vim. If you want a good regular
8 * expression library, get the original code.
9 *
10 * NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
11 */
12
13#ifndef _REGEXP_H
14#define _REGEXP_H
15
16/*
17 * The number of sub-matches is limited to 10.
18 * The first one (index 0) is the whole match, referenced with "\0".
19 * The second one (index 1) is the first sub-match, referenced with "\1".
20 * This goes up to the tenth (index 9), referenced with "\9".
21 */
22#define NSUBEXP 10
23
24/*
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020025 * In the NFA engine: how many braces are allowed.
26 * TODO(RE): Use dynamic memory allocation instead of static, like here
27 */
28#define NFA_MAX_BRACES 20
29
30typedef struct regengine regengine_T;
31
32typedef struct thread thread_T;
33
34/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000035 * Structure returned by vim_regcomp() to pass on to vim_regexec().
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020036 * This is the general structure. For the actual matcher, two specific
37 * structures are used. See code below.
38 */
39typedef struct regprog
40{
41 regengine_T *engine;
42 unsigned regflags;
43} regprog_T;
44
45/*
46 * Structure used by the back track matcher.
Bram Moolenaar071d4272004-06-13 20:20:40 +000047 * These fields are only to be used in regexp.c!
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020048 * See regexp.c for an explanation.
Bram Moolenaar071d4272004-06-13 20:20:40 +000049 */
50typedef struct
51{
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020052 /* These two members implement regprog_T */
53 regengine_T *engine;
54 unsigned regflags;
55
Bram Moolenaar071d4272004-06-13 20:20:40 +000056 int regstart;
57 char_u reganch;
58 char_u *regmust;
59 int regmlen;
Bram Moolenaar071d4272004-06-13 20:20:40 +000060 char_u reghasz;
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020061 char_u program[1]; /* actually longer.. */
62} bt_regprog_T;
63
64/*
65 * Structure representing a NFA state.
66 * A NFA state may have no outgoing edge, when it is a NFA_MATCH state.
67 */
68typedef struct nfa_state nfa_state_T;
69struct nfa_state
70{
71 int c;
72 nfa_state_T *out;
73 nfa_state_T *out1;
74 int id;
75 int lastlist;
76 int visits;
77 thread_T *lastthread;
78 int negated;
79};
80
81/*
82 * Structure used by the NFA matcher.
83 */
84typedef struct
85{
86 /* These two members implement regprog_T */
87 regengine_T *engine;
88 unsigned regflags;
89
90 regprog_T regprog;
91 nfa_state_T *start;
92 int nstate;
93 nfa_state_T state[0]; /* actually longer.. */
94} nfa_regprog_T;
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96/*
97 * Structure to be used for single-line matching.
98 * Sub-match "no" starts at "startp[no]" and ends just before "endp[no]".
99 * When there is no match, the pointer is NULL.
100 */
101typedef struct
102{
103 regprog_T *regprog;
104 char_u *startp[NSUBEXP];
105 char_u *endp[NSUBEXP];
106 int rm_ic;
107} regmatch_T;
108
109/*
110 * Structure to be used for multi-line matching.
111 * Sub-match "no" starts in line "startpos[no].lnum" column "startpos[no].col"
112 * and ends in line "endpos[no].lnum" just before column "endpos[no].col".
113 * The line numbers are relative to the first line, thus startpos[0].lnum is
114 * always 0.
115 * When there is no match, the line number is -1.
116 */
117typedef struct
118{
119 regprog_T *regprog;
120 lpos_T startpos[NSUBEXP];
121 lpos_T endpos[NSUBEXP];
122 int rmm_ic;
Bram Moolenaarbbebc852005-07-18 21:47:53 +0000123 colnr_T rmm_maxcol; /* when not zero: maximum column */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124} regmmatch_T;
125
126/*
127 * Structure used to store external references: "\z\(\)" to "\z\1".
128 * Use a reference count to avoid the need to copy this around. When it goes
129 * from 1 to zero the matches need to be freed.
130 */
131typedef struct
132{
133 short refcnt;
134 char_u *matches[NSUBEXP];
135} reg_extmatch_T;
136
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +0200137struct regengine
138{
139 regprog_T *(*regcomp)(char_u*, int);
140 int (*regexec)(regmatch_T*, char_u*, colnr_T);
141#if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
142 || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
143 int (*regexec_nl)(regmatch_T*, char_u*, colnr_T);
144#endif
145 long (*regexec_multi)(regmmatch_T*, win_T*, buf_T*, linenr_T, colnr_T, proftime_T*);
146#ifdef DEBUG
147 char_u *expr;
148#endif
149};
150
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151#endif /* _REGEXP_H */