Mercurial > vim
annotate src/regexp.h @ 5357:8115b4c7a154
Added tag v7-4-030 for changeset 0978e99043d2
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 19 Sep 2013 20:49:04 +0200 |
parents | 05b8436873d4 |
children | 0ea551fa607d |
rev | line source |
---|---|
7 | 1 /* 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 /* | |
4444 | 25 * 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 | |
30 typedef struct regengine regengine_T; | |
31 | |
32 /* | |
7 | 33 * Structure returned by vim_regcomp() to pass on to vim_regexec(). |
4444 | 34 * This is the general structure. For the actual matcher, two specific |
35 * structures are used. See code below. | |
36 */ | |
37 typedef struct regprog | |
38 { | |
39 regengine_T *engine; | |
40 unsigned regflags; | |
41 } regprog_T; | |
42 | |
43 /* | |
44 * Structure used by the back track matcher. | |
7 | 45 * These fields are only to be used in regexp.c! |
4444 | 46 * See regexp.c for an explanation. |
7 | 47 */ |
48 typedef struct | |
49 { | |
4444 | 50 /* These two members implement regprog_T */ |
51 regengine_T *engine; | |
52 unsigned regflags; | |
53 | |
7 | 54 int regstart; |
55 char_u reganch; | |
56 char_u *regmust; | |
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 | 59 char_u reghasz; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4647
diff
changeset
|
60 #endif |
4444 | 61 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 */ | |
68 typedef struct nfa_state nfa_state_T; | |
69 struct nfa_state | |
70 { | |
71 int c; | |
72 nfa_state_T *out; | |
73 nfa_state_T *out1; | |
74 int id; | |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4690
diff
changeset
|
75 int lastlist[2]; /* 0: normal, 1: recursive */ |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
76 int val; |
4444 | 77 }; |
78 | |
79 /* | |
80 * Structure used by the NFA matcher. | |
81 */ | |
82 typedef struct | |
83 { | |
84 /* These two members implement regprog_T */ | |
85 regengine_T *engine; | |
7 | 86 unsigned regflags; |
4444 | 87 |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
88 nfa_state_T *start; /* points into state[] */ |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
89 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
90 int reganch; /* pattern starts with ^ */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
91 int regstart; /* char at start of pattern */ |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
92 char_u *match_text; /* plain text to match with */ |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
93 |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
94 int has_zend; /* pattern contains \ze */ |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
95 int has_backref; /* pattern contains \1 .. \9 */ |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4647
diff
changeset
|
96 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4647
diff
changeset
|
97 int reghasz; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4647
diff
changeset
|
98 #endif |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
99 #ifdef DEBUG |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
100 char_u *pattern; |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
101 #endif |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
102 int nsubexp; /* number of () */ |
4444 | 103 int nstate; |
4837
05b8436873d4
updated for version 7.3.1165
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
104 nfa_state_T state[1]; /* actually longer.. */ |
4444 | 105 } nfa_regprog_T; |
7 | 106 |
107 /* | |
108 * Structure to be used for single-line matching. | |
109 * Sub-match "no" starts at "startp[no]" and ends just before "endp[no]". | |
110 * When there is no match, the pointer is NULL. | |
111 */ | |
112 typedef struct | |
113 { | |
114 regprog_T *regprog; | |
115 char_u *startp[NSUBEXP]; | |
116 char_u *endp[NSUBEXP]; | |
117 int rm_ic; | |
118 } regmatch_T; | |
119 | |
120 /* | |
121 * Structure to be used for multi-line matching. | |
122 * Sub-match "no" starts in line "startpos[no].lnum" column "startpos[no].col" | |
123 * and ends in line "endpos[no].lnum" just before column "endpos[no].col". | |
124 * The line numbers are relative to the first line, thus startpos[0].lnum is | |
125 * always 0. | |
126 * When there is no match, the line number is -1. | |
127 */ | |
128 typedef struct | |
129 { | |
130 regprog_T *regprog; | |
131 lpos_T startpos[NSUBEXP]; | |
132 lpos_T endpos[NSUBEXP]; | |
133 int rmm_ic; | |
418 | 134 colnr_T rmm_maxcol; /* when not zero: maximum column */ |
7 | 135 } regmmatch_T; |
136 | |
137 /* | |
138 * Structure used to store external references: "\z\(\)" to "\z\1". | |
139 * Use a reference count to avoid the need to copy this around. When it goes | |
140 * from 1 to zero the matches need to be freed. | |
141 */ | |
142 typedef struct | |
143 { | |
144 short refcnt; | |
145 char_u *matches[NSUBEXP]; | |
146 } reg_extmatch_T; | |
147 | |
4444 | 148 struct regengine |
149 { | |
150 regprog_T *(*regcomp)(char_u*, int); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
151 void (*regfree)(regprog_T *); |
4444 | 152 int (*regexec)(regmatch_T*, char_u*, colnr_T); |
153 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \ | |
154 || defined(FIND_REPLACE_DIALOG) || defined(PROTO) | |
155 int (*regexec_nl)(regmatch_T*, char_u*, colnr_T); | |
156 #endif | |
157 long (*regexec_multi)(regmmatch_T*, win_T*, buf_T*, linenr_T, colnr_T, proftime_T*); | |
158 #ifdef DEBUG | |
159 char_u *expr; | |
160 #endif | |
161 }; | |
162 | |
7 | 163 #endif /* _REGEXP_H */ |