Mercurial > vim
annotate src/regexp_nfa.c @ 6274:3005da486a71 v7.4.471
updated for version 7.4.471
Problem: MS-Windows: When printer name contains multi-byte, the name is
displayed as ???.
Solution: Convert the printer name from the active codepage to 'encoding'.
(Yasuhiro Matsumoto)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 09 Oct 2014 17:05:56 +0200 |
parents | 8515b42f939c |
children | 7f2472960aa1 |
rev | line source |
---|---|
4444 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * NFA regular expression implementation. | |
4 * | |
5 * This file is included in "regexp.c". | |
6 */ | |
7 | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
8 /* |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
9 * Logging of NFA engine. |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
10 * |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
11 * The NFA engine can write four log files: |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
12 * - Error log: Contains NFA engine's fatal errors. |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
13 * - Dump log: Contains compiled NFA state machine's information. |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
14 * - Run log: Contains information of matching procedure. |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
15 * - Debug log: Contains detailed information of matching procedure. Can be |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
16 * disabled by undefining NFA_REGEXP_DEBUG_LOG. |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
17 * The first one can also be used without debug mode. |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
18 * The last three are enabled when compiled as debug mode and individually |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
19 * disabled by commenting them out. |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
20 * The log files can get quite big! |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
21 * Do disable all of this when compiling Vim for debugging, undefine DEBUG in |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
22 * regexp.c |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
23 */ |
4444 | 24 #ifdef DEBUG |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
25 # define NFA_REGEXP_ERROR_LOG "nfa_regexp_error.log" |
4444 | 26 # define ENABLE_LOG |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
27 # define NFA_REGEXP_DUMP_LOG "nfa_regexp_dump.log" |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
28 # define NFA_REGEXP_RUN_LOG "nfa_regexp_run.log" |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
29 # define NFA_REGEXP_DEBUG_LOG "nfa_regexp_debug.log" |
4444 | 30 #endif |
31 | |
5296 | 32 /* Added to NFA_ANY - NFA_NUPPER_IC to include a NL. */ |
33 #define NFA_ADD_NL 31 | |
34 | |
4444 | 35 enum |
36 { | |
37 NFA_SPLIT = -1024, | |
38 NFA_MATCH, | |
5370 | 39 NFA_EMPTY, /* matches 0-length */ |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
40 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
41 NFA_START_COLL, /* [abc] start */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
42 NFA_END_COLL, /* [abc] end */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
43 NFA_START_NEG_COLL, /* [^abc] start */ |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
44 NFA_END_NEG_COLL, /* [^abc] end (postfix only) */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
45 NFA_RANGE, /* range of the two previous items |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
46 * (postfix only) */ |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
47 NFA_RANGE_MIN, /* low end of a range */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
48 NFA_RANGE_MAX, /* high end of a range */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
49 |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
50 NFA_CONCAT, /* concatenate two previous items (postfix |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
51 * only) */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
52 NFA_OR, /* \| (postfix only) */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
53 NFA_STAR, /* greedy * (posfix only) */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
54 NFA_STAR_NONGREEDY, /* non-greedy * (postfix only) */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
55 NFA_QUEST, /* greedy \? (postfix only) */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
56 NFA_QUEST_NONGREEDY, /* non-greedy \? (postfix only) */ |
4444 | 57 |
58 NFA_BOL, /* ^ Begin line */ | |
59 NFA_EOL, /* $ End line */ | |
60 NFA_BOW, /* \< Begin word */ | |
61 NFA_EOW, /* \> End word */ | |
62 NFA_BOF, /* \%^ Begin file */ | |
63 NFA_EOF, /* \%$ End file */ | |
64 NFA_NEWL, | |
65 NFA_ZSTART, /* Used for \zs */ | |
66 NFA_ZEND, /* Used for \ze */ | |
67 NFA_NOPEN, /* Start of subexpression marked with \%( */ | |
68 NFA_NCLOSE, /* End of subexpr. marked with \%( ... \) */ | |
69 NFA_START_INVISIBLE, | |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
70 NFA_START_INVISIBLE_FIRST, |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
71 NFA_START_INVISIBLE_NEG, |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
72 NFA_START_INVISIBLE_NEG_FIRST, |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
73 NFA_START_INVISIBLE_BEFORE, |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
74 NFA_START_INVISIBLE_BEFORE_FIRST, |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
75 NFA_START_INVISIBLE_BEFORE_NEG, |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
76 NFA_START_INVISIBLE_BEFORE_NEG_FIRST, |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
77 NFA_START_PATTERN, |
4444 | 78 NFA_END_INVISIBLE, |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
79 NFA_END_INVISIBLE_NEG, |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
80 NFA_END_PATTERN, |
4444 | 81 NFA_COMPOSING, /* Next nodes in NFA are part of the |
82 composing multibyte char */ | |
83 NFA_END_COMPOSING, /* End of a composing char in the NFA */ | |
5901 | 84 NFA_ANY_COMPOSING, /* \%C: Any composing characters. */ |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
85 NFA_OPT_CHARS, /* \%[abc] */ |
4444 | 86 |
87 /* The following are used only in the postfix form, not in the NFA */ | |
88 NFA_PREV_ATOM_NO_WIDTH, /* Used for \@= */ | |
89 NFA_PREV_ATOM_NO_WIDTH_NEG, /* Used for \@! */ | |
90 NFA_PREV_ATOM_JUST_BEFORE, /* Used for \@<= */ | |
91 NFA_PREV_ATOM_JUST_BEFORE_NEG, /* Used for \@<! */ | |
92 NFA_PREV_ATOM_LIKE_PATTERN, /* Used for \@> */ | |
93 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
94 NFA_BACKREF1, /* \1 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
95 NFA_BACKREF2, /* \2 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
96 NFA_BACKREF3, /* \3 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
97 NFA_BACKREF4, /* \4 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
98 NFA_BACKREF5, /* \5 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
99 NFA_BACKREF6, /* \6 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
100 NFA_BACKREF7, /* \7 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
101 NFA_BACKREF8, /* \8 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
102 NFA_BACKREF9, /* \9 */ |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
103 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
104 NFA_ZREF1, /* \z1 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
105 NFA_ZREF2, /* \z2 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
106 NFA_ZREF3, /* \z3 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
107 NFA_ZREF4, /* \z4 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
108 NFA_ZREF5, /* \z5 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
109 NFA_ZREF6, /* \z6 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
110 NFA_ZREF7, /* \z7 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
111 NFA_ZREF8, /* \z8 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
112 NFA_ZREF9, /* \z9 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
113 #endif |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
114 NFA_SKIP, /* Skip characters */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
115 |
4444 | 116 NFA_MOPEN, |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
117 NFA_MOPEN1, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
118 NFA_MOPEN2, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
119 NFA_MOPEN3, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
120 NFA_MOPEN4, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
121 NFA_MOPEN5, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
122 NFA_MOPEN6, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
123 NFA_MOPEN7, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
124 NFA_MOPEN8, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
125 NFA_MOPEN9, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
126 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
127 NFA_MCLOSE, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
128 NFA_MCLOSE1, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
129 NFA_MCLOSE2, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
130 NFA_MCLOSE3, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
131 NFA_MCLOSE4, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
132 NFA_MCLOSE5, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
133 NFA_MCLOSE6, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
134 NFA_MCLOSE7, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
135 NFA_MCLOSE8, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
136 NFA_MCLOSE9, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
137 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
138 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
139 NFA_ZOPEN, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
140 NFA_ZOPEN1, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
141 NFA_ZOPEN2, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
142 NFA_ZOPEN3, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
143 NFA_ZOPEN4, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
144 NFA_ZOPEN5, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
145 NFA_ZOPEN6, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
146 NFA_ZOPEN7, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
147 NFA_ZOPEN8, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
148 NFA_ZOPEN9, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
149 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
150 NFA_ZCLOSE, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
151 NFA_ZCLOSE1, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
152 NFA_ZCLOSE2, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
153 NFA_ZCLOSE3, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
154 NFA_ZCLOSE4, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
155 NFA_ZCLOSE5, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
156 NFA_ZCLOSE6, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
157 NFA_ZCLOSE7, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
158 NFA_ZCLOSE8, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
159 NFA_ZCLOSE9, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
160 #endif |
4444 | 161 |
162 /* NFA_FIRST_NL */ | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
163 NFA_ANY, /* Match any one character. */ |
4444 | 164 NFA_IDENT, /* Match identifier char */ |
165 NFA_SIDENT, /* Match identifier char but no digit */ | |
166 NFA_KWORD, /* Match keyword char */ | |
167 NFA_SKWORD, /* Match word char but no digit */ | |
168 NFA_FNAME, /* Match file name char */ | |
169 NFA_SFNAME, /* Match file name char but no digit */ | |
170 NFA_PRINT, /* Match printable char */ | |
171 NFA_SPRINT, /* Match printable char but no digit */ | |
172 NFA_WHITE, /* Match whitespace char */ | |
173 NFA_NWHITE, /* Match non-whitespace char */ | |
174 NFA_DIGIT, /* Match digit char */ | |
175 NFA_NDIGIT, /* Match non-digit char */ | |
176 NFA_HEX, /* Match hex char */ | |
177 NFA_NHEX, /* Match non-hex char */ | |
178 NFA_OCTAL, /* Match octal char */ | |
179 NFA_NOCTAL, /* Match non-octal char */ | |
180 NFA_WORD, /* Match word char */ | |
181 NFA_NWORD, /* Match non-word char */ | |
182 NFA_HEAD, /* Match head char */ | |
183 NFA_NHEAD, /* Match non-head char */ | |
184 NFA_ALPHA, /* Match alpha char */ | |
185 NFA_NALPHA, /* Match non-alpha char */ | |
186 NFA_LOWER, /* Match lowercase char */ | |
187 NFA_NLOWER, /* Match non-lowercase char */ | |
188 NFA_UPPER, /* Match uppercase char */ | |
189 NFA_NUPPER, /* Match non-uppercase char */ | |
5296 | 190 NFA_LOWER_IC, /* Match [a-z] */ |
191 NFA_NLOWER_IC, /* Match [^a-z] */ | |
192 NFA_UPPER_IC, /* Match [A-Z] */ | |
193 NFA_NUPPER_IC, /* Match [^A-Z] */ | |
194 | |
195 NFA_FIRST_NL = NFA_ANY + NFA_ADD_NL, | |
196 NFA_LAST_NL = NFA_NUPPER_IC + NFA_ADD_NL, | |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
197 |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
198 NFA_CURSOR, /* Match cursor pos */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
199 NFA_LNUM, /* Match line number */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
200 NFA_LNUM_GT, /* Match > line number */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
201 NFA_LNUM_LT, /* Match < line number */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
202 NFA_COL, /* Match cursor column */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
203 NFA_COL_GT, /* Match > cursor column */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
204 NFA_COL_LT, /* Match < cursor column */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
205 NFA_VCOL, /* Match cursor virtual column */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
206 NFA_VCOL_GT, /* Match > cursor virtual column */ |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
207 NFA_VCOL_LT, /* Match < cursor virtual column */ |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
208 NFA_MARK, /* Match mark */ |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
209 NFA_MARK_GT, /* Match > mark */ |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
210 NFA_MARK_LT, /* Match < mark */ |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
211 NFA_VISUAL, /* Match Visual area */ |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
212 |
4444 | 213 /* Character classes [:alnum:] etc */ |
214 NFA_CLASS_ALNUM, | |
215 NFA_CLASS_ALPHA, | |
216 NFA_CLASS_BLANK, | |
217 NFA_CLASS_CNTRL, | |
218 NFA_CLASS_DIGIT, | |
219 NFA_CLASS_GRAPH, | |
220 NFA_CLASS_LOWER, | |
221 NFA_CLASS_PRINT, | |
222 NFA_CLASS_PUNCT, | |
223 NFA_CLASS_SPACE, | |
224 NFA_CLASS_UPPER, | |
225 NFA_CLASS_XDIGIT, | |
226 NFA_CLASS_TAB, | |
227 NFA_CLASS_RETURN, | |
228 NFA_CLASS_BACKSPACE, | |
229 NFA_CLASS_ESCAPE | |
230 }; | |
231 | |
232 /* Keep in sync with classchars. */ | |
233 static int nfa_classcodes[] = { | |
234 NFA_ANY, NFA_IDENT, NFA_SIDENT, NFA_KWORD,NFA_SKWORD, | |
235 NFA_FNAME, NFA_SFNAME, NFA_PRINT, NFA_SPRINT, | |
236 NFA_WHITE, NFA_NWHITE, NFA_DIGIT, NFA_NDIGIT, | |
237 NFA_HEX, NFA_NHEX, NFA_OCTAL, NFA_NOCTAL, | |
238 NFA_WORD, NFA_NWORD, NFA_HEAD, NFA_NHEAD, | |
239 NFA_ALPHA, NFA_NALPHA, NFA_LOWER, NFA_NLOWER, | |
240 NFA_UPPER, NFA_NUPPER | |
241 }; | |
242 | |
5511 | 243 static char_u e_nul_found[] = N_("E865: (NFA) Regexp end encountered prematurely"); |
4444 | 244 static char_u e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c"); |
5511 | 245 static char_u e_ill_char_class[] = N_("E877: (NFA regexp) Invalid character class: %ld"); |
4444 | 246 |
247 /* NFA regexp \ze operator encountered. */ | |
4569
f262fb02889d
updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents:
4567
diff
changeset
|
248 static int nfa_has_zend; |
4444 | 249 |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
250 /* NFA regexp \1 .. \9 encountered. */ |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
251 static int nfa_has_backref; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
252 |
4720
bd6bef0bd0fb
updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
253 #ifdef FEAT_SYN_HL |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
254 /* NFA regexp has \z( ), set zsubexpr. */ |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
255 static int nfa_has_zsubexpr; |
4720
bd6bef0bd0fb
updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
256 #endif |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
257 |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
258 /* Number of sub expressions actually being used during execution. 1 if only |
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
259 * the whole match (subexpr 0) is used. */ |
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
260 static int nfa_nsubexpr; |
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
261 |
4444 | 262 static int *post_start; /* holds the postfix form of r.e. */ |
263 static int *post_end; | |
264 static int *post_ptr; | |
265 | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
266 static int nstate; /* Number of states in the NFA. Also used when |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
267 * executing. */ |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
268 static int istate; /* Index in the state vector, used in alloc_state() */ |
4444 | 269 |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
270 /* If not NULL match must end at this position */ |
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
271 static save_se_T *nfa_endp = NULL; |
4444 | 272 |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
273 /* listid is global, so that it increases on recursive calls to |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
274 * nfa_regmatch(), which means we don't have to clear the lastlist field of |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
275 * all the states. */ |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
276 static int nfa_listid; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
277 static int nfa_alt_listid; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
278 |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
279 /* 0 for first call to nfa_regmatch(), 1 for recursive call. */ |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
280 static int nfa_ll_index = 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
281 |
4770
b20dbf3a5370
updated for version 7.3.1132
Bram Moolenaar <bram@vim.org>
parents:
4768
diff
changeset
|
282 static int nfa_regcomp_start __ARGS((char_u *expr, int re_flags)); |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
283 static int nfa_get_reganch __ARGS((nfa_state_T *start, int depth)); |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
284 static int nfa_get_regstart __ARGS((nfa_state_T *start, int depth)); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
285 static char_u *nfa_get_match_text __ARGS((nfa_state_T *start)); |
4938
bcb84438bb5b
updated for version 7.3.1214
Bram Moolenaar <bram@vim.org>
parents:
4924
diff
changeset
|
286 static int realloc_post_list __ARGS((void)); |
4444 | 287 static int nfa_recognize_char_class __ARGS((char_u *start, char_u *end, int extra_newl)); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
288 static int nfa_emit_equi_class __ARGS((int c)); |
4444 | 289 static int nfa_regatom __ARGS((void)); |
290 static int nfa_regpiece __ARGS((void)); | |
291 static int nfa_regconcat __ARGS((void)); | |
292 static int nfa_regbranch __ARGS((void)); | |
293 static int nfa_reg __ARGS((int paren)); | |
294 #ifdef DEBUG | |
295 static void nfa_set_code __ARGS((int c)); | |
296 static void nfa_postfix_dump __ARGS((char_u *expr, int retval)); | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
297 static void nfa_print_state __ARGS((FILE *debugf, nfa_state_T *state)); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
298 static void nfa_print_state2 __ARGS((FILE *debugf, nfa_state_T *state, garray_T *indent)); |
4444 | 299 static void nfa_dump __ARGS((nfa_regprog_T *prog)); |
300 #endif | |
301 static int *re2post __ARGS((void)); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
302 static nfa_state_T *alloc_state __ARGS((int c, nfa_state_T *out, nfa_state_T *out1)); |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
303 static void st_error __ARGS((int *postfix, int *end, int *p)); |
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
304 static int nfa_max_width __ARGS((nfa_state_T *startstate, int depth)); |
4444 | 305 static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size)); |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
306 static void nfa_postprocess __ARGS((nfa_regprog_T *prog)); |
4444 | 307 static int check_char_class __ARGS((int class, int c)); |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
308 static void nfa_save_listids __ARGS((nfa_regprog_T *prog, int *list)); |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
309 static void nfa_restore_listids __ARGS((nfa_regprog_T *prog, int *list)); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
310 static int nfa_re_num_cmp __ARGS((long_u val, int op, long_u pos)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
311 static long nfa_regtry __ARGS((nfa_regprog_T *prog, colnr_T col)); |
4444 | 312 static long nfa_regexec_both __ARGS((char_u *line, colnr_T col)); |
313 static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags)); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
314 static void nfa_regfree __ARGS((regprog_T *prog)); |
5838 | 315 static int nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr)); |
4444 | 316 static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm)); |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
317 static int match_follows __ARGS((nfa_state_T *startstate, int depth)); |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
318 static int failure_chance __ARGS((nfa_state_T *state, int depth)); |
4444 | 319 |
320 /* helper functions used when doing re2post() ... regatom() parsing */ | |
321 #define EMIT(c) do { \ | |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
322 if (post_ptr >= post_end && realloc_post_list() == FAIL) \ |
4444 | 323 return FAIL; \ |
324 *post_ptr++ = c; \ | |
325 } while (0) | |
326 | |
327 /* | |
328 * Initialize internal variables before NFA compilation. | |
329 * Return OK on success, FAIL otherwise. | |
330 */ | |
331 static int | |
332 nfa_regcomp_start(expr, re_flags) | |
333 char_u *expr; | |
334 int re_flags; /* see vim_regcomp() */ | |
335 { | |
4458 | 336 size_t postfix_size; |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
337 int nstate_max; |
4444 | 338 |
339 nstate = 0; | |
340 istate = 0; | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
341 /* A reasonable estimation for maximum size */ |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
342 nstate_max = (int)(STRLEN(expr) + 1) * 25; |
4444 | 343 |
4454 | 344 /* Some items blow up in size, such as [A-z]. Add more space for that. |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
345 * When it is still not enough realloc_post_list() will be used. */ |
4458 | 346 nstate_max += 1000; |
4454 | 347 |
348 /* Size for postfix representation of expr. */ | |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
349 postfix_size = sizeof(int) * nstate_max; |
4454 | 350 |
4444 | 351 post_start = (int *)lalloc(postfix_size, TRUE); |
352 if (post_start == NULL) | |
353 return FAIL; | |
354 post_ptr = post_start; | |
4454 | 355 post_end = post_start + nstate_max; |
4444 | 356 nfa_has_zend = FALSE; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
357 nfa_has_backref = FALSE; |
4444 | 358 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
359 /* shared with BT engine */ |
4444 | 360 regcomp_start(expr, re_flags); |
361 | |
362 return OK; | |
363 } | |
364 | |
365 /* | |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
366 * Figure out if the NFA state list starts with an anchor, must match at start |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
367 * of the line. |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
368 */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
369 static int |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
370 nfa_get_reganch(start, depth) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
371 nfa_state_T *start; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
372 int depth; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
373 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
374 nfa_state_T *p = start; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
375 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
376 if (depth > 4) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
377 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
378 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
379 while (p != NULL) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
380 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
381 switch (p->c) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
382 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
383 case NFA_BOL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
384 case NFA_BOF: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
385 return 1; /* yes! */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
386 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
387 case NFA_ZSTART: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
388 case NFA_ZEND: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
389 case NFA_CURSOR: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
390 case NFA_VISUAL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
391 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
392 case NFA_MOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
393 case NFA_MOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
394 case NFA_MOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
395 case NFA_MOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
396 case NFA_MOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
397 case NFA_MOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
398 case NFA_MOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
399 case NFA_MOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
400 case NFA_MOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
401 case NFA_MOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
402 case NFA_NOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
403 #ifdef FEAT_SYN_HL |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
404 case NFA_ZOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
405 case NFA_ZOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
406 case NFA_ZOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
407 case NFA_ZOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
408 case NFA_ZOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
409 case NFA_ZOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
410 case NFA_ZOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
411 case NFA_ZOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
412 case NFA_ZOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
413 case NFA_ZOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
414 #endif |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
415 p = p->out; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
416 break; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
417 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
418 case NFA_SPLIT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
419 return nfa_get_reganch(p->out, depth + 1) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
420 && nfa_get_reganch(p->out1, depth + 1); |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
421 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
422 default: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
423 return 0; /* noooo */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
424 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
425 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
426 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
427 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
428 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
429 /* |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
430 * Figure out if the NFA state list starts with a character which must match |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
431 * at start of the match. |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
432 */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
433 static int |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
434 nfa_get_regstart(start, depth) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
435 nfa_state_T *start; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
436 int depth; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
437 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
438 nfa_state_T *p = start; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
439 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
440 if (depth > 4) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
441 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
442 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
443 while (p != NULL) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
444 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
445 switch (p->c) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
446 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
447 /* all kinds of zero-width matches */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
448 case NFA_BOL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
449 case NFA_BOF: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
450 case NFA_BOW: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
451 case NFA_EOW: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
452 case NFA_ZSTART: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
453 case NFA_ZEND: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
454 case NFA_CURSOR: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
455 case NFA_VISUAL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
456 case NFA_LNUM: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
457 case NFA_LNUM_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
458 case NFA_LNUM_LT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
459 case NFA_COL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
460 case NFA_COL_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
461 case NFA_COL_LT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
462 case NFA_VCOL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
463 case NFA_VCOL_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
464 case NFA_VCOL_LT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
465 case NFA_MARK: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
466 case NFA_MARK_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
467 case NFA_MARK_LT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
468 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
469 case NFA_MOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
470 case NFA_MOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
471 case NFA_MOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
472 case NFA_MOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
473 case NFA_MOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
474 case NFA_MOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
475 case NFA_MOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
476 case NFA_MOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
477 case NFA_MOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
478 case NFA_MOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
479 case NFA_NOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
480 #ifdef FEAT_SYN_HL |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
481 case NFA_ZOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
482 case NFA_ZOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
483 case NFA_ZOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
484 case NFA_ZOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
485 case NFA_ZOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
486 case NFA_ZOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
487 case NFA_ZOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
488 case NFA_ZOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
489 case NFA_ZOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
490 case NFA_ZOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
491 #endif |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
492 p = p->out; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
493 break; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
494 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
495 case NFA_SPLIT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
496 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
497 int c1 = nfa_get_regstart(p->out, depth + 1); |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
498 int c2 = nfa_get_regstart(p->out1, depth + 1); |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
499 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
500 if (c1 == c2) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
501 return c1; /* yes! */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
502 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
503 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
504 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
505 default: |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
506 if (p->c > 0) |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
507 return p->c; /* yes! */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
508 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
509 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
510 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
511 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
512 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
513 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
514 /* |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
515 * Figure out if the NFA state list contains just literal text and nothing |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
516 * else. If so return a string in allocated memory with what must match after |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
517 * regstart. Otherwise return NULL. |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
518 */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
519 static char_u * |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
520 nfa_get_match_text(start) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
521 nfa_state_T *start; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
522 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
523 nfa_state_T *p = start; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
524 int len = 0; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
525 char_u *ret; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
526 char_u *s; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
527 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
528 if (p->c != NFA_MOPEN) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
529 return NULL; /* just in case */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
530 p = p->out; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
531 while (p->c > 0) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
532 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
533 len += MB_CHAR2LEN(p->c); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
534 p = p->out; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
535 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
536 if (p->c != NFA_MCLOSE || p->out->c != NFA_MATCH) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
537 return NULL; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
538 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
539 ret = alloc(len); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
540 if (ret != NULL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
541 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
542 len = 0; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
543 p = start->out->out; /* skip first char, it goes into regstart */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
544 s = ret; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
545 while (p->c > 0) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
546 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
547 #ifdef FEAT_MBYTE |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
548 if (has_mbyte) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
549 s += (*mb_char2bytes)(p->c, s); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
550 else |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
551 #endif |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
552 *s++ = p->c; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
553 p = p->out; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
554 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
555 *s = NUL; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
556 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
557 return ret; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
558 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
559 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
560 /* |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
561 * Allocate more space for post_start. Called when |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
562 * running above the estimated number of states. |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
563 */ |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
564 static int |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
565 realloc_post_list() |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
566 { |
4667
9e7ef781d494
updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents:
4661
diff
changeset
|
567 int nstate_max = (int)(post_end - post_start); |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
568 int new_max = nstate_max + 1000; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
569 int *new_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
570 int *old_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
571 |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
572 new_start = (int *)lalloc(new_max * sizeof(int), TRUE); |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
573 if (new_start == NULL) |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
574 return FAIL; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
575 mch_memmove(new_start, post_start, nstate_max * sizeof(int)); |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
576 old_start = post_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
577 post_start = new_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
578 post_ptr = new_start + (post_ptr - old_start); |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
579 post_end = post_start + new_max; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
580 vim_free(old_start); |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
581 return OK; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
582 } |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
583 |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
584 /* |
4444 | 585 * Search between "start" and "end" and try to recognize a |
586 * character class in expanded form. For example [0-9]. | |
587 * On success, return the id the character class to be emitted. | |
588 * On failure, return 0 (=FAIL) | |
589 * Start points to the first char of the range, while end should point | |
590 * to the closing brace. | |
5296 | 591 * Keep in mind that 'ignorecase' applies at execution time, thus [a-z] may |
592 * need to be interpreted as [a-zA-Z]. | |
4444 | 593 */ |
594 static int | |
595 nfa_recognize_char_class(start, end, extra_newl) | |
596 char_u *start; | |
597 char_u *end; | |
598 int extra_newl; | |
599 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
600 # define CLASS_not 0x80 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
601 # define CLASS_af 0x40 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
602 # define CLASS_AF 0x20 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
603 # define CLASS_az 0x10 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
604 # define CLASS_AZ 0x08 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
605 # define CLASS_o7 0x04 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
606 # define CLASS_o9 0x02 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
607 # define CLASS_underscore 0x01 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
608 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
609 int newl = FALSE; |
4444 | 610 char_u *p; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
611 int config = 0; |
4444 | 612 |
613 if (extra_newl == TRUE) | |
614 newl = TRUE; | |
615 | |
616 if (*end != ']') | |
617 return FAIL; | |
618 p = start; | |
619 if (*p == '^') | |
620 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
621 config |= CLASS_not; |
4720
bd6bef0bd0fb
updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
622 p++; |
4444 | 623 } |
624 | |
625 while (p < end) | |
626 { | |
627 if (p + 2 < end && *(p + 1) == '-') | |
628 { | |
629 switch (*p) | |
630 { | |
631 case '0': | |
632 if (*(p + 2) == '9') | |
633 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
634 config |= CLASS_o9; |
4444 | 635 break; |
636 } | |
637 else | |
638 if (*(p + 2) == '7') | |
639 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
640 config |= CLASS_o7; |
4444 | 641 break; |
642 } | |
643 case 'a': | |
644 if (*(p + 2) == 'z') | |
645 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
646 config |= CLASS_az; |
4444 | 647 break; |
648 } | |
649 else | |
650 if (*(p + 2) == 'f') | |
651 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
652 config |= CLASS_af; |
4444 | 653 break; |
654 } | |
655 case 'A': | |
656 if (*(p + 2) == 'Z') | |
657 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
658 config |= CLASS_AZ; |
4444 | 659 break; |
660 } | |
661 else | |
662 if (*(p + 2) == 'F') | |
663 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
664 config |= CLASS_AF; |
4444 | 665 break; |
666 } | |
667 /* FALLTHROUGH */ | |
668 default: | |
669 return FAIL; | |
670 } | |
671 p += 3; | |
672 } | |
673 else if (p + 1 < end && *p == '\\' && *(p + 1) == 'n') | |
674 { | |
675 newl = TRUE; | |
676 p += 2; | |
677 } | |
678 else if (*p == '_') | |
679 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
680 config |= CLASS_underscore; |
4444 | 681 p ++; |
682 } | |
683 else if (*p == '\n') | |
684 { | |
685 newl = TRUE; | |
686 p ++; | |
687 } | |
688 else | |
689 return FAIL; | |
690 } /* while (p < end) */ | |
691 | |
692 if (p != end) | |
693 return FAIL; | |
694 | |
695 if (newl == TRUE) | |
5296 | 696 extra_newl = NFA_ADD_NL; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
697 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
698 switch (config) |
4444 | 699 { |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
700 case CLASS_o9: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
701 return extra_newl + NFA_DIGIT; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
702 case CLASS_not | CLASS_o9: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
703 return extra_newl + NFA_NDIGIT; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
704 case CLASS_af | CLASS_AF | CLASS_o9: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
705 return extra_newl + NFA_HEX; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
706 case CLASS_not | CLASS_af | CLASS_AF | CLASS_o9: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
707 return extra_newl + NFA_NHEX; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
708 case CLASS_o7: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
709 return extra_newl + NFA_OCTAL; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
710 case CLASS_not | CLASS_o7: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
711 return extra_newl + NFA_NOCTAL; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
712 case CLASS_az | CLASS_AZ | CLASS_o9 | CLASS_underscore: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
713 return extra_newl + NFA_WORD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
714 case CLASS_not | CLASS_az | CLASS_AZ | CLASS_o9 | CLASS_underscore: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
715 return extra_newl + NFA_NWORD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
716 case CLASS_az | CLASS_AZ | CLASS_underscore: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
717 return extra_newl + NFA_HEAD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
718 case CLASS_not | CLASS_az | CLASS_AZ | CLASS_underscore: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
719 return extra_newl + NFA_NHEAD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
720 case CLASS_az | CLASS_AZ: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
721 return extra_newl + NFA_ALPHA; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
722 case CLASS_not | CLASS_az | CLASS_AZ: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
723 return extra_newl + NFA_NALPHA; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
724 case CLASS_az: |
5296 | 725 return extra_newl + NFA_LOWER_IC; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
726 case CLASS_not | CLASS_az: |
5296 | 727 return extra_newl + NFA_NLOWER_IC; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
728 case CLASS_AZ: |
5296 | 729 return extra_newl + NFA_UPPER_IC; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
730 case CLASS_not | CLASS_AZ: |
5296 | 731 return extra_newl + NFA_NUPPER_IC; |
4444 | 732 } |
733 return FAIL; | |
734 } | |
735 | |
736 /* | |
737 * Produce the bytes for equivalence class "c". | |
738 * Currently only handles latin1, latin9 and utf-8. | |
739 * Emits bytes in postfix notation: 'a,b,NFA_OR,c,NFA_OR' is | |
740 * equivalent to 'a OR b OR c' | |
741 * | |
742 * NOTE! When changing this function, also update reg_equi_class() | |
743 */ | |
744 static int | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
745 nfa_emit_equi_class(c) |
4444 | 746 int c; |
747 { | |
5351 | 748 #define EMIT2(c) EMIT(c); EMIT(NFA_CONCAT); |
749 #ifdef FEAT_MBYTE | |
750 # define EMITMBC(c) EMIT(c); EMIT(NFA_CONCAT); | |
751 #else | |
752 # define EMITMBC(c) | |
753 #endif | |
4444 | 754 |
755 #ifdef FEAT_MBYTE | |
756 if (enc_utf8 || STRCMP(p_enc, "latin1") == 0 | |
757 || STRCMP(p_enc, "iso-8859-15") == 0) | |
758 #endif | |
759 { | |
760 switch (c) | |
761 { | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
762 case 'A': case 0300: case 0301: case 0302: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
763 case 0303: case 0304: case 0305: |
5351 | 764 CASEMBC(0x100) CASEMBC(0x102) CASEMBC(0x104) CASEMBC(0x1cd) |
765 CASEMBC(0x1de) CASEMBC(0x1e0) CASEMBC(0x1ea2) | |
766 EMIT2('A'); EMIT2(0300); EMIT2(0301); EMIT2(0302); | |
767 EMIT2(0303); EMIT2(0304); EMIT2(0305); | |
768 EMITMBC(0x100) EMITMBC(0x102) EMITMBC(0x104) | |
769 EMITMBC(0x1cd) EMITMBC(0x1de) EMITMBC(0x1e0) | |
770 EMITMBC(0x1ea2) | |
771 return OK; | |
772 | |
773 case 'B': CASEMBC(0x1e02) CASEMBC(0x1e06) | |
774 EMIT2('B'); EMITMBC(0x1e02) EMITMBC(0x1e06) | |
4444 | 775 return OK; |
776 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
777 case 'C': case 0307: |
5351 | 778 CASEMBC(0x106) CASEMBC(0x108) CASEMBC(0x10a) CASEMBC(0x10c) |
779 EMIT2('C'); EMIT2(0307); EMITMBC(0x106) EMITMBC(0x108) | |
780 EMITMBC(0x10a) EMITMBC(0x10c) | |
781 return OK; | |
782 | |
783 case 'D': CASEMBC(0x10e) CASEMBC(0x110) CASEMBC(0x1e0a) | |
784 CASEMBC(0x1e0e) CASEMBC(0x1e10) | |
785 EMIT2('D'); EMITMBC(0x10e) EMITMBC(0x110) EMITMBC(0x1e0a) | |
786 EMITMBC(0x1e0e) EMITMBC(0x1e10) | |
4444 | 787 return OK; |
788 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
789 case 'E': case 0310: case 0311: case 0312: case 0313: |
5351 | 790 CASEMBC(0x112) CASEMBC(0x114) CASEMBC(0x116) CASEMBC(0x118) |
791 CASEMBC(0x11a) CASEMBC(0x1eba) CASEMBC(0x1ebc) | |
792 EMIT2('E'); EMIT2(0310); EMIT2(0311); EMIT2(0312); | |
793 EMIT2(0313); | |
794 EMITMBC(0x112) EMITMBC(0x114) EMITMBC(0x116) | |
795 EMITMBC(0x118) EMITMBC(0x11a) EMITMBC(0x1eba) | |
796 EMITMBC(0x1ebc) | |
797 return OK; | |
798 | |
799 case 'F': CASEMBC(0x1e1e) | |
800 EMIT2('F'); EMITMBC(0x1e1e) | |
801 return OK; | |
802 | |
803 case 'G': CASEMBC(0x11c) CASEMBC(0x11e) CASEMBC(0x120) | |
804 CASEMBC(0x122) CASEMBC(0x1e4) CASEMBC(0x1e6) CASEMBC(0x1f4) | |
805 CASEMBC(0x1e20) | |
806 EMIT2('G'); EMITMBC(0x11c) EMITMBC(0x11e) EMITMBC(0x120) | |
807 EMITMBC(0x122) EMITMBC(0x1e4) EMITMBC(0x1e6) | |
808 EMITMBC(0x1f4) EMITMBC(0x1e20) | |
809 return OK; | |
810 | |
811 case 'H': CASEMBC(0x124) CASEMBC(0x126) CASEMBC(0x1e22) | |
812 CASEMBC(0x1e26) CASEMBC(0x1e28) | |
813 EMIT2('H'); EMITMBC(0x124) EMITMBC(0x126) EMITMBC(0x1e22) | |
814 EMITMBC(0x1e26) EMITMBC(0x1e28) | |
4444 | 815 return OK; |
816 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
817 case 'I': case 0314: case 0315: case 0316: case 0317: |
5351 | 818 CASEMBC(0x128) CASEMBC(0x12a) CASEMBC(0x12c) CASEMBC(0x12e) |
819 CASEMBC(0x130) CASEMBC(0x1cf) CASEMBC(0x1ec8) | |
820 EMIT2('I'); EMIT2(0314); EMIT2(0315); EMIT2(0316); | |
821 EMIT2(0317); EMITMBC(0x128) EMITMBC(0x12a) | |
822 EMITMBC(0x12c) EMITMBC(0x12e) EMITMBC(0x130) | |
823 EMITMBC(0x1cf) EMITMBC(0x1ec8) | |
824 return OK; | |
825 | |
826 case 'J': CASEMBC(0x134) | |
827 EMIT2('J'); EMITMBC(0x134) | |
828 return OK; | |
829 | |
830 case 'K': CASEMBC(0x136) CASEMBC(0x1e8) CASEMBC(0x1e30) | |
831 CASEMBC(0x1e34) | |
832 EMIT2('K'); EMITMBC(0x136) EMITMBC(0x1e8) EMITMBC(0x1e30) | |
833 EMITMBC(0x1e34) | |
834 return OK; | |
835 | |
836 case 'L': CASEMBC(0x139) CASEMBC(0x13b) CASEMBC(0x13d) | |
837 CASEMBC(0x13f) CASEMBC(0x141) CASEMBC(0x1e3a) | |
838 EMIT2('L'); EMITMBC(0x139) EMITMBC(0x13b) EMITMBC(0x13d) | |
839 EMITMBC(0x13f) EMITMBC(0x141) EMITMBC(0x1e3a) | |
840 return OK; | |
841 | |
842 case 'M': CASEMBC(0x1e3e) CASEMBC(0x1e40) | |
843 EMIT2('M'); EMITMBC(0x1e3e) EMITMBC(0x1e40) | |
4444 | 844 return OK; |
845 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
846 case 'N': case 0321: |
5351 | 847 CASEMBC(0x143) CASEMBC(0x145) CASEMBC(0x147) CASEMBC(0x1e44) |
848 CASEMBC(0x1e48) | |
849 EMIT2('N'); EMIT2(0321); EMITMBC(0x143) EMITMBC(0x145) | |
850 EMITMBC(0x147) EMITMBC(0x1e44) EMITMBC(0x1e48) | |
4444 | 851 return OK; |
852 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
853 case 'O': case 0322: case 0323: case 0324: case 0325: |
5351 | 854 case 0326: case 0330: |
855 CASEMBC(0x14c) CASEMBC(0x14e) CASEMBC(0x150) CASEMBC(0x1a0) | |
856 CASEMBC(0x1d1) CASEMBC(0x1ea) CASEMBC(0x1ec) CASEMBC(0x1ece) | |
857 EMIT2('O'); EMIT2(0322); EMIT2(0323); EMIT2(0324); | |
858 EMIT2(0325); EMIT2(0326); EMIT2(0330); | |
859 EMITMBC(0x14c) EMITMBC(0x14e) EMITMBC(0x150) | |
860 EMITMBC(0x1a0) EMITMBC(0x1d1) EMITMBC(0x1ea) | |
861 EMITMBC(0x1ec) EMITMBC(0x1ece) | |
862 return OK; | |
863 | |
864 case 'P': case 0x1e54: case 0x1e56: | |
865 EMIT2('P'); EMITMBC(0x1e54) EMITMBC(0x1e56) | |
866 return OK; | |
867 | |
868 case 'R': CASEMBC(0x154) CASEMBC(0x156) CASEMBC(0x158) | |
869 CASEMBC(0x1e58) CASEMBC(0x1e5e) | |
870 EMIT2('R'); EMITMBC(0x154) EMITMBC(0x156) EMITMBC(0x158) | |
871 EMITMBC(0x1e58) EMITMBC(0x1e5e) | |
872 return OK; | |
873 | |
874 case 'S': CASEMBC(0x15a) CASEMBC(0x15c) CASEMBC(0x15e) | |
875 CASEMBC(0x160) CASEMBC(0x1e60) | |
876 EMIT2('S'); EMITMBC(0x15a) EMITMBC(0x15c) EMITMBC(0x15e) | |
877 EMITMBC(0x160) EMITMBC(0x1e60) | |
878 return OK; | |
879 | |
880 case 'T': CASEMBC(0x162) CASEMBC(0x164) CASEMBC(0x166) | |
881 CASEMBC(0x1e6a) CASEMBC(0x1e6e) | |
882 EMIT2('T'); EMITMBC(0x162) EMITMBC(0x164) EMITMBC(0x166) | |
883 EMITMBC(0x1e6a) EMITMBC(0x1e6e) | |
4444 | 884 return OK; |
885 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
886 case 'U': case 0331: case 0332: case 0333: case 0334: |
5351 | 887 CASEMBC(0x168) CASEMBC(0x16a) CASEMBC(0x16c) CASEMBC(0x16e) |
888 CASEMBC(0x170) CASEMBC(0x172) CASEMBC(0x1af) CASEMBC(0x1d3) | |
889 CASEMBC(0x1ee6) | |
890 EMIT2('U'); EMIT2(0331); EMIT2(0332); EMIT2(0333); | |
891 EMIT2(0334); EMITMBC(0x168) EMITMBC(0x16a) | |
892 EMITMBC(0x16c) EMITMBC(0x16e) EMITMBC(0x170) | |
893 EMITMBC(0x172) EMITMBC(0x1af) EMITMBC(0x1d3) | |
894 EMITMBC(0x1ee6) | |
895 return OK; | |
896 | |
897 case 'V': CASEMBC(0x1e7c) | |
898 EMIT2('V'); EMITMBC(0x1e7c) | |
899 return OK; | |
900 | |
901 case 'W': CASEMBC(0x174) CASEMBC(0x1e80) CASEMBC(0x1e82) | |
902 CASEMBC(0x1e84) CASEMBC(0x1e86) | |
903 EMIT2('W'); EMITMBC(0x174) EMITMBC(0x1e80) EMITMBC(0x1e82) | |
904 EMITMBC(0x1e84) EMITMBC(0x1e86) | |
905 return OK; | |
906 | |
907 case 'X': CASEMBC(0x1e8a) CASEMBC(0x1e8c) | |
908 EMIT2('X'); EMITMBC(0x1e8a) EMITMBC(0x1e8c) | |
4444 | 909 return OK; |
910 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
911 case 'Y': case 0335: |
5351 | 912 CASEMBC(0x176) CASEMBC(0x178) CASEMBC(0x1e8e) CASEMBC(0x1ef2) |
913 CASEMBC(0x1ef6) CASEMBC(0x1ef8) | |
914 EMIT2('Y'); EMIT2(0335); EMITMBC(0x176) EMITMBC(0x178) | |
915 EMITMBC(0x1e8e) EMITMBC(0x1ef2) EMITMBC(0x1ef6) | |
916 EMITMBC(0x1ef8) | |
917 return OK; | |
918 | |
919 case 'Z': CASEMBC(0x179) CASEMBC(0x17b) CASEMBC(0x17d) | |
920 CASEMBC(0x1b5) CASEMBC(0x1e90) CASEMBC(0x1e94) | |
921 EMIT2('Z'); EMITMBC(0x179) EMITMBC(0x17b) EMITMBC(0x17d) | |
922 EMITMBC(0x1b5) EMITMBC(0x1e90) EMITMBC(0x1e94) | |
4444 | 923 return OK; |
924 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
925 case 'a': case 0340: case 0341: case 0342: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
926 case 0343: case 0344: case 0345: |
5351 | 927 CASEMBC(0x101) CASEMBC(0x103) CASEMBC(0x105) CASEMBC(0x1ce) |
928 CASEMBC(0x1df) CASEMBC(0x1e1) CASEMBC(0x1ea3) | |
929 EMIT2('a'); EMIT2(0340); EMIT2(0341); EMIT2(0342); | |
930 EMIT2(0343); EMIT2(0344); EMIT2(0345); | |
931 EMITMBC(0x101) EMITMBC(0x103) EMITMBC(0x105) | |
932 EMITMBC(0x1ce) EMITMBC(0x1df) EMITMBC(0x1e1) | |
933 EMITMBC(0x1ea3) | |
934 return OK; | |
935 | |
936 case 'b': CASEMBC(0x1e03) CASEMBC(0x1e07) | |
937 EMIT2('b'); EMITMBC(0x1e03) EMITMBC(0x1e07) | |
4444 | 938 return OK; |
939 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
940 case 'c': case 0347: |
5351 | 941 CASEMBC(0x107) CASEMBC(0x109) CASEMBC(0x10b) CASEMBC(0x10d) |
942 EMIT2('c'); EMIT2(0347); EMITMBC(0x107) EMITMBC(0x109) | |
943 EMITMBC(0x10b) EMITMBC(0x10d) | |
944 return OK; | |
945 | |
946 case 'd': CASEMBC(0x10f) CASEMBC(0x111) CASEMBC(0x1d0b) | |
947 CASEMBC(0x1e11) | |
948 EMIT2('d'); EMITMBC(0x10f) EMITMBC(0x111) EMITMBC(0x1e0b) | |
949 EMITMBC(0x01e0f) EMITMBC(0x1e11) | |
4444 | 950 return OK; |
951 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
952 case 'e': case 0350: case 0351: case 0352: case 0353: |
5351 | 953 CASEMBC(0x113) CASEMBC(0x115) CASEMBC(0x117) CASEMBC(0x119) |
954 CASEMBC(0x11b) CASEMBC(0x1ebb) CASEMBC(0x1ebd) | |
955 EMIT2('e'); EMIT2(0350); EMIT2(0351); EMIT2(0352); | |
956 EMIT2(0353); EMITMBC(0x113) EMITMBC(0x115) | |
957 EMITMBC(0x117) EMITMBC(0x119) EMITMBC(0x11b) | |
958 EMITMBC(0x1ebb) EMITMBC(0x1ebd) | |
959 return OK; | |
960 | |
961 case 'f': CASEMBC(0x1e1f) | |
962 EMIT2('f'); EMITMBC(0x1e1f) | |
963 return OK; | |
964 | |
965 case 'g': CASEMBC(0x11d) CASEMBC(0x11f) CASEMBC(0x121) | |
966 CASEMBC(0x123) CASEMBC(0x1e5) CASEMBC(0x1e7) CASEMBC(0x1f5) | |
967 CASEMBC(0x1e21) | |
968 EMIT2('g'); EMITMBC(0x11d) EMITMBC(0x11f) EMITMBC(0x121) | |
969 EMITMBC(0x123) EMITMBC(0x1e5) EMITMBC(0x1e7) | |
970 EMITMBC(0x1f5) EMITMBC(0x1e21) | |
971 return OK; | |
972 | |
973 case 'h': CASEMBC(0x125) CASEMBC(0x127) CASEMBC(0x1e23) | |
974 CASEMBC(0x1e27) CASEMBC(0x1e29) CASEMBC(0x1e96) | |
975 EMIT2('h'); EMITMBC(0x125) EMITMBC(0x127) EMITMBC(0x1e23) | |
976 EMITMBC(0x1e27) EMITMBC(0x1e29) EMITMBC(0x1e96) | |
4444 | 977 return OK; |
978 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
979 case 'i': case 0354: case 0355: case 0356: case 0357: |
5351 | 980 CASEMBC(0x129) CASEMBC(0x12b) CASEMBC(0x12d) CASEMBC(0x12f) |
981 CASEMBC(0x1d0) CASEMBC(0x1ec9) | |
982 EMIT2('i'); EMIT2(0354); EMIT2(0355); EMIT2(0356); | |
983 EMIT2(0357); EMITMBC(0x129) EMITMBC(0x12b) | |
984 EMITMBC(0x12d) EMITMBC(0x12f) EMITMBC(0x1d0) | |
985 EMITMBC(0x1ec9) | |
986 return OK; | |
987 | |
988 case 'j': CASEMBC(0x135) CASEMBC(0x1f0) | |
989 EMIT2('j'); EMITMBC(0x135) EMITMBC(0x1f0) | |
990 return OK; | |
991 | |
992 case 'k': CASEMBC(0x137) CASEMBC(0x1e9) CASEMBC(0x1e31) | |
993 CASEMBC(0x1e35) | |
994 EMIT2('k'); EMITMBC(0x137) EMITMBC(0x1e9) EMITMBC(0x1e31) | |
995 EMITMBC(0x1e35) | |
996 return OK; | |
997 | |
998 case 'l': CASEMBC(0x13a) CASEMBC(0x13c) CASEMBC(0x13e) | |
999 CASEMBC(0x140) CASEMBC(0x142) CASEMBC(0x1e3b) | |
1000 EMIT2('l'); EMITMBC(0x13a) EMITMBC(0x13c) EMITMBC(0x13e) | |
1001 EMITMBC(0x140) EMITMBC(0x142) EMITMBC(0x1e3b) | |
1002 return OK; | |
1003 | |
1004 case 'm': CASEMBC(0x1e3f) CASEMBC(0x1e41) | |
1005 EMIT2('m'); EMITMBC(0x1e3f) EMITMBC(0x1e41) | |
4444 | 1006 return OK; |
1007 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1008 case 'n': case 0361: |
5351 | 1009 CASEMBC(0x144) CASEMBC(0x146) CASEMBC(0x148) CASEMBC(0x149) |
1010 CASEMBC(0x1e45) CASEMBC(0x1e49) | |
1011 EMIT2('n'); EMIT2(0361); EMITMBC(0x144) EMITMBC(0x146) | |
1012 EMITMBC(0x148) EMITMBC(0x149) EMITMBC(0x1e45) | |
1013 EMITMBC(0x1e49) | |
4444 | 1014 return OK; |
1015 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1016 case 'o': case 0362: case 0363: case 0364: case 0365: |
5351 | 1017 case 0366: case 0370: |
1018 CASEMBC(0x14d) CASEMBC(0x14f) CASEMBC(0x151) CASEMBC(0x1a1) | |
1019 CASEMBC(0x1d2) CASEMBC(0x1eb) CASEMBC(0x1ed) CASEMBC(0x1ecf) | |
1020 EMIT2('o'); EMIT2(0362); EMIT2(0363); EMIT2(0364); | |
1021 EMIT2(0365); EMIT2(0366); EMIT2(0370); | |
1022 EMITMBC(0x14d) EMITMBC(0x14f) EMITMBC(0x151) | |
1023 EMITMBC(0x1a1) EMITMBC(0x1d2) EMITMBC(0x1eb) | |
1024 EMITMBC(0x1ed) EMITMBC(0x1ecf) | |
1025 return OK; | |
1026 | |
1027 case 'p': CASEMBC(0x1e55) CASEMBC(0x1e57) | |
1028 EMIT2('p'); EMITMBC(0x1e55) EMITMBC(0x1e57) | |
1029 return OK; | |
1030 | |
1031 case 'r': CASEMBC(0x155) CASEMBC(0x157) CASEMBC(0x159) | |
1032 CASEMBC(0x1e59) CASEMBC(0x1e5f) | |
1033 EMIT2('r'); EMITMBC(0x155) EMITMBC(0x157) EMITMBC(0x159) | |
1034 EMITMBC(0x1e59) EMITMBC(0x1e5f) | |
1035 return OK; | |
1036 | |
1037 case 's': CASEMBC(0x15b) CASEMBC(0x15d) CASEMBC(0x15f) | |
1038 CASEMBC(0x161) CASEMBC(0x1e61) | |
1039 EMIT2('s'); EMITMBC(0x15b) EMITMBC(0x15d) EMITMBC(0x15f) | |
1040 EMITMBC(0x161) EMITMBC(0x1e61) | |
1041 return OK; | |
1042 | |
1043 case 't': CASEMBC(0x163) CASEMBC(0x165) CASEMBC(0x167) | |
1044 CASEMBC(0x1e6b) CASEMBC(0x1e6f) CASEMBC(0x1e97) | |
1045 EMIT2('t'); EMITMBC(0x163) EMITMBC(0x165) EMITMBC(0x167) | |
1046 EMITMBC(0x1e6b) EMITMBC(0x1e6f) EMITMBC(0x1e97) | |
4444 | 1047 return OK; |
1048 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1049 case 'u': case 0371: case 0372: case 0373: case 0374: |
5351 | 1050 CASEMBC(0x169) CASEMBC(0x16b) CASEMBC(0x16d) CASEMBC(0x16f) |
1051 CASEMBC(0x171) CASEMBC(0x173) CASEMBC(0x1b0) CASEMBC(0x1d4) | |
1052 CASEMBC(0x1ee7) | |
1053 EMIT2('u'); EMIT2(0371); EMIT2(0372); EMIT2(0373); | |
1054 EMIT2(0374); EMITMBC(0x169) EMITMBC(0x16b) | |
1055 EMITMBC(0x16d) EMITMBC(0x16f) EMITMBC(0x171) | |
1056 EMITMBC(0x173) EMITMBC(0x1b0) EMITMBC(0x1d4) | |
1057 EMITMBC(0x1ee7) | |
1058 return OK; | |
1059 | |
1060 case 'v': CASEMBC(0x1e7d) | |
1061 EMIT2('v'); EMITMBC(0x1e7d) | |
1062 return OK; | |
1063 | |
1064 case 'w': CASEMBC(0x175) CASEMBC(0x1e81) CASEMBC(0x1e83) | |
1065 CASEMBC(0x1e85) CASEMBC(0x1e87) CASEMBC(0x1e98) | |
1066 EMIT2('w'); EMITMBC(0x175) EMITMBC(0x1e81) EMITMBC(0x1e83) | |
1067 EMITMBC(0x1e85) EMITMBC(0x1e87) EMITMBC(0x1e98) | |
1068 return OK; | |
1069 | |
1070 case 'x': CASEMBC(0x1e8b) CASEMBC(0x1e8d) | |
1071 EMIT2('x'); EMITMBC(0x1e8b) EMITMBC(0x1e8d) | |
4444 | 1072 return OK; |
1073 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1074 case 'y': case 0375: case 0377: |
5351 | 1075 CASEMBC(0x177) CASEMBC(0x1e8f) CASEMBC(0x1e99) |
1076 CASEMBC(0x1ef3) CASEMBC(0x1ef7) CASEMBC(0x1ef9) | |
1077 EMIT2('y'); EMIT2(0375); EMIT2(0377); EMITMBC(0x177) | |
1078 EMITMBC(0x1e8f) EMITMBC(0x1e99) EMITMBC(0x1ef3) | |
1079 EMITMBC(0x1ef7) EMITMBC(0x1ef9) | |
4444 | 1080 return OK; |
1081 | |
5351 | 1082 case 'z': CASEMBC(0x17a) CASEMBC(0x17c) CASEMBC(0x17e) |
1083 CASEMBC(0x1b6) CASEMBC(0x1e91) CASEMBC(0x1e95) | |
1084 EMIT2('z'); EMITMBC(0x17a) EMITMBC(0x17c) EMITMBC(0x17e) | |
1085 EMITMBC(0x1b6) EMITMBC(0x1e91) EMITMBC(0x1e95) | |
1086 return OK; | |
1087 | |
1088 /* default: character itself */ | |
4444 | 1089 } |
1090 } | |
1091 | |
5351 | 1092 EMIT2(c); |
4444 | 1093 return OK; |
1094 #undef EMIT2 | |
5351 | 1095 #undef EMITMBC |
4444 | 1096 } |
1097 | |
1098 /* | |
1099 * Code to parse regular expression. | |
1100 * | |
1101 * We try to reuse parsing functions in regexp.c to | |
1102 * minimize surprise and keep the syntax consistent. | |
1103 */ | |
1104 | |
1105 /* | |
1106 * Parse the lowest level. | |
1107 * | |
1108 * An atom can be one of a long list of items. Many atoms match one character | |
1109 * in the text. It is often an ordinary character or a character class. | |
1110 * Braces can be used to make a pattern into an atom. The "\z(\)" construct | |
1111 * is only for syntax highlighting. | |
1112 * | |
1113 * atom ::= ordinary-atom | |
1114 * or \( pattern \) | |
1115 * or \%( pattern \) | |
1116 * or \z( pattern \) | |
1117 */ | |
1118 static int | |
1119 nfa_regatom() | |
1120 { | |
1121 int c; | |
1122 int charclass; | |
1123 int equiclass; | |
1124 int collclass; | |
1125 int got_coll_char; | |
1126 char_u *p; | |
1127 char_u *endp; | |
1128 #ifdef FEAT_MBYTE | |
1129 char_u *old_regparse = regparse; | |
1130 #endif | |
1131 int extra = 0; | |
1132 int emit_range; | |
1133 int negated; | |
1134 int result; | |
1135 int startc = -1; | |
1136 int endc = -1; | |
1137 int oldstartc = -1; | |
1138 | |
1139 c = getchr(); | |
1140 switch (c) | |
1141 { | |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1142 case NUL: |
5511 | 1143 EMSG_RET_FAIL(_(e_nul_found)); |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1144 |
4444 | 1145 case Magic('^'): |
1146 EMIT(NFA_BOL); | |
1147 break; | |
1148 | |
1149 case Magic('$'): | |
1150 EMIT(NFA_EOL); | |
1151 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
1152 had_eol = TRUE; | |
1153 #endif | |
1154 break; | |
1155 | |
1156 case Magic('<'): | |
1157 EMIT(NFA_BOW); | |
1158 break; | |
1159 | |
1160 case Magic('>'): | |
1161 EMIT(NFA_EOW); | |
1162 break; | |
1163 | |
1164 case Magic('_'): | |
1165 c = no_Magic(getchr()); | |
5511 | 1166 if (c == NUL) |
1167 EMSG_RET_FAIL(_(e_nul_found)); | |
1168 | |
4444 | 1169 if (c == '^') /* "\_^" is start-of-line */ |
1170 { | |
1171 EMIT(NFA_BOL); | |
1172 break; | |
1173 } | |
1174 if (c == '$') /* "\_$" is end-of-line */ | |
1175 { | |
1176 EMIT(NFA_EOL); | |
1177 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
1178 had_eol = TRUE; | |
1179 #endif | |
1180 break; | |
1181 } | |
1182 | |
5296 | 1183 extra = NFA_ADD_NL; |
4444 | 1184 |
1185 /* "\_[" is collection plus newline */ | |
1186 if (c == '[') | |
4517
9a2183bd8295
updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents:
4515
diff
changeset
|
1187 goto collection; |
4444 | 1188 |
1189 /* "\_x" is character class plus newline */ | |
1190 /*FALLTHROUGH*/ | |
1191 | |
1192 /* | |
1193 * Character classes. | |
1194 */ | |
1195 case Magic('.'): | |
1196 case Magic('i'): | |
1197 case Magic('I'): | |
1198 case Magic('k'): | |
1199 case Magic('K'): | |
1200 case Magic('f'): | |
1201 case Magic('F'): | |
1202 case Magic('p'): | |
1203 case Magic('P'): | |
1204 case Magic('s'): | |
1205 case Magic('S'): | |
1206 case Magic('d'): | |
1207 case Magic('D'): | |
1208 case Magic('x'): | |
1209 case Magic('X'): | |
1210 case Magic('o'): | |
1211 case Magic('O'): | |
1212 case Magic('w'): | |
1213 case Magic('W'): | |
1214 case Magic('h'): | |
1215 case Magic('H'): | |
1216 case Magic('a'): | |
1217 case Magic('A'): | |
1218 case Magic('l'): | |
1219 case Magic('L'): | |
1220 case Magic('u'): | |
1221 case Magic('U'): | |
1222 p = vim_strchr(classchars, no_Magic(c)); | |
1223 if (p == NULL) | |
1224 { | |
5511 | 1225 if (extra == NFA_ADD_NL) |
1226 { | |
1227 EMSGN(_(e_ill_char_class), c); | |
1228 rc_did_emsg = TRUE; | |
1229 return FAIL; | |
1230 } | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1231 EMSGN("INTERNAL: Unknown character class char: %ld", c); |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1232 return FAIL; |
4444 | 1233 } |
1234 #ifdef FEAT_MBYTE | |
1235 /* When '.' is followed by a composing char ignore the dot, so that | |
1236 * the composing char is matched here. */ | |
1237 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr())) | |
1238 { | |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
1239 old_regparse = regparse; |
4444 | 1240 c = getchr(); |
1241 goto nfa_do_multibyte; | |
1242 } | |
1243 #endif | |
1244 EMIT(nfa_classcodes[p - classchars]); | |
5296 | 1245 if (extra == NFA_ADD_NL) |
4444 | 1246 { |
1247 EMIT(NFA_NEWL); | |
1248 EMIT(NFA_OR); | |
1249 regflags |= RF_HASNL; | |
1250 } | |
1251 break; | |
1252 | |
1253 case Magic('n'): | |
1254 if (reg_string) | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1255 /* In a string "\n" matches a newline character. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1256 EMIT(NL); |
4444 | 1257 else |
1258 { | |
1259 /* In buffer text "\n" matches the end of a line. */ | |
1260 EMIT(NFA_NEWL); | |
1261 regflags |= RF_HASNL; | |
1262 } | |
1263 break; | |
1264 | |
1265 case Magic('('): | |
1266 if (nfa_reg(REG_PAREN) == FAIL) | |
1267 return FAIL; /* cascaded error */ | |
1268 break; | |
1269 | |
1270 case Magic('|'): | |
1271 case Magic('&'): | |
1272 case Magic(')'): | |
4450 | 1273 EMSGN(_(e_misplaced), no_Magic(c)); |
4444 | 1274 return FAIL; |
1275 | |
1276 case Magic('='): | |
1277 case Magic('?'): | |
1278 case Magic('+'): | |
1279 case Magic('@'): | |
1280 case Magic('*'): | |
1281 case Magic('{'): | |
1282 /* these should follow an atom, not form an atom */ | |
4450 | 1283 EMSGN(_(e_misplaced), no_Magic(c)); |
4444 | 1284 return FAIL; |
1285 | |
4714
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1286 case Magic('~'): |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1287 { |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1288 char_u *lp; |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1289 |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1290 /* Previous substitute pattern. |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1291 * Generated as "\%(pattern\)". */ |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1292 if (reg_prev_sub == NULL) |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1293 { |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1294 EMSG(_(e_nopresub)); |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1295 return FAIL; |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1296 } |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1297 for (lp = reg_prev_sub; *lp != NUL; mb_cptr_adv(lp)) |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1298 { |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1299 EMIT(PTR2CHAR(lp)); |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1300 if (lp != reg_prev_sub) |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1301 EMIT(NFA_CONCAT); |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1302 } |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1303 EMIT(NFA_NOPEN); |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1304 break; |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1305 } |
4444 | 1306 |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1307 case Magic('1'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1308 case Magic('2'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1309 case Magic('3'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1310 case Magic('4'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1311 case Magic('5'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1312 case Magic('6'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1313 case Magic('7'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1314 case Magic('8'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1315 case Magic('9'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1316 EMIT(NFA_BACKREF1 + (no_Magic(c) - '1')); |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1317 nfa_has_backref = TRUE; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1318 break; |
4444 | 1319 |
1320 case Magic('z'): | |
1321 c = no_Magic(getchr()); | |
1322 switch (c) | |
1323 { | |
1324 case 's': | |
1325 EMIT(NFA_ZSTART); | |
6170 | 1326 if (re_mult_next("\\zs") == FAIL) |
1327 return FAIL; | |
4444 | 1328 break; |
1329 case 'e': | |
1330 EMIT(NFA_ZEND); | |
1331 nfa_has_zend = TRUE; | |
6170 | 1332 if (re_mult_next("\\ze") == FAIL) |
1333 return FAIL; | |
4569
f262fb02889d
updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents:
4567
diff
changeset
|
1334 break; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1335 #ifdef FEAT_SYN_HL |
4444 | 1336 case '1': |
1337 case '2': | |
1338 case '3': | |
1339 case '4': | |
1340 case '5': | |
1341 case '6': | |
1342 case '7': | |
1343 case '8': | |
1344 case '9': | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1345 /* \z1...\z9 */ |
4688
371cc0c44097
updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
1346 if (reg_do_extmatch != REX_USE) |
371cc0c44097
updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
1347 EMSG_RET_FAIL(_(e_z1_not_allowed)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1348 EMIT(NFA_ZREF1 + (no_Magic(c) - '1')); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1349 /* No need to set nfa_has_backref, the sub-matches don't |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
1350 * change when \z1 .. \z9 matches or not. */ |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1351 re_has_z = REX_USE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1352 break; |
4444 | 1353 case '(': |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1354 /* \z( */ |
4688
371cc0c44097
updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
1355 if (reg_do_extmatch != REX_SET) |
371cc0c44097
updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
1356 EMSG_RET_FAIL(_(e_z_not_allowed)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1357 if (nfa_reg(REG_ZPAREN) == FAIL) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1358 return FAIL; /* cascaded error */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1359 re_has_z = REX_SET; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1360 break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1361 #endif |
4444 | 1362 default: |
4450 | 1363 EMSGN(_("E867: (NFA) Unknown operator '\\z%c'"), |
4444 | 1364 no_Magic(c)); |
1365 return FAIL; | |
1366 } | |
1367 break; | |
1368 | |
1369 case Magic('%'): | |
1370 c = no_Magic(getchr()); | |
1371 switch (c) | |
1372 { | |
1373 /* () without a back reference */ | |
1374 case '(': | |
1375 if (nfa_reg(REG_NPAREN) == FAIL) | |
1376 return FAIL; | |
1377 EMIT(NFA_NOPEN); | |
1378 break; | |
1379 | |
1380 case 'd': /* %d123 decimal */ | |
1381 case 'o': /* %o123 octal */ | |
1382 case 'x': /* %xab hex 2 */ | |
1383 case 'u': /* %uabcd hex 4 */ | |
1384 case 'U': /* %U1234abcd hex 8 */ | |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1385 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1386 int nr; |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1387 |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1388 switch (c) |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1389 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1390 case 'd': nr = getdecchrs(); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1391 case 'o': nr = getoctchrs(); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1392 case 'x': nr = gethexchrs(2); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1393 case 'u': nr = gethexchrs(4); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1394 case 'U': nr = gethexchrs(8); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1395 default: nr = -1; break; |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1396 } |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1397 |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1398 if (nr < 0) |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1399 EMSG2_RET_FAIL( |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1400 _("E678: Invalid character after %s%%[dxouU]"), |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1401 reg_magic == MAGIC_ALL); |
5360 | 1402 /* A NUL is stored in the text as NL */ |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1403 /* TODO: what if a composing character follows? */ |
5360 | 1404 EMIT(nr == 0 ? 0x0a : nr); |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1405 } |
4444 | 1406 break; |
1407 | |
1408 /* Catch \%^ and \%$ regardless of where they appear in the | |
1409 * pattern -- regardless of whether or not it makes sense. */ | |
1410 case '^': | |
1411 EMIT(NFA_BOF); | |
1412 break; | |
1413 | |
1414 case '$': | |
1415 EMIT(NFA_EOF); | |
1416 break; | |
1417 | |
1418 case '#': | |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1419 EMIT(NFA_CURSOR); |
4444 | 1420 break; |
1421 | |
1422 case 'V': | |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
1423 EMIT(NFA_VISUAL); |
4444 | 1424 break; |
1425 | |
5901 | 1426 case 'C': |
1427 EMIT(NFA_ANY_COMPOSING); | |
1428 break; | |
1429 | |
4444 | 1430 case '[': |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1431 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1432 int n; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1433 |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1434 /* \%[abc] */ |
4944
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1435 for (n = 0; (c = peekchr()) != ']'; ++n) |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1436 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1437 if (c == NUL) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1438 EMSG2_RET_FAIL(_(e_missing_sb), |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1439 reg_magic == MAGIC_ALL); |
4944
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1440 /* recursive call! */ |
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1441 if (nfa_regatom() == FAIL) |
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1442 return FAIL; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1443 } |
4944
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1444 getchr(); /* get the ] */ |
4760
532a9855bd30
updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents:
4758
diff
changeset
|
1445 if (n == 0) |
532a9855bd30
updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents:
4758
diff
changeset
|
1446 EMSG2_RET_FAIL(_(e_empty_sb), |
532a9855bd30
updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents:
4758
diff
changeset
|
1447 reg_magic == MAGIC_ALL); |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1448 EMIT(NFA_OPT_CHARS); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1449 EMIT(n); |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1450 |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1451 /* Emit as "\%(\%[abc]\)" to be able to handle |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1452 * "\%[abc]*" which would cause the empty string to be |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1453 * matched an unlimited number of times. NFA_NOPEN is |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1454 * added only once at a position, while NFA_SPLIT is |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1455 * added multiple times. This is more efficient than |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1456 * not allowsing NFA_SPLIT multiple times, it is used |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1457 * a lot. */ |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1458 EMIT(NFA_NOPEN); |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1459 break; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1460 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1461 |
4444 | 1462 default: |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1463 { |
4655
779ca415f8e1
updated for version 7.3.1075
Bram Moolenaar <bram@vim.org>
parents:
4651
diff
changeset
|
1464 int n = 0; |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1465 int cmp = c; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1466 |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1467 if (c == '<' || c == '>') |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1468 c = getchr(); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1469 while (VIM_ISDIGIT(c)) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1470 { |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1471 n = n * 10 + (c - '0'); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1472 c = getchr(); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1473 } |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1474 if (c == 'l' || c == 'c' || c == 'v') |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1475 { |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1476 if (c == 'l') |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1477 /* \%{n}l \%{n}<l \%{n}>l */ |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1478 EMIT(cmp == '<' ? NFA_LNUM_LT : |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1479 cmp == '>' ? NFA_LNUM_GT : NFA_LNUM); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1480 else if (c == 'c') |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1481 /* \%{n}c \%{n}<c \%{n}>c */ |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1482 EMIT(cmp == '<' ? NFA_COL_LT : |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1483 cmp == '>' ? NFA_COL_GT : NFA_COL); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1484 else |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1485 /* \%{n}v \%{n}<v \%{n}>v */ |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1486 EMIT(cmp == '<' ? NFA_VCOL_LT : |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1487 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1488 EMIT(n); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1489 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1490 } |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1491 else if (c == '\'' && n == 0) |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1492 { |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1493 /* \%'m \%<'m \%>'m */ |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1494 EMIT(cmp == '<' ? NFA_MARK_LT : |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1495 cmp == '>' ? NFA_MARK_GT : NFA_MARK); |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1496 EMIT(getchr()); |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1497 break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1498 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1499 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1500 EMSGN(_("E867: (NFA) Unknown operator '\\%%%c'"), |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1501 no_Magic(c)); |
4444 | 1502 return FAIL; |
1503 } | |
1504 break; | |
1505 | |
1506 case Magic('['): | |
4517
9a2183bd8295
updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents:
4515
diff
changeset
|
1507 collection: |
4444 | 1508 /* |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1509 * [abc] uses NFA_START_COLL - NFA_END_COLL |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1510 * [^abc] uses NFA_START_NEG_COLL - NFA_END_NEG_COLL |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1511 * Each character is produced as a regular state, using |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1512 * NFA_CONCAT to bind them together. |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1513 * Besides normal characters there can be: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1514 * - character classes NFA_CLASS_* |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1515 * - ranges, two characters followed by NFA_RANGE. |
4444 | 1516 */ |
1517 | |
1518 p = regparse; | |
1519 endp = skip_anyof(p); | |
1520 if (*endp == ']') | |
1521 { | |
1522 /* | |
1523 * Try to reverse engineer character classes. For example, | |
5296 | 1524 * recognize that [0-9] stands for \d and [A-Za-z_] for \h, |
4444 | 1525 * and perform the necessary substitutions in the NFA. |
1526 */ | |
1527 result = nfa_recognize_char_class(regparse, endp, | |
5296 | 1528 extra == NFA_ADD_NL); |
4444 | 1529 if (result != FAIL) |
1530 { | |
5296 | 1531 if (result >= NFA_FIRST_NL && result <= NFA_LAST_NL) |
4444 | 1532 { |
5296 | 1533 EMIT(result - NFA_ADD_NL); |
4444 | 1534 EMIT(NFA_NEWL); |
1535 EMIT(NFA_OR); | |
1536 } | |
5296 | 1537 else |
1538 EMIT(result); | |
4444 | 1539 regparse = endp; |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1540 mb_ptr_adv(regparse); |
4444 | 1541 return OK; |
1542 } | |
1543 /* | |
1544 * Failed to recognize a character class. Use the simple | |
1545 * version that turns [abc] into 'a' OR 'b' OR 'c' | |
1546 */ | |
1547 startc = endc = oldstartc = -1; | |
1548 negated = FALSE; | |
1549 if (*regparse == '^') /* negated range */ | |
1550 { | |
1551 negated = TRUE; | |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1552 mb_ptr_adv(regparse); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1553 EMIT(NFA_START_NEG_COLL); |
4444 | 1554 } |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1555 else |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1556 EMIT(NFA_START_COLL); |
4444 | 1557 if (*regparse == '-') |
1558 { | |
1559 startc = '-'; | |
1560 EMIT(startc); | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1561 EMIT(NFA_CONCAT); |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1562 mb_ptr_adv(regparse); |
4444 | 1563 } |
1564 /* Emit the OR branches for each character in the [] */ | |
1565 emit_range = FALSE; | |
1566 while (regparse < endp) | |
1567 { | |
1568 oldstartc = startc; | |
1569 startc = -1; | |
1570 got_coll_char = FALSE; | |
1571 if (*regparse == '[') | |
1572 { | |
1573 /* Check for [: :], [= =], [. .] */ | |
1574 equiclass = collclass = 0; | |
1575 charclass = get_char_class(®parse); | |
1576 if (charclass == CLASS_NONE) | |
1577 { | |
1578 equiclass = get_equi_class(®parse); | |
1579 if (equiclass == 0) | |
1580 collclass = get_coll_element(®parse); | |
1581 } | |
1582 | |
1583 /* Character class like [:alpha:] */ | |
1584 if (charclass != CLASS_NONE) | |
1585 { | |
1586 switch (charclass) | |
1587 { | |
1588 case CLASS_ALNUM: | |
1589 EMIT(NFA_CLASS_ALNUM); | |
1590 break; | |
1591 case CLASS_ALPHA: | |
1592 EMIT(NFA_CLASS_ALPHA); | |
1593 break; | |
1594 case CLASS_BLANK: | |
1595 EMIT(NFA_CLASS_BLANK); | |
1596 break; | |
1597 case CLASS_CNTRL: | |
1598 EMIT(NFA_CLASS_CNTRL); | |
1599 break; | |
1600 case CLASS_DIGIT: | |
1601 EMIT(NFA_CLASS_DIGIT); | |
1602 break; | |
1603 case CLASS_GRAPH: | |
1604 EMIT(NFA_CLASS_GRAPH); | |
1605 break; | |
1606 case CLASS_LOWER: | |
1607 EMIT(NFA_CLASS_LOWER); | |
1608 break; | |
1609 case CLASS_PRINT: | |
1610 EMIT(NFA_CLASS_PRINT); | |
1611 break; | |
1612 case CLASS_PUNCT: | |
1613 EMIT(NFA_CLASS_PUNCT); | |
1614 break; | |
1615 case CLASS_SPACE: | |
1616 EMIT(NFA_CLASS_SPACE); | |
1617 break; | |
1618 case CLASS_UPPER: | |
1619 EMIT(NFA_CLASS_UPPER); | |
1620 break; | |
1621 case CLASS_XDIGIT: | |
1622 EMIT(NFA_CLASS_XDIGIT); | |
1623 break; | |
1624 case CLASS_TAB: | |
1625 EMIT(NFA_CLASS_TAB); | |
1626 break; | |
1627 case CLASS_RETURN: | |
1628 EMIT(NFA_CLASS_RETURN); | |
1629 break; | |
1630 case CLASS_BACKSPACE: | |
1631 EMIT(NFA_CLASS_BACKSPACE); | |
1632 break; | |
1633 case CLASS_ESCAPE: | |
1634 EMIT(NFA_CLASS_ESCAPE); | |
1635 break; | |
1636 } | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1637 EMIT(NFA_CONCAT); |
4444 | 1638 continue; |
1639 } | |
1640 /* Try equivalence class [=a=] and the like */ | |
1641 if (equiclass != 0) | |
1642 { | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1643 result = nfa_emit_equi_class(equiclass); |
4444 | 1644 if (result == FAIL) |
1645 { | |
1646 /* should never happen */ | |
1647 EMSG_RET_FAIL(_("E868: Error building NFA with equivalence class!")); | |
1648 } | |
1649 continue; | |
1650 } | |
1651 /* Try collating class like [. .] */ | |
1652 if (collclass != 0) | |
1653 { | |
1654 startc = collclass; /* allow [.a.]-x as a range */ | |
1655 /* Will emit the proper atom at the end of the | |
1656 * while loop. */ | |
1657 } | |
1658 } | |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1659 /* Try a range like 'a-x' or '\t-z'. Also allows '-' as a |
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1660 * start character. */ |
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1661 if (*regparse == '-' && oldstartc != -1) |
4444 | 1662 { |
1663 emit_range = TRUE; | |
1664 startc = oldstartc; | |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1665 mb_ptr_adv(regparse); |
4444 | 1666 continue; /* reading the end of the range */ |
1667 } | |
1668 | |
1669 /* Now handle simple and escaped characters. | |
1670 * Only "\]", "\^", "\]" and "\\" are special in Vi. Vim | |
1671 * accepts "\t", "\e", etc., but only when the 'l' flag in | |
1672 * 'cpoptions' is not included. | |
1673 * Posix doesn't recognize backslash at all. | |
1674 */ | |
1675 if (*regparse == '\\' | |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4742
diff
changeset
|
1676 && !reg_cpo_bsl |
4444 | 1677 && regparse + 1 <= endp |
1678 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL | |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4742
diff
changeset
|
1679 || (!reg_cpo_lit |
4444 | 1680 && vim_strchr(REGEXP_ABBR, regparse[1]) |
1681 != NULL) | |
1682 ) | |
1683 ) | |
1684 { | |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1685 mb_ptr_adv(regparse); |
4444 | 1686 |
4507
9dbbddb2ed10
updated for version 7.3.1001
Bram Moolenaar <bram@vim.org>
parents:
4503
diff
changeset
|
1687 if (*regparse == 'n') |
4444 | 1688 startc = reg_string ? NL : NFA_NEWL; |
1689 else | |
1690 if (*regparse == 'd' | |
1691 || *regparse == 'o' | |
1692 || *regparse == 'x' | |
1693 || *regparse == 'u' | |
1694 || *regparse == 'U' | |
1695 ) | |
1696 { | |
1697 /* TODO(RE) This needs more testing */ | |
1698 startc = coll_get_char(); | |
1699 got_coll_char = TRUE; | |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1700 mb_ptr_back(old_regparse, regparse); |
4444 | 1701 } |
1702 else | |
1703 { | |
1704 /* \r,\t,\e,\b */ | |
1705 startc = backslash_trans(*regparse); | |
1706 } | |
1707 } | |
1708 | |
1709 /* Normal printable char */ | |
1710 if (startc == -1) | |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1711 startc = PTR2CHAR(regparse); |
4444 | 1712 |
1713 /* Previous char was '-', so this char is end of range. */ | |
1714 if (emit_range) | |
1715 { | |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1716 endc = startc; |
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1717 startc = oldstartc; |
4444 | 1718 if (startc > endc) |
1719 EMSG_RET_FAIL(_(e_invrange)); | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1720 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1721 if (endc > startc + 2) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1722 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1723 /* Emit a range instead of the sequence of |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1724 * individual characters. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1725 if (startc == 0) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1726 /* \x00 is translated to \x0a, start at \x01. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1727 EMIT(1); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1728 else |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1729 --post_ptr; /* remove NFA_CONCAT */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1730 EMIT(endc); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1731 EMIT(NFA_RANGE); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1732 EMIT(NFA_CONCAT); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1733 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1734 else |
4444 | 1735 #ifdef FEAT_MBYTE |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1736 if (has_mbyte && ((*mb_char2len)(startc) > 1 |
4444 | 1737 || (*mb_char2len)(endc) > 1)) |
1738 { | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1739 /* Emit the characters in the range. |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1740 * "startc" was already emitted, so skip it. |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1741 * */ |
4444 | 1742 for (c = startc + 1; c <= endc; c++) |
1743 { | |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1744 EMIT(c); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1745 EMIT(NFA_CONCAT); |
4444 | 1746 } |
1747 } | |
1748 else | |
1749 #endif | |
1750 { | |
1751 #ifdef EBCDIC | |
1752 int alpha_only = FALSE; | |
1753 | |
1754 /* for alphabetical range skip the gaps | |
1755 * 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. */ | |
1756 if (isalpha(startc) && isalpha(endc)) | |
1757 alpha_only = TRUE; | |
1758 #endif | |
1759 /* Emit the range. "startc" was already emitted, so | |
1760 * skip it. */ | |
1761 for (c = startc + 1; c <= endc; c++) | |
1762 #ifdef EBCDIC | |
1763 if (!alpha_only || isalpha(startc)) | |
1764 #endif | |
1765 { | |
1766 EMIT(c); | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1767 EMIT(NFA_CONCAT); |
4444 | 1768 } |
1769 } | |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1770 emit_range = FALSE; |
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1771 startc = -1; |
4444 | 1772 } |
1773 else | |
1774 { | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1775 /* This char (startc) is not part of a range. Just |
4444 | 1776 * emit it. |
1777 * Normally, simply emit startc. But if we get char | |
1778 * code=0 from a collating char, then replace it with | |
1779 * 0x0a. | |
1780 * This is needed to completely mimic the behaviour of | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1781 * the backtracking engine. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1782 if (startc == NFA_NEWL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1783 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1784 /* Line break can't be matched as part of the |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1785 * collection, add an OR below. But not for negated |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1786 * range. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1787 if (!negated) |
5296 | 1788 extra = NFA_ADD_NL; |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1789 } |
4444 | 1790 else |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1791 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1792 if (got_coll_char == TRUE && startc == 0) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1793 EMIT(0x0a); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1794 else |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1795 EMIT(startc); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1796 EMIT(NFA_CONCAT); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1797 } |
4444 | 1798 } |
1799 | |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1800 mb_ptr_adv(regparse); |
4444 | 1801 } /* while (p < endp) */ |
1802 | |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1803 mb_ptr_back(old_regparse, regparse); |
4444 | 1804 if (*regparse == '-') /* if last, '-' is just a char */ |
1805 { | |
1806 EMIT('-'); | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1807 EMIT(NFA_CONCAT); |
4444 | 1808 } |
1809 | |
1810 /* skip the trailing ] */ | |
1811 regparse = endp; | |
4573
37e444aeb33b
updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents:
4571
diff
changeset
|
1812 mb_ptr_adv(regparse); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1813 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1814 /* Mark end of the collection. */ |
4444 | 1815 if (negated == TRUE) |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1816 EMIT(NFA_END_NEG_COLL); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1817 else |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1818 EMIT(NFA_END_COLL); |
4615
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1819 |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1820 /* \_[] also matches \n but it's not negated */ |
5296 | 1821 if (extra == NFA_ADD_NL) |
4615
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1822 { |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1823 EMIT(reg_string ? NL : NFA_NEWL); |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1824 EMIT(NFA_OR); |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1825 } |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1826 |
4444 | 1827 return OK; |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1828 } /* if exists closing ] */ |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1829 |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1830 if (reg_strict) |
4444 | 1831 EMSG_RET_FAIL(_(e_missingbracket)); |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1832 /* FALLTHROUGH */ |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1833 |
4444 | 1834 default: |
1835 { | |
1836 #ifdef FEAT_MBYTE | |
1837 int plen; | |
1838 | |
1839 nfa_do_multibyte: | |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1840 /* plen is length of current char with composing chars */ |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1841 if (enc_utf8 && ((*mb_char2len)(c) |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1842 != (plen = (*mb_ptr2len)(old_regparse)) |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1843 || utf_iscomposing(c))) |
4444 | 1844 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1845 int i = 0; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1846 |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
1847 /* A base character plus composing characters, or just one |
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
1848 * or more composing characters. |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1849 * This requires creating a separate atom as if enclosing |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1850 * the characters in (), where NFA_COMPOSING is the ( and |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1851 * NFA_END_COMPOSING is the ). Note that right now we are |
4444 | 1852 * building the postfix form, not the NFA itself; |
1853 * a composing char could be: a, b, c, NFA_COMPOSING | |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1854 * where 'b' and 'c' are chars with codes > 256. */ |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1855 for (;;) |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1856 { |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1857 EMIT(c); |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1858 if (i > 0) |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1859 EMIT(NFA_CONCAT); |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1860 if ((i += utf_char2len(c)) >= plen) |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1861 break; |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1862 c = utf_ptr2char(old_regparse + i); |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1863 } |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1864 EMIT(NFA_COMPOSING); |
4444 | 1865 regparse = old_regparse + plen; |
1866 } | |
1867 else | |
1868 #endif | |
1869 { | |
1870 c = no_Magic(c); | |
1871 EMIT(c); | |
1872 } | |
1873 return OK; | |
1874 } | |
1875 } | |
1876 | |
1877 return OK; | |
1878 } | |
1879 | |
1880 /* | |
1881 * Parse something followed by possible [*+=]. | |
1882 * | |
1883 * A piece is an atom, possibly followed by a multi, an indication of how many | |
1884 * times the atom can be matched. Example: "a*" matches any sequence of "a" | |
1885 * characters: "", "a", "aa", etc. | |
1886 * | |
1887 * piece ::= atom | |
1888 * or atom multi | |
1889 */ | |
1890 static int | |
1891 nfa_regpiece() | |
1892 { | |
1893 int i; | |
1894 int op; | |
1895 int ret; | |
1896 long minval, maxval; | |
1897 int greedy = TRUE; /* Braces are prefixed with '-' ? */ | |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
1898 parse_state_T old_state; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
1899 parse_state_T new_state; |
4444 | 1900 int c2; |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
1901 int old_post_pos; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
1902 int my_post_start; |
4444 | 1903 int quest; |
1904 | |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
1905 /* Save the current parse state, so that we can use it if <atom>{m,n} is |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
1906 * next. */ |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
1907 save_parse_state(&old_state); |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
1908 |
4444 | 1909 /* store current pos in the postfix form, for \{m,n} involving 0s */ |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
1910 my_post_start = (int)(post_ptr - post_start); |
4444 | 1911 |
1912 ret = nfa_regatom(); | |
1913 if (ret == FAIL) | |
1914 return FAIL; /* cascaded error */ | |
1915 | |
1916 op = peekchr(); | |
1917 if (re_multi_type(op) == NOT_MULTI) | |
1918 return OK; | |
1919 | |
1920 skipchr(); | |
1921 switch (op) | |
1922 { | |
1923 case Magic('*'): | |
1924 EMIT(NFA_STAR); | |
1925 break; | |
1926 | |
1927 case Magic('+'): | |
1928 /* | |
1929 * Trick: Normally, (a*)\+ would match the whole input "aaa". The | |
1930 * first and only submatch would be "aaa". But the backtracking | |
1931 * engine interprets the plus as "try matching one more time", and | |
1932 * a* matches a second time at the end of the input, the empty | |
1933 * string. | |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1934 * The submatch will be the empty string. |
4444 | 1935 * |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
1936 * In order to be consistent with the old engine, we replace |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
1937 * <atom>+ with <atom><atom>* |
4444 | 1938 */ |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
1939 restore_parse_state(&old_state); |
4444 | 1940 curchr = -1; |
1941 if (nfa_regatom() == FAIL) | |
1942 return FAIL; | |
1943 EMIT(NFA_STAR); | |
1944 EMIT(NFA_CONCAT); | |
1945 skipchr(); /* skip the \+ */ | |
1946 break; | |
1947 | |
1948 case Magic('@'): | |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1949 c2 = getdecchrs(); |
4444 | 1950 op = no_Magic(getchr()); |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1951 i = 0; |
4444 | 1952 switch(op) |
1953 { | |
1954 case '=': | |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1955 /* \@= */ |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1956 i = NFA_PREV_ATOM_NO_WIDTH; |
4444 | 1957 break; |
4661
0dce3d812e7a
updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents:
4657
diff
changeset
|
1958 case '!': |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1959 /* \@! */ |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1960 i = NFA_PREV_ATOM_NO_WIDTH_NEG; |
4661
0dce3d812e7a
updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents:
4657
diff
changeset
|
1961 break; |
4444 | 1962 case '<': |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1963 op = no_Magic(getchr()); |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1964 if (op == '=') |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1965 /* \@<= */ |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1966 i = NFA_PREV_ATOM_JUST_BEFORE; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1967 else if (op == '!') |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1968 /* \@<! */ |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1969 i = NFA_PREV_ATOM_JUST_BEFORE_NEG; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1970 break; |
4444 | 1971 case '>': |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
1972 /* \@> */ |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
1973 i = NFA_PREV_ATOM_LIKE_PATTERN; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
1974 break; |
4444 | 1975 } |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1976 if (i == 0) |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1977 { |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1978 EMSGN(_("E869: (NFA) Unknown operator '\\@%c'"), op); |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1979 return FAIL; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1980 } |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1981 EMIT(i); |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1982 if (i == NFA_PREV_ATOM_JUST_BEFORE |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1983 || i == NFA_PREV_ATOM_JUST_BEFORE_NEG) |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
1984 EMIT(c2); |
4444 | 1985 break; |
1986 | |
1987 case Magic('?'): | |
1988 case Magic('='): | |
1989 EMIT(NFA_QUEST); | |
1990 break; | |
1991 | |
1992 case Magic('{'): | |
1993 /* a{2,5} will expand to 'aaa?a?a?' | |
1994 * a{-1,3} will expand to 'aa??a??', where ?? is the nongreedy | |
1995 * version of '?' | |
1996 * \v(ab){2,3} will expand to '(ab)(ab)(ab)?', where all the | |
1997 * parenthesis have the same id | |
1998 */ | |
1999 | |
2000 greedy = TRUE; | |
2001 c2 = peekchr(); | |
2002 if (c2 == '-' || c2 == Magic('-')) | |
2003 { | |
2004 skipchr(); | |
2005 greedy = FALSE; | |
2006 } | |
2007 if (!read_limits(&minval, &maxval)) | |
2008 EMSG_RET_FAIL(_("E870: (NFA regexp) Error reading repetition limits")); | |
4762
47906f888725
updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents:
4760
diff
changeset
|
2009 |
4444 | 2010 /* <atom>{0,inf}, <atom>{0,} and <atom>{} are equivalent to |
2011 * <atom>* */ | |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2012 if (minval == 0 && maxval == MAX_LIMIT) |
4444 | 2013 { |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2014 if (greedy) |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2015 /* \{}, \{0,} */ |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2016 EMIT(NFA_STAR); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2017 else |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2018 /* \{-}, \{-0,} */ |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2019 EMIT(NFA_STAR_NONGREEDY); |
4444 | 2020 break; |
2021 } | |
2022 | |
2023 /* Special case: x{0} or x{-0} */ | |
2024 if (maxval == 0) | |
2025 { | |
2026 /* Ignore result of previous call to nfa_regatom() */ | |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2027 post_ptr = post_start + my_post_start; |
5370 | 2028 /* NFA_EMPTY is 0-length and works everywhere */ |
2029 EMIT(NFA_EMPTY); | |
4444 | 2030 return OK; |
2031 } | |
2032 | |
2033 /* Ignore previous call to nfa_regatom() */ | |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2034 post_ptr = post_start + my_post_start; |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2035 /* Save parse state after the repeated atom and the \{} */ |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2036 save_parse_state(&new_state); |
4444 | 2037 |
2038 quest = (greedy == TRUE? NFA_QUEST : NFA_QUEST_NONGREEDY); | |
2039 for (i = 0; i < maxval; i++) | |
2040 { | |
2041 /* Goto beginning of the repeated atom */ | |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2042 restore_parse_state(&old_state); |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2043 old_post_pos = (int)(post_ptr - post_start); |
4444 | 2044 if (nfa_regatom() == FAIL) |
2045 return FAIL; | |
2046 /* after "minval" times, atoms are optional */ | |
2047 if (i + 1 > minval) | |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2048 { |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2049 if (maxval == MAX_LIMIT) |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2050 { |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2051 if (greedy) |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2052 EMIT(NFA_STAR); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2053 else |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2054 EMIT(NFA_STAR_NONGREEDY); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2055 } |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2056 else |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2057 EMIT(quest); |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2058 } |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2059 if (old_post_pos != my_post_start) |
4444 | 2060 EMIT(NFA_CONCAT); |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2061 if (i + 1 > minval && maxval == MAX_LIMIT) |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2062 break; |
4444 | 2063 } |
2064 | |
2065 /* Go to just after the repeated atom and the \{} */ | |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2066 restore_parse_state(&new_state); |
4444 | 2067 curchr = -1; |
2068 | |
2069 break; | |
2070 | |
2071 | |
2072 default: | |
2073 break; | |
2074 } /* end switch */ | |
2075 | |
2076 if (re_multi_type(peekchr()) != NOT_MULTI) | |
2077 /* Can't have a multi follow a multi. */ | |
2078 EMSG_RET_FAIL(_("E871: (NFA regexp) Can't have a multi follow a multi !")); | |
2079 | |
2080 return OK; | |
2081 } | |
2082 | |
2083 /* | |
2084 * Parse one or more pieces, concatenated. It matches a match for the | |
2085 * first piece, followed by a match for the second piece, etc. Example: | |
2086 * "f[0-9]b", first matches "f", then a digit and then "b". | |
2087 * | |
2088 * concat ::= piece | |
2089 * or piece piece | |
2090 * or piece piece piece | |
2091 * etc. | |
2092 */ | |
2093 static int | |
2094 nfa_regconcat() | |
2095 { | |
2096 int cont = TRUE; | |
2097 int first = TRUE; | |
2098 | |
2099 while (cont) | |
2100 { | |
2101 switch (peekchr()) | |
2102 { | |
2103 case NUL: | |
2104 case Magic('|'): | |
2105 case Magic('&'): | |
2106 case Magic(')'): | |
2107 cont = FALSE; | |
2108 break; | |
2109 | |
2110 case Magic('Z'): | |
2111 #ifdef FEAT_MBYTE | |
2112 regflags |= RF_ICOMBINE; | |
2113 #endif | |
2114 skipchr_keepstart(); | |
2115 break; | |
2116 case Magic('c'): | |
2117 regflags |= RF_ICASE; | |
2118 skipchr_keepstart(); | |
2119 break; | |
2120 case Magic('C'): | |
2121 regflags |= RF_NOICASE; | |
2122 skipchr_keepstart(); | |
2123 break; | |
2124 case Magic('v'): | |
2125 reg_magic = MAGIC_ALL; | |
2126 skipchr_keepstart(); | |
2127 curchr = -1; | |
2128 break; | |
2129 case Magic('m'): | |
2130 reg_magic = MAGIC_ON; | |
2131 skipchr_keepstart(); | |
2132 curchr = -1; | |
2133 break; | |
2134 case Magic('M'): | |
2135 reg_magic = MAGIC_OFF; | |
2136 skipchr_keepstart(); | |
2137 curchr = -1; | |
2138 break; | |
2139 case Magic('V'): | |
2140 reg_magic = MAGIC_NONE; | |
2141 skipchr_keepstart(); | |
2142 curchr = -1; | |
2143 break; | |
2144 | |
2145 default: | |
2146 if (nfa_regpiece() == FAIL) | |
2147 return FAIL; | |
2148 if (first == FALSE) | |
2149 EMIT(NFA_CONCAT); | |
2150 else | |
2151 first = FALSE; | |
2152 break; | |
2153 } | |
2154 } | |
2155 | |
2156 return OK; | |
2157 } | |
2158 | |
2159 /* | |
2160 * Parse a branch, one or more concats, separated by "\&". It matches the | |
2161 * last concat, but only if all the preceding concats also match at the same | |
2162 * position. Examples: | |
2163 * "foobeep\&..." matches "foo" in "foobeep". | |
2164 * ".*Peter\&.*Bob" matches in a line containing both "Peter" and "Bob" | |
2165 * | |
2166 * branch ::= concat | |
2167 * or concat \& concat | |
2168 * or concat \& concat \& concat | |
2169 * etc. | |
2170 */ | |
2171 static int | |
2172 nfa_regbranch() | |
2173 { | |
2174 int ch; | |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2175 int old_post_pos; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2176 |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2177 old_post_pos = (int)(post_ptr - post_start); |
4444 | 2178 |
2179 /* First branch, possibly the only one */ | |
2180 if (nfa_regconcat() == FAIL) | |
2181 return FAIL; | |
2182 | |
2183 ch = peekchr(); | |
2184 /* Try next concats */ | |
2185 while (ch == Magic('&')) | |
2186 { | |
2187 skipchr(); | |
2188 EMIT(NFA_NOPEN); | |
2189 EMIT(NFA_PREV_ATOM_NO_WIDTH); | |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2190 old_post_pos = (int)(post_ptr - post_start); |
4444 | 2191 if (nfa_regconcat() == FAIL) |
2192 return FAIL; | |
5370 | 2193 /* if concat is empty do emit a node */ |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2194 if (old_post_pos == (int)(post_ptr - post_start)) |
5370 | 2195 EMIT(NFA_EMPTY); |
4444 | 2196 EMIT(NFA_CONCAT); |
2197 ch = peekchr(); | |
2198 } | |
2199 | |
5370 | 2200 /* if a branch is empty, emit one node for it */ |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2201 if (old_post_pos == (int)(post_ptr - post_start)) |
5370 | 2202 EMIT(NFA_EMPTY); |
4444 | 2203 |
2204 return OK; | |
2205 } | |
2206 | |
2207 /* | |
2208 * Parse a pattern, one or more branches, separated by "\|". It matches | |
2209 * anything that matches one of the branches. Example: "foo\|beep" matches | |
2210 * "foo" and matches "beep". If more than one branch matches, the first one | |
2211 * is used. | |
2212 * | |
2213 * pattern ::= branch | |
2214 * or branch \| branch | |
2215 * or branch \| branch \| branch | |
2216 * etc. | |
2217 */ | |
2218 static int | |
2219 nfa_reg(paren) | |
2220 int paren; /* REG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN */ | |
2221 { | |
2222 int parno = 0; | |
2223 | |
2224 if (paren == REG_PAREN) | |
2225 { | |
2226 if (regnpar >= NSUBEXP) /* Too many `(' */ | |
2227 EMSG_RET_FAIL(_("E872: (NFA regexp) Too many '('")); | |
2228 parno = regnpar++; | |
2229 } | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2230 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2231 else if (paren == REG_ZPAREN) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2232 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2233 /* Make a ZOPEN node. */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2234 if (regnzpar >= NSUBEXP) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2235 EMSG_RET_FAIL(_("E879: (NFA regexp) Too many \\z(")); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2236 parno = regnzpar++; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2237 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2238 #endif |
4444 | 2239 |
2240 if (nfa_regbranch() == FAIL) | |
2241 return FAIL; /* cascaded error */ | |
2242 | |
2243 while (peekchr() == Magic('|')) | |
2244 { | |
2245 skipchr(); | |
2246 if (nfa_regbranch() == FAIL) | |
2247 return FAIL; /* cascaded error */ | |
2248 EMIT(NFA_OR); | |
2249 } | |
2250 | |
2251 /* Check for proper termination. */ | |
2252 if (paren != REG_NOPAREN && getchr() != Magic(')')) | |
2253 { | |
2254 if (paren == REG_NPAREN) | |
2255 EMSG2_RET_FAIL(_(e_unmatchedpp), reg_magic == MAGIC_ALL); | |
2256 else | |
2257 EMSG2_RET_FAIL(_(e_unmatchedp), reg_magic == MAGIC_ALL); | |
2258 } | |
2259 else if (paren == REG_NOPAREN && peekchr() != NUL) | |
2260 { | |
2261 if (peekchr() == Magic(')')) | |
2262 EMSG2_RET_FAIL(_(e_unmatchedpar), reg_magic == MAGIC_ALL); | |
2263 else | |
2264 EMSG_RET_FAIL(_("E873: (NFA regexp) proper termination error")); | |
2265 } | |
2266 /* | |
2267 * Here we set the flag allowing back references to this set of | |
2268 * parentheses. | |
2269 */ | |
2270 if (paren == REG_PAREN) | |
2271 { | |
2272 had_endbrace[parno] = TRUE; /* have seen the close paren */ | |
2273 EMIT(NFA_MOPEN + parno); | |
2274 } | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2275 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2276 else if (paren == REG_ZPAREN) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2277 EMIT(NFA_ZOPEN + parno); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2278 #endif |
4444 | 2279 |
2280 return OK; | |
2281 } | |
2282 | |
2283 #ifdef DEBUG | |
2284 static char_u code[50]; | |
2285 | |
2286 static void | |
2287 nfa_set_code(c) | |
2288 int c; | |
2289 { | |
2290 int addnl = FALSE; | |
2291 | |
2292 if (c >= NFA_FIRST_NL && c <= NFA_LAST_NL) | |
2293 { | |
2294 addnl = TRUE; | |
5296 | 2295 c -= NFA_ADD_NL; |
4444 | 2296 } |
2297 | |
2298 STRCPY(code, ""); | |
2299 switch (c) | |
2300 { | |
2301 case NFA_MATCH: STRCPY(code, "NFA_MATCH "); break; | |
2302 case NFA_SPLIT: STRCPY(code, "NFA_SPLIT "); break; | |
2303 case NFA_CONCAT: STRCPY(code, "NFA_CONCAT "); break; | |
2304 case NFA_NEWL: STRCPY(code, "NFA_NEWL "); break; | |
2305 case NFA_ZSTART: STRCPY(code, "NFA_ZSTART"); break; | |
2306 case NFA_ZEND: STRCPY(code, "NFA_ZEND"); break; | |
2307 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2308 case NFA_BACKREF1: STRCPY(code, "NFA_BACKREF1"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2309 case NFA_BACKREF2: STRCPY(code, "NFA_BACKREF2"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2310 case NFA_BACKREF3: STRCPY(code, "NFA_BACKREF3"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2311 case NFA_BACKREF4: STRCPY(code, "NFA_BACKREF4"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2312 case NFA_BACKREF5: STRCPY(code, "NFA_BACKREF5"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2313 case NFA_BACKREF6: STRCPY(code, "NFA_BACKREF6"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2314 case NFA_BACKREF7: STRCPY(code, "NFA_BACKREF7"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2315 case NFA_BACKREF8: STRCPY(code, "NFA_BACKREF8"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2316 case NFA_BACKREF9: STRCPY(code, "NFA_BACKREF9"); break; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2317 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2318 case NFA_ZREF1: STRCPY(code, "NFA_ZREF1"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2319 case NFA_ZREF2: STRCPY(code, "NFA_ZREF2"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2320 case NFA_ZREF3: STRCPY(code, "NFA_ZREF3"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2321 case NFA_ZREF4: STRCPY(code, "NFA_ZREF4"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2322 case NFA_ZREF5: STRCPY(code, "NFA_ZREF5"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2323 case NFA_ZREF6: STRCPY(code, "NFA_ZREF6"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2324 case NFA_ZREF7: STRCPY(code, "NFA_ZREF7"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2325 case NFA_ZREF8: STRCPY(code, "NFA_ZREF8"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2326 case NFA_ZREF9: STRCPY(code, "NFA_ZREF9"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2327 #endif |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2328 case NFA_SKIP: STRCPY(code, "NFA_SKIP"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2329 |
4444 | 2330 case NFA_PREV_ATOM_NO_WIDTH: |
2331 STRCPY(code, "NFA_PREV_ATOM_NO_WIDTH"); break; | |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
2332 case NFA_PREV_ATOM_NO_WIDTH_NEG: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
2333 STRCPY(code, "NFA_PREV_ATOM_NO_WIDTH_NEG"); break; |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2334 case NFA_PREV_ATOM_JUST_BEFORE: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2335 STRCPY(code, "NFA_PREV_ATOM_JUST_BEFORE"); break; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2336 case NFA_PREV_ATOM_JUST_BEFORE_NEG: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2337 STRCPY(code, "NFA_PREV_ATOM_JUST_BEFORE_NEG"); break; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2338 case NFA_PREV_ATOM_LIKE_PATTERN: |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2339 STRCPY(code, "NFA_PREV_ATOM_LIKE_PATTERN"); break; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2340 |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
2341 case NFA_NOPEN: STRCPY(code, "NFA_NOPEN"); break; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
2342 case NFA_NCLOSE: STRCPY(code, "NFA_NCLOSE"); break; |
4444 | 2343 case NFA_START_INVISIBLE: STRCPY(code, "NFA_START_INVISIBLE"); break; |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2344 case NFA_START_INVISIBLE_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2345 STRCPY(code, "NFA_START_INVISIBLE_FIRST"); break; |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2346 case NFA_START_INVISIBLE_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2347 STRCPY(code, "NFA_START_INVISIBLE_NEG"); break; |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2348 case NFA_START_INVISIBLE_NEG_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2349 STRCPY(code, "NFA_START_INVISIBLE_NEG_FIRST"); break; |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2350 case NFA_START_INVISIBLE_BEFORE: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2351 STRCPY(code, "NFA_START_INVISIBLE_BEFORE"); break; |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2352 case NFA_START_INVISIBLE_BEFORE_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2353 STRCPY(code, "NFA_START_INVISIBLE_BEFORE_FIRST"); break; |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2354 case NFA_START_INVISIBLE_BEFORE_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2355 STRCPY(code, "NFA_START_INVISIBLE_BEFORE_NEG"); break; |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2356 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2357 STRCPY(code, "NFA_START_INVISIBLE_BEFORE_NEG_FIRST"); break; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2358 case NFA_START_PATTERN: STRCPY(code, "NFA_START_PATTERN"); break; |
4444 | 2359 case NFA_END_INVISIBLE: STRCPY(code, "NFA_END_INVISIBLE"); break; |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2360 case NFA_END_INVISIBLE_NEG: STRCPY(code, "NFA_END_INVISIBLE_NEG"); break; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2361 case NFA_END_PATTERN: STRCPY(code, "NFA_END_PATTERN"); break; |
4444 | 2362 |
2363 case NFA_COMPOSING: STRCPY(code, "NFA_COMPOSING"); break; | |
2364 case NFA_END_COMPOSING: STRCPY(code, "NFA_END_COMPOSING"); break; | |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
2365 case NFA_OPT_CHARS: STRCPY(code, "NFA_OPT_CHARS"); break; |
4444 | 2366 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2367 case NFA_MOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2368 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2369 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2370 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2371 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2372 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2373 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2374 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2375 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2376 case NFA_MOPEN9: |
4444 | 2377 STRCPY(code, "NFA_MOPEN(x)"); |
2378 code[10] = c - NFA_MOPEN + '0'; | |
2379 break; | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2380 case NFA_MCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2381 case NFA_MCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2382 case NFA_MCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2383 case NFA_MCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2384 case NFA_MCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2385 case NFA_MCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2386 case NFA_MCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2387 case NFA_MCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2388 case NFA_MCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2389 case NFA_MCLOSE9: |
4444 | 2390 STRCPY(code, "NFA_MCLOSE(x)"); |
2391 code[11] = c - NFA_MCLOSE + '0'; | |
2392 break; | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2393 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2394 case NFA_ZOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2395 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2396 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2397 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2398 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2399 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2400 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2401 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2402 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2403 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2404 STRCPY(code, "NFA_ZOPEN(x)"); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2405 code[10] = c - NFA_ZOPEN + '0'; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2406 break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2407 case NFA_ZCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2408 case NFA_ZCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2409 case NFA_ZCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2410 case NFA_ZCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2411 case NFA_ZCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2412 case NFA_ZCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2413 case NFA_ZCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2414 case NFA_ZCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2415 case NFA_ZCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2416 case NFA_ZCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2417 STRCPY(code, "NFA_ZCLOSE(x)"); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2418 code[11] = c - NFA_ZCLOSE + '0'; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2419 break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2420 #endif |
4444 | 2421 case NFA_EOL: STRCPY(code, "NFA_EOL "); break; |
2422 case NFA_BOL: STRCPY(code, "NFA_BOL "); break; | |
2423 case NFA_EOW: STRCPY(code, "NFA_EOW "); break; | |
2424 case NFA_BOW: STRCPY(code, "NFA_BOW "); break; | |
4671
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
2425 case NFA_EOF: STRCPY(code, "NFA_EOF "); break; |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
2426 case NFA_BOF: STRCPY(code, "NFA_BOF "); break; |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2427 case NFA_LNUM: STRCPY(code, "NFA_LNUM "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2428 case NFA_LNUM_GT: STRCPY(code, "NFA_LNUM_GT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2429 case NFA_LNUM_LT: STRCPY(code, "NFA_LNUM_LT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2430 case NFA_COL: STRCPY(code, "NFA_COL "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2431 case NFA_COL_GT: STRCPY(code, "NFA_COL_GT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2432 case NFA_COL_LT: STRCPY(code, "NFA_COL_LT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2433 case NFA_VCOL: STRCPY(code, "NFA_VCOL "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2434 case NFA_VCOL_GT: STRCPY(code, "NFA_VCOL_GT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2435 case NFA_VCOL_LT: STRCPY(code, "NFA_VCOL_LT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2436 case NFA_MARK: STRCPY(code, "NFA_MARK "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2437 case NFA_MARK_GT: STRCPY(code, "NFA_MARK_GT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2438 case NFA_MARK_LT: STRCPY(code, "NFA_MARK_LT "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2439 case NFA_CURSOR: STRCPY(code, "NFA_CURSOR "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2440 case NFA_VISUAL: STRCPY(code, "NFA_VISUAL "); break; |
5901 | 2441 case NFA_ANY_COMPOSING: STRCPY(code, "NFA_ANY_COMPOSING "); break; |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2442 |
4444 | 2443 case NFA_STAR: STRCPY(code, "NFA_STAR "); break; |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2444 case NFA_STAR_NONGREEDY: STRCPY(code, "NFA_STAR_NONGREEDY "); break; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2445 case NFA_QUEST: STRCPY(code, "NFA_QUEST"); break; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2446 case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break; |
5370 | 2447 case NFA_EMPTY: STRCPY(code, "NFA_EMPTY"); break; |
4444 | 2448 case NFA_OR: STRCPY(code, "NFA_OR"); break; |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2449 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2450 case NFA_START_COLL: STRCPY(code, "NFA_START_COLL"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2451 case NFA_END_COLL: STRCPY(code, "NFA_END_COLL"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2452 case NFA_START_NEG_COLL: STRCPY(code, "NFA_START_NEG_COLL"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2453 case NFA_END_NEG_COLL: STRCPY(code, "NFA_END_NEG_COLL"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2454 case NFA_RANGE: STRCPY(code, "NFA_RANGE"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2455 case NFA_RANGE_MIN: STRCPY(code, "NFA_RANGE_MIN"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2456 case NFA_RANGE_MAX: STRCPY(code, "NFA_RANGE_MAX"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2457 |
4444 | 2458 case NFA_CLASS_ALNUM: STRCPY(code, "NFA_CLASS_ALNUM"); break; |
2459 case NFA_CLASS_ALPHA: STRCPY(code, "NFA_CLASS_ALPHA"); break; | |
2460 case NFA_CLASS_BLANK: STRCPY(code, "NFA_CLASS_BLANK"); break; | |
2461 case NFA_CLASS_CNTRL: STRCPY(code, "NFA_CLASS_CNTRL"); break; | |
2462 case NFA_CLASS_DIGIT: STRCPY(code, "NFA_CLASS_DIGIT"); break; | |
2463 case NFA_CLASS_GRAPH: STRCPY(code, "NFA_CLASS_GRAPH"); break; | |
2464 case NFA_CLASS_LOWER: STRCPY(code, "NFA_CLASS_LOWER"); break; | |
2465 case NFA_CLASS_PRINT: STRCPY(code, "NFA_CLASS_PRINT"); break; | |
2466 case NFA_CLASS_PUNCT: STRCPY(code, "NFA_CLASS_PUNCT"); break; | |
2467 case NFA_CLASS_SPACE: STRCPY(code, "NFA_CLASS_SPACE"); break; | |
2468 case NFA_CLASS_UPPER: STRCPY(code, "NFA_CLASS_UPPER"); break; | |
2469 case NFA_CLASS_XDIGIT: STRCPY(code, "NFA_CLASS_XDIGIT"); break; | |
2470 case NFA_CLASS_TAB: STRCPY(code, "NFA_CLASS_TAB"); break; | |
2471 case NFA_CLASS_RETURN: STRCPY(code, "NFA_CLASS_RETURN"); break; | |
2472 case NFA_CLASS_BACKSPACE: STRCPY(code, "NFA_CLASS_BACKSPACE"); break; | |
2473 case NFA_CLASS_ESCAPE: STRCPY(code, "NFA_CLASS_ESCAPE"); break; | |
2474 | |
2475 case NFA_ANY: STRCPY(code, "NFA_ANY"); break; | |
2476 case NFA_IDENT: STRCPY(code, "NFA_IDENT"); break; | |
2477 case NFA_SIDENT:STRCPY(code, "NFA_SIDENT"); break; | |
2478 case NFA_KWORD: STRCPY(code, "NFA_KWORD"); break; | |
2479 case NFA_SKWORD:STRCPY(code, "NFA_SKWORD"); break; | |
2480 case NFA_FNAME: STRCPY(code, "NFA_FNAME"); break; | |
2481 case NFA_SFNAME:STRCPY(code, "NFA_SFNAME"); break; | |
2482 case NFA_PRINT: STRCPY(code, "NFA_PRINT"); break; | |
2483 case NFA_SPRINT:STRCPY(code, "NFA_SPRINT"); break; | |
2484 case NFA_WHITE: STRCPY(code, "NFA_WHITE"); break; | |
2485 case NFA_NWHITE:STRCPY(code, "NFA_NWHITE"); break; | |
2486 case NFA_DIGIT: STRCPY(code, "NFA_DIGIT"); break; | |
2487 case NFA_NDIGIT:STRCPY(code, "NFA_NDIGIT"); break; | |
2488 case NFA_HEX: STRCPY(code, "NFA_HEX"); break; | |
2489 case NFA_NHEX: STRCPY(code, "NFA_NHEX"); break; | |
2490 case NFA_OCTAL: STRCPY(code, "NFA_OCTAL"); break; | |
2491 case NFA_NOCTAL:STRCPY(code, "NFA_NOCTAL"); break; | |
2492 case NFA_WORD: STRCPY(code, "NFA_WORD"); break; | |
2493 case NFA_NWORD: STRCPY(code, "NFA_NWORD"); break; | |
2494 case NFA_HEAD: STRCPY(code, "NFA_HEAD"); break; | |
2495 case NFA_NHEAD: STRCPY(code, "NFA_NHEAD"); break; | |
2496 case NFA_ALPHA: STRCPY(code, "NFA_ALPHA"); break; | |
2497 case NFA_NALPHA:STRCPY(code, "NFA_NALPHA"); break; | |
2498 case NFA_LOWER: STRCPY(code, "NFA_LOWER"); break; | |
2499 case NFA_NLOWER:STRCPY(code, "NFA_NLOWER"); break; | |
2500 case NFA_UPPER: STRCPY(code, "NFA_UPPER"); break; | |
2501 case NFA_NUPPER:STRCPY(code, "NFA_NUPPER"); break; | |
5296 | 2502 case NFA_LOWER_IC: STRCPY(code, "NFA_LOWER_IC"); break; |
2503 case NFA_NLOWER_IC: STRCPY(code, "NFA_NLOWER_IC"); break; | |
2504 case NFA_UPPER_IC: STRCPY(code, "NFA_UPPER_IC"); break; | |
2505 case NFA_NUPPER_IC: STRCPY(code, "NFA_NUPPER_IC"); break; | |
4444 | 2506 |
2507 default: | |
2508 STRCPY(code, "CHAR(x)"); | |
2509 code[5] = c; | |
2510 } | |
2511 | |
2512 if (addnl == TRUE) | |
2513 STRCAT(code, " + NEWLINE "); | |
2514 | |
2515 } | |
2516 | |
2517 #ifdef ENABLE_LOG | |
2518 static FILE *log_fd; | |
2519 | |
2520 /* | |
2521 * Print the postfix notation of the current regexp. | |
2522 */ | |
2523 static void | |
2524 nfa_postfix_dump(expr, retval) | |
2525 char_u *expr; | |
2526 int retval; | |
2527 { | |
2528 int *p; | |
2529 FILE *f; | |
2530 | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2531 f = fopen(NFA_REGEXP_DUMP_LOG, "a"); |
4444 | 2532 if (f != NULL) |
2533 { | |
2534 fprintf(f, "\n-------------------------\n"); | |
2535 if (retval == FAIL) | |
2536 fprintf(f, ">>> NFA engine failed ... \n"); | |
2537 else if (retval == OK) | |
2538 fprintf(f, ">>> NFA engine succeeded !\n"); | |
2539 fprintf(f, "Regexp: \"%s\"\nPostfix notation (char): \"", expr); | |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
2540 for (p = post_start; *p && p < post_ptr; p++) |
4444 | 2541 { |
2542 nfa_set_code(*p); | |
2543 fprintf(f, "%s, ", code); | |
2544 } | |
2545 fprintf(f, "\"\nPostfix notation (int): "); | |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
2546 for (p = post_start; *p && p < post_ptr; p++) |
4444 | 2547 fprintf(f, "%d ", *p); |
2548 fprintf(f, "\n\n"); | |
2549 fclose(f); | |
2550 } | |
2551 } | |
2552 | |
2553 /* | |
2554 * Print the NFA starting with a root node "state". | |
2555 */ | |
2556 static void | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2557 nfa_print_state(debugf, state) |
4444 | 2558 FILE *debugf; |
2559 nfa_state_T *state; | |
2560 { | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2561 garray_T indent; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2562 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2563 ga_init2(&indent, 1, 64); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2564 ga_append(&indent, '\0'); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2565 nfa_print_state2(debugf, state, &indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2566 ga_clear(&indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2567 } |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2568 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2569 static void |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2570 nfa_print_state2(debugf, state, indent) |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2571 FILE *debugf; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2572 nfa_state_T *state; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2573 garray_T *indent; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2574 { |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2575 char_u *p; |
4444 | 2576 |
2577 if (state == NULL) | |
2578 return; | |
2579 | |
2580 fprintf(debugf, "(%2d)", abs(state->id)); | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2581 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2582 /* Output indent */ |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2583 p = (char_u *)indent->ga_data; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2584 if (indent->ga_len >= 3) |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2585 { |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2586 int last = indent->ga_len - 3; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2587 char_u save[2]; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2588 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2589 STRNCPY(save, &p[last], 2); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2590 STRNCPY(&p[last], "+-", 2); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2591 fprintf(debugf, " %s", p); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2592 STRNCPY(&p[last], save, 2); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2593 } |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2594 else |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2595 fprintf(debugf, " %s", p); |
4444 | 2596 |
2597 nfa_set_code(state->c); | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2598 fprintf(debugf, "%s (%d) (id=%d) val=%d\n", |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2599 code, |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2600 state->c, |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2601 abs(state->id), |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2602 state->val); |
4444 | 2603 if (state->id < 0) |
2604 return; | |
2605 | |
2606 state->id = abs(state->id) * -1; | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2607 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2608 /* grow indent for state->out */ |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2609 indent->ga_len -= 1; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2610 if (state->out1) |
4537
5cc98a5898cf
updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents:
4535
diff
changeset
|
2611 ga_concat(indent, (char_u *)"| "); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2612 else |
4537
5cc98a5898cf
updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents:
4535
diff
changeset
|
2613 ga_concat(indent, (char_u *)" "); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2614 ga_append(indent, '\0'); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2615 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2616 nfa_print_state2(debugf, state->out, indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2617 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2618 /* replace last part of indent for state->out1 */ |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2619 indent->ga_len -= 3; |
4537
5cc98a5898cf
updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents:
4535
diff
changeset
|
2620 ga_concat(indent, (char_u *)" "); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2621 ga_append(indent, '\0'); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2622 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2623 nfa_print_state2(debugf, state->out1, indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2624 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2625 /* shrink indent */ |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2626 indent->ga_len -= 3; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2627 ga_append(indent, '\0'); |
4444 | 2628 } |
2629 | |
2630 /* | |
2631 * Print the NFA state machine. | |
2632 */ | |
2633 static void | |
2634 nfa_dump(prog) | |
2635 nfa_regprog_T *prog; | |
2636 { | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2637 FILE *debugf = fopen(NFA_REGEXP_DUMP_LOG, "a"); |
4444 | 2638 |
2639 if (debugf != NULL) | |
2640 { | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2641 nfa_print_state(debugf, prog->start); |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2642 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2643 if (prog->reganch) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2644 fprintf(debugf, "reganch: %d\n", prog->reganch); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2645 if (prog->regstart != NUL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2646 fprintf(debugf, "regstart: %c (decimal: %d)\n", |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2647 prog->regstart, prog->regstart); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2648 if (prog->match_text != NULL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2649 fprintf(debugf, "match_text: \"%s\"\n", prog->match_text); |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2650 |
4444 | 2651 fclose(debugf); |
2652 } | |
2653 } | |
2654 #endif /* ENABLE_LOG */ | |
2655 #endif /* DEBUG */ | |
2656 | |
2657 /* | |
2658 * Parse r.e. @expr and convert it into postfix form. | |
2659 * Return the postfix string on success, NULL otherwise. | |
2660 */ | |
2661 static int * | |
2662 re2post() | |
2663 { | |
2664 if (nfa_reg(REG_NOPAREN) == FAIL) | |
2665 return NULL; | |
2666 EMIT(NFA_MOPEN); | |
2667 return post_start; | |
2668 } | |
2669 | |
2670 /* NB. Some of the code below is inspired by Russ's. */ | |
2671 | |
2672 /* | |
2673 * Represents an NFA state plus zero or one or two arrows exiting. | |
2674 * if c == MATCH, no arrows out; matching state. | |
2675 * If c == SPLIT, unlabeled arrows to out and out1 (if != NULL). | |
2676 * If c < 256, labeled arrow with character c to out. | |
2677 */ | |
2678 | |
2679 static nfa_state_T *state_ptr; /* points to nfa_prog->state */ | |
2680 | |
2681 /* | |
2682 * Allocate and initialize nfa_state_T. | |
2683 */ | |
2684 static nfa_state_T * | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
2685 alloc_state(c, out, out1) |
4444 | 2686 int c; |
2687 nfa_state_T *out; | |
2688 nfa_state_T *out1; | |
2689 { | |
2690 nfa_state_T *s; | |
2691 | |
2692 if (istate >= nstate) | |
2693 return NULL; | |
2694 | |
2695 s = &state_ptr[istate++]; | |
2696 | |
2697 s->c = c; | |
2698 s->out = out; | |
2699 s->out1 = out1; | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2700 s->val = 0; |
4444 | 2701 |
2702 s->id = istate; | |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
2703 s->lastlist[0] = 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
2704 s->lastlist[1] = 0; |
4444 | 2705 |
2706 return s; | |
2707 } | |
2708 | |
2709 /* | |
2710 * A partially built NFA without the matching state filled in. | |
2711 * Frag_T.start points at the start state. | |
2712 * Frag_T.out is a list of places that need to be set to the | |
2713 * next state for this fragment. | |
2714 */ | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2715 |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2716 /* Since the out pointers in the list are always |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2717 * uninitialized, we use the pointers themselves |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2718 * as storage for the Ptrlists. */ |
4444 | 2719 typedef union Ptrlist Ptrlist; |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2720 union Ptrlist |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2721 { |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2722 Ptrlist *next; |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2723 nfa_state_T *s; |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2724 }; |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2725 |
4444 | 2726 struct Frag |
2727 { | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2728 nfa_state_T *start; |
4444 | 2729 Ptrlist *out; |
2730 }; | |
2731 typedef struct Frag Frag_T; | |
2732 | |
2733 static Frag_T frag __ARGS((nfa_state_T *start, Ptrlist *out)); | |
2734 static Ptrlist *list1 __ARGS((nfa_state_T **outp)); | |
2735 static void patch __ARGS((Ptrlist *l, nfa_state_T *s)); | |
2736 static Ptrlist *append __ARGS((Ptrlist *l1, Ptrlist *l2)); | |
2737 static void st_push __ARGS((Frag_T s, Frag_T **p, Frag_T *stack_end)); | |
2738 static Frag_T st_pop __ARGS((Frag_T **p, Frag_T *stack)); | |
2739 | |
2740 /* | |
4456 | 2741 * Initialize a Frag_T struct and return it. |
4444 | 2742 */ |
2743 static Frag_T | |
2744 frag(start, out) | |
2745 nfa_state_T *start; | |
2746 Ptrlist *out; | |
2747 { | |
4456 | 2748 Frag_T n; |
2749 | |
2750 n.start = start; | |
2751 n.out = out; | |
4444 | 2752 return n; |
2753 } | |
2754 | |
2755 /* | |
2756 * Create singleton list containing just outp. | |
2757 */ | |
2758 static Ptrlist * | |
2759 list1(outp) | |
2760 nfa_state_T **outp; | |
2761 { | |
2762 Ptrlist *l; | |
2763 | |
2764 l = (Ptrlist *)outp; | |
2765 l->next = NULL; | |
2766 return l; | |
2767 } | |
2768 | |
2769 /* | |
2770 * Patch the list of states at out to point to start. | |
2771 */ | |
2772 static void | |
2773 patch(l, s) | |
2774 Ptrlist *l; | |
2775 nfa_state_T *s; | |
2776 { | |
2777 Ptrlist *next; | |
2778 | |
2779 for (; l; l = next) | |
2780 { | |
2781 next = l->next; | |
2782 l->s = s; | |
2783 } | |
2784 } | |
2785 | |
2786 | |
2787 /* | |
2788 * Join the two lists l1 and l2, returning the combination. | |
2789 */ | |
2790 static Ptrlist * | |
2791 append(l1, l2) | |
2792 Ptrlist *l1; | |
2793 Ptrlist *l2; | |
2794 { | |
2795 Ptrlist *oldl1; | |
2796 | |
2797 oldl1 = l1; | |
2798 while (l1->next) | |
2799 l1 = l1->next; | |
2800 l1->next = l2; | |
2801 return oldl1; | |
2802 } | |
2803 | |
2804 /* | |
2805 * Stack used for transforming postfix form into NFA. | |
2806 */ | |
2807 static Frag_T empty; | |
2808 | |
2809 static void | |
2810 st_error(postfix, end, p) | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2811 int *postfix UNUSED; |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2812 int *end UNUSED; |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2813 int *p UNUSED; |
4444 | 2814 { |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2815 #ifdef NFA_REGEXP_ERROR_LOG |
4444 | 2816 FILE *df; |
2817 int *p2; | |
2818 | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2819 df = fopen(NFA_REGEXP_ERROR_LOG, "a"); |
4444 | 2820 if (df) |
2821 { | |
2822 fprintf(df, "Error popping the stack!\n"); | |
2823 #ifdef DEBUG | |
2824 fprintf(df, "Current regexp is \"%s\"\n", nfa_regengine.expr); | |
2825 #endif | |
2826 fprintf(df, "Postfix form is: "); | |
2827 #ifdef DEBUG | |
2828 for (p2 = postfix; p2 < end; p2++) | |
2829 { | |
2830 nfa_set_code(*p2); | |
2831 fprintf(df, "%s, ", code); | |
2832 } | |
2833 nfa_set_code(*p); | |
2834 fprintf(df, "\nCurrent position is: "); | |
2835 for (p2 = postfix; p2 <= p; p2 ++) | |
2836 { | |
2837 nfa_set_code(*p2); | |
2838 fprintf(df, "%s, ", code); | |
2839 } | |
2840 #else | |
2841 for (p2 = postfix; p2 < end; p2++) | |
2842 { | |
2843 fprintf(df, "%d, ", *p2); | |
2844 } | |
2845 fprintf(df, "\nCurrent position is: "); | |
2846 for (p2 = postfix; p2 <= p; p2 ++) | |
2847 { | |
2848 fprintf(df, "%d, ", *p2); | |
2849 } | |
2850 #endif | |
2851 fprintf(df, "\n--------------------------\n"); | |
2852 fclose(df); | |
2853 } | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2854 #endif |
4444 | 2855 EMSG(_("E874: (NFA) Could not pop the stack !")); |
2856 } | |
2857 | |
2858 /* | |
2859 * Push an item onto the stack. | |
2860 */ | |
2861 static void | |
2862 st_push(s, p, stack_end) | |
2863 Frag_T s; | |
2864 Frag_T **p; | |
2865 Frag_T *stack_end; | |
2866 { | |
2867 Frag_T *stackp = *p; | |
2868 | |
2869 if (stackp >= stack_end) | |
2870 return; | |
2871 *stackp = s; | |
2872 *p = *p + 1; | |
2873 } | |
2874 | |
2875 /* | |
2876 * Pop an item from the stack. | |
2877 */ | |
2878 static Frag_T | |
2879 st_pop(p, stack) | |
2880 Frag_T **p; | |
2881 Frag_T *stack; | |
2882 { | |
2883 Frag_T *stackp; | |
2884 | |
2885 *p = *p - 1; | |
2886 stackp = *p; | |
2887 if (stackp < stack) | |
2888 return empty; | |
2889 return **p; | |
2890 } | |
2891 | |
2892 /* | |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2893 * Estimate the maximum byte length of anything matching "state". |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2894 * When unknown or unlimited return -1. |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2895 */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2896 static int |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2897 nfa_max_width(startstate, depth) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2898 nfa_state_T *startstate; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2899 int depth; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2900 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2901 int l, r; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2902 nfa_state_T *state = startstate; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2903 int len = 0; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2904 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2905 /* detect looping in a NFA_SPLIT */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2906 if (depth > 4) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2907 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2908 |
4958
0a379dea13c9
updated for version 7.3.1224
Bram Moolenaar <bram@vim.org>
parents:
4944
diff
changeset
|
2909 while (state != NULL) |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2910 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2911 switch (state->c) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2912 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2913 case NFA_END_INVISIBLE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2914 case NFA_END_INVISIBLE_NEG: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2915 /* the end, return what we have */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2916 return len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2917 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2918 case NFA_SPLIT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2919 /* two alternatives, use the maximum */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2920 l = nfa_max_width(state->out, depth + 1); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2921 r = nfa_max_width(state->out1, depth + 1); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2922 if (l < 0 || r < 0) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2923 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2924 return len + (l > r ? l : r); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2925 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2926 case NFA_ANY: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2927 case NFA_START_COLL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2928 case NFA_START_NEG_COLL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2929 /* matches some character, including composing chars */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2930 #ifdef FEAT_MBYTE |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2931 if (enc_utf8) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2932 len += MB_MAXBYTES; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2933 else if (has_mbyte) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2934 len += 2; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2935 else |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2936 #endif |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2937 ++len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2938 if (state->c != NFA_ANY) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2939 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2940 /* skip over the characters */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2941 state = state->out1->out; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2942 continue; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2943 } |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2944 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2945 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2946 case NFA_DIGIT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2947 case NFA_WHITE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2948 case NFA_HEX: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2949 case NFA_OCTAL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2950 /* ascii */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2951 ++len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2952 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2953 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2954 case NFA_IDENT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2955 case NFA_SIDENT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2956 case NFA_KWORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2957 case NFA_SKWORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2958 case NFA_FNAME: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2959 case NFA_SFNAME: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2960 case NFA_PRINT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2961 case NFA_SPRINT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2962 case NFA_NWHITE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2963 case NFA_NDIGIT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2964 case NFA_NHEX: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2965 case NFA_NOCTAL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2966 case NFA_WORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2967 case NFA_NWORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2968 case NFA_HEAD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2969 case NFA_NHEAD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2970 case NFA_ALPHA: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2971 case NFA_NALPHA: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2972 case NFA_LOWER: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2973 case NFA_NLOWER: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2974 case NFA_UPPER: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2975 case NFA_NUPPER: |
5296 | 2976 case NFA_LOWER_IC: |
2977 case NFA_NLOWER_IC: | |
2978 case NFA_UPPER_IC: | |
2979 case NFA_NUPPER_IC: | |
5901 | 2980 case NFA_ANY_COMPOSING: |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2981 /* possibly non-ascii */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2982 #ifdef FEAT_MBYTE |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2983 if (has_mbyte) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2984 len += 3; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2985 else |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2986 #endif |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2987 ++len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2988 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2989 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2990 case NFA_START_INVISIBLE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2991 case NFA_START_INVISIBLE_NEG: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2992 case NFA_START_INVISIBLE_BEFORE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2993 case NFA_START_INVISIBLE_BEFORE_NEG: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2994 /* zero-width, out1 points to the END state */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2995 state = state->out1->out; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2996 continue; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2997 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2998 case NFA_BACKREF1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2999 case NFA_BACKREF2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3000 case NFA_BACKREF3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3001 case NFA_BACKREF4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3002 case NFA_BACKREF5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3003 case NFA_BACKREF6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3004 case NFA_BACKREF7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3005 case NFA_BACKREF8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3006 case NFA_BACKREF9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3007 #ifdef FEAT_SYN_HL |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3008 case NFA_ZREF1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3009 case NFA_ZREF2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3010 case NFA_ZREF3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3011 case NFA_ZREF4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3012 case NFA_ZREF5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3013 case NFA_ZREF6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3014 case NFA_ZREF7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3015 case NFA_ZREF8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3016 case NFA_ZREF9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3017 #endif |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3018 case NFA_NEWL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3019 case NFA_SKIP: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3020 /* unknown width */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3021 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3022 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3023 case NFA_BOL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3024 case NFA_EOL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3025 case NFA_BOF: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3026 case NFA_EOF: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3027 case NFA_BOW: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3028 case NFA_EOW: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3029 case NFA_MOPEN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3030 case NFA_MOPEN1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3031 case NFA_MOPEN2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3032 case NFA_MOPEN3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3033 case NFA_MOPEN4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3034 case NFA_MOPEN5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3035 case NFA_MOPEN6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3036 case NFA_MOPEN7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3037 case NFA_MOPEN8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3038 case NFA_MOPEN9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3039 #ifdef FEAT_SYN_HL |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3040 case NFA_ZOPEN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3041 case NFA_ZOPEN1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3042 case NFA_ZOPEN2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3043 case NFA_ZOPEN3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3044 case NFA_ZOPEN4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3045 case NFA_ZOPEN5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3046 case NFA_ZOPEN6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3047 case NFA_ZOPEN7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3048 case NFA_ZOPEN8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3049 case NFA_ZOPEN9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3050 case NFA_ZCLOSE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3051 case NFA_ZCLOSE1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3052 case NFA_ZCLOSE2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3053 case NFA_ZCLOSE3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3054 case NFA_ZCLOSE4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3055 case NFA_ZCLOSE5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3056 case NFA_ZCLOSE6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3057 case NFA_ZCLOSE7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3058 case NFA_ZCLOSE8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3059 case NFA_ZCLOSE9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3060 #endif |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3061 case NFA_MCLOSE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3062 case NFA_MCLOSE1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3063 case NFA_MCLOSE2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3064 case NFA_MCLOSE3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3065 case NFA_MCLOSE4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3066 case NFA_MCLOSE5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3067 case NFA_MCLOSE6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3068 case NFA_MCLOSE7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3069 case NFA_MCLOSE8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3070 case NFA_MCLOSE9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3071 case NFA_NOPEN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3072 case NFA_NCLOSE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3073 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3074 case NFA_LNUM_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3075 case NFA_LNUM_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3076 case NFA_COL_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3077 case NFA_COL_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3078 case NFA_VCOL_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3079 case NFA_VCOL_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3080 case NFA_MARK_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3081 case NFA_MARK_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3082 case NFA_VISUAL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3083 case NFA_LNUM: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3084 case NFA_CURSOR: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3085 case NFA_COL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3086 case NFA_VCOL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3087 case NFA_MARK: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3088 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3089 case NFA_ZSTART: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3090 case NFA_ZEND: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3091 case NFA_OPT_CHARS: |
5370 | 3092 case NFA_EMPTY: |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3093 case NFA_START_PATTERN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3094 case NFA_END_PATTERN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3095 case NFA_COMPOSING: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3096 case NFA_END_COMPOSING: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3097 /* zero-width */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3098 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3099 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3100 default: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3101 if (state->c < 0) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3102 /* don't know what this is */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3103 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3104 /* normal character */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3105 len += MB_CHAR2LEN(state->c); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3106 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3107 } |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3108 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3109 /* normal way to continue */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3110 state = state->out; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3111 } |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3112 |
4958
0a379dea13c9
updated for version 7.3.1224
Bram Moolenaar <bram@vim.org>
parents:
4944
diff
changeset
|
3113 /* unrecognized, "cannot happen" */ |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3114 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3115 } |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
3116 |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3117 /* |
4444 | 3118 * Convert a postfix form into its equivalent NFA. |
3119 * Return the NFA start state on success, NULL otherwise. | |
3120 */ | |
3121 static nfa_state_T * | |
3122 post2nfa(postfix, end, nfa_calc_size) | |
3123 int *postfix; | |
3124 int *end; | |
3125 int nfa_calc_size; | |
3126 { | |
3127 int *p; | |
3128 int mopen; | |
3129 int mclose; | |
3130 Frag_T *stack = NULL; | |
3131 Frag_T *stackp = NULL; | |
3132 Frag_T *stack_end = NULL; | |
3133 Frag_T e1; | |
3134 Frag_T e2; | |
3135 Frag_T e; | |
3136 nfa_state_T *s; | |
3137 nfa_state_T *s1; | |
3138 nfa_state_T *matchstate; | |
4484 | 3139 nfa_state_T *ret = NULL; |
4444 | 3140 |
3141 if (postfix == NULL) | |
3142 return NULL; | |
3143 | |
4456 | 3144 #define PUSH(s) st_push((s), &stackp, stack_end) |
4444 | 3145 #define POP() st_pop(&stackp, stack); \ |
3146 if (stackp < stack) \ | |
3147 { \ | |
3148 st_error(postfix, end, p); \ | |
3149 return NULL; \ | |
3150 } | |
3151 | |
3152 if (nfa_calc_size == FALSE) | |
3153 { | |
3154 /* Allocate space for the stack. Max states on the stack : nstate */ | |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3155 stack = (Frag_T *)lalloc((nstate + 1) * sizeof(Frag_T), TRUE); |
4444 | 3156 stackp = stack; |
4462 | 3157 stack_end = stack + (nstate + 1); |
4444 | 3158 } |
3159 | |
3160 for (p = postfix; p < end; ++p) | |
3161 { | |
3162 switch (*p) | |
3163 { | |
3164 case NFA_CONCAT: | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3165 /* Concatenation. |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3166 * Pay attention: this operator does not exist in the r.e. itself |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3167 * (it is implicit, really). It is added when r.e. is translated |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3168 * to postfix form in re2post(). */ |
4444 | 3169 if (nfa_calc_size == TRUE) |
3170 { | |
4458 | 3171 /* nstate += 0; */ |
4444 | 3172 break; |
3173 } | |
3174 e2 = POP(); | |
3175 e1 = POP(); | |
3176 patch(e1.out, e2.start); | |
3177 PUSH(frag(e1.start, e2.out)); | |
3178 break; | |
3179 | |
3180 case NFA_OR: | |
3181 /* Alternation */ | |
3182 if (nfa_calc_size == TRUE) | |
3183 { | |
4458 | 3184 nstate++; |
4444 | 3185 break; |
3186 } | |
3187 e2 = POP(); | |
3188 e1 = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3189 s = alloc_state(NFA_SPLIT, e1.start, e2.start); |
4444 | 3190 if (s == NULL) |
4484 | 3191 goto theend; |
4444 | 3192 PUSH(frag(s, append(e1.out, e2.out))); |
3193 break; | |
3194 | |
3195 case NFA_STAR: | |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3196 /* Zero or more, prefer more */ |
4444 | 3197 if (nfa_calc_size == TRUE) |
3198 { | |
4458 | 3199 nstate++; |
4444 | 3200 break; |
3201 } | |
3202 e = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3203 s = alloc_state(NFA_SPLIT, e.start, NULL); |
4444 | 3204 if (s == NULL) |
4484 | 3205 goto theend; |
4444 | 3206 patch(e.out, s); |
3207 PUSH(frag(s, list1(&s->out1))); | |
3208 break; | |
3209 | |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3210 case NFA_STAR_NONGREEDY: |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3211 /* Zero or more, prefer zero */ |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3212 if (nfa_calc_size == TRUE) |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3213 { |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3214 nstate++; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3215 break; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3216 } |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3217 e = POP(); |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3218 s = alloc_state(NFA_SPLIT, NULL, e.start); |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3219 if (s == NULL) |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3220 goto theend; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3221 patch(e.out, s); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3222 PUSH(frag(s, list1(&s->out))); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3223 break; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3224 |
4444 | 3225 case NFA_QUEST: |
3226 /* one or zero atoms=> greedy match */ | |
3227 if (nfa_calc_size == TRUE) | |
3228 { | |
4458 | 3229 nstate++; |
4444 | 3230 break; |
3231 } | |
3232 e = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3233 s = alloc_state(NFA_SPLIT, e.start, NULL); |
4444 | 3234 if (s == NULL) |
4484 | 3235 goto theend; |
4444 | 3236 PUSH(frag(s, append(e.out, list1(&s->out1)))); |
3237 break; | |
3238 | |
3239 case NFA_QUEST_NONGREEDY: | |
3240 /* zero or one atoms => non-greedy match */ | |
3241 if (nfa_calc_size == TRUE) | |
3242 { | |
4458 | 3243 nstate++; |
4444 | 3244 break; |
3245 } | |
3246 e = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3247 s = alloc_state(NFA_SPLIT, NULL, e.start); |
4444 | 3248 if (s == NULL) |
4484 | 3249 goto theend; |
4444 | 3250 PUSH(frag(s, append(e.out, list1(&s->out)))); |
3251 break; | |
3252 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3253 case NFA_END_COLL: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3254 case NFA_END_NEG_COLL: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3255 /* On the stack is the sequence starting with NFA_START_COLL or |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3256 * NFA_START_NEG_COLL and all possible characters. Patch it to |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3257 * add the output to the start. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3258 if (nfa_calc_size == TRUE) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3259 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3260 nstate++; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3261 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3262 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3263 e = POP(); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3264 s = alloc_state(NFA_END_COLL, NULL, NULL); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3265 if (s == NULL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3266 goto theend; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3267 patch(e.out, s); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3268 e.start->out1 = s; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3269 PUSH(frag(e.start, list1(&s->out))); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3270 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3271 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3272 case NFA_RANGE: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3273 /* Before this are two characters, the low and high end of a |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3274 * range. Turn them into two states with MIN and MAX. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3275 if (nfa_calc_size == TRUE) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3276 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3277 /* nstate += 0; */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3278 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3279 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3280 e2 = POP(); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3281 e1 = POP(); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3282 e2.start->val = e2.start->c; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3283 e2.start->c = NFA_RANGE_MAX; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3284 e1.start->val = e1.start->c; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3285 e1.start->c = NFA_RANGE_MIN; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3286 patch(e1.out, e2.start); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3287 PUSH(frag(e1.start, e2.out)); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3288 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3289 |
5370 | 3290 case NFA_EMPTY: |
3291 /* 0-length, used in a repetition with max/min count of 0 */ | |
4444 | 3292 if (nfa_calc_size == TRUE) |
3293 { | |
4458 | 3294 nstate++; |
4444 | 3295 break; |
3296 } | |
5370 | 3297 s = alloc_state(NFA_EMPTY, NULL, NULL); |
4444 | 3298 if (s == NULL) |
4484 | 3299 goto theend; |
4444 | 3300 PUSH(frag(s, list1(&s->out))); |
3301 break; | |
3302 | |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3303 case NFA_OPT_CHARS: |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3304 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3305 int n; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3306 |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3307 /* \%[abc] implemented as: |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3308 * NFA_SPLIT |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3309 * +-CHAR(a) |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3310 * | +-NFA_SPLIT |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3311 * | +-CHAR(b) |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3312 * | | +-NFA_SPLIT |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3313 * | | +-CHAR(c) |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3314 * | | | +-next |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3315 * | | +- next |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3316 * | +- next |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3317 * +- next |
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
3318 */ |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3319 n = *++p; /* get number of characters */ |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3320 if (nfa_calc_size == TRUE) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3321 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3322 nstate += n; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3323 break; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3324 } |
4758
b25a1b2e3175
updated for version 7.3.1126
Bram Moolenaar <bram@vim.org>
parents:
4756
diff
changeset
|
3325 s = NULL; /* avoid compiler warning */ |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3326 e1.out = NULL; /* stores list with out1's */ |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3327 s1 = NULL; /* previous NFA_SPLIT to connect to */ |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3328 while (n-- > 0) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3329 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3330 e = POP(); /* get character */ |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3331 s = alloc_state(NFA_SPLIT, e.start, NULL); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3332 if (s == NULL) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3333 goto theend; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3334 if (e1.out == NULL) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3335 e1 = e; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3336 patch(e.out, s1); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3337 append(e1.out, list1(&s->out1)); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3338 s1 = s; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3339 } |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3340 PUSH(frag(s, e1.out)); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3341 break; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3342 } |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3343 |
4444 | 3344 case NFA_PREV_ATOM_NO_WIDTH: |
4661
0dce3d812e7a
updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents:
4657
diff
changeset
|
3345 case NFA_PREV_ATOM_NO_WIDTH_NEG: |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3346 case NFA_PREV_ATOM_JUST_BEFORE: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3347 case NFA_PREV_ATOM_JUST_BEFORE_NEG: |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3348 case NFA_PREV_ATOM_LIKE_PATTERN: |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3349 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3350 int before = (*p == NFA_PREV_ATOM_JUST_BEFORE |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3351 || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG); |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3352 int pattern = (*p == NFA_PREV_ATOM_LIKE_PATTERN); |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3353 int start_state; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3354 int end_state; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3355 int n = 0; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3356 nfa_state_T *zend; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3357 nfa_state_T *skip; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3358 |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3359 switch (*p) |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3360 { |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3361 case NFA_PREV_ATOM_NO_WIDTH: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3362 start_state = NFA_START_INVISIBLE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3363 end_state = NFA_END_INVISIBLE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3364 break; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3365 case NFA_PREV_ATOM_NO_WIDTH_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3366 start_state = NFA_START_INVISIBLE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3367 end_state = NFA_END_INVISIBLE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3368 break; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3369 case NFA_PREV_ATOM_JUST_BEFORE: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3370 start_state = NFA_START_INVISIBLE_BEFORE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3371 end_state = NFA_END_INVISIBLE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3372 break; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3373 case NFA_PREV_ATOM_JUST_BEFORE_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3374 start_state = NFA_START_INVISIBLE_BEFORE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3375 end_state = NFA_END_INVISIBLE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3376 break; |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4815
diff
changeset
|
3377 default: /* NFA_PREV_ATOM_LIKE_PATTERN: */ |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3378 start_state = NFA_START_PATTERN; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3379 end_state = NFA_END_PATTERN; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3380 break; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3381 } |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3382 |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3383 if (before) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3384 n = *++p; /* get the count */ |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3385 |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
3386 /* The \@= operator: match the preceding atom with zero width. |
4661
0dce3d812e7a
updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents:
4657
diff
changeset
|
3387 * The \@! operator: no match for the preceding atom. |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3388 * The \@<= operator: match for the preceding atom. |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3389 * The \@<! operator: no match for the preceding atom. |
4444 | 3390 * Surrounds the preceding atom with START_INVISIBLE and |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
3391 * END_INVISIBLE, similarly to MOPEN. */ |
4444 | 3392 |
3393 if (nfa_calc_size == TRUE) | |
3394 { | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3395 nstate += pattern ? 4 : 2; |
4444 | 3396 break; |
3397 } | |
3398 e = POP(); | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3399 s1 = alloc_state(end_state, NULL, NULL); |
4444 | 3400 if (s1 == NULL) |
4484 | 3401 goto theend; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3402 |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3403 s = alloc_state(start_state, e.start, s1); |
4444 | 3404 if (s == NULL) |
4484 | 3405 goto theend; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3406 if (pattern) |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3407 { |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3408 /* NFA_ZEND -> NFA_END_PATTERN -> NFA_SKIP -> what follows. */ |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3409 skip = alloc_state(NFA_SKIP, NULL, NULL); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3410 zend = alloc_state(NFA_ZEND, s1, NULL); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3411 s1->out= skip; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3412 patch(e.out, zend); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3413 PUSH(frag(s, list1(&skip->out))); |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3414 } |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3415 else |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3416 { |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3417 patch(e.out, s1); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3418 PUSH(frag(s, list1(&s1->out))); |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3419 if (before) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3420 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3421 if (n <= 0) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3422 /* See if we can guess the maximum width, it avoids a |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3423 * lot of pointless tries. */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3424 n = nfa_max_width(e.start, 0); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3425 s->val = n; /* store the count */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3426 } |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3427 } |
4444 | 3428 break; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3429 } |
4444 | 3430 |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
3431 #ifdef FEAT_MBYTE |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3432 case NFA_COMPOSING: /* char with composing char */ |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3433 #if 0 |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3434 /* TODO */ |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3435 if (regflags & RF_ICOMBINE) |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3436 { |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
3437 /* use the base character only */ |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3438 } |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3439 #endif |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3440 /* FALLTHROUGH */ |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
3441 #endif |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3442 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3443 case NFA_MOPEN: /* \( \) Submatch */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3444 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3445 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3446 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3447 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3448 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3449 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3450 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3451 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3452 case NFA_MOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3453 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3454 case NFA_ZOPEN: /* \z( \) Submatch */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3455 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3456 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3457 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3458 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3459 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3460 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3461 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3462 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3463 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3464 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3465 case NFA_NOPEN: /* \%( \) "Invisible Submatch" */ |
4444 | 3466 if (nfa_calc_size == TRUE) |
3467 { | |
3468 nstate += 2; | |
3469 break; | |
3470 } | |
3471 | |
3472 mopen = *p; | |
3473 switch (*p) | |
3474 { | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3475 case NFA_NOPEN: mclose = NFA_NCLOSE; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3476 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3477 case NFA_ZOPEN: mclose = NFA_ZCLOSE; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3478 case NFA_ZOPEN1: mclose = NFA_ZCLOSE1; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3479 case NFA_ZOPEN2: mclose = NFA_ZCLOSE2; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3480 case NFA_ZOPEN3: mclose = NFA_ZCLOSE3; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3481 case NFA_ZOPEN4: mclose = NFA_ZCLOSE4; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3482 case NFA_ZOPEN5: mclose = NFA_ZCLOSE5; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3483 case NFA_ZOPEN6: mclose = NFA_ZCLOSE6; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3484 case NFA_ZOPEN7: mclose = NFA_ZCLOSE7; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3485 case NFA_ZOPEN8: mclose = NFA_ZCLOSE8; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3486 case NFA_ZOPEN9: mclose = NFA_ZCLOSE9; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3487 #endif |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
3488 #ifdef FEAT_MBYTE |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3489 case NFA_COMPOSING: mclose = NFA_END_COMPOSING; break; |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
3490 #endif |
4444 | 3491 default: |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3492 /* NFA_MOPEN, NFA_MOPEN1 .. NFA_MOPEN9 */ |
4444 | 3493 mclose = *p + NSUBEXP; |
3494 break; | |
3495 } | |
3496 | |
3497 /* Allow "NFA_MOPEN" as a valid postfix representation for | |
3498 * the empty regexp "". In this case, the NFA will be | |
3499 * NFA_MOPEN -> NFA_MCLOSE. Note that this also allows | |
3500 * empty groups of parenthesis, and empty mbyte chars */ | |
3501 if (stackp == stack) | |
3502 { | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3503 s = alloc_state(mopen, NULL, NULL); |
4444 | 3504 if (s == NULL) |
4484 | 3505 goto theend; |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3506 s1 = alloc_state(mclose, NULL, NULL); |
4444 | 3507 if (s1 == NULL) |
4484 | 3508 goto theend; |
4444 | 3509 patch(list1(&s->out), s1); |
3510 PUSH(frag(s, list1(&s1->out))); | |
3511 break; | |
3512 } | |
3513 | |
3514 /* At least one node was emitted before NFA_MOPEN, so | |
3515 * at least one node will be between NFA_MOPEN and NFA_MCLOSE */ | |
3516 e = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3517 s = alloc_state(mopen, e.start, NULL); /* `(' */ |
4444 | 3518 if (s == NULL) |
4484 | 3519 goto theend; |
4444 | 3520 |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3521 s1 = alloc_state(mclose, NULL, NULL); /* `)' */ |
4444 | 3522 if (s1 == NULL) |
4484 | 3523 goto theend; |
4444 | 3524 patch(e.out, s1); |
3525 | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
3526 #ifdef FEAT_MBYTE |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3527 if (mopen == NFA_COMPOSING) |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3528 /* COMPOSING->out1 = END_COMPOSING */ |
4444 | 3529 patch(list1(&s->out1), s1); |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
3530 #endif |
4444 | 3531 |
3532 PUSH(frag(s, list1(&s1->out))); | |
3533 break; | |
3534 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3535 case NFA_BACKREF1: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3536 case NFA_BACKREF2: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3537 case NFA_BACKREF3: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3538 case NFA_BACKREF4: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3539 case NFA_BACKREF5: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3540 case NFA_BACKREF6: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3541 case NFA_BACKREF7: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3542 case NFA_BACKREF8: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3543 case NFA_BACKREF9: |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3544 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3545 case NFA_ZREF1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3546 case NFA_ZREF2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3547 case NFA_ZREF3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3548 case NFA_ZREF4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3549 case NFA_ZREF5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3550 case NFA_ZREF6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3551 case NFA_ZREF7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3552 case NFA_ZREF8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3553 case NFA_ZREF9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3554 #endif |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3555 if (nfa_calc_size == TRUE) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3556 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3557 nstate += 2; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3558 break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3559 } |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3560 s = alloc_state(*p, NULL, NULL); |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3561 if (s == NULL) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3562 goto theend; |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3563 s1 = alloc_state(NFA_SKIP, NULL, NULL); |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3564 if (s1 == NULL) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3565 goto theend; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3566 patch(list1(&s->out), s1); |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3567 PUSH(frag(s, list1(&s1->out))); |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3568 break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3569 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3570 case NFA_LNUM: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3571 case NFA_LNUM_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3572 case NFA_LNUM_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3573 case NFA_VCOL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3574 case NFA_VCOL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3575 case NFA_VCOL_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3576 case NFA_COL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3577 case NFA_COL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3578 case NFA_COL_LT: |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
3579 case NFA_MARK: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
3580 case NFA_MARK_GT: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
3581 case NFA_MARK_LT: |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3582 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3583 int n = *++p; /* lnum, col or mark name */ |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3584 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3585 if (nfa_calc_size == TRUE) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3586 { |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3587 nstate += 1; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3588 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3589 } |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3590 s = alloc_state(p[-1], NULL, NULL); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3591 if (s == NULL) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3592 goto theend; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3593 s->val = n; |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3594 PUSH(frag(s, list1(&s->out))); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3595 break; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3596 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3597 |
4444 | 3598 case NFA_ZSTART: |
3599 case NFA_ZEND: | |
3600 default: | |
3601 /* Operands */ | |
3602 if (nfa_calc_size == TRUE) | |
3603 { | |
4458 | 3604 nstate++; |
4444 | 3605 break; |
3606 } | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3607 s = alloc_state(*p, NULL, NULL); |
4444 | 3608 if (s == NULL) |
4484 | 3609 goto theend; |
4444 | 3610 PUSH(frag(s, list1(&s->out))); |
3611 break; | |
3612 | |
3613 } /* switch(*p) */ | |
3614 | |
3615 } /* for(p = postfix; *p; ++p) */ | |
3616 | |
3617 if (nfa_calc_size == TRUE) | |
3618 { | |
4458 | 3619 nstate++; |
4484 | 3620 goto theend; /* Return value when counting size is ignored anyway */ |
4444 | 3621 } |
3622 | |
3623 e = POP(); | |
3624 if (stackp != stack) | |
3625 EMSG_RET_NULL(_("E875: (NFA regexp) (While converting from postfix to NFA), too many states left on stack")); | |
3626 | |
3627 if (istate >= nstate) | |
3628 EMSG_RET_NULL(_("E876: (NFA regexp) Not enough space to store the whole NFA ")); | |
3629 | |
3630 matchstate = &state_ptr[istate++]; /* the match state */ | |
3631 matchstate->c = NFA_MATCH; | |
3632 matchstate->out = matchstate->out1 = NULL; | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3633 matchstate->id = 0; |
4444 | 3634 |
3635 patch(e.out, matchstate); | |
4484 | 3636 ret = e.start; |
3637 | |
3638 theend: | |
3639 vim_free(stack); | |
3640 return ret; | |
4444 | 3641 |
3642 #undef POP1 | |
3643 #undef PUSH1 | |
3644 #undef POP2 | |
3645 #undef PUSH2 | |
3646 #undef POP | |
3647 #undef PUSH | |
3648 } | |
3649 | |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3650 /* |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3651 * After building the NFA program, inspect it to add optimization hints. |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3652 */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3653 static void |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3654 nfa_postprocess(prog) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3655 nfa_regprog_T *prog; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3656 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3657 int i; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3658 int c; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3659 |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3660 for (i = 0; i < prog->nstate; ++i) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3661 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3662 c = prog->state[i].c; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3663 if (c == NFA_START_INVISIBLE |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3664 || c == NFA_START_INVISIBLE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3665 || c == NFA_START_INVISIBLE_BEFORE |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3666 || c == NFA_START_INVISIBLE_BEFORE_NEG) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3667 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3668 int directly; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3669 |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3670 /* Do it directly when what follows is possibly the end of the |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3671 * match. */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3672 if (match_follows(prog->state[i].out1->out, 0)) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3673 directly = TRUE; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3674 else |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3675 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3676 int ch_invisible = failure_chance(prog->state[i].out, 0); |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3677 int ch_follows = failure_chance(prog->state[i].out1->out, 0); |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3678 |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3679 /* Postpone when the invisible match is expensive or has a |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3680 * lower chance of failing. */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3681 if (c == NFA_START_INVISIBLE_BEFORE |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3682 || c == NFA_START_INVISIBLE_BEFORE_NEG) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3683 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3684 /* "before" matches are very expensive when |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3685 * unbounded, always prefer what follows then, |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3686 * unless what follows will always match. |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3687 * Otherwise strongly prefer what follows. */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3688 if (prog->state[i].val <= 0 && ch_follows > 0) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3689 directly = FALSE; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3690 else |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3691 directly = ch_follows * 10 < ch_invisible; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3692 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3693 else |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3694 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3695 /* normal invisible, first do the one with the |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3696 * highest failure chance */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3697 directly = ch_follows < ch_invisible; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3698 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3699 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3700 if (directly) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3701 /* switch to the _FIRST state */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3702 ++prog->state[i].c; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3703 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3704 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3705 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3706 |
4444 | 3707 /**************************************************************** |
3708 * NFA execution code. | |
3709 ****************************************************************/ | |
3710 | |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3711 typedef struct |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3712 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3713 int in_use; /* number of subexpr with useful info */ |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3714 |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3715 /* When REG_MULTI is TRUE list.multi is used, otherwise list.line. */ |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3716 union |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3717 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3718 struct multipos |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3719 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3720 lpos_T start; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3721 lpos_T end; |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3722 } multi[NSUBEXP]; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3723 struct linepos |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3724 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3725 char_u *start; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3726 char_u *end; |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3727 } line[NSUBEXP]; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3728 } list; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3729 } regsub_T; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3730 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3731 typedef struct |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3732 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3733 regsub_T norm; /* \( .. \) matches */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3734 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3735 regsub_T synt; /* \z( .. \) matches */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3736 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3737 } regsubs_T; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3738 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3739 /* nfa_pim_T stores a Postponed Invisible Match. */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3740 typedef struct nfa_pim_S nfa_pim_T; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3741 struct nfa_pim_S |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3742 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3743 int result; /* NFA_PIM_*, see below */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3744 nfa_state_T *state; /* the invisible match start state */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3745 regsubs_T subs; /* submatch info, only party used */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3746 union |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3747 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3748 lpos_T pos; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3749 char_u *ptr; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3750 } end; /* where the match must end */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3751 }; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3752 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3753 /* Values for done in nfa_pim_T. */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3754 #define NFA_PIM_UNUSED 0 /* pim not used */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3755 #define NFA_PIM_TODO 1 /* pim not done yet */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3756 #define NFA_PIM_MATCH 2 /* pim executed, matches */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3757 #define NFA_PIM_NOMATCH 3 /* pim executed, no match */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3758 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3759 |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
3760 /* nfa_thread_T contains execution information of a NFA state */ |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
3761 typedef struct |
4444 | 3762 { |
3763 nfa_state_T *state; | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3764 int count; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3765 nfa_pim_T pim; /* if pim.result != NFA_PIM_UNUSED: postponed |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3766 * invisible match */ |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3767 regsubs_T subs; /* submatch info, only party used */ |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
3768 } nfa_thread_T; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
3769 |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
3770 /* nfa_list_T contains the alternative NFA execution states. */ |
4444 | 3771 typedef struct |
3772 { | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3773 nfa_thread_T *t; /* allocated array of states */ |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3774 int n; /* nr of states currently in "t" */ |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3775 int len; /* max nr of states in "t" */ |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3776 int id; /* ID of the list */ |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
3777 int has_pim; /* TRUE when any state has a PIM */ |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
3778 } nfa_list_T; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
3779 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3780 #ifdef ENABLE_LOG |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3781 static void log_subsexpr __ARGS((regsubs_T *subs)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3782 static void log_subexpr __ARGS((regsub_T *sub)); |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
3783 static char *pim_info __ARGS((nfa_pim_T *pim)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3784 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3785 static void |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3786 log_subsexpr(subs) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3787 regsubs_T *subs; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3788 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3789 log_subexpr(&subs->norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3790 # ifdef FEAT_SYN_HL |
4770
b20dbf3a5370
updated for version 7.3.1132
Bram Moolenaar <bram@vim.org>
parents:
4768
diff
changeset
|
3791 if (nfa_has_zsubexpr) |
b20dbf3a5370
updated for version 7.3.1132
Bram Moolenaar <bram@vim.org>
parents:
4768
diff
changeset
|
3792 log_subexpr(&subs->synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3793 # endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3794 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3795 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3796 static void |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3797 log_subexpr(sub) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3798 regsub_T *sub; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3799 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3800 int j; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3801 |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3802 for (j = 0; j < sub->in_use; j++) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3803 if (REG_MULTI) |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3804 fprintf(log_fd, "*** group %d, start: c=%d, l=%d, end: c=%d, l=%d\n", |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3805 j, |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3806 sub->list.multi[j].start.col, |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3807 (int)sub->list.multi[j].start.lnum, |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3808 sub->list.multi[j].end.col, |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3809 (int)sub->list.multi[j].end.lnum); |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3810 else |
4746
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3811 { |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3812 char *s = (char *)sub->list.line[j].start; |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3813 char *e = (char *)sub->list.line[j].end; |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3814 |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3815 fprintf(log_fd, "*** group %d, start: \"%s\", end: \"%s\"\n", |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3816 j, |
4746
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3817 s == NULL ? "NULL" : s, |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3818 e == NULL ? "NULL" : e); |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3819 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3820 } |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3821 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3822 static char * |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
3823 pim_info(pim) |
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
3824 nfa_pim_T *pim; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3825 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3826 static char buf[30]; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3827 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3828 if (pim == NULL || pim->result == NFA_PIM_UNUSED) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3829 buf[0] = NUL; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3830 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3831 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3832 sprintf(buf, " PIM col %d", REG_MULTI ? (int)pim->end.pos.col |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3833 : (int)(pim->end.ptr - reginput)); |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3834 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3835 return buf; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3836 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3837 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3838 #endif |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3839 |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
3840 /* Used during execution: whether a match has been found. */ |
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
3841 static int nfa_match; |
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
3842 |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3843 static void copy_pim __ARGS((nfa_pim_T *to, nfa_pim_T *from)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3844 static void clear_sub __ARGS((regsub_T *sub)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3845 static void copy_sub __ARGS((regsub_T *to, regsub_T *from)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3846 static void copy_sub_off __ARGS((regsub_T *to, regsub_T *from)); |
5372 | 3847 static void copy_ze_off __ARGS((regsub_T *to, regsub_T *from)); |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3848 static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2)); |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
3849 static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen)); |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
3850 static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim)); |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
3851 static int pim_equal __ARGS((nfa_pim_T *one, nfa_pim_T *two)); |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
3852 static int state_in_list __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs)); |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
3853 static regsubs_T *addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs_arg, nfa_pim_T *pim, int off)); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3854 static void addstate_here __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int *ip)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3855 |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3856 /* |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3857 * Copy postponed invisible match info from "from" to "to". |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3858 */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3859 static void |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3860 copy_pim(to, from) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3861 nfa_pim_T *to; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3862 nfa_pim_T *from; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3863 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3864 to->result = from->result; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3865 to->state = from->state; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3866 copy_sub(&to->subs.norm, &from->subs.norm); |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3867 #ifdef FEAT_SYN_HL |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3868 if (nfa_has_zsubexpr) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3869 copy_sub(&to->subs.synt, &from->subs.synt); |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3870 #endif |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3871 to->end = from->end; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3872 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3873 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3874 static void |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3875 clear_sub(sub) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3876 regsub_T *sub; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3877 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3878 if (REG_MULTI) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3879 /* Use 0xff to set lnum to -1 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3880 vim_memset(sub->list.multi, 0xff, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3881 sizeof(struct multipos) * nfa_nsubexpr); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3882 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3883 vim_memset(sub->list.line, 0, sizeof(struct linepos) * nfa_nsubexpr); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3884 sub->in_use = 0; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3885 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3886 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3887 /* |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3888 * Copy the submatches from "from" to "to". |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3889 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3890 static void |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3891 copy_sub(to, from) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3892 regsub_T *to; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3893 regsub_T *from; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3894 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3895 to->in_use = from->in_use; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3896 if (from->in_use > 0) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3897 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3898 /* Copy the match start and end positions. */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3899 if (REG_MULTI) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3900 mch_memmove(&to->list.multi[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3901 &from->list.multi[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3902 sizeof(struct multipos) * from->in_use); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3903 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3904 mch_memmove(&to->list.line[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3905 &from->list.line[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3906 sizeof(struct linepos) * from->in_use); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3907 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3908 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3909 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3910 /* |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3911 * Like copy_sub() but exclude the main match. |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3912 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3913 static void |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3914 copy_sub_off(to, from) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3915 regsub_T *to; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3916 regsub_T *from; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3917 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3918 if (to->in_use < from->in_use) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3919 to->in_use = from->in_use; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3920 if (from->in_use > 1) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3921 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3922 /* Copy the match start and end positions. */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3923 if (REG_MULTI) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3924 mch_memmove(&to->list.multi[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3925 &from->list.multi[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3926 sizeof(struct multipos) * (from->in_use - 1)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3927 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3928 mch_memmove(&to->list.line[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3929 &from->list.line[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3930 sizeof(struct linepos) * (from->in_use - 1)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3931 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3932 } |
4444 | 3933 |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3934 /* |
5372 | 3935 * Like copy_sub() but only do the end of the main match if \ze is present. |
3936 */ | |
3937 static void | |
3938 copy_ze_off(to, from) | |
3939 regsub_T *to; | |
3940 regsub_T *from; | |
3941 { | |
3942 if (nfa_has_zend) | |
3943 { | |
3944 if (REG_MULTI) | |
3945 { | |
3946 if (from->list.multi[0].end.lnum >= 0) | |
3947 to->list.multi[0].end = from->list.multi[0].end; | |
3948 } | |
3949 else | |
3950 { | |
3951 if (from->list.line[0].end != NULL) | |
3952 to->list.line[0].end = from->list.line[0].end; | |
3953 } | |
3954 } | |
3955 } | |
3956 | |
3957 /* | |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
3958 * Return TRUE if "sub1" and "sub2" have the same start positions. |
5893 | 3959 * When using back-references also check the end position. |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3960 */ |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3961 static int |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3962 sub_equal(sub1, sub2) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3963 regsub_T *sub1; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3964 regsub_T *sub2; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3965 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3966 int i; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3967 int todo; |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
3968 linenr_T s1; |
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
3969 linenr_T s2; |
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
3970 char_u *sp1; |
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
3971 char_u *sp2; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3972 |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3973 todo = sub1->in_use > sub2->in_use ? sub1->in_use : sub2->in_use; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3974 if (REG_MULTI) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3975 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3976 for (i = 0; i < todo; ++i) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3977 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3978 if (i < sub1->in_use) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3979 s1 = sub1->list.multi[i].start.lnum; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3980 else |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
3981 s1 = -1; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3982 if (i < sub2->in_use) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3983 s2 = sub2->list.multi[i].start.lnum; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3984 else |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
3985 s2 = -1; |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
3986 if (s1 != s2) |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3987 return FALSE; |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
3988 if (s1 != -1 && sub1->list.multi[i].start.col |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3989 != sub2->list.multi[i].start.col) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
3990 return FALSE; |
5893 | 3991 |
3992 if (nfa_has_backref) | |
3993 { | |
3994 if (i < sub1->in_use) | |
3995 s1 = sub1->list.multi[i].end.lnum; | |
3996 else | |
3997 s1 = -1; | |
3998 if (i < sub2->in_use) | |
3999 s2 = sub2->list.multi[i].end.lnum; | |
4000 else | |
4001 s2 = -1; | |
4002 if (s1 != s2) | |
4003 return FALSE; | |
4004 if (s1 != -1 && sub1->list.multi[i].end.col | |
4005 != sub2->list.multi[i].end.col) | |
4006 return FALSE; | |
4007 } | |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4008 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4009 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4010 else |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4011 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4012 for (i = 0; i < todo; ++i) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4013 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4014 if (i < sub1->in_use) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4015 sp1 = sub1->list.line[i].start; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4016 else |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4017 sp1 = NULL; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4018 if (i < sub2->in_use) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4019 sp2 = sub2->list.line[i].start; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4020 else |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4021 sp2 = NULL; |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4022 if (sp1 != sp2) |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4023 return FALSE; |
5893 | 4024 if (nfa_has_backref) |
4025 { | |
4026 if (i < sub1->in_use) | |
4027 sp1 = sub1->list.line[i].end; | |
4028 else | |
4029 sp1 = NULL; | |
4030 if (i < sub2->in_use) | |
4031 sp2 = sub2->list.line[i].end; | |
4032 else | |
4033 sp2 = NULL; | |
4034 if (sp1 != sp2) | |
4035 return FALSE; | |
4036 } | |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4037 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4038 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4039 |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4040 return TRUE; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4041 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4042 |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4043 #ifdef ENABLE_LOG |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4044 static void |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4045 report_state(char *action, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4046 regsub_T *sub, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4047 nfa_state_T *state, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4048 int lid, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4049 nfa_pim_T *pim) |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4050 { |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4051 int col; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4052 |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4053 if (sub->in_use <= 0) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4054 col = -1; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4055 else if (REG_MULTI) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4056 col = sub->list.multi[0].start.col; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4057 else |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4058 col = (int)(sub->list.line[0].start - regline); |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4059 nfa_set_code(state->c); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4060 fprintf(log_fd, "> %s state %d to list %d. char %d: %s (start col %d)%s\n", |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4061 action, abs(state->id), lid, state->c, code, col, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4062 pim_info(pim)); |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4063 } |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4064 #endif |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4065 |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4066 /* |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4067 * Return TRUE if the same state is already in list "l" with the same |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4068 * positions as "subs". |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4069 */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4070 static int |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4071 has_state_with_pos(l, state, subs, pim) |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4072 nfa_list_T *l; /* runtime state list */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4073 nfa_state_T *state; /* state to update */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4074 regsubs_T *subs; /* pointers to subexpressions */ |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4075 nfa_pim_T *pim; /* postponed match or NULL */ |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4076 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4077 nfa_thread_T *thread; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4078 int i; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4079 |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4080 for (i = 0; i < l->n; ++i) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4081 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4082 thread = &l->t[i]; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4083 if (thread->state->id == state->id |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4084 && sub_equal(&thread->subs.norm, &subs->norm) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4085 #ifdef FEAT_SYN_HL |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4086 && (!nfa_has_zsubexpr |
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4087 || sub_equal(&thread->subs.synt, &subs->synt)) |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4088 #endif |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4089 && pim_equal(&thread->pim, pim)) |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4090 return TRUE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4091 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4092 return FALSE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4093 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4094 |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4095 /* |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4096 * Return TRUE if "one" and "two" are equal. That includes when both are not |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4097 * set. |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4098 */ |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4099 static int |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4100 pim_equal(one, two) |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4101 nfa_pim_T *one; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4102 nfa_pim_T *two; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4103 { |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4104 int one_unused = (one == NULL || one->result == NFA_PIM_UNUSED); |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4105 int two_unused = (two == NULL || two->result == NFA_PIM_UNUSED); |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4106 |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4107 if (one_unused) |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4108 /* one is unused: equal when two is also unused */ |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4109 return two_unused; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4110 if (two_unused) |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4111 /* one is used and two is not: not equal */ |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4112 return FALSE; |
5298 | 4113 /* compare the state id */ |
4114 if (one->state->id != two->state->id) | |
4115 return FALSE; | |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4116 /* compare the position */ |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4117 if (REG_MULTI) |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4118 return one->end.pos.lnum == two->end.pos.lnum |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4119 && one->end.pos.col == two->end.pos.col; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4120 return one->end.ptr == two->end.ptr; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4121 } |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4122 |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4123 /* |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4124 * Return TRUE if "state" leads to a NFA_MATCH without advancing the input. |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4125 */ |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4126 static int |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4127 match_follows(startstate, depth) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4128 nfa_state_T *startstate; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4129 int depth; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4130 { |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4131 nfa_state_T *state = startstate; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4132 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4133 /* avoid too much recursion */ |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4134 if (depth > 10) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4135 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4136 |
5184
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5074
diff
changeset
|
4137 while (state != NULL) |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4138 { |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4139 switch (state->c) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4140 { |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4141 case NFA_MATCH: |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4142 case NFA_MCLOSE: |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4143 case NFA_END_INVISIBLE: |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4144 case NFA_END_INVISIBLE_NEG: |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4145 case NFA_END_PATTERN: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4146 return TRUE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4147 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4148 case NFA_SPLIT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4149 return match_follows(state->out, depth + 1) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4150 || match_follows(state->out1, depth + 1); |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4151 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4152 case NFA_START_INVISIBLE: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4153 case NFA_START_INVISIBLE_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4154 case NFA_START_INVISIBLE_BEFORE: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4155 case NFA_START_INVISIBLE_BEFORE_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4156 case NFA_START_INVISIBLE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4157 case NFA_START_INVISIBLE_NEG_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4158 case NFA_START_INVISIBLE_BEFORE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4159 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4160 case NFA_COMPOSING: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4161 /* skip ahead to next state */ |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4162 state = state->out1->out; |
5184
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5074
diff
changeset
|
4163 continue; |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4164 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4165 case NFA_ANY: |
5901 | 4166 case NFA_ANY_COMPOSING: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4167 case NFA_IDENT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4168 case NFA_SIDENT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4169 case NFA_KWORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4170 case NFA_SKWORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4171 case NFA_FNAME: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4172 case NFA_SFNAME: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4173 case NFA_PRINT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4174 case NFA_SPRINT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4175 case NFA_WHITE: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4176 case NFA_NWHITE: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4177 case NFA_DIGIT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4178 case NFA_NDIGIT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4179 case NFA_HEX: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4180 case NFA_NHEX: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4181 case NFA_OCTAL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4182 case NFA_NOCTAL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4183 case NFA_WORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4184 case NFA_NWORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4185 case NFA_HEAD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4186 case NFA_NHEAD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4187 case NFA_ALPHA: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4188 case NFA_NALPHA: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4189 case NFA_LOWER: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4190 case NFA_NLOWER: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4191 case NFA_UPPER: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4192 case NFA_NUPPER: |
5296 | 4193 case NFA_LOWER_IC: |
4194 case NFA_NLOWER_IC: | |
4195 case NFA_UPPER_IC: | |
4196 case NFA_NUPPER_IC: | |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4197 case NFA_START_COLL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4198 case NFA_START_NEG_COLL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4199 case NFA_NEWL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4200 /* state will advance input */ |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4201 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4202 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4203 default: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4204 if (state->c > 0) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4205 /* state will advance input */ |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4206 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4207 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4208 /* Others: zero-width or possibly zero-width, might still find |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4209 * a match at the same position, keep looking. */ |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4210 break; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4211 } |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4212 state = state->out; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4213 } |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4214 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4215 } |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4216 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4217 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4218 /* |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4219 * Return TRUE if "state" is already in list "l". |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4220 */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4221 static int |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4222 state_in_list(l, state, subs) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4223 nfa_list_T *l; /* runtime state list */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4224 nfa_state_T *state; /* state to update */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4225 regsubs_T *subs; /* pointers to subexpressions */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4226 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4227 if (state->lastlist[nfa_ll_index] == l->id) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4228 { |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4229 if (!nfa_has_backref || has_state_with_pos(l, state, subs, NULL)) |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4230 return TRUE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4231 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4232 return FALSE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4233 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4234 |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4235 /* |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4236 * Add "state" and possibly what follows to state list ".". |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4237 * Returns "subs_arg", possibly copied into temp_subs. |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4238 */ |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4239 |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4240 static regsubs_T * |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4241 addstate(l, state, subs_arg, pim, off) |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4242 nfa_list_T *l; /* runtime state list */ |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4243 nfa_state_T *state; /* state to update */ |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4244 regsubs_T *subs_arg; /* pointers to subexpressions */ |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4245 nfa_pim_T *pim; /* postponed look-behind match */ |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4246 int off; /* byte offset, when -1 go to next line */ |
4444 | 4247 { |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4248 int subidx; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4249 nfa_thread_T *thread; |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4250 lpos_T save_lpos; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4251 int save_in_use; |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4252 char_u *save_ptr; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4253 int i; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4254 regsub_T *sub; |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4255 regsubs_T *subs = subs_arg; |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4256 static regsubs_T temp_subs; |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4257 #ifdef ENABLE_LOG |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4258 int did_print = FALSE; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4259 #endif |
4444 | 4260 |
4261 switch (state->c) | |
4262 { | |
4263 case NFA_NCLOSE: | |
4264 case NFA_MCLOSE: | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4265 case NFA_MCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4266 case NFA_MCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4267 case NFA_MCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4268 case NFA_MCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4269 case NFA_MCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4270 case NFA_MCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4271 case NFA_MCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4272 case NFA_MCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4273 case NFA_MCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4274 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4275 case NFA_ZCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4276 case NFA_ZCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4277 case NFA_ZCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4278 case NFA_ZCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4279 case NFA_ZCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4280 case NFA_ZCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4281 case NFA_ZCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4282 case NFA_ZCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4283 case NFA_ZCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4284 case NFA_ZCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4285 #endif |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4286 case NFA_MOPEN: |
4748
4b9503f0c7d3
updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents:
4746
diff
changeset
|
4287 case NFA_ZEND: |
4815
6419ee8098c8
updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents:
4813
diff
changeset
|
4288 case NFA_SPLIT: |
5370 | 4289 case NFA_EMPTY: |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4290 /* These nodes are not added themselves but their "out" and/or |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4291 * "out1" may be added below. */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4292 break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4293 |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4294 case NFA_BOL: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4295 case NFA_BOF: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4296 /* "^" won't match past end-of-line, don't bother trying. |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4297 * Except when at the end of the line, or when we are going to the |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4298 * next line for a look-behind match. */ |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4299 if (reginput > regline |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4300 && *reginput != NUL |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4301 && (nfa_endp == NULL |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4302 || !REG_MULTI |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4303 || reglnum == nfa_endp->se_u.pos.lnum)) |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4304 goto skip_add; |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4305 /* FALLTHROUGH */ |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4306 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4307 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4308 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4309 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4310 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4311 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4312 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4313 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4314 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4315 case NFA_MOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4316 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4317 case NFA_ZOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4318 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4319 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4320 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4321 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4322 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4323 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4324 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4325 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4326 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4327 #endif |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4328 case NFA_NOPEN: |
4748
4b9503f0c7d3
updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents:
4746
diff
changeset
|
4329 case NFA_ZSTART: |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4330 /* These nodes need to be added so that we can bail out when it |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4331 * was added to this list before at the same position to avoid an |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4332 * endless loop for "\(\)*" */ |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
4333 |
4444 | 4334 default: |
5502 | 4335 if (state->lastlist[nfa_ll_index] == l->id && state->c != NFA_SKIP) |
4444 | 4336 { |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4337 /* This state is already in the list, don't add it again, |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
4338 * unless it is an MOPEN that is used for a backreference or |
5895 | 4339 * when there is a PIM. For NFA_MATCH check the position, |
4340 * lower position is preferred. */ | |
4341 if (!nfa_has_backref && pim == NULL && !l->has_pim | |
4342 && state->c != NFA_MATCH) | |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4343 { |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4344 skip_add: |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4345 #ifdef ENABLE_LOG |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4346 nfa_set_code(state->c); |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4347 fprintf(log_fd, "> Not adding state %d to list %d. char %d: %s\n", |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4348 abs(state->id), l->id, state->c, code); |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4349 #endif |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4350 return subs; |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4351 } |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4352 |
4815
6419ee8098c8
updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents:
4813
diff
changeset
|
4353 /* Do not add the state again when it exists with the same |
6419ee8098c8
updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents:
4813
diff
changeset
|
4354 * positions. */ |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4355 if (has_state_with_pos(l, state, subs, pim)) |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4356 goto skip_add; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4357 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4358 |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
4359 /* When there are backreferences or PIMs the number of states may |
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
4360 * be (a lot) bigger than anticipated. */ |
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
4361 if (l->n == l->len) |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4362 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4363 int newlen = l->len * 3 / 2 + 50; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4364 |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4365 if (subs != &temp_subs) |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4366 { |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4367 /* "subs" may point into the current array, need to make a |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4368 * copy before it becomes invalid. */ |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4369 copy_sub(&temp_subs.norm, &subs->norm); |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4370 #ifdef FEAT_SYN_HL |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4371 if (nfa_has_zsubexpr) |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4372 copy_sub(&temp_subs.synt, &subs->synt); |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4373 #endif |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4374 subs = &temp_subs; |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4375 } |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4376 |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4377 l->t = vim_realloc(l->t, newlen * sizeof(nfa_thread_T)); |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4378 l->len = newlen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4379 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4380 |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4381 /* add the state to the list */ |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4382 state->lastlist[nfa_ll_index] = l->id; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4383 thread = &l->t[l->n++]; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4384 thread->state = state; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4385 if (pim == NULL) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4386 thread->pim.result = NFA_PIM_UNUSED; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4387 else |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
4388 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4389 copy_pim(&thread->pim, pim); |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
4390 l->has_pim = TRUE; |
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
4391 } |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4392 copy_sub(&thread->subs.norm, &subs->norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4393 #ifdef FEAT_SYN_HL |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4394 if (nfa_has_zsubexpr) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4395 copy_sub(&thread->subs.synt, &subs->synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4396 #endif |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4397 #ifdef ENABLE_LOG |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4398 report_state("Adding", &thread->subs.norm, state, l->id, pim); |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4399 did_print = TRUE; |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4400 #endif |
4444 | 4401 } |
4402 | |
4403 #ifdef ENABLE_LOG | |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4404 if (!did_print) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4405 report_state("Processing", &subs->norm, state, l->id, pim); |
4444 | 4406 #endif |
4407 switch (state->c) | |
4408 { | |
4409 case NFA_MATCH: | |
5901 | 4410 // nfa_match = TRUE; |
4444 | 4411 break; |
4412 | |
4413 case NFA_SPLIT: | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4414 /* order matters here */ |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4415 subs = addstate(l, state->out, subs, pim, off); |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4416 subs = addstate(l, state->out1, subs, pim, off); |
4444 | 4417 break; |
4418 | |
5370 | 4419 case NFA_EMPTY: |
4444 | 4420 case NFA_NOPEN: |
4421 case NFA_NCLOSE: | |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4422 subs = addstate(l, state->out, subs, pim, off); |
4444 | 4423 break; |
4424 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4425 case NFA_MOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4426 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4427 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4428 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4429 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4430 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4431 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4432 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4433 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4434 case NFA_MOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4435 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4436 case NFA_ZOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4437 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4438 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4439 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4440 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4441 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4442 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4443 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4444 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4445 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4446 #endif |
4444 | 4447 case NFA_ZSTART: |
4448 if (state->c == NFA_ZSTART) | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4449 { |
4444 | 4450 subidx = 0; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4451 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4452 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4453 #ifdef FEAT_SYN_HL |
5300 | 4454 else if (state->c >= NFA_ZOPEN && state->c <= NFA_ZOPEN9) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4455 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4456 subidx = state->c - NFA_ZOPEN; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4457 sub = &subs->synt; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4458 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4459 #endif |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4460 else |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4461 { |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4462 subidx = state->c - NFA_MOPEN; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4463 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4464 } |
4444 | 4465 |
5210
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4466 /* avoid compiler warnings */ |
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4467 save_ptr = NULL; |
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4468 save_lpos.lnum = 0; |
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4469 save_lpos.col = 0; |
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4470 |
4815
6419ee8098c8
updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents:
4813
diff
changeset
|
4471 /* Set the position (with "off" added) in the subexpression. Save |
6419ee8098c8
updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents:
4813
diff
changeset
|
4472 * and restore it when it was in use. Otherwise fill any gap. */ |
4444 | 4473 if (REG_MULTI) |
4474 { | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4475 if (subidx < sub->in_use) |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4476 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4477 save_lpos = sub->list.multi[subidx].start; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4478 save_in_use = -1; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4479 } |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4480 else |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4481 { |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4482 save_in_use = sub->in_use; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4483 for (i = sub->in_use; i < subidx; ++i) |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4484 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4485 sub->list.multi[i].start.lnum = -1; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4486 sub->list.multi[i].end.lnum = -1; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4487 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4488 sub->in_use = subidx + 1; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4489 } |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4490 if (off == -1) |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4491 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4492 sub->list.multi[subidx].start.lnum = reglnum + 1; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4493 sub->list.multi[subidx].start.col = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4494 } |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4495 else |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4496 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4497 sub->list.multi[subidx].start.lnum = reglnum; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4498 sub->list.multi[subidx].start.col = |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4499 (colnr_T)(reginput - regline + off); |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4500 } |
4444 | 4501 } |
4502 else | |
4503 { | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4504 if (subidx < sub->in_use) |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4505 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4506 save_ptr = sub->list.line[subidx].start; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4507 save_in_use = -1; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4508 } |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4509 else |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4510 { |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4511 save_in_use = sub->in_use; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4512 for (i = sub->in_use; i < subidx; ++i) |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4513 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4514 sub->list.line[i].start = NULL; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4515 sub->list.line[i].end = NULL; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4516 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4517 sub->in_use = subidx + 1; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4518 } |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4519 sub->list.line[subidx].start = reginput + off; |
4444 | 4520 } |
4521 | |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4522 subs = addstate(l, state->out, subs, pim, off); |
5300 | 4523 /* "subs" may have changed, need to set "sub" again */ |
4524 #ifdef FEAT_SYN_HL | |
4525 if (state->c >= NFA_ZOPEN && state->c <= NFA_ZOPEN9) | |
4526 sub = &subs->synt; | |
4527 else | |
4528 #endif | |
4529 sub = &subs->norm; | |
4444 | 4530 |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4531 if (save_in_use == -1) |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4532 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4533 if (REG_MULTI) |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4534 sub->list.multi[subidx].start = save_lpos; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4535 else |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4536 sub->list.line[subidx].start = save_ptr; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4537 } |
4444 | 4538 else |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4539 sub->in_use = save_in_use; |
4444 | 4540 break; |
4541 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4542 case NFA_MCLOSE: |
5336 | 4543 if (nfa_has_zend && (REG_MULTI |
4544 ? subs->norm.list.multi[0].end.lnum >= 0 | |
4545 : subs->norm.list.line[0].end != NULL)) | |
4444 | 4546 { |
5336 | 4547 /* Do not overwrite the position set by \ze. */ |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4548 subs = addstate(l, state->out, subs, pim, off); |
4444 | 4549 break; |
4550 } | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4551 case NFA_MCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4552 case NFA_MCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4553 case NFA_MCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4554 case NFA_MCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4555 case NFA_MCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4556 case NFA_MCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4557 case NFA_MCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4558 case NFA_MCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4559 case NFA_MCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4560 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4561 case NFA_ZCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4562 case NFA_ZCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4563 case NFA_ZCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4564 case NFA_ZCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4565 case NFA_ZCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4566 case NFA_ZCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4567 case NFA_ZCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4568 case NFA_ZCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4569 case NFA_ZCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4570 case NFA_ZCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4571 #endif |
4444 | 4572 case NFA_ZEND: |
4573 if (state->c == NFA_ZEND) | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4574 { |
4444 | 4575 subidx = 0; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4576 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4577 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4578 #ifdef FEAT_SYN_HL |
5300 | 4579 else if (state->c >= NFA_ZCLOSE && state->c <= NFA_ZCLOSE9) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4580 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4581 subidx = state->c - NFA_ZCLOSE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4582 sub = &subs->synt; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4583 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4584 #endif |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4585 else |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4586 { |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4587 subidx = state->c - NFA_MCLOSE; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4588 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4589 } |
4444 | 4590 |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4591 /* We don't fill in gaps here, there must have been an MOPEN that |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4592 * has done that. */ |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4593 save_in_use = sub->in_use; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4594 if (sub->in_use <= subidx) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4595 sub->in_use = subidx + 1; |
4444 | 4596 if (REG_MULTI) |
4597 { | |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4598 save_lpos = sub->list.multi[subidx].end; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4599 if (off == -1) |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4600 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4601 sub->list.multi[subidx].end.lnum = reglnum + 1; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4602 sub->list.multi[subidx].end.col = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4603 } |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4604 else |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4605 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4606 sub->list.multi[subidx].end.lnum = reglnum; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4607 sub->list.multi[subidx].end.col = |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4608 (colnr_T)(reginput - regline + off); |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4609 } |
5210
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4610 /* avoid compiler warnings */ |
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4611 save_ptr = NULL; |
4444 | 4612 } |
4613 else | |
4614 { | |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4615 save_ptr = sub->list.line[subidx].end; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4616 sub->list.line[subidx].end = reginput + off; |
5210
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4617 /* avoid compiler warnings */ |
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4618 save_lpos.lnum = 0; |
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4619 save_lpos.col = 0; |
4444 | 4620 } |
4621 | |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4622 subs = addstate(l, state->out, subs, pim, off); |
5300 | 4623 /* "subs" may have changed, need to set "sub" again */ |
4624 #ifdef FEAT_SYN_HL | |
4625 if (state->c >= NFA_ZCLOSE && state->c <= NFA_ZCLOSE9) | |
4626 sub = &subs->synt; | |
4627 else | |
4628 #endif | |
4629 sub = &subs->norm; | |
4444 | 4630 |
4631 if (REG_MULTI) | |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4632 sub->list.multi[subidx].end = save_lpos; |
4444 | 4633 else |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4634 sub->list.line[subidx].end = save_ptr; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4635 sub->in_use = save_in_use; |
4444 | 4636 break; |
4637 } | |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4638 return subs; |
4444 | 4639 } |
4640 | |
4641 /* | |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4642 * Like addstate(), but the new state(s) are put at position "*ip". |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4643 * Used for zero-width matches, next state to use is the added one. |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4644 * This makes sure the order of states to be tried does not change, which |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4645 * matters for alternatives. |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4646 */ |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4647 static void |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4648 addstate_here(l, state, subs, pim, ip) |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4649 nfa_list_T *l; /* runtime state list */ |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4650 nfa_state_T *state; /* state to update */ |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4651 regsubs_T *subs; /* pointers to subexpressions */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4652 nfa_pim_T *pim; /* postponed look-behind match */ |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4653 int *ip; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4654 { |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4655 int tlen = l->n; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4656 int count; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4657 int listidx = *ip; |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4658 |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4659 /* first add the state(s) at the end, so that we know how many there are */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4660 addstate(l, state, subs, pim, 0); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4661 |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4662 /* when "*ip" was at the end of the list, nothing to do */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4663 if (listidx + 1 == tlen) |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4664 return; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4665 |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4666 /* re-order to put the new state at the current position */ |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4667 count = l->n - tlen; |
4924
6ae32a64e153
updated for version 7.3.1207
Bram Moolenaar <bram@vim.org>
parents:
4897
diff
changeset
|
4668 if (count == 0) |
6ae32a64e153
updated for version 7.3.1207
Bram Moolenaar <bram@vim.org>
parents:
4897
diff
changeset
|
4669 return; /* no state got added */ |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4670 if (count == 1) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4671 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4672 /* overwrite the current state */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4673 l->t[listidx] = l->t[l->n - 1]; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4674 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4675 else if (count > 1) |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4676 { |
5058
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4677 if (l->n + count - 1 >= l->len) |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4678 { |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4679 /* not enough space to move the new states, reallocate the list |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4680 * and move the states to the right position */ |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4681 nfa_thread_T *newl; |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4682 |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4683 l->len = l->len * 3 / 2 + 50; |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4684 newl = (nfa_thread_T *)alloc(l->len * sizeof(nfa_thread_T)); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4685 if (newl == NULL) |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4686 return; |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4687 mch_memmove(&(newl[0]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4688 &(l->t[0]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4689 sizeof(nfa_thread_T) * listidx); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4690 mch_memmove(&(newl[listidx]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4691 &(l->t[l->n - count]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4692 sizeof(nfa_thread_T) * count); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4693 mch_memmove(&(newl[listidx + count]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4694 &(l->t[listidx + 1]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4695 sizeof(nfa_thread_T) * (l->n - count - listidx - 1)); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4696 vim_free(l->t); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4697 l->t = newl; |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4698 } |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4699 else |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4700 { |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4701 /* make space for new states, then move them from the |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4702 * end to the current position */ |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4703 mch_memmove(&(l->t[listidx + count]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4704 &(l->t[listidx + 1]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4705 sizeof(nfa_thread_T) * (l->n - listidx - 1)); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4706 mch_memmove(&(l->t[listidx]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4707 &(l->t[l->n - 1]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4708 sizeof(nfa_thread_T) * count); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4709 } |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4710 } |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4711 --l->n; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4712 *ip = listidx - 1; |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4713 } |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4714 |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4715 /* |
4444 | 4716 * Check character class "class" against current character c. |
4717 */ | |
4718 static int | |
4719 check_char_class(class, c) | |
4720 int class; | |
4721 int c; | |
4722 { | |
4723 switch (class) | |
4724 { | |
4725 case NFA_CLASS_ALNUM: | |
4464 | 4726 if (c >= 1 && c <= 255 && isalnum(c)) |
4444 | 4727 return OK; |
4728 break; | |
4729 case NFA_CLASS_ALPHA: | |
4464 | 4730 if (c >= 1 && c <= 255 && isalpha(c)) |
4444 | 4731 return OK; |
4732 break; | |
4733 case NFA_CLASS_BLANK: | |
4734 if (c == ' ' || c == '\t') | |
4735 return OK; | |
4736 break; | |
4737 case NFA_CLASS_CNTRL: | |
4464 | 4738 if (c >= 1 && c <= 255 && iscntrl(c)) |
4444 | 4739 return OK; |
4740 break; | |
4741 case NFA_CLASS_DIGIT: | |
4742 if (VIM_ISDIGIT(c)) | |
4743 return OK; | |
4744 break; | |
4745 case NFA_CLASS_GRAPH: | |
4464 | 4746 if (c >= 1 && c <= 255 && isgraph(c)) |
4444 | 4747 return OK; |
4748 break; | |
4749 case NFA_CLASS_LOWER: | |
4750 if (MB_ISLOWER(c)) | |
4751 return OK; | |
4752 break; | |
4753 case NFA_CLASS_PRINT: | |
4754 if (vim_isprintc(c)) | |
4755 return OK; | |
4756 break; | |
4757 case NFA_CLASS_PUNCT: | |
4464 | 4758 if (c >= 1 && c <= 255 && ispunct(c)) |
4444 | 4759 return OK; |
4760 break; | |
4761 case NFA_CLASS_SPACE: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
4762 if ((c >= 9 && c <= 13) || (c == ' ')) |
4444 | 4763 return OK; |
4764 break; | |
4765 case NFA_CLASS_UPPER: | |
4766 if (MB_ISUPPER(c)) | |
4767 return OK; | |
4768 break; | |
4769 case NFA_CLASS_XDIGIT: | |
4770 if (vim_isxdigit(c)) | |
4771 return OK; | |
4772 break; | |
4773 case NFA_CLASS_TAB: | |
4774 if (c == '\t') | |
4775 return OK; | |
4776 break; | |
4777 case NFA_CLASS_RETURN: | |
4778 if (c == '\r') | |
4779 return OK; | |
4780 break; | |
4781 case NFA_CLASS_BACKSPACE: | |
4782 if (c == '\b') | |
4783 return OK; | |
4784 break; | |
4785 case NFA_CLASS_ESCAPE: | |
4786 if (c == '\033') | |
4787 return OK; | |
4788 break; | |
4789 | |
4790 default: | |
4791 /* should not be here :P */ | |
5511 | 4792 EMSGN(_(e_ill_char_class), class); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
4793 return FAIL; |
4444 | 4794 } |
4795 return FAIL; | |
4796 } | |
4797 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4798 /* |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4799 * Check for a match with subexpression "subidx". |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4800 * Return TRUE if it matches. |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4801 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4802 static int |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4803 match_backref(sub, subidx, bytelen) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4804 regsub_T *sub; /* pointers to subexpressions */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4805 int subidx; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4806 int *bytelen; /* out: length of match in bytes */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4807 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4808 int len; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4809 |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4810 if (sub->in_use <= subidx) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4811 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4812 retempty: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4813 /* backref was not set, match an empty string */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4814 *bytelen = 0; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4815 return TRUE; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4816 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4817 |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4818 if (REG_MULTI) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4819 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4820 if (sub->list.multi[subidx].start.lnum < 0 |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4821 || sub->list.multi[subidx].end.lnum < 0) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4822 goto retempty; |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4823 if (sub->list.multi[subidx].start.lnum == reglnum |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4824 && sub->list.multi[subidx].end.lnum == reglnum) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4825 { |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4826 len = sub->list.multi[subidx].end.col |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4827 - sub->list.multi[subidx].start.col; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4828 if (cstrncmp(regline + sub->list.multi[subidx].start.col, |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4829 reginput, &len) == 0) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4830 { |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4831 *bytelen = len; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4832 return TRUE; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4833 } |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4834 } |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4835 else |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4836 { |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4837 if (match_with_backref( |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4838 sub->list.multi[subidx].start.lnum, |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4839 sub->list.multi[subidx].start.col, |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4840 sub->list.multi[subidx].end.lnum, |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4841 sub->list.multi[subidx].end.col, |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4842 bytelen) == RA_MATCH) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4843 return TRUE; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4844 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4845 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4846 else |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4847 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4848 if (sub->list.line[subidx].start == NULL |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4849 || sub->list.line[subidx].end == NULL) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4850 goto retempty; |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4851 len = (int)(sub->list.line[subidx].end - sub->list.line[subidx].start); |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4852 if (cstrncmp(sub->list.line[subidx].start, reginput, &len) == 0) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4853 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4854 *bytelen = len; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4855 return TRUE; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4856 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4857 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4858 return FALSE; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4859 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4860 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4861 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4862 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4863 static int match_zref __ARGS((int subidx, int *bytelen)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4864 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4865 /* |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4866 * Check for a match with \z subexpression "subidx". |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4867 * Return TRUE if it matches. |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4868 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4869 static int |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4870 match_zref(subidx, bytelen) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4871 int subidx; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4872 int *bytelen; /* out: length of match in bytes */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4873 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4874 int len; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4875 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4876 cleanup_zsubexpr(); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4877 if (re_extmatch_in == NULL || re_extmatch_in->matches[subidx] == NULL) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4878 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4879 /* backref was not set, match an empty string */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4880 *bytelen = 0; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4881 return TRUE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4882 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4883 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4884 len = (int)STRLEN(re_extmatch_in->matches[subidx]); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4885 if (cstrncmp(re_extmatch_in->matches[subidx], reginput, &len) == 0) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4886 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4887 *bytelen = len; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4888 return TRUE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4889 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4890 return FALSE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4891 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4892 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4893 |
4444 | 4894 /* |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4895 * Save list IDs for all NFA states of "prog" into "list". |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4896 * Also reset the IDs to zero. |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4897 * Only used for the recursive value lastlist[1]. |
4444 | 4898 */ |
4899 static void | |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4900 nfa_save_listids(prog, list) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4901 nfa_regprog_T *prog; |
4444 | 4902 int *list; |
4903 { | |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4904 int i; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4905 nfa_state_T *p; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4906 |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4907 /* Order in the list is reverse, it's a bit faster that way. */ |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4908 p = &prog->state[0]; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4909 for (i = prog->nstate; --i >= 0; ) |
4444 | 4910 { |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4911 list[i] = p->lastlist[1]; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4912 p->lastlist[1] = 0; |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4913 ++p; |
4444 | 4914 } |
4915 } | |
4916 | |
4917 /* | |
4918 * Restore list IDs from "list" to all NFA states. | |
4919 */ | |
4920 static void | |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4921 nfa_restore_listids(prog, list) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4922 nfa_regprog_T *prog; |
4444 | 4923 int *list; |
4924 { | |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4925 int i; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4926 nfa_state_T *p; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4927 |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4928 p = &prog->state[0]; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4929 for (i = prog->nstate; --i >= 0; ) |
4444 | 4930 { |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4931 p->lastlist[1] = list[i]; |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4932 ++p; |
4444 | 4933 } |
4934 } | |
4935 | |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4936 static int |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4937 nfa_re_num_cmp(val, op, pos) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4938 long_u val; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4939 int op; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4940 long_u pos; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4941 { |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4942 if (op == 1) return pos > val; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4943 if (op == 2) return pos < val; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4944 return val == pos; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4945 } |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
4946 |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4947 static int recursive_regmatch __ARGS((nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T *prog, regsubs_T *submatch, regsubs_T *m, int **listids)); |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4948 static int nfa_regmatch __ARGS((nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *submatch, regsubs_T *m)); |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4949 |
4444 | 4950 /* |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4951 * Recursively call nfa_regmatch() |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4952 * "pim" is NULL or contains info about a Postponed Invisible Match (start |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4953 * position). |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4954 */ |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4955 static int |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4956 recursive_regmatch(state, pim, prog, submatch, m, listids) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4957 nfa_state_T *state; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4958 nfa_pim_T *pim; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4959 nfa_regprog_T *prog; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4960 regsubs_T *submatch; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4961 regsubs_T *m; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4962 int **listids; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4963 { |
4887
dc78a26f6f64
updated for version 7.3.1189
Bram Moolenaar <bram@vim.org>
parents:
4879
diff
changeset
|
4964 int save_reginput_col = (int)(reginput - regline); |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4965 int save_reglnum = reglnum; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4966 int save_nfa_match = nfa_match; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4967 int save_nfa_listid = nfa_listid; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4968 save_se_T *save_nfa_endp = nfa_endp; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4969 save_se_T endpos; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4970 save_se_T *endposp = NULL; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4971 int result; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4972 int need_restore = FALSE; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4973 |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4974 if (pim != NULL) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4975 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4976 /* start at the position where the postponed match was */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4977 if (REG_MULTI) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4978 reginput = regline + pim->end.pos.col; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4979 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4980 reginput = pim->end.ptr; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4981 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4982 |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
4983 if (state->c == NFA_START_INVISIBLE_BEFORE |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4984 || state->c == NFA_START_INVISIBLE_BEFORE_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4985 || state->c == NFA_START_INVISIBLE_BEFORE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4986 || state->c == NFA_START_INVISIBLE_BEFORE_NEG_FIRST) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4987 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4988 /* The recursive match must end at the current position. When "pim" is |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4989 * not NULL it specifies the current position. */ |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4990 endposp = &endpos; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4991 if (REG_MULTI) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
4992 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4993 if (pim == NULL) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4994 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4995 endpos.se_u.pos.col = (int)(reginput - regline); |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4996 endpos.se_u.pos.lnum = reglnum; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4997 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4998 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4999 endpos.se_u.pos = pim->end.pos; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5000 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5001 else |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5002 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5003 if (pim == NULL) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5004 endpos.se_u.ptr = reginput; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5005 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5006 endpos.se_u.ptr = pim->end.ptr; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5007 } |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5008 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5009 /* Go back the specified number of bytes, or as far as the |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5010 * start of the previous line, to try matching "\@<=" or |
5188
fa76be660fa9
updated for version 7.4a.020
Bram Moolenaar <bram@vim.org>
parents:
5184
diff
changeset
|
5011 * not matching "\@<!". This is very inefficient, limit the number of |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
5012 * bytes if possible. */ |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5013 if (state->val <= 0) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5014 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5015 if (REG_MULTI) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5016 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5017 regline = reg_getline(--reglnum); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5018 if (regline == NULL) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5019 /* can't go before the first line */ |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5020 regline = reg_getline(++reglnum); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5021 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5022 reginput = regline; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5023 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5024 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5025 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5026 if (REG_MULTI && (int)(reginput - regline) < state->val) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5027 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5028 /* Not enough bytes in this line, go to end of |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5029 * previous line. */ |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5030 regline = reg_getline(--reglnum); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5031 if (regline == NULL) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5032 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5033 /* can't go before the first line */ |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5034 regline = reg_getline(++reglnum); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5035 reginput = regline; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5036 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5037 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5038 reginput = regline + STRLEN(regline); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5039 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5040 if ((int)(reginput - regline) >= state->val) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5041 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5042 reginput -= state->val; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5043 #ifdef FEAT_MBYTE |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5044 if (has_mbyte) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5045 reginput -= mb_head_off(regline, reginput); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5046 #endif |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5047 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5048 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5049 reginput = regline; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5050 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5051 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5052 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5053 #ifdef ENABLE_LOG |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5054 if (log_fd != stderr) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5055 fclose(log_fd); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5056 log_fd = NULL; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5057 #endif |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5058 /* Have to clear the lastlist field of the NFA nodes, so that |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5059 * nfa_regmatch() and addstate() can run properly after recursion. */ |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5060 if (nfa_ll_index == 1) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5061 { |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5062 /* Already calling nfa_regmatch() recursively. Save the lastlist[1] |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5063 * values and clear them. */ |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5064 if (*listids == NULL) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5065 { |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5066 *listids = (int *)lalloc(sizeof(int) * nstate, TRUE); |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5067 if (*listids == NULL) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5068 { |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5069 EMSG(_("E878: (NFA) Could not allocate memory for branch traversal!")); |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5070 return 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5071 } |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5072 } |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5073 nfa_save_listids(prog, *listids); |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5074 need_restore = TRUE; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5075 /* any value of nfa_listid will do */ |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5076 } |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5077 else |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5078 { |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5079 /* First recursive nfa_regmatch() call, switch to the second lastlist |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5080 * entry. Make sure nfa_listid is different from a previous recursive |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5081 * call, because some states may still have this ID. */ |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5082 ++nfa_ll_index; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5083 if (nfa_listid <= nfa_alt_listid) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5084 nfa_listid = nfa_alt_listid; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5085 } |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5086 |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5087 /* Call nfa_regmatch() to check if the current concat matches at this |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5088 * position. The concat ends with the node NFA_END_INVISIBLE */ |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5089 nfa_endp = endposp; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5090 result = nfa_regmatch(prog, state->out, submatch, m); |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5091 |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5092 if (need_restore) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5093 nfa_restore_listids(prog, *listids); |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5094 else |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5095 { |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5096 --nfa_ll_index; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5097 nfa_alt_listid = nfa_listid; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5098 } |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5099 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5100 /* restore position in input text */ |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5101 reglnum = save_reglnum; |
4877
9e36c6b1ebf4
updated for version 7.3.1184
Bram Moolenaar <bram@vim.org>
parents:
4845
diff
changeset
|
5102 if (REG_MULTI) |
9e36c6b1ebf4
updated for version 7.3.1184
Bram Moolenaar <bram@vim.org>
parents:
4845
diff
changeset
|
5103 regline = reg_getline(reglnum); |
4887
dc78a26f6f64
updated for version 7.3.1189
Bram Moolenaar <bram@vim.org>
parents:
4879
diff
changeset
|
5104 reginput = regline + save_reginput_col; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5105 nfa_match = save_nfa_match; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5106 nfa_endp = save_nfa_endp; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5107 nfa_listid = save_nfa_listid; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5108 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5109 #ifdef ENABLE_LOG |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5110 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5111 if (log_fd != NULL) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5112 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5113 fprintf(log_fd, "****************************\n"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5114 fprintf(log_fd, "FINISHED RUNNING nfa_regmatch() recursively\n"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5115 fprintf(log_fd, "MATCH = %s\n", result == TRUE ? "OK" : "FALSE"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5116 fprintf(log_fd, "****************************\n"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5117 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5118 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5119 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5120 EMSG(_("Could not open temporary log file for writing, displaying on stderr ... ")); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5121 log_fd = stderr; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5122 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5123 #endif |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5124 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5125 return result; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5126 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5127 |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5128 static int skip_to_start __ARGS((int c, colnr_T *colp)); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5129 static long find_match_text __ARGS((colnr_T startcol, int regstart, char_u *match_text)); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5130 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5131 /* |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5132 * Estimate the chance of a match with "state" failing. |
4821
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5133 * empty match: 0 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5134 * NFA_ANY: 1 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5135 * specific character: 99 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5136 */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5137 static int |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5138 failure_chance(state, depth) |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5139 nfa_state_T *state; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5140 int depth; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5141 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5142 int c = state->c; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5143 int l, r; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5144 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5145 /* detect looping */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5146 if (depth > 4) |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5147 return 1; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5148 |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5149 switch (c) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5150 { |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5151 case NFA_SPLIT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5152 if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT) |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5153 /* avoid recursive stuff */ |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5154 return 1; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5155 /* two alternatives, use the lowest failure chance */ |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5156 l = failure_chance(state->out, depth + 1); |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5157 r = failure_chance(state->out1, depth + 1); |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5158 return l < r ? l : r; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5159 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5160 case NFA_ANY: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5161 /* matches anything, unlikely to fail */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5162 return 1; |
4821
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5163 |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5164 case NFA_MATCH: |
4821
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5165 case NFA_MCLOSE: |
5901 | 5166 case NFA_ANY_COMPOSING: |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5167 /* empty match works always */ |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5168 return 0; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5169 |
4897
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5170 case NFA_START_INVISIBLE: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5171 case NFA_START_INVISIBLE_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5172 case NFA_START_INVISIBLE_NEG: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5173 case NFA_START_INVISIBLE_NEG_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5174 case NFA_START_INVISIBLE_BEFORE: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5175 case NFA_START_INVISIBLE_BEFORE_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5176 case NFA_START_INVISIBLE_BEFORE_NEG: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5177 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5178 case NFA_START_PATTERN: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5179 /* recursive regmatch is expensive, use low failure chance */ |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5180 return 5; |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5181 |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5182 case NFA_BOL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5183 case NFA_EOL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5184 case NFA_BOF: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5185 case NFA_EOF: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5186 case NFA_NEWL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5187 return 99; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5188 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5189 case NFA_BOW: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5190 case NFA_EOW: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5191 return 90; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5192 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5193 case NFA_MOPEN: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5194 case NFA_MOPEN1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5195 case NFA_MOPEN2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5196 case NFA_MOPEN3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5197 case NFA_MOPEN4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5198 case NFA_MOPEN5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5199 case NFA_MOPEN6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5200 case NFA_MOPEN7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5201 case NFA_MOPEN8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5202 case NFA_MOPEN9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5203 #ifdef FEAT_SYN_HL |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5204 case NFA_ZOPEN: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5205 case NFA_ZOPEN1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5206 case NFA_ZOPEN2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5207 case NFA_ZOPEN3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5208 case NFA_ZOPEN4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5209 case NFA_ZOPEN5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5210 case NFA_ZOPEN6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5211 case NFA_ZOPEN7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5212 case NFA_ZOPEN8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5213 case NFA_ZOPEN9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5214 case NFA_ZCLOSE: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5215 case NFA_ZCLOSE1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5216 case NFA_ZCLOSE2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5217 case NFA_ZCLOSE3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5218 case NFA_ZCLOSE4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5219 case NFA_ZCLOSE5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5220 case NFA_ZCLOSE6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5221 case NFA_ZCLOSE7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5222 case NFA_ZCLOSE8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5223 case NFA_ZCLOSE9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5224 #endif |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5225 case NFA_NOPEN: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5226 case NFA_MCLOSE1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5227 case NFA_MCLOSE2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5228 case NFA_MCLOSE3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5229 case NFA_MCLOSE4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5230 case NFA_MCLOSE5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5231 case NFA_MCLOSE6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5232 case NFA_MCLOSE7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5233 case NFA_MCLOSE8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5234 case NFA_MCLOSE9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5235 case NFA_NCLOSE: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5236 return failure_chance(state->out, depth + 1); |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5237 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5238 case NFA_BACKREF1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5239 case NFA_BACKREF2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5240 case NFA_BACKREF3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5241 case NFA_BACKREF4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5242 case NFA_BACKREF5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5243 case NFA_BACKREF6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5244 case NFA_BACKREF7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5245 case NFA_BACKREF8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5246 case NFA_BACKREF9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5247 #ifdef FEAT_SYN_HL |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5248 case NFA_ZREF1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5249 case NFA_ZREF2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5250 case NFA_ZREF3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5251 case NFA_ZREF4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5252 case NFA_ZREF5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5253 case NFA_ZREF6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5254 case NFA_ZREF7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5255 case NFA_ZREF8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5256 case NFA_ZREF9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5257 #endif |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5258 /* backreferences don't match in many places */ |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5259 return 94; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5260 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5261 case NFA_LNUM_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5262 case NFA_LNUM_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5263 case NFA_COL_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5264 case NFA_COL_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5265 case NFA_VCOL_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5266 case NFA_VCOL_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5267 case NFA_MARK_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5268 case NFA_MARK_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5269 case NFA_VISUAL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5270 /* before/after positions don't match very often */ |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5271 return 85; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5272 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5273 case NFA_LNUM: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5274 return 90; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5275 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5276 case NFA_CURSOR: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5277 case NFA_COL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5278 case NFA_VCOL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5279 case NFA_MARK: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5280 /* specific positions rarely match */ |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5281 return 98; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5282 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5283 case NFA_COMPOSING: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5284 return 95; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5285 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5286 default: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5287 if (c > 0) |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5288 /* character match fails often */ |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5289 return 95; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5290 } |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5291 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5292 /* something else, includes character classes */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5293 return 50; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5294 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5295 |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5296 /* |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5297 * Skip until the char "c" we know a match must start with. |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5298 */ |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5299 static int |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5300 skip_to_start(c, colp) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5301 int c; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5302 colnr_T *colp; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5303 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5304 char_u *s; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5305 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5306 /* Used often, do some work to avoid call overhead. */ |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5307 if (!ireg_ic |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5308 #ifdef FEAT_MBYTE |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5309 && !has_mbyte |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5310 #endif |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5311 ) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5312 s = vim_strbyte(regline + *colp, c); |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5313 else |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5314 s = cstrchr(regline + *colp, c); |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5315 if (s == NULL) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5316 return FAIL; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5317 *colp = (int)(s - regline); |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5318 return OK; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5319 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5320 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5321 /* |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5322 * Check for a match with match_text. |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
5323 * Called after skip_to_start() has found regstart. |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5324 * Returns zero for no match, 1 for a match. |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5325 */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5326 static long |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5327 find_match_text(startcol, regstart, match_text) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5328 colnr_T startcol; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5329 int regstart; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5330 char_u *match_text; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5331 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5332 colnr_T col = startcol; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5333 int c1, c2; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5334 int len1, len2; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5335 int match; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5336 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5337 for (;;) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5338 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5339 match = TRUE; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5340 len2 = MB_CHAR2LEN(regstart); /* skip regstart */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5341 for (len1 = 0; match_text[len1] != NUL; len1 += MB_CHAR2LEN(c1)) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5342 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5343 c1 = PTR2CHAR(match_text + len1); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5344 c2 = PTR2CHAR(regline + col + len2); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5345 if (c1 != c2 && (!ireg_ic || MB_TOLOWER(c1) != MB_TOLOWER(c2))) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5346 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5347 match = FALSE; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5348 break; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5349 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5350 len2 += MB_CHAR2LEN(c2); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5351 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5352 if (match |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5353 #ifdef FEAT_MBYTE |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5354 /* check that no composing char follows */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5355 && !(enc_utf8 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5356 && utf_iscomposing(PTR2CHAR(regline + col + len2))) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5357 #endif |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5358 ) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5359 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5360 cleanup_subexpr(); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5361 if (REG_MULTI) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5362 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5363 reg_startpos[0].lnum = reglnum; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5364 reg_startpos[0].col = col; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5365 reg_endpos[0].lnum = reglnum; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5366 reg_endpos[0].col = col + len2; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5367 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5368 else |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5369 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5370 reg_startp[0] = regline + col; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5371 reg_endp[0] = regline + col + len2; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5372 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5373 return 1L; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5374 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5375 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5376 /* Try finding regstart after the current match. */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5377 col += MB_CHAR2LEN(regstart); /* skip regstart */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5378 if (skip_to_start(regstart, &col) == FAIL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5379 break; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5380 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5381 return 0L; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5382 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5383 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5384 /* |
4444 | 5385 * Main matching routine. |
5386 * | |
5387 * Run NFA to determine whether it matches reginput. | |
5388 * | |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
5389 * When "nfa_endp" is not NULL it is a required end-of-match position. |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5390 * |
4444 | 5391 * Return TRUE if there is a match, FALSE otherwise. |
5372 | 5392 * When there is a match "submatch" contains the positions. |
4444 | 5393 * Note: Caller must ensure that: start != NULL. |
5394 */ | |
5395 static int | |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5396 nfa_regmatch(prog, start, submatch, m) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5397 nfa_regprog_T *prog; |
4444 | 5398 nfa_state_T *start; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5399 regsubs_T *submatch; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5400 regsubs_T *m; |
4444 | 5401 { |
5402 int result; | |
5403 int size = 0; | |
5404 int flag = 0; | |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5405 int go_to_nextline = FALSE; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5406 nfa_thread_T *t; |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5407 nfa_list_T list[2]; |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5408 int listidx; |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5409 nfa_list_T *thislist; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5410 nfa_list_T *nextlist; |
4444 | 5411 int *listids = NULL; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5412 nfa_state_T *add_state; |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5413 int add_here; |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5414 int add_count; |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4815
diff
changeset
|
5415 int add_off = 0; |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5416 int toplevel = start->c == NFA_MOPEN; |
4460 | 5417 #ifdef NFA_REGEXP_DEBUG_LOG |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
5418 FILE *debug = fopen(NFA_REGEXP_DEBUG_LOG, "a"); |
4444 | 5419 |
5420 if (debug == NULL) | |
5421 { | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
5422 EMSG2(_("(NFA) COULD NOT OPEN %s !"), NFA_REGEXP_DEBUG_LOG); |
4444 | 5423 return FALSE; |
5424 } | |
5425 #endif | |
5310 | 5426 /* Some patterns may take a long time to match, especially when using |
5427 * recursive_regmatch(). Allow interrupting them with CTRL-C. */ | |
5428 fast_breakcheck(); | |
5429 if (got_int) | |
5430 return FALSE; | |
5431 | |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
5432 nfa_match = FALSE; |
4444 | 5433 |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
5434 /* Allocate memory for the lists of nodes. */ |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5435 size = (nstate + 1) * sizeof(nfa_thread_T); |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
5436 list[0].t = (nfa_thread_T *)lalloc(size, TRUE); |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
5437 list[0].len = nstate + 1; |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
5438 list[1].t = (nfa_thread_T *)lalloc(size, TRUE); |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
5439 list[1].len = nstate + 1; |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5440 if (list[0].t == NULL || list[1].t == NULL) |
4444 | 5441 goto theend; |
5442 | |
5443 #ifdef ENABLE_LOG | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
5444 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a"); |
4444 | 5445 if (log_fd != NULL) |
5446 { | |
5447 fprintf(log_fd, "**********************************\n"); | |
5448 nfa_set_code(start->c); | |
5449 fprintf(log_fd, " RUNNING nfa_regmatch() starting with state %d, code %s\n", | |
5450 abs(start->id), code); | |
5451 fprintf(log_fd, "**********************************\n"); | |
5452 } | |
5453 else | |
5454 { | |
5455 EMSG(_("Could not open temporary log file for writing, displaying on stderr ... ")); | |
5456 log_fd = stderr; | |
5457 } | |
5458 #endif | |
5459 | |
5460 thislist = &list[0]; | |
5461 thislist->n = 0; | |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
5462 thislist->has_pim = FALSE; |
4444 | 5463 nextlist = &list[1]; |
5464 nextlist->n = 0; | |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
5465 nextlist->has_pim = FALSE; |
4444 | 5466 #ifdef ENABLE_LOG |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5467 fprintf(log_fd, "(---) STARTSTATE first\n"); |
4444 | 5468 #endif |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5469 thislist->id = nfa_listid + 1; |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5470 |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5471 /* Inline optimized code for addstate(thislist, start, m, 0) if we know |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5472 * it's the first MOPEN. */ |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5473 if (toplevel) |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5474 { |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5475 if (REG_MULTI) |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5476 { |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5477 m->norm.list.multi[0].start.lnum = reglnum; |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5478 m->norm.list.multi[0].start.col = (colnr_T)(reginput - regline); |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5479 } |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5480 else |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5481 m->norm.list.line[0].start = reginput; |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5482 m->norm.in_use = 1; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5483 addstate(thislist, start->out, m, NULL, 0); |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5484 } |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5485 else |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5486 addstate(thislist, start, m, NULL, 0); |
4444 | 5487 |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5488 #define ADD_STATE_IF_MATCH(state) \ |
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5489 if (result) { \ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5490 add_state = state->out; \ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5491 add_off = clen; \ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5492 } |
4444 | 5493 |
5494 /* | |
5495 * Run for each character. | |
5496 */ | |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5497 for (;;) |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5498 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5499 int curc; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5500 int clen; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5501 |
4444 | 5502 #ifdef FEAT_MBYTE |
5503 if (has_mbyte) | |
5504 { | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5505 curc = (*mb_ptr2char)(reginput); |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5506 clen = (*mb_ptr2len)(reginput); |
4444 | 5507 } |
5508 else | |
5509 #endif | |
5510 { | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5511 curc = *reginput; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5512 clen = 1; |
4444 | 5513 } |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5514 if (curc == NUL) |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5515 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5516 clen = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5517 go_to_nextline = FALSE; |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5518 } |
4444 | 5519 |
5520 /* swap lists */ | |
5521 thislist = &list[flag]; | |
5522 nextlist = &list[flag ^= 1]; | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5523 nextlist->n = 0; /* clear nextlist */ |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
5524 nextlist->has_pim = FALSE; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5525 ++nfa_listid; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5526 thislist->id = nfa_listid; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5527 nextlist->id = nfa_listid + 1; |
4444 | 5528 |
5529 #ifdef ENABLE_LOG | |
5530 fprintf(log_fd, "------------------------------------------\n"); | |
5531 fprintf(log_fd, ">>> Reginput is \"%s\"\n", reginput); | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5532 fprintf(log_fd, ">>> Advanced one character ... Current char is %c (code %d) \n", curc, (int)curc); |
4444 | 5533 fprintf(log_fd, ">>> Thislist has %d states available: ", thislist->n); |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5534 { |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5535 int i; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5536 |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5537 for (i = 0; i < thislist->n; i++) |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5538 fprintf(log_fd, "%d ", abs(thislist->t[i].state->id)); |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5539 } |
4444 | 5540 fprintf(log_fd, "\n"); |
5541 #endif | |
5542 | |
4460 | 5543 #ifdef NFA_REGEXP_DEBUG_LOG |
4444 | 5544 fprintf(debug, "\n-------------------\n"); |
5545 #endif | |
4480 | 5546 /* |
5547 * If the state lists are empty we can stop. | |
5548 */ | |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5549 if (thislist->n == 0) |
4480 | 5550 break; |
4444 | 5551 |
5552 /* compute nextlist */ | |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5553 for (listidx = 0; listidx < thislist->n; ++listidx) |
4444 | 5554 { |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5555 t = &thislist->t[listidx]; |
4444 | 5556 |
4460 | 5557 #ifdef NFA_REGEXP_DEBUG_LOG |
4444 | 5558 nfa_set_code(t->state->c); |
5559 fprintf(debug, "%s, ", code); | |
5560 #endif | |
5561 #ifdef ENABLE_LOG | |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5562 { |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5563 int col; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5564 |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
5565 if (t->subs.norm.in_use <= 0) |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5566 col = -1; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5567 else if (REG_MULTI) |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
5568 col = t->subs.norm.list.multi[0].start.col; |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5569 else |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
5570 col = (int)(t->subs.norm.list.line[0].start - regline); |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5571 nfa_set_code(t->state->c); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5572 fprintf(log_fd, "(%d) char %d %s (start col %d)%s ... \n", |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5573 abs(t->state->id), (int)t->state->c, code, col, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5574 pim_info(&t->pim)); |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5575 } |
4444 | 5576 #endif |
5577 | |
5578 /* | |
5579 * Handle the possible codes of the current state. | |
5580 * The most important is NFA_MATCH. | |
5581 */ | |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5582 add_state = NULL; |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5583 add_here = FALSE; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5584 add_count = 0; |
4444 | 5585 switch (t->state->c) |
5586 { | |
5587 case NFA_MATCH: | |
4567
96c1a7850097
updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents:
4565
diff
changeset
|
5588 { |
5901 | 5589 #ifdef FEAT_MBYTE |
5590 /* If the match ends before a composing characters and | |
5591 * ireg_icombine is not set, that is not really a match. */ | |
5592 if (enc_utf8 && !ireg_icombine && utf_iscomposing(curc)) | |
5593 break; | |
5594 #endif | |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
5595 nfa_match = TRUE; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5596 copy_sub(&submatch->norm, &t->subs.norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5597 #ifdef FEAT_SYN_HL |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5598 if (nfa_has_zsubexpr) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5599 copy_sub(&submatch->synt, &t->subs.synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5600 #endif |
4444 | 5601 #ifdef ENABLE_LOG |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5602 log_subsexpr(&t->subs); |
4444 | 5603 #endif |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5604 /* Found the left-most longest match, do not look at any other |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
5605 * states at this position. When the list of states is going |
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
5606 * to be empty quit without advancing, so that "reginput" is |
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
5607 * correct. */ |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5608 if (nextlist->n == 0) |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
5609 clen = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5610 goto nextchar; |
4567
96c1a7850097
updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents:
4565
diff
changeset
|
5611 } |
4444 | 5612 |
5613 case NFA_END_INVISIBLE: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5614 case NFA_END_INVISIBLE_NEG: |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5615 case NFA_END_PATTERN: |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5616 /* |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5617 * This is only encountered after a NFA_START_INVISIBLE or |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5618 * NFA_START_INVISIBLE_BEFORE node. |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5619 * They surround a zero-width group, used with "\@=", "\&", |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5620 * "\@!", "\@<=" and "\@<!". |
4444 | 5621 * If we got here, it means that the current "invisible" group |
5622 * finished successfully, so return control to the parent | |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5623 * nfa_regmatch(). For a look-behind match only when it ends |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5624 * in the position in "nfa_endp". |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5625 * Submatches are stored in *m, and used in the parent call. |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5626 */ |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5627 #ifdef ENABLE_LOG |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5628 if (nfa_endp != NULL) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5629 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5630 if (REG_MULTI) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5631 fprintf(log_fd, "Current lnum: %d, endp lnum: %d; current col: %d, endp col: %d\n", |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5632 (int)reglnum, |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5633 (int)nfa_endp->se_u.pos.lnum, |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5634 (int)(reginput - regline), |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5635 nfa_endp->se_u.pos.col); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5636 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5637 fprintf(log_fd, "Current col: %d, endp col: %d\n", |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5638 (int)(reginput - regline), |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5639 (int)(nfa_endp->se_u.ptr - reginput)); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5640 } |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5641 #endif |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5642 /* If "nfa_endp" is set it's only a match if it ends at |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5643 * "nfa_endp" */ |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5644 if (nfa_endp != NULL && (REG_MULTI |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5645 ? (reglnum != nfa_endp->se_u.pos.lnum |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5646 || (int)(reginput - regline) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5647 != nfa_endp->se_u.pos.col) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5648 : reginput != nfa_endp->se_u.ptr)) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5649 break; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5650 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5651 /* do not set submatches for \@! */ |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5652 if (t->state->c != NFA_END_INVISIBLE_NEG) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5653 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5654 copy_sub(&m->norm, &t->subs.norm); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5655 #ifdef FEAT_SYN_HL |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5656 if (nfa_has_zsubexpr) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5657 copy_sub(&m->synt, &t->subs.synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5658 #endif |
4444 | 5659 } |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5660 #ifdef ENABLE_LOG |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5661 fprintf(log_fd, "Match found:\n"); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5662 log_subsexpr(m); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5663 #endif |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5664 nfa_match = TRUE; |
5334 | 5665 /* See comment above at "goto nextchar". */ |
5666 if (nextlist->n == 0) | |
5667 clen = 0; | |
5668 goto nextchar; | |
4444 | 5669 |
5670 case NFA_START_INVISIBLE: | |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5671 case NFA_START_INVISIBLE_FIRST: |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5672 case NFA_START_INVISIBLE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5673 case NFA_START_INVISIBLE_NEG_FIRST: |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5674 case NFA_START_INVISIBLE_BEFORE: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5675 case NFA_START_INVISIBLE_BEFORE_FIRST: |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5676 case NFA_START_INVISIBLE_BEFORE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5677 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
4444 | 5678 { |
4821
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5679 #ifdef ENABLE_LOG |
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5680 fprintf(log_fd, "Failure chance invisible: %d, what follows: %d\n", |
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5681 failure_chance(t->state->out, 0), |
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5682 failure_chance(t->state->out1->out, 0)); |
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5683 #endif |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5684 /* Do it directly if there already is a PIM or when |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5685 * nfa_postprocess() detected it will work better. */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5686 if (t->pim.result != NFA_PIM_UNUSED |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5687 || t->state->c == NFA_START_INVISIBLE_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5688 || t->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5689 || t->state->c == NFA_START_INVISIBLE_BEFORE_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5690 || t->state->c == NFA_START_INVISIBLE_BEFORE_NEG_FIRST) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5691 { |
5029
c9e2ccc53f2e
updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents:
5006
diff
changeset
|
5692 int in_use = m->norm.in_use; |
c9e2ccc53f2e
updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents:
5006
diff
changeset
|
5693 |
5370 | 5694 /* Copy submatch info for the recursive call, opposite |
5695 * of what happens on success below. */ | |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
5696 copy_sub_off(&m->norm, &t->subs.norm); |
5370 | 5697 #ifdef FEAT_SYN_HL |
5698 if (nfa_has_zsubexpr) | |
5699 copy_sub_off(&m->synt, &t->subs.synt); | |
5700 #endif | |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
5701 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5702 /* |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5703 * First try matching the invisible match, then what |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5704 * follows. |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5705 */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5706 result = recursive_regmatch(t->state, NULL, prog, |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5707 submatch, m, &listids); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5708 |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5709 /* for \@! and \@<! it is a match when the result is |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5710 * FALSE */ |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5711 if (result != (t->state->c == NFA_START_INVISIBLE_NEG |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5712 || t->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5713 || t->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5714 == NFA_START_INVISIBLE_BEFORE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5715 || t->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5716 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5717 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5718 /* Copy submatch info from the recursive call */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5719 copy_sub_off(&t->subs.norm, &m->norm); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5720 #ifdef FEAT_SYN_HL |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
5721 if (nfa_has_zsubexpr) |
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
5722 copy_sub_off(&t->subs.synt, &m->synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5723 #endif |
5372 | 5724 /* If the pattern has \ze and it matched in the |
5725 * sub pattern, use it. */ | |
5726 copy_ze_off(&t->subs.norm, &m->norm); | |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5727 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5728 /* t->state->out1 is the corresponding |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5729 * END_INVISIBLE node; Add its out to the current |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5730 * list (zero-width match). */ |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5731 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5732 add_state = t->state->out1->out; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5733 } |
5029
c9e2ccc53f2e
updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents:
5006
diff
changeset
|
5734 m->norm.in_use = in_use; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5735 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5736 else |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5737 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5738 nfa_pim_T pim; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5739 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5740 /* |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5741 * First try matching what follows. Only if a match |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5742 * is found verify the invisible match matches. Add a |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5743 * nfa_pim_T to the following states, it contains info |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5744 * about the invisible match. |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5745 */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5746 pim.state = t->state; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5747 pim.result = NFA_PIM_TODO; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5748 pim.subs.norm.in_use = 0; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5749 #ifdef FEAT_SYN_HL |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5750 pim.subs.synt.in_use = 0; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5751 #endif |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5752 if (REG_MULTI) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5753 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5754 pim.end.pos.col = (int)(reginput - regline); |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5755 pim.end.pos.lnum = reglnum; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5756 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5757 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5758 pim.end.ptr = reginput; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5759 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5760 /* t->state->out1 is the corresponding END_INVISIBLE |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5761 * node; Add its out to the current list (zero-width |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5762 * match). */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5763 addstate_here(thislist, t->state->out1->out, &t->subs, |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5764 &pim, &listidx); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5765 } |
4444 | 5766 } |
5767 break; | |
5768 | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5769 case NFA_START_PATTERN: |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5770 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5771 nfa_state_T *skip = NULL; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5772 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5773 int skip_lid = 0; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5774 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5775 |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5776 /* There is no point in trying to match the pattern if the |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5777 * output state is not going to be added to the list. */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5778 if (state_in_list(nextlist, t->state->out1->out, &t->subs)) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5779 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5780 skip = t->state->out1->out; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5781 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5782 skip_lid = nextlist->id; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5783 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5784 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5785 else if (state_in_list(nextlist, |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5786 t->state->out1->out->out, &t->subs)) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5787 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5788 skip = t->state->out1->out->out; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5789 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5790 skip_lid = nextlist->id; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5791 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5792 } |
4897
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5793 else if (state_in_list(thislist, |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5794 t->state->out1->out->out, &t->subs)) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5795 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5796 skip = t->state->out1->out->out; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5797 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5798 skip_lid = thislist->id; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5799 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5800 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5801 if (skip != NULL) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5802 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5803 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5804 nfa_set_code(skip->c); |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5805 fprintf(log_fd, "> Not trying to match pattern, output state %d is already in list %d. char %d: %s\n", |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5806 abs(skip->id), skip_lid, skip->c, code); |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5807 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5808 break; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5809 } |
5370 | 5810 /* Copy submatch info to the recursive call, opposite of what |
5811 * happens afterwards. */ | |
5812 copy_sub_off(&m->norm, &t->subs.norm); | |
5813 #ifdef FEAT_SYN_HL | |
5814 if (nfa_has_zsubexpr) | |
5815 copy_sub_off(&m->synt, &t->subs.synt); | |
5816 #endif | |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5817 |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5818 /* First try matching the pattern. */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5819 result = recursive_regmatch(t->state, NULL, prog, |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5820 submatch, m, &listids); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5821 if (result) |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5822 { |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5823 int bytelen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5824 |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5825 #ifdef ENABLE_LOG |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5826 fprintf(log_fd, "NFA_START_PATTERN matches:\n"); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5827 log_subsexpr(m); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5828 #endif |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5829 /* Copy submatch info from the recursive call */ |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5830 copy_sub_off(&t->subs.norm, &m->norm); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5831 #ifdef FEAT_SYN_HL |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
5832 if (nfa_has_zsubexpr) |
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
5833 copy_sub_off(&t->subs.synt, &m->synt); |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5834 #endif |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5835 /* Now we need to skip over the matched text and then |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5836 * continue with what follows. */ |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5837 if (REG_MULTI) |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5838 /* TODO: multi-line match */ |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5839 bytelen = m->norm.list.multi[0].end.col |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5840 - (int)(reginput - regline); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5841 else |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5842 bytelen = (int)(m->norm.list.line[0].end - reginput); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5843 |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5844 #ifdef ENABLE_LOG |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5845 fprintf(log_fd, "NFA_START_PATTERN length: %d\n", bytelen); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5846 #endif |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5847 if (bytelen == 0) |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5848 { |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5849 /* empty match, output of corresponding |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5850 * NFA_END_PATTERN/NFA_SKIP to be used at current |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5851 * position */ |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5852 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5853 add_state = t->state->out1->out->out; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5854 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5855 else if (bytelen <= clen) |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5856 { |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5857 /* match current character, output of corresponding |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5858 * NFA_END_PATTERN to be used at next position. */ |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5859 add_state = t->state->out1->out->out; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5860 add_off = clen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5861 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5862 else |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5863 { |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5864 /* skip over the matched characters, set character |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5865 * count in NFA_SKIP */ |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5866 add_state = t->state->out1->out; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5867 add_off = bytelen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5868 add_count = bytelen - clen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5869 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5870 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5871 break; |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5872 } |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5873 |
4444 | 5874 case NFA_BOL: |
5875 if (reginput == regline) | |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5876 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5877 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5878 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5879 } |
4444 | 5880 break; |
5881 | |
5882 case NFA_EOL: | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5883 if (curc == NUL) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5884 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5885 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5886 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5887 } |
4444 | 5888 break; |
5889 | |
5890 case NFA_BOW: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5891 result = TRUE; |
4444 | 5892 |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5893 if (curc == NUL) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5894 result = FALSE; |
4444 | 5895 #ifdef FEAT_MBYTE |
5896 else if (has_mbyte) | |
5897 { | |
5898 int this_class; | |
5899 | |
5900 /* Get class of current and previous char (if it exists). */ | |
4503 | 5901 this_class = mb_get_class_buf(reginput, reg_buf); |
4444 | 5902 if (this_class <= 1) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5903 result = FALSE; |
4444 | 5904 else if (reg_prev_class() == this_class) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5905 result = FALSE; |
4444 | 5906 } |
5907 #endif | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5908 else if (!vim_iswordc_buf(curc, reg_buf) |
4503 | 5909 || (reginput > regline |
5910 && vim_iswordc_buf(reginput[-1], reg_buf))) | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5911 result = FALSE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5912 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5913 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5914 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5915 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5916 } |
4444 | 5917 break; |
5918 | |
5919 case NFA_EOW: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5920 result = TRUE; |
4444 | 5921 if (reginput == regline) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5922 result = FALSE; |
4444 | 5923 #ifdef FEAT_MBYTE |
5924 else if (has_mbyte) | |
5925 { | |
5926 int this_class, prev_class; | |
5927 | |
5928 /* Get class of current and previous char (if it exists). */ | |
4503 | 5929 this_class = mb_get_class_buf(reginput, reg_buf); |
4444 | 5930 prev_class = reg_prev_class(); |
5931 if (this_class == prev_class | |
5932 || prev_class == 0 || prev_class == 1) | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5933 result = FALSE; |
4444 | 5934 } |
5935 #endif | |
4503 | 5936 else if (!vim_iswordc_buf(reginput[-1], reg_buf) |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5937 || (reginput[0] != NUL |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5938 && vim_iswordc_buf(curc, reg_buf))) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5939 result = FALSE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5940 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5941 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5942 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5943 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5944 } |
4444 | 5945 break; |
5946 | |
4671
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5947 case NFA_BOF: |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5948 if (reglnum == 0 && reginput == regline |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5949 && (!REG_MULTI || reg_firstlnum == 1)) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5950 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5951 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5952 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5953 } |
4671
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5954 break; |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5955 |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5956 case NFA_EOF: |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5957 if (reglnum == reg_maxline && curc == NUL) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5958 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5959 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5960 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5961 } |
4671
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5962 break; |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
5963 |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
5964 #ifdef FEAT_MBYTE |
4444 | 5965 case NFA_COMPOSING: |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
5966 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5967 int mc = curc; |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
5968 int len = 0; |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
5969 nfa_state_T *end; |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
5970 nfa_state_T *sta; |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5971 int cchars[MAX_MCO]; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5972 int ccount = 0; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5973 int j; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5974 |
4444 | 5975 sta = t->state->out; |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
5976 len = 0; |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5977 if (utf_iscomposing(sta->c)) |
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5978 { |
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5979 /* Only match composing character(s), ignore base |
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5980 * character. Used for ".{composing}" and "{composing}" |
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5981 * (no preceding character). */ |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5982 len += mb_char2len(mc); |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5983 } |
4551
f0c37f5cf4ea
updated for version 7.3.1023
Bram Moolenaar <bram@vim.org>
parents:
4549
diff
changeset
|
5984 if (ireg_icombine && len == 0) |
4444 | 5985 { |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5986 /* If \Z was present, then ignore composing characters. |
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
5987 * When ignoring the base character this always matches. */ |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5988 if (len == 0 && sta->c != curc) |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
5989 result = FAIL; |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5990 else |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5991 result = OK; |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
5992 while (sta->c != NFA_END_COMPOSING) |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
5993 sta = sta->out; |
4444 | 5994 } |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5995 |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5996 /* Check base character matches first, unless ignored. */ |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5997 else if (len > 0 || mc == sta->c) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5998 { |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
5999 if (len == 0) |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6000 { |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6001 len += mb_char2len(mc); |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6002 sta = sta->out; |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6003 } |
4444 | 6004 |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6005 /* We don't care about the order of composing characters. |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6006 * Get them into cchars[] first. */ |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6007 while (len < clen) |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6008 { |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6009 mc = mb_ptr2char(reginput + len); |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6010 cchars[ccount++] = mc; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6011 len += mb_char2len(mc); |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6012 if (ccount == MAX_MCO) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6013 break; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6014 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6015 |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6016 /* Check that each composing char in the pattern matches a |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6017 * composing char in the text. We do not check if all |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6018 * composing chars are matched. */ |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6019 result = OK; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6020 while (sta->c != NFA_END_COMPOSING) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6021 { |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6022 for (j = 0; j < ccount; ++j) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6023 if (cchars[j] == sta->c) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6024 break; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6025 if (j == ccount) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6026 { |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6027 result = FAIL; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6028 break; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6029 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6030 sta = sta->out; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6031 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6032 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6033 else |
4525
36ddcf4cecbc
updated for version 7.3.1010
Bram Moolenaar <bram@vim.org>
parents:
4517
diff
changeset
|
6034 result = FAIL; |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6035 |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6036 end = t->state->out1; /* NFA_END_COMPOSING */ |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6037 ADD_STATE_IF_MATCH(end); |
4444 | 6038 break; |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6039 } |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6040 #endif |
4444 | 6041 |
6042 case NFA_NEWL: | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6043 if (curc == NUL && !reg_line_lbr && REG_MULTI |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6044 && reglnum <= reg_maxline) |
4444 | 6045 { |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6046 go_to_nextline = TRUE; |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6047 /* Pass -1 for the offset, which means taking the position |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6048 * at the start of the next line. */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6049 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6050 add_off = -1; |
4444 | 6051 } |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6052 else if (curc == '\n' && reg_line_lbr) |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6053 { |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6054 /* match \n as if it is an ordinary character */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6055 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6056 add_off = 1; |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6057 } |
4444 | 6058 break; |
6059 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6060 case NFA_START_COLL: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6061 case NFA_START_NEG_COLL: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6062 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6063 /* What follows is a list of characters, until NFA_END_COLL. |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6064 * One of them must match or none of them must match. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6065 nfa_state_T *state; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6066 int result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6067 int c1, c2; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6068 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6069 /* Never match EOL. If it's part of the collection it is added |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6070 * as a separate state with an OR. */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6071 if (curc == NUL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6072 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6073 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6074 state = t->state->out; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6075 result_if_matched = (t->state->c == NFA_START_COLL); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6076 for (;;) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6077 { |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6078 if (state->c == NFA_END_COLL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6079 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6080 result = !result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6081 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6082 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6083 if (state->c == NFA_RANGE_MIN) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6084 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6085 c1 = state->val; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6086 state = state->out; /* advance to NFA_RANGE_MAX */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6087 c2 = state->val; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6088 #ifdef ENABLE_LOG |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6089 fprintf(log_fd, "NFA_RANGE_MIN curc=%d c1=%d c2=%d\n", |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6090 curc, c1, c2); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6091 #endif |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6092 if (curc >= c1 && curc <= c2) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6093 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6094 result = result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6095 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6096 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6097 if (ireg_ic) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6098 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6099 int curc_low = MB_TOLOWER(curc); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6100 int done = FALSE; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6101 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6102 for ( ; c1 <= c2; ++c1) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6103 if (MB_TOLOWER(c1) == curc_low) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6104 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6105 result = result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6106 done = TRUE; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6107 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6108 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6109 if (done) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6110 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6111 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6112 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6113 else if (state->c < 0 ? check_char_class(state->c, curc) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6114 : (curc == state->c |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6115 || (ireg_ic && MB_TOLOWER(curc) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6116 == MB_TOLOWER(state->c)))) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6117 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6118 result = result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6119 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6120 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6121 state = state->out; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6122 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6123 if (result) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6124 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6125 /* next state is in out of the NFA_END_COLL, out1 of |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6126 * START points to the END state */ |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6127 add_state = t->state->out1->out; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6128 add_off = clen; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6129 } |
4444 | 6130 break; |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6131 } |
4444 | 6132 |
6133 case NFA_ANY: | |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6134 /* Any char except '\0', (end of input) does not match. */ |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6135 if (curc > 0) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6136 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6137 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6138 add_off = clen; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6139 } |
4444 | 6140 break; |
6141 | |
5901 | 6142 case NFA_ANY_COMPOSING: |
6143 /* On a composing character skip over it. Otherwise do | |
6144 * nothing. Always matches. */ | |
6145 #ifdef FEAT_MBYTE | |
6146 if (enc_utf8 && utf_iscomposing(curc)) | |
6147 { | |
6148 add_off = clen; | |
6149 } | |
6150 else | |
6151 #endif | |
6152 { | |
6153 add_here = TRUE; | |
6154 add_off = 0; | |
6155 } | |
6156 add_state = t->state->out; | |
6157 break; | |
6158 | |
4444 | 6159 /* |
6160 * Character classes like \a for alpha, \d for digit etc. | |
6161 */ | |
6162 case NFA_IDENT: /* \i */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6163 result = vim_isIDc(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6164 ADD_STATE_IF_MATCH(t->state); |
4444 | 6165 break; |
6166 | |
6167 case NFA_SIDENT: /* \I */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6168 result = !VIM_ISDIGIT(curc) && vim_isIDc(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6169 ADD_STATE_IF_MATCH(t->state); |
4444 | 6170 break; |
6171 | |
6172 case NFA_KWORD: /* \k */ | |
4503 | 6173 result = vim_iswordp_buf(reginput, reg_buf); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6174 ADD_STATE_IF_MATCH(t->state); |
4444 | 6175 break; |
6176 | |
6177 case NFA_SKWORD: /* \K */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6178 result = !VIM_ISDIGIT(curc) |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6179 && vim_iswordp_buf(reginput, reg_buf); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6180 ADD_STATE_IF_MATCH(t->state); |
4444 | 6181 break; |
6182 | |
6183 case NFA_FNAME: /* \f */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6184 result = vim_isfilec(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6185 ADD_STATE_IF_MATCH(t->state); |
4444 | 6186 break; |
6187 | |
6188 case NFA_SFNAME: /* \F */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6189 result = !VIM_ISDIGIT(curc) && vim_isfilec(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6190 ADD_STATE_IF_MATCH(t->state); |
4444 | 6191 break; |
6192 | |
6193 case NFA_PRINT: /* \p */ | |
5221
9982ec574beb
updated for version 7.4a.036
Bram Moolenaar <bram@vim.org>
parents:
5212
diff
changeset
|
6194 result = vim_isprintc(PTR2CHAR(reginput)); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6195 ADD_STATE_IF_MATCH(t->state); |
4444 | 6196 break; |
6197 | |
6198 case NFA_SPRINT: /* \P */ | |
5221
9982ec574beb
updated for version 7.4a.036
Bram Moolenaar <bram@vim.org>
parents:
5212
diff
changeset
|
6199 result = !VIM_ISDIGIT(curc) && vim_isprintc(PTR2CHAR(reginput)); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6200 ADD_STATE_IF_MATCH(t->state); |
4444 | 6201 break; |
6202 | |
6203 case NFA_WHITE: /* \s */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6204 result = vim_iswhite(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6205 ADD_STATE_IF_MATCH(t->state); |
4444 | 6206 break; |
6207 | |
6208 case NFA_NWHITE: /* \S */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6209 result = curc != NUL && !vim_iswhite(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6210 ADD_STATE_IF_MATCH(t->state); |
4444 | 6211 break; |
6212 | |
6213 case NFA_DIGIT: /* \d */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6214 result = ri_digit(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6215 ADD_STATE_IF_MATCH(t->state); |
4444 | 6216 break; |
6217 | |
6218 case NFA_NDIGIT: /* \D */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6219 result = curc != NUL && !ri_digit(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6220 ADD_STATE_IF_MATCH(t->state); |
4444 | 6221 break; |
6222 | |
6223 case NFA_HEX: /* \x */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6224 result = ri_hex(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6225 ADD_STATE_IF_MATCH(t->state); |
4444 | 6226 break; |
6227 | |
6228 case NFA_NHEX: /* \X */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6229 result = curc != NUL && !ri_hex(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6230 ADD_STATE_IF_MATCH(t->state); |
4444 | 6231 break; |
6232 | |
6233 case NFA_OCTAL: /* \o */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6234 result = ri_octal(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6235 ADD_STATE_IF_MATCH(t->state); |
4444 | 6236 break; |
6237 | |
6238 case NFA_NOCTAL: /* \O */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6239 result = curc != NUL && !ri_octal(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6240 ADD_STATE_IF_MATCH(t->state); |
4444 | 6241 break; |
6242 | |
6243 case NFA_WORD: /* \w */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6244 result = ri_word(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6245 ADD_STATE_IF_MATCH(t->state); |
4444 | 6246 break; |
6247 | |
6248 case NFA_NWORD: /* \W */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6249 result = curc != NUL && !ri_word(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6250 ADD_STATE_IF_MATCH(t->state); |
4444 | 6251 break; |
6252 | |
6253 case NFA_HEAD: /* \h */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6254 result = ri_head(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6255 ADD_STATE_IF_MATCH(t->state); |
4444 | 6256 break; |
6257 | |
6258 case NFA_NHEAD: /* \H */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6259 result = curc != NUL && !ri_head(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6260 ADD_STATE_IF_MATCH(t->state); |
4444 | 6261 break; |
6262 | |
6263 case NFA_ALPHA: /* \a */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6264 result = ri_alpha(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6265 ADD_STATE_IF_MATCH(t->state); |
4444 | 6266 break; |
6267 | |
6268 case NFA_NALPHA: /* \A */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6269 result = curc != NUL && !ri_alpha(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6270 ADD_STATE_IF_MATCH(t->state); |
4444 | 6271 break; |
6272 | |
6273 case NFA_LOWER: /* \l */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6274 result = ri_lower(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6275 ADD_STATE_IF_MATCH(t->state); |
4444 | 6276 break; |
6277 | |
6278 case NFA_NLOWER: /* \L */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6279 result = curc != NUL && !ri_lower(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6280 ADD_STATE_IF_MATCH(t->state); |
4444 | 6281 break; |
6282 | |
6283 case NFA_UPPER: /* \u */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6284 result = ri_upper(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6285 ADD_STATE_IF_MATCH(t->state); |
4444 | 6286 break; |
6287 | |
6288 case NFA_NUPPER: /* \U */ | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6289 result = curc != NUL && !ri_upper(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6290 ADD_STATE_IF_MATCH(t->state); |
4444 | 6291 break; |
6292 | |
5296 | 6293 case NFA_LOWER_IC: /* [a-z] */ |
6294 result = ri_lower(curc) || (ireg_ic && ri_upper(curc)); | |
6295 ADD_STATE_IF_MATCH(t->state); | |
6296 break; | |
6297 | |
6298 case NFA_NLOWER_IC: /* [^a-z] */ | |
6299 result = curc != NUL | |
6300 && !(ri_lower(curc) || (ireg_ic && ri_upper(curc))); | |
6301 ADD_STATE_IF_MATCH(t->state); | |
6302 break; | |
6303 | |
6304 case NFA_UPPER_IC: /* [A-Z] */ | |
6305 result = ri_upper(curc) || (ireg_ic && ri_lower(curc)); | |
6306 ADD_STATE_IF_MATCH(t->state); | |
6307 break; | |
6308 | |
6309 case NFA_NUPPER_IC: /* ^[A-Z] */ | |
6310 result = curc != NUL | |
6311 && !(ri_upper(curc) || (ireg_ic && ri_lower(curc))); | |
6312 ADD_STATE_IF_MATCH(t->state); | |
6313 break; | |
6314 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6315 case NFA_BACKREF1: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6316 case NFA_BACKREF2: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6317 case NFA_BACKREF3: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6318 case NFA_BACKREF4: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6319 case NFA_BACKREF5: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6320 case NFA_BACKREF6: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6321 case NFA_BACKREF7: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6322 case NFA_BACKREF8: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6323 case NFA_BACKREF9: |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6324 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6325 case NFA_ZREF1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6326 case NFA_ZREF2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6327 case NFA_ZREF3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6328 case NFA_ZREF4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6329 case NFA_ZREF5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6330 case NFA_ZREF6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6331 case NFA_ZREF7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6332 case NFA_ZREF8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6333 case NFA_ZREF9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6334 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6335 /* \1 .. \9 \z1 .. \z9 */ |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6336 { |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6337 int subidx; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6338 int bytelen; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6339 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6340 if (t->state->c <= NFA_BACKREF9) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6341 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6342 subidx = t->state->c - NFA_BACKREF1 + 1; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6343 result = match_backref(&t->subs.norm, subidx, &bytelen); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6344 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6345 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6346 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6347 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6348 subidx = t->state->c - NFA_ZREF1 + 1; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6349 result = match_zref(subidx, &bytelen); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6350 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6351 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6352 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6353 if (result) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6354 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6355 if (bytelen == 0) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6356 { |
4692
08fbb1ce1bc5
updated for version 7.3.1093
Bram Moolenaar <bram@vim.org>
parents:
4690
diff
changeset
|
6357 /* empty match always works, output of NFA_SKIP to be |
08fbb1ce1bc5
updated for version 7.3.1093
Bram Moolenaar <bram@vim.org>
parents:
4690
diff
changeset
|
6358 * used next */ |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6359 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6360 add_state = t->state->out->out; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6361 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6362 else if (bytelen <= clen) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6363 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6364 /* match current character, jump ahead to out of |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6365 * NFA_SKIP */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6366 add_state = t->state->out->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6367 add_off = clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6368 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6369 else |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6370 { |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
6371 /* skip over the matched characters, set character |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6372 * count in NFA_SKIP */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6373 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6374 add_off = bytelen; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6375 add_count = bytelen - clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6376 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6377 } |
4482 | 6378 break; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6379 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6380 case NFA_SKIP: |
4748
4b9503f0c7d3
updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents:
4746
diff
changeset
|
6381 /* character of previous matching \1 .. \9 or \@> */ |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6382 if (t->count - clen <= 0) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6383 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6384 /* end of match, go to what follows */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6385 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6386 add_off = clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6387 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6388 else |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6389 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6390 /* add state again with decremented count */ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6391 add_state = t->state; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6392 add_off = 0; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6393 add_count = t->count - clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6394 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6395 break; |
4482 | 6396 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6397 case NFA_LNUM: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6398 case NFA_LNUM_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6399 case NFA_LNUM_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6400 result = (REG_MULTI && |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6401 nfa_re_num_cmp(t->state->val, t->state->c - NFA_LNUM, |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6402 (long_u)(reglnum + reg_firstlnum))); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6403 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6404 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6405 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6406 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6407 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6408 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6409 |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6410 case NFA_COL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6411 case NFA_COL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6412 case NFA_COL_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6413 result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_COL, |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6414 (long_u)(reginput - regline) + 1); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6415 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6416 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6417 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6418 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6419 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6420 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6421 |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6422 case NFA_VCOL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6423 case NFA_VCOL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6424 case NFA_VCOL_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6425 result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_VCOL, |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6426 (long_u)win_linetabsize( |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6427 reg_win == NULL ? curwin : reg_win, |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6428 regline, (colnr_T)(reginput - regline)) + 1); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6429 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6430 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6431 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6432 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6433 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6434 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6435 |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6436 case NFA_MARK: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6437 case NFA_MARK_GT: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6438 case NFA_MARK_LT: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6439 { |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6440 pos_T *pos = getmark_buf(reg_buf, t->state->val, FALSE); |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6441 |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6442 /* Compare the mark position to the match position. */ |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6443 result = (pos != NULL /* mark doesn't exist */ |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6444 && pos->lnum > 0 /* mark isn't set in reg_buf */ |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6445 && (pos->lnum == reglnum + reg_firstlnum |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6446 ? (pos->col == (colnr_T)(reginput - regline) |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6447 ? t->state->c == NFA_MARK |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6448 : (pos->col < (colnr_T)(reginput - regline) |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6449 ? t->state->c == NFA_MARK_GT |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6450 : t->state->c == NFA_MARK_LT)) |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6451 : (pos->lnum < reglnum + reg_firstlnum |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6452 ? t->state->c == NFA_MARK_GT |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6453 : t->state->c == NFA_MARK_LT))); |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6454 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6455 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6456 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6457 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6458 } |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6459 break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6460 } |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6461 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6462 case NFA_CURSOR: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6463 result = (reg_win != NULL |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6464 && (reglnum + reg_firstlnum == reg_win->w_cursor.lnum) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6465 && ((colnr_T)(reginput - regline) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6466 == reg_win->w_cursor.col)); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6467 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6468 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6469 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6470 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6471 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6472 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6473 |
4756
96f3348f9f11
updated for version 7.3.1125
Bram Moolenaar <bram@vim.org>
parents:
4750
diff
changeset
|
6474 case NFA_VISUAL: |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6475 result = reg_match_visual(); |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6476 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6477 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6478 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6479 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6480 } |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6481 break; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6482 |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6483 case NFA_MOPEN1: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6484 case NFA_MOPEN2: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6485 case NFA_MOPEN3: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6486 case NFA_MOPEN4: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6487 case NFA_MOPEN5: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6488 case NFA_MOPEN6: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6489 case NFA_MOPEN7: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6490 case NFA_MOPEN8: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6491 case NFA_MOPEN9: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6492 #ifdef FEAT_SYN_HL |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6493 case NFA_ZOPEN: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6494 case NFA_ZOPEN1: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6495 case NFA_ZOPEN2: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6496 case NFA_ZOPEN3: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6497 case NFA_ZOPEN4: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6498 case NFA_ZOPEN5: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6499 case NFA_ZOPEN6: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6500 case NFA_ZOPEN7: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6501 case NFA_ZOPEN8: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6502 case NFA_ZOPEN9: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6503 #endif |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6504 case NFA_NOPEN: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6505 case NFA_ZSTART: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6506 /* These states are only added to be able to bail out when |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6507 * they are added again, nothing is to be done. */ |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6508 break; |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6509 |
4444 | 6510 default: /* regular character */ |
4559
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6511 { |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6512 int c = t->state->c; |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6513 |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6514 #ifdef DEBUG |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6515 if (c < 0) |
4559
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6516 EMSGN("INTERNAL: Negative state char: %ld", c); |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6517 #endif |
4559
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6518 result = (c == curc); |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6519 |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6520 if (!result && ireg_ic) |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6521 result = MB_TOLOWER(c) == MB_TOLOWER(curc); |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6522 #ifdef FEAT_MBYTE |
5901 | 6523 /* If ireg_icombine is not set only skip over the character |
6524 * itself. When it is set skip over composing characters. */ | |
6525 if (result && enc_utf8 && !ireg_icombine) | |
6526 clen = utf_char2len(curc); | |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6527 #endif |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6528 ADD_STATE_IF_MATCH(t->state); |
4444 | 6529 break; |
4559
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6530 } |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6531 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6532 } /* switch (t->state->c) */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6533 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6534 if (add_state != NULL) |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6535 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6536 nfa_pim_T *pim; |
5401 | 6537 nfa_pim_T pim_copy; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6538 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6539 if (t->pim.result == NFA_PIM_UNUSED) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6540 pim = NULL; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6541 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6542 pim = &t->pim; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6543 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6544 /* Handle the postponed invisible match if the match might end |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6545 * without advancing and before the end of the line. */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6546 if (pim != NULL && (clen == 0 || match_follows(add_state, 0))) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6547 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6548 if (pim->result == NFA_PIM_TODO) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6549 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6550 #ifdef ENABLE_LOG |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6551 fprintf(log_fd, "\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6552 fprintf(log_fd, "==================================\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6553 fprintf(log_fd, "Postponed recursive nfa_regmatch()\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6554 fprintf(log_fd, "\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6555 #endif |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6556 result = recursive_regmatch(pim->state, pim, |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6557 prog, submatch, m, &listids); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6558 pim->result = result ? NFA_PIM_MATCH : NFA_PIM_NOMATCH; |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6559 /* for \@! and \@<! it is a match when the result is |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6560 * FALSE */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6561 if (result != (pim->state->c == NFA_START_INVISIBLE_NEG |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6562 || pim->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6563 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6564 == NFA_START_INVISIBLE_BEFORE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6565 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6566 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6567 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6568 /* Copy submatch info from the recursive call */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6569 copy_sub_off(&pim->subs.norm, &m->norm); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6570 #ifdef FEAT_SYN_HL |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
6571 if (nfa_has_zsubexpr) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6572 copy_sub_off(&pim->subs.synt, &m->synt); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6573 #endif |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6574 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6575 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6576 else |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6577 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6578 result = (pim->result == NFA_PIM_MATCH); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6579 #ifdef ENABLE_LOG |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6580 fprintf(log_fd, "\n"); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6581 fprintf(log_fd, "Using previous recursive nfa_regmatch() result, result == %d\n", pim->result); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6582 fprintf(log_fd, "MATCH = %s\n", result == TRUE ? "OK" : "FALSE"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6583 fprintf(log_fd, "\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6584 #endif |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6585 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6586 |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6587 /* for \@! and \@<! it is a match when result is FALSE */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6588 if (result != (pim->state->c == NFA_START_INVISIBLE_NEG |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6589 || pim->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6590 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6591 == NFA_START_INVISIBLE_BEFORE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6592 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6593 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6594 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6595 /* Copy submatch info from the recursive call */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6596 copy_sub_off(&t->subs.norm, &pim->subs.norm); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6597 #ifdef FEAT_SYN_HL |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
6598 if (nfa_has_zsubexpr) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6599 copy_sub_off(&t->subs.synt, &pim->subs.synt); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6600 #endif |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6601 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6602 else |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6603 /* look-behind match failed, don't add the state */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6604 continue; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6605 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6606 /* Postponed invisible match was handled, don't add it to |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6607 * following states. */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6608 pim = NULL; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6609 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6610 |
5401 | 6611 /* If "pim" points into l->t it will become invalid when |
6612 * adding the state causes the list to be reallocated. Make a | |
6613 * local copy to avoid that. */ | |
6614 if (pim == &t->pim) | |
6615 { | |
6616 copy_pim(&pim_copy, pim); | |
6617 pim = &pim_copy; | |
6618 } | |
6619 | |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6620 if (add_here) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6621 addstate_here(thislist, add_state, &t->subs, pim, &listidx); |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6622 else |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6623 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6624 addstate(nextlist, add_state, &t->subs, pim, add_off); |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6625 if (add_count > 0) |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6626 nextlist->t[nextlist->n - 1].count = add_count; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6627 } |
4444 | 6628 } |
6629 | |
6630 } /* for (thislist = thislist; thislist->state; thislist++) */ | |
6631 | |
4557
888c12c899e5
updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents:
4555
diff
changeset
|
6632 /* Look for the start of a match in the current position by adding the |
888c12c899e5
updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents:
4555
diff
changeset
|
6633 * start state to the list of states. |
888c12c899e5
updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents:
4555
diff
changeset
|
6634 * The first found match is the leftmost one, thus the order of states |
888c12c899e5
updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents:
4555
diff
changeset
|
6635 * matters! |
888c12c899e5
updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents:
4555
diff
changeset
|
6636 * Do not add the start state in recursive calls of nfa_regmatch(), |
888c12c899e5
updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents:
4555
diff
changeset
|
6637 * because recursive calls should only start in the first position. |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6638 * Unless "nfa_endp" is not NULL, then we match the end position. |
4557
888c12c899e5
updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents:
4555
diff
changeset
|
6639 * Also don't start a match past the first line. */ |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6640 if (nfa_match == FALSE |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6641 && ((toplevel |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6642 && reglnum == 0 |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6643 && clen != 0 |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6644 && (ireg_maxcol == 0 |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6645 || (colnr_T)(reginput - regline) < ireg_maxcol)) |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6646 || (nfa_endp != NULL |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6647 && (REG_MULTI |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6648 ? (reglnum < nfa_endp->se_u.pos.lnum |
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6649 || (reglnum == nfa_endp->se_u.pos.lnum |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6650 && (int)(reginput - regline) |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6651 < nfa_endp->se_u.pos.col)) |
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6652 : reginput < nfa_endp->se_u.ptr)))) |
4444 | 6653 { |
6654 #ifdef ENABLE_LOG | |
6655 fprintf(log_fd, "(---) STARTSTATE\n"); | |
6656 #endif | |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6657 /* Inline optimized code for addstate() if we know the state is |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6658 * the first MOPEN. */ |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6659 if (toplevel) |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6660 { |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6661 int add = TRUE; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6662 int c; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6663 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6664 if (prog->regstart != NUL && clen != 0) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6665 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6666 if (nextlist->n == 0) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6667 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6668 colnr_T col = (colnr_T)(reginput - regline) + clen; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6669 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6670 /* Nextlist is empty, we can skip ahead to the |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6671 * character that must appear at the start. */ |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6672 if (skip_to_start(prog->regstart, &col) == FAIL) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6673 break; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6674 #ifdef ENABLE_LOG |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6675 fprintf(log_fd, " Skipping ahead %d bytes to regstart\n", |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6676 col - ((colnr_T)(reginput - regline) + clen)); |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6677 #endif |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6678 reginput = regline + col - clen; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6679 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6680 else |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6681 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6682 /* Checking if the required start character matches is |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6683 * cheaper than adding a state that won't match. */ |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6684 c = PTR2CHAR(reginput + clen); |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6685 if (c != prog->regstart && (!ireg_ic || MB_TOLOWER(c) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6686 != MB_TOLOWER(prog->regstart))) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6687 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6688 #ifdef ENABLE_LOG |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6689 fprintf(log_fd, " Skipping start state, regstart does not match\n"); |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6690 #endif |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6691 add = FALSE; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6692 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6693 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6694 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6695 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6696 if (add) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6697 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6698 if (REG_MULTI) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6699 m->norm.list.multi[0].start.col = |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6700 (colnr_T)(reginput - regline) + clen; |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6701 else |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6702 m->norm.list.line[0].start = reginput + clen; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6703 addstate(nextlist, start->out, m, NULL, clen); |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6704 } |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6705 } |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6706 else |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6707 addstate(nextlist, start, m, NULL, clen); |
4444 | 6708 } |
6709 | |
6710 #ifdef ENABLE_LOG | |
6711 fprintf(log_fd, ">>> Thislist had %d states available: ", thislist->n); | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6712 { |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6713 int i; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6714 |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6715 for (i = 0; i < thislist->n; i++) |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6716 fprintf(log_fd, "%d ", abs(thislist->t[i].state->id)); |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6717 } |
4444 | 6718 fprintf(log_fd, "\n"); |
6719 #endif | |
6720 | |
6721 nextchar: | |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6722 /* Advance to the next character, or advance to the next line, or |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6723 * finish. */ |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6724 if (clen != 0) |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6725 reginput += clen; |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6726 else if (go_to_nextline || (nfa_endp != NULL && REG_MULTI |
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6727 && reglnum < nfa_endp->se_u.pos.lnum)) |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6728 reg_nextline(); |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6729 else |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6730 break; |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6731 } |
4444 | 6732 |
6733 #ifdef ENABLE_LOG | |
6734 if (log_fd != stderr) | |
6735 fclose(log_fd); | |
6736 log_fd = NULL; | |
6737 #endif | |
6738 | |
6739 theend: | |
6740 /* Free memory */ | |
6741 vim_free(list[0].t); | |
6742 vim_free(list[1].t); | |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
6743 vim_free(listids); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6744 #undef ADD_STATE_IF_MATCH |
4460 | 6745 #ifdef NFA_REGEXP_DEBUG_LOG |
4444 | 6746 fclose(debug); |
6747 #endif | |
6748 | |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
6749 return nfa_match; |
4444 | 6750 } |
6751 | |
6752 /* | |
6753 * Try match of "prog" with at regline["col"]. | |
6754 * Returns 0 for failure, number of lines contained in the match otherwise. | |
6755 */ | |
6756 static long | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6757 nfa_regtry(prog, col) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6758 nfa_regprog_T *prog; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6759 colnr_T col; |
4444 | 6760 { |
6761 int i; | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6762 regsubs_T subs, m; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6763 nfa_state_T *start = prog->start; |
4444 | 6764 #ifdef ENABLE_LOG |
6765 FILE *f; | |
6766 #endif | |
6767 | |
6768 reginput = regline + col; | |
6769 | |
6770 #ifdef ENABLE_LOG | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
6771 f = fopen(NFA_REGEXP_RUN_LOG, "a"); |
4444 | 6772 if (f != NULL) |
6773 { | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6774 fprintf(f, "\n\n\t=======================================================\n"); |
4444 | 6775 #ifdef DEBUG |
6776 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr); | |
6777 #endif | |
6778 fprintf(f, "\tInput text is \"%s\" \n", reginput); | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6779 fprintf(f, "\t=======================================================\n\n"); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
6780 nfa_print_state(f, start); |
4444 | 6781 fprintf(f, "\n\n"); |
6782 fclose(f); | |
6783 } | |
6784 else | |
6785 EMSG(_("Could not open temporary log file for writing ")); | |
6786 #endif | |
6787 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6788 clear_sub(&subs.norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6789 clear_sub(&m.norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6790 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6791 clear_sub(&subs.synt); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6792 clear_sub(&m.synt); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6793 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6794 |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
6795 if (nfa_regmatch(prog, start, &subs, &m) == FALSE) |
4444 | 6796 return 0; |
6797 | |
6798 cleanup_subexpr(); | |
6799 if (REG_MULTI) | |
6800 { | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6801 for (i = 0; i < subs.norm.in_use; i++) |
4444 | 6802 { |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6803 reg_startpos[i] = subs.norm.list.multi[i].start; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6804 reg_endpos[i] = subs.norm.list.multi[i].end; |
4444 | 6805 } |
6806 | |
6807 if (reg_startpos[0].lnum < 0) | |
6808 { | |
6809 reg_startpos[0].lnum = 0; | |
6810 reg_startpos[0].col = col; | |
6811 } | |
6812 if (reg_endpos[0].lnum < 0) | |
6813 { | |
4569
f262fb02889d
updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents:
4567
diff
changeset
|
6814 /* pattern has a \ze but it didn't match, use current end */ |
4444 | 6815 reg_endpos[0].lnum = reglnum; |
6816 reg_endpos[0].col = (int)(reginput - regline); | |
6817 } | |
6818 else | |
6819 /* Use line number of "\ze". */ | |
6820 reglnum = reg_endpos[0].lnum; | |
6821 } | |
6822 else | |
6823 { | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6824 for (i = 0; i < subs.norm.in_use; i++) |
4444 | 6825 { |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6826 reg_startp[i] = subs.norm.list.line[i].start; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6827 reg_endp[i] = subs.norm.list.line[i].end; |
4444 | 6828 } |
6829 | |
6830 if (reg_startp[0] == NULL) | |
6831 reg_startp[0] = regline + col; | |
6832 if (reg_endp[0] == NULL) | |
6833 reg_endp[0] = reginput; | |
6834 } | |
6835 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6836 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6837 /* Package any found \z(...\) matches for export. Default is none. */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6838 unref_extmatch(re_extmatch_out); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6839 re_extmatch_out = NULL; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6840 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6841 if (prog->reghasz == REX_SET) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6842 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6843 cleanup_zsubexpr(); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6844 re_extmatch_out = make_extmatch(); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6845 for (i = 0; i < subs.synt.in_use; i++) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6846 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6847 if (REG_MULTI) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6848 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6849 struct multipos *mpos = &subs.synt.list.multi[i]; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6850 |
5820 | 6851 /* Only accept single line matches that are valid. */ |
6852 if (mpos->start.lnum >= 0 | |
6853 && mpos->start.lnum == mpos->end.lnum | |
6854 && mpos->end.col >= mpos->start.col) | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6855 re_extmatch_out->matches[i] = |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6856 vim_strnsave(reg_getline(mpos->start.lnum) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6857 + mpos->start.col, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6858 mpos->end.col - mpos->start.col); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6859 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6860 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6861 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6862 struct linepos *lpos = &subs.synt.list.line[i]; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6863 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6864 if (lpos->start != NULL && lpos->end != NULL) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6865 re_extmatch_out->matches[i] = |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6866 vim_strnsave(lpos->start, |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6867 (int)(lpos->end - lpos->start)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6868 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6869 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6870 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6871 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6872 |
4444 | 6873 return 1 + reglnum; |
6874 } | |
6875 | |
6876 /* | |
6877 * Match a regexp against a string ("line" points to the string) or multiple | |
6878 * lines ("line" is NULL, use reg_getline()). | |
6879 * | |
6880 * Returns 0 for failure, number of lines contained in the match otherwise. | |
6881 */ | |
6882 static long | |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6883 nfa_regexec_both(line, startcol) |
4444 | 6884 char_u *line; |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6885 colnr_T startcol; /* column to start looking for match */ |
4444 | 6886 { |
6887 nfa_regprog_T *prog; | |
6888 long retval = 0L; | |
6889 int i; | |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6890 colnr_T col = startcol; |
4444 | 6891 |
6892 if (REG_MULTI) | |
6893 { | |
6894 prog = (nfa_regprog_T *)reg_mmatch->regprog; | |
6895 line = reg_getline((linenr_T)0); /* relative to the cursor */ | |
6896 reg_startpos = reg_mmatch->startpos; | |
6897 reg_endpos = reg_mmatch->endpos; | |
6898 } | |
6899 else | |
6900 { | |
6901 prog = (nfa_regprog_T *)reg_match->regprog; | |
6902 reg_startp = reg_match->startp; | |
6903 reg_endp = reg_match->endp; | |
6904 } | |
6905 | |
6906 /* Be paranoid... */ | |
6907 if (prog == NULL || line == NULL) | |
6908 { | |
6909 EMSG(_(e_null)); | |
6910 goto theend; | |
6911 } | |
6912 | |
6913 /* If pattern contains "\c" or "\C": overrule value of ireg_ic */ | |
6914 if (prog->regflags & RF_ICASE) | |
6915 ireg_ic = TRUE; | |
6916 else if (prog->regflags & RF_NOICASE) | |
6917 ireg_ic = FALSE; | |
6918 | |
6919 #ifdef FEAT_MBYTE | |
6920 /* If pattern contains "\Z" overrule value of ireg_icombine */ | |
6921 if (prog->regflags & RF_ICOMBINE) | |
6922 ireg_icombine = TRUE; | |
6923 #endif | |
6924 | |
6925 regline = line; | |
6926 reglnum = 0; /* relative to line */ | |
6927 | |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
6928 nfa_has_zend = prog->has_zend; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
6929 nfa_has_backref = prog->has_backref; |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
6930 nfa_nsubexpr = prog->nsubexp; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
6931 nfa_listid = 1; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
6932 nfa_alt_listid = 2; |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
6933 #ifdef DEBUG |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
6934 nfa_regengine.expr = prog->pattern; |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
6935 #endif |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
6936 |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6937 if (prog->reganch && col > 0) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6938 return 0L; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6939 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6940 need_clear_subexpr = TRUE; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6941 #ifdef FEAT_SYN_HL |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6942 /* Clear the external match subpointers if necessary. */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6943 if (prog->reghasz == REX_SET) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6944 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6945 nfa_has_zsubexpr = TRUE; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6946 need_clear_zsubexpr = TRUE; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6947 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6948 else |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6949 nfa_has_zsubexpr = FALSE; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6950 #endif |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6951 |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6952 if (prog->regstart != NUL) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6953 { |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6954 /* Skip ahead until a character we know the match must start with. |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6955 * When there is none there is no match. */ |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6956 if (skip_to_start(prog->regstart, &col) == FAIL) |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6957 return 0L; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6958 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6959 /* If match_text is set it contains the full text that must match. |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6960 * Nothing else to try. Doesn't handle combining chars well. */ |
4811
9909e44879b9
updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents:
4809
diff
changeset
|
6961 if (prog->match_text != NULL |
9909e44879b9
updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents:
4809
diff
changeset
|
6962 #ifdef FEAT_MBYTE |
9909e44879b9
updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents:
4809
diff
changeset
|
6963 && !ireg_icombine |
9909e44879b9
updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents:
4809
diff
changeset
|
6964 #endif |
9909e44879b9
updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents:
4809
diff
changeset
|
6965 ) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6966 return find_match_text(col, prog->regstart, prog->match_text); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6967 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
6968 |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6969 /* If the start column is past the maximum column: no need to try. */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6970 if (ireg_maxcol > 0 && col >= ireg_maxcol) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6971 goto theend; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
6972 |
4444 | 6973 nstate = prog->nstate; |
6974 for (i = 0; i < nstate; ++i) | |
6975 { | |
6976 prog->state[i].id = i; | |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
6977 prog->state[i].lastlist[0] = 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
6978 prog->state[i].lastlist[1] = 0; |
4444 | 6979 } |
6980 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6981 retval = nfa_regtry(prog, col); |
4444 | 6982 |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
6983 #ifdef DEBUG |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
6984 nfa_regengine.expr = NULL; |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
6985 #endif |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
6986 |
4444 | 6987 theend: |
6988 return retval; | |
6989 } | |
6990 | |
6991 /* | |
6992 * Compile a regular expression into internal code for the NFA matcher. | |
6993 * Returns the program in allocated space. Returns NULL for an error. | |
6994 */ | |
6995 static regprog_T * | |
6996 nfa_regcomp(expr, re_flags) | |
6997 char_u *expr; | |
6998 int re_flags; | |
6999 { | |
4541
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7000 nfa_regprog_T *prog = NULL; |
4458 | 7001 size_t prog_size; |
4444 | 7002 int *postfix; |
7003 | |
7004 if (expr == NULL) | |
7005 return NULL; | |
7006 | |
7007 #ifdef DEBUG | |
7008 nfa_regengine.expr = expr; | |
7009 #endif | |
7010 | |
7011 init_class_tab(); | |
7012 | |
7013 if (nfa_regcomp_start(expr, re_flags) == FAIL) | |
7014 return NULL; | |
7015 | |
7016 /* Build postfix form of the regexp. Needed to build the NFA | |
4541
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7017 * (and count its size). */ |
4444 | 7018 postfix = re2post(); |
7019 if (postfix == NULL) | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
7020 { |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
7021 /* TODO: only give this error for debugging? */ |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
7022 if (post_ptr >= post_end) |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
7023 EMSGN("Internal error: estimated max number of states insufficient: %ld", post_end - post_start); |
4444 | 7024 goto fail; /* Cascaded (syntax?) error */ |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
7025 } |
4444 | 7026 |
7027 /* | |
7028 * In order to build the NFA, we parse the input regexp twice: | |
7029 * 1. first pass to count size (so we can allocate space) | |
7030 * 2. second to emit code | |
7031 */ | |
7032 #ifdef ENABLE_LOG | |
7033 { | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
7034 FILE *f = fopen(NFA_REGEXP_RUN_LOG, "a"); |
4444 | 7035 |
7036 if (f != NULL) | |
7037 { | |
7038 fprintf(f, "\n*****************************\n\n\n\n\tCompiling regexp \"%s\" ... hold on !\n", expr); | |
7039 fclose(f); | |
7040 } | |
7041 } | |
7042 #endif | |
7043 | |
7044 /* | |
7045 * PASS 1 | |
7046 * Count number of NFA states in "nstate". Do not build the NFA. | |
7047 */ | |
7048 post2nfa(postfix, post_ptr, TRUE); | |
4541
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7049 |
4837
05b8436873d4
updated for version 7.3.1165
Bram Moolenaar <bram@vim.org>
parents:
4821
diff
changeset
|
7050 /* allocate the regprog with space for the compiled regexp */ |
05b8436873d4
updated for version 7.3.1165
Bram Moolenaar <bram@vim.org>
parents:
4821
diff
changeset
|
7051 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1); |
4541
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7052 prog = (nfa_regprog_T *)lalloc(prog_size, TRUE); |
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7053 if (prog == NULL) |
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7054 goto fail; |
4444 | 7055 state_ptr = prog->state; |
7056 | |
7057 /* | |
7058 * PASS 2 | |
7059 * Build the NFA | |
7060 */ | |
7061 prog->start = post2nfa(postfix, post_ptr, FALSE); | |
7062 if (prog->start == NULL) | |
7063 goto fail; | |
7064 | |
7065 prog->regflags = regflags; | |
7066 prog->engine = &nfa_regengine; | |
7067 prog->nstate = nstate; | |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
7068 prog->has_zend = nfa_has_zend; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
7069 prog->has_backref = nfa_has_backref; |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
7070 prog->nsubexp = regnpar; |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7071 |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
7072 nfa_postprocess(prog); |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
7073 |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7074 prog->reganch = nfa_get_reganch(prog->start, 0); |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7075 prog->regstart = nfa_get_regstart(prog->start, 0); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7076 prog->match_text = nfa_get_match_text(prog->start); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7077 |
4444 | 7078 #ifdef ENABLE_LOG |
7079 nfa_postfix_dump(expr, OK); | |
7080 nfa_dump(prog); | |
7081 #endif | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7082 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7083 /* Remember whether this pattern has any \z specials in it. */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7084 prog->reghasz = re_has_z; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7085 #endif |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
7086 #ifdef DEBUG |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7087 prog->pattern = vim_strsave(expr); |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
7088 nfa_regengine.expr = NULL; |
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
7089 #endif |
4444 | 7090 |
7091 out: | |
7092 vim_free(post_start); | |
7093 post_start = post_ptr = post_end = NULL; | |
7094 state_ptr = NULL; | |
7095 return (regprog_T *)prog; | |
7096 | |
7097 fail: | |
7098 vim_free(prog); | |
7099 prog = NULL; | |
7100 #ifdef ENABLE_LOG | |
7101 nfa_postfix_dump(expr, FAIL); | |
7102 #endif | |
7103 #ifdef DEBUG | |
7104 nfa_regengine.expr = NULL; | |
7105 #endif | |
7106 goto out; | |
7107 } | |
7108 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7109 /* |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7110 * Free a compiled regexp program, returned by nfa_regcomp(). |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7111 */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7112 static void |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7113 nfa_regfree(prog) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7114 regprog_T *prog; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7115 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7116 if (prog != NULL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7117 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7118 vim_free(((nfa_regprog_T *)prog)->match_text); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7119 #ifdef DEBUG |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7120 vim_free(((nfa_regprog_T *)prog)->pattern); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7121 #endif |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7122 vim_free(prog); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7123 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7124 } |
4444 | 7125 |
7126 /* | |
7127 * Match a regexp against a string. | |
7128 * "rmp->regprog" is a compiled regexp as returned by nfa_regcomp(). | |
7129 * Uses curbuf for line count and 'iskeyword'. | |
5838 | 7130 * If "line_lbr" is TRUE consider a "\n" in "line" to be a line break. |
4444 | 7131 * |
7132 * Return TRUE if there is a match, FALSE if not. | |
7133 */ | |
7134 static int | |
5838 | 7135 nfa_regexec_nl(rmp, line, col, line_lbr) |
4444 | 7136 regmatch_T *rmp; |
7137 char_u *line; /* string to match against */ | |
7138 colnr_T col; /* column to start looking for match */ | |
5838 | 7139 int line_lbr; |
4444 | 7140 { |
7141 reg_match = rmp; | |
7142 reg_mmatch = NULL; | |
7143 reg_maxline = 0; | |
5838 | 7144 reg_line_lbr = line_lbr; |
4444 | 7145 reg_buf = curbuf; |
7146 reg_win = NULL; | |
7147 ireg_ic = rmp->rm_ic; | |
7148 #ifdef FEAT_MBYTE | |
7149 ireg_icombine = FALSE; | |
7150 #endif | |
7151 ireg_maxcol = 0; | |
7152 return (nfa_regexec_both(line, col) != 0); | |
7153 } | |
7154 | |
7155 | |
7156 /* | |
7157 * Match a regexp against multiple lines. | |
7158 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). | |
7159 * Uses curbuf for line count and 'iskeyword'. | |
7160 * | |
7161 * Return zero if there is no match. Return number of lines contained in the | |
7162 * match otherwise. | |
7163 * | |
7164 * Note: the body is the same as bt_regexec() except for nfa_regexec_both() | |
7165 * | |
7166 * ! Also NOTE : match may actually be in another line. e.g.: | |
7167 * when r.e. is \nc, cursor is at 'a' and the text buffer looks like | |
7168 * | |
7169 * +-------------------------+ | |
7170 * |a | | |
7171 * |b | | |
7172 * |c | | |
7173 * | | | |
7174 * +-------------------------+ | |
7175 * | |
7176 * then nfa_regexec_multi() returns 3. while the original | |
7177 * vim_regexec_multi() returns 0 and a second call at line 2 will return 2. | |
7178 * | |
7179 * FIXME if this behavior is not compatible. | |
7180 */ | |
7181 static long | |
7182 nfa_regexec_multi(rmp, win, buf, lnum, col, tm) | |
7183 regmmatch_T *rmp; | |
7184 win_T *win; /* window in which to search or NULL */ | |
7185 buf_T *buf; /* buffer in which to search */ | |
7186 linenr_T lnum; /* nr of line to start looking for match */ | |
7187 colnr_T col; /* column to start looking for match */ | |
7188 proftime_T *tm UNUSED; /* timeout limit or NULL */ | |
7189 { | |
7190 reg_match = NULL; | |
7191 reg_mmatch = rmp; | |
7192 reg_buf = buf; | |
7193 reg_win = win; | |
7194 reg_firstlnum = lnum; | |
7195 reg_maxline = reg_buf->b_ml.ml_line_count - lnum; | |
7196 reg_line_lbr = FALSE; | |
7197 ireg_ic = rmp->rmm_ic; | |
7198 #ifdef FEAT_MBYTE | |
7199 ireg_icombine = FALSE; | |
7200 #endif | |
7201 ireg_maxcol = rmp->rmm_maxcol; | |
7202 | |
4503 | 7203 return nfa_regexec_both(NULL, col); |
4444 | 7204 } |
7205 | |
7206 #ifdef DEBUG | |
7207 # undef ENABLE_LOG | |
7208 #endif |