comparison src/regexp.h @ 4444:ccecb03e5e8b v7.3.970

updated for version 7.3.970 Problem: Syntax highlighting can be slow. Solution: Include the NFA regexp engine. Add the 'regexpengine' option to select which one is used. (various authors, including Ken Takata, Andrei Aiordachioaie, Russ Cox, Xiaozhou Liua, Ian Young)
author Bram Moolenaar <bram@vim.org>
date Sun, 19 May 2013 19:40:29 +0200
parents 84825cc6f049
children 5cc98a5898cf
comparison
equal deleted inserted replaced
4443:34f806b8147f 4444:ccecb03e5e8b
20 * This goes up to the tenth (index 9), referenced with "\9". 20 * This goes up to the tenth (index 9), referenced with "\9".
21 */ 21 */
22 #define NSUBEXP 10 22 #define NSUBEXP 10
23 23
24 /* 24 /*
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 typedef struct thread thread_T;
33
34 /*
25 * Structure returned by vim_regcomp() to pass on to vim_regexec(). 35 * Structure returned by vim_regcomp() to pass on to vim_regexec().
36 * This is the general structure. For the actual matcher, two specific
37 * structures are used. See code below.
38 */
39 typedef struct regprog
40 {
41 regengine_T *engine;
42 unsigned regflags;
43 } regprog_T;
44
45 /*
46 * Structure used by the back track matcher.
26 * These fields are only to be used in regexp.c! 47 * These fields are only to be used in regexp.c!
27 * See regep.c for an explanation. 48 * See regexp.c for an explanation.
28 */ 49 */
29 typedef struct 50 typedef struct
30 { 51 {
52 /* These two members implement regprog_T */
53 regengine_T *engine;
54 unsigned regflags;
55
31 int regstart; 56 int regstart;
32 char_u reganch; 57 char_u reganch;
33 char_u *regmust; 58 char_u *regmust;
34 int regmlen; 59 int regmlen;
60 char_u reghasz;
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;
75 int lastlist;
76 int visits;
77 thread_T *lastthread;
78 int negated;
79 };
80
81 /*
82 * Structure used by the NFA matcher.
83 */
84 typedef struct
85 {
86 /* These two members implement regprog_T */
87 regengine_T *engine;
35 unsigned regflags; 88 unsigned regflags;
36 char_u reghasz; 89
37 char_u program[1]; /* actually longer.. */ 90 regprog_T regprog;
38 } regprog_T; 91 nfa_state_T *start;
92 int nstate;
93 nfa_state_T state[0]; /* actually longer.. */
94 } nfa_regprog_T;
39 95
40 /* 96 /*
41 * Structure to be used for single-line matching. 97 * Structure to be used for single-line matching.
42 * Sub-match "no" starts at "startp[no]" and ends just before "endp[no]". 98 * Sub-match "no" starts at "startp[no]" and ends just before "endp[no]".
43 * When there is no match, the pointer is NULL. 99 * When there is no match, the pointer is NULL.
76 { 132 {
77 short refcnt; 133 short refcnt;
78 char_u *matches[NSUBEXP]; 134 char_u *matches[NSUBEXP];
79 } reg_extmatch_T; 135 } reg_extmatch_T;
80 136
137 struct 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
81 #endif /* _REGEXP_H */ 151 #endif /* _REGEXP_H */