annotate src/regexp.h @ 4696:ed4e689bbea1 v7.3.1095

updated for version 7.3.1095 Problem: Compiler warnings for shadowed variables. (Christian Brabandt) Solution: Rename new_state() to alloc_state(). Remove unnecessary declaration.
author Bram Moolenaar <bram@vim.org>
date Sun, 02 Jun 2013 16:40:55 +0200
parents 9d97a0c045ef
children ec72bb4a0fc2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * This is NOT the original regular expression code as written by Henry
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Spencer. This code has been modified specifically for use with Vim, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * should not be used apart from compiling Vim. If you want a good regular
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 * expression library, get the original code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 * NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE NOTICE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 #ifndef _REGEXP_H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #define _REGEXP_H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 * The number of sub-matches is limited to 10.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * The first one (index 0) is the whole match, referenced with "\0".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 * The second one (index 1) is the first sub-match, referenced with "\1".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 * This goes up to the tenth (index 9), referenced with "\9".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #define NSUBEXP 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
25 * In the NFA engine: how many braces are allowed.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
26 * TODO(RE): Use dynamic memory allocation instead of static, like here
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
27 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
28 #define NFA_MAX_BRACES 20
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
29
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
30 typedef struct regengine regengine_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
31
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
32 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 * Structure returned by vim_regcomp() to pass on to vim_regexec().
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
34 * This is the general structure. For the actual matcher, two specific
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
35 * structures are used. See code below.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
36 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
37 typedef struct regprog
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
38 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
39 regengine_T *engine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
40 unsigned regflags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
41 } regprog_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
42
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
43 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
44 * Structure used by the back track matcher.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 * These fields are only to be used in regexp.c!
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
46 * See regexp.c for an explanation.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 {
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
50 /* These two members implement regprog_T */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
51 regengine_T *engine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
52 unsigned regflags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
53
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 int regstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 char_u reganch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 char_u *regmust;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 int regmlen;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4647
diff changeset
58 #ifdef FEAT_SYN_HL
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
59 char_u reghasz;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4647
diff changeset
60 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
61 char_u program[1]; /* actually longer.. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
62 } bt_regprog_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
63
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
64 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
65 * Structure representing a NFA state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
66 * A NFA state may have no outgoing edge, when it is a NFA_MATCH state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
67 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
68 typedef struct nfa_state nfa_state_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
69 struct nfa_state
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
70 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
71 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
72 nfa_state_T *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
73 nfa_state_T *out1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
74 int id;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
75 int lastlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
76 int negated;
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
77 int val;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
78 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
79
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
80 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
81 * Structure used by the NFA matcher.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
82 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
83 typedef struct
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
84 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
85 /* These two members implement regprog_T */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
86 regengine_T *engine;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 unsigned regflags;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
88
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
89 nfa_state_T *start; /* points into state[] */
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
90 int has_zend; /* pattern contains \ze */
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
91 int has_backref; /* pattern contains \1 .. \9 */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4647
diff changeset
92 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4647
diff changeset
93 int reghasz;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4647
diff changeset
94 #endif
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
95 #ifdef DEBUG
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
96 char_u *pattern;
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
97 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
98 int nsubexp; /* number of () */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
99 int nstate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
100 nfa_state_T state[0]; /* actually longer.. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
101 } nfa_regprog_T;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 * Structure to be used for single-line matching.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 * Sub-match "no" starts at "startp[no]" and ends just before "endp[no]".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 * When there is no match, the pointer is NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 regprog_T *regprog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 char_u *startp[NSUBEXP];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 char_u *endp[NSUBEXP];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 int rm_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 } regmatch_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 * Structure to be used for multi-line matching.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 * Sub-match "no" starts in line "startpos[no].lnum" column "startpos[no].col"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 * and ends in line "endpos[no].lnum" just before column "endpos[no].col".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 * The line numbers are relative to the first line, thus startpos[0].lnum is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 * always 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 * When there is no match, the line number is -1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 regprog_T *regprog;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 lpos_T startpos[NSUBEXP];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 lpos_T endpos[NSUBEXP];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 int rmm_ic;
418
84825cc6f049 updated for version 7.0109
vimboss
parents: 410
diff changeset
130 colnr_T rmm_maxcol; /* when not zero: maximum column */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 } regmmatch_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 * Structure used to store external references: "\z\(\)" to "\z\1".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 * Use a reference count to avoid the need to copy this around. When it goes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 * from 1 to zero the matches need to be freed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 typedef struct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 short refcnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 char_u *matches[NSUBEXP];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 } reg_extmatch_T;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
144 struct regengine
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
145 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
146 regprog_T *(*regcomp)(char_u*, int);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
147 int (*regexec)(regmatch_T*, char_u*, colnr_T);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
148 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
149 || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
150 int (*regexec_nl)(regmatch_T*, char_u*, colnr_T);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
151 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
152 long (*regexec_multi)(regmmatch_T*, win_T*, buf_T*, linenr_T, colnr_T, proftime_T*);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
153 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
154 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
155 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
156 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents: 418
diff changeset
157
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 #endif /* _REGEXP_H */