Mercurial > vim
annotate src/regexp_nfa.c @ 23584:397f95f103e8 v8.2.2334
patch 8.2.2334: Pascal-like filetypes not always detected
Commit: https://github.com/vim/vim/commit/a0122dcd1cc9e9bb62c071a9b91426a8bce4f8d9
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jan 12 17:42:24 2021 +0100
patch 8.2.2334: Pascal-like filetypes not always detected
Problem: Pascal-like filetypes not always detected.
Solution: Improved Puppet, InstantFPC and Pascal detection. (Doug Kearns,
closes #7662)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 12 Jan 2021 17:45:04 +0100 |
parents | a7cdfc8e4b6e |
children | 585695c70392 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9371
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
4444 | 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 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
32 // Added to NFA_ANY - NFA_NUPPER_IC to include a NL. |
5296 | 33 #define NFA_ADD_NL 31 |
34 | |
4444 | 35 enum |
36 { | |
37 NFA_SPLIT = -1024, | |
38 NFA_MATCH, | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
39 NFA_EMPTY, // matches 0-length |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
40 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
41 NFA_START_COLL, // [abc] start |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
42 NFA_END_COLL, // [abc] end |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
43 NFA_START_NEG_COLL, // [^abc] start |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
44 NFA_END_NEG_COLL, // [^abc] end (postfix only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
45 NFA_RANGE, // range of the two previous items |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
46 // (postfix only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
47 NFA_RANGE_MIN, // low end of a range |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
48 NFA_RANGE_MAX, // high end of a range |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
49 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
50 NFA_CONCAT, // concatenate two previous items (postfix |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
51 // only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
52 NFA_OR, // \| (postfix only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
53 NFA_STAR, // greedy * (postfix only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
54 NFA_STAR_NONGREEDY, // non-greedy * (postfix only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
55 NFA_QUEST, // greedy \? (postfix only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
56 NFA_QUEST_NONGREEDY, // non-greedy \? (postfix only) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
57 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
58 NFA_BOL, // ^ Begin line |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
59 NFA_EOL, // $ End line |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
60 NFA_BOW, // \< Begin word |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
61 NFA_EOW, // \> End word |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
62 NFA_BOF, // \%^ Begin file |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
63 NFA_EOF, // \%$ End file |
4444 | 64 NFA_NEWL, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
65 NFA_ZSTART, // Used for \zs |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
66 NFA_ZEND, // Used for \ze |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
67 NFA_NOPEN, // Start of subexpression marked with \%( |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
68 NFA_NCLOSE, // End of subexpr. marked with \%( ... \) |
4444 | 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, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
81 NFA_COMPOSING, // Next nodes in NFA are part of the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
82 // composing multibyte char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
83 NFA_END_COMPOSING, // End of a composing char in the NFA |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
84 NFA_ANY_COMPOSING, // \%C: Any composing characters. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
85 NFA_OPT_CHARS, // \%[abc] |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
86 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
87 // The following are used only in the postfix form, not in the NFA |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
88 NFA_PREV_ATOM_NO_WIDTH, // Used for \@= |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
89 NFA_PREV_ATOM_NO_WIDTH_NEG, // Used for \@! |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
90 NFA_PREV_ATOM_JUST_BEFORE, // Used for \@<= |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
91 NFA_PREV_ATOM_JUST_BEFORE_NEG, // Used for \@<! |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
92 NFA_PREV_ATOM_LIKE_PATTERN, // Used for \@> |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
93 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
94 NFA_BACKREF1, // \1 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
95 NFA_BACKREF2, // \2 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
96 NFA_BACKREF3, // \3 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
97 NFA_BACKREF4, // \4 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
98 NFA_BACKREF5, // \5 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
99 NFA_BACKREF6, // \6 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
100 NFA_BACKREF7, // \7 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
101 NFA_BACKREF8, // \8 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
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 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
104 NFA_ZREF1, // \z1 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
105 NFA_ZREF2, // \z2 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
106 NFA_ZREF3, // \z3 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
107 NFA_ZREF4, // \z4 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
108 NFA_ZREF5, // \z5 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
109 NFA_ZREF6, // \z6 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
110 NFA_ZREF7, // \z7 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
111 NFA_ZREF8, // \z8 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
112 NFA_ZREF9, // \z9 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
113 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
114 NFA_SKIP, // Skip characters |
4571
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 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
162 // NFA_FIRST_NL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
163 NFA_ANY, // Match any one character. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
164 NFA_IDENT, // Match identifier char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
165 NFA_SIDENT, // Match identifier char but no digit |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
166 NFA_KWORD, // Match keyword char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
167 NFA_SKWORD, // Match word char but no digit |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
168 NFA_FNAME, // Match file name char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
169 NFA_SFNAME, // Match file name char but no digit |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
170 NFA_PRINT, // Match printable char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
171 NFA_SPRINT, // Match printable char but no digit |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
172 NFA_WHITE, // Match whitespace char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
173 NFA_NWHITE, // Match non-whitespace char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
174 NFA_DIGIT, // Match digit char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
175 NFA_NDIGIT, // Match non-digit char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
176 NFA_HEX, // Match hex char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
177 NFA_NHEX, // Match non-hex char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
178 NFA_OCTAL, // Match octal char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
179 NFA_NOCTAL, // Match non-octal char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
180 NFA_WORD, // Match word char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
181 NFA_NWORD, // Match non-word char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
182 NFA_HEAD, // Match head char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
183 NFA_NHEAD, // Match non-head char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
184 NFA_ALPHA, // Match alpha char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
185 NFA_NALPHA, // Match non-alpha char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
186 NFA_LOWER, // Match lowercase char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
187 NFA_NLOWER, // Match non-lowercase char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
188 NFA_UPPER, // Match uppercase char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
189 NFA_NUPPER, // Match non-uppercase char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
190 NFA_LOWER_IC, // Match [a-z] |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
191 NFA_NLOWER_IC, // Match [^a-z] |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
192 NFA_UPPER_IC, // Match [A-Z] |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
193 NFA_NUPPER_IC, // Match [^A-Z] |
5296 | 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 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
198 NFA_CURSOR, // Match cursor pos |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
199 NFA_LNUM, // Match line number |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
200 NFA_LNUM_GT, // Match > line number |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
201 NFA_LNUM_LT, // Match < line number |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
202 NFA_COL, // Match cursor column |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
203 NFA_COL_GT, // Match > cursor column |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
204 NFA_COL_LT, // Match < cursor column |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
205 NFA_VCOL, // Match cursor virtual column |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
206 NFA_VCOL_GT, // Match > cursor virtual column |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
207 NFA_VCOL_LT, // Match < cursor virtual column |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
208 NFA_MARK, // Match mark |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
209 NFA_MARK_GT, // Match > mark |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
210 NFA_MARK_LT, // Match < mark |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
211 NFA_VISUAL, // Match Visual area |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
212 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
213 // Character classes [:alnum:] etc |
4444 | 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, | |
15709
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
229 NFA_CLASS_ESCAPE, |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
230 NFA_CLASS_IDENT, |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
231 NFA_CLASS_KEYWORD, |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
232 NFA_CLASS_FNAME |
4444 | 233 }; |
234 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
235 // Keep in sync with classchars. |
4444 | 236 static int nfa_classcodes[] = { |
237 NFA_ANY, NFA_IDENT, NFA_SIDENT, NFA_KWORD,NFA_SKWORD, | |
238 NFA_FNAME, NFA_SFNAME, NFA_PRINT, NFA_SPRINT, | |
239 NFA_WHITE, NFA_NWHITE, NFA_DIGIT, NFA_NDIGIT, | |
240 NFA_HEX, NFA_NHEX, NFA_OCTAL, NFA_NOCTAL, | |
241 NFA_WORD, NFA_NWORD, NFA_HEAD, NFA_NHEAD, | |
242 NFA_ALPHA, NFA_NALPHA, NFA_LOWER, NFA_NLOWER, | |
243 NFA_UPPER, NFA_NUPPER | |
244 }; | |
245 | |
5511 | 246 static char_u e_nul_found[] = N_("E865: (NFA) Regexp end encountered prematurely"); |
4444 | 247 static char_u e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c"); |
15876
0c49755f460e
patch 8.1.0945: internal error when using pattern with NL in the range
Bram Moolenaar <Bram@vim.org>
parents:
15824
diff
changeset
|
248 static char_u e_ill_char_class[] = N_("E877: (NFA regexp) Invalid character class: %d"); |
20677
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
249 static char_u e_value_too_large[] = N_("E951: \\% value too large"); |
4444 | 250 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
251 // Variables only used in nfa_regcomp() and descendants. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
252 static int nfa_re_flags; // re_flags passed to nfa_regcomp() |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
253 static int *post_start; // holds the postfix form of r.e. |
4444 | 254 static int *post_end; |
255 static int *post_ptr; | |
23471
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
256 |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
257 // Set when the pattern should use the NFA engine. |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
258 // E.g. [[:upper:]] only allows 8bit characters for BT engine, |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
259 // while NFA engine handles multibyte characters correctly. |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
260 static int wants_nfa; |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
261 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
262 static int nstate; // Number of states in the NFA. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
263 static int istate; // Index in the state vector, used in alloc_state() |
4444 | 264 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
265 // If not NULL match must end at this position |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
266 static save_se_T *nfa_endp = NULL; |
4444 | 267 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
268 // 0 for first call to nfa_regmatch(), 1 for recursive call. |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
269 static int nfa_ll_index = 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
270 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
271 static int realloc_post_list(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
272 static int nfa_reg(int paren); |
4444 | 273 #ifdef DEBUG |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
274 static void nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent); |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
275 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
276 static int match_follows(nfa_state_T *startstate, int depth); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
277 static int failure_chance(nfa_state_T *state, int depth); |
4444 | 278 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
279 // helper functions used when doing re2post() ... regatom() parsing |
4444 | 280 #define EMIT(c) do { \ |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
281 if (post_ptr >= post_end && realloc_post_list() == FAIL) \ |
4444 | 282 return FAIL; \ |
283 *post_ptr++ = c; \ | |
284 } while (0) | |
285 | |
286 /* | |
287 * Initialize internal variables before NFA compilation. | |
288 * Return OK on success, FAIL otherwise. | |
289 */ | |
290 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
291 nfa_regcomp_start( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
292 char_u *expr, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
293 int re_flags) // see vim_regcomp() |
4444 | 294 { |
4458 | 295 size_t postfix_size; |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
296 int nstate_max; |
4444 | 297 |
298 nstate = 0; | |
299 istate = 0; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
300 // A reasonable estimation for maximum size |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
301 nstate_max = (int)(STRLEN(expr) + 1) * 25; |
4444 | 302 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
303 // Some items blow up in size, such as [A-z]. Add more space for that. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
304 // When it is still not enough realloc_post_list() will be used. |
4458 | 305 nstate_max += 1000; |
4454 | 306 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
307 // Size for postfix representation of expr. |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
308 postfix_size = sizeof(int) * nstate_max; |
4454 | 309 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
310 post_start = alloc(postfix_size); |
4444 | 311 if (post_start == NULL) |
312 return FAIL; | |
313 post_ptr = post_start; | |
4454 | 314 post_end = post_start + nstate_max; |
23471
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
315 wants_nfa = FALSE; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
316 rex.nfa_has_zend = FALSE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
317 rex.nfa_has_backref = FALSE; |
4444 | 318 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
319 // shared with BT engine |
4444 | 320 regcomp_start(expr, re_flags); |
321 | |
322 return OK; | |
323 } | |
324 | |
325 /* | |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
326 * 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
|
327 * of the line. |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
328 */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
329 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
330 nfa_get_reganch(nfa_state_T *start, int depth) |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
331 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
332 nfa_state_T *p = start; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
333 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
334 if (depth > 4) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
335 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
336 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
337 while (p != NULL) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
338 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
339 switch (p->c) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
340 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
341 case NFA_BOL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
342 case NFA_BOF: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
343 return 1; // yes! |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
344 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
345 case NFA_ZSTART: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
346 case NFA_ZEND: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
347 case NFA_CURSOR: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
348 case NFA_VISUAL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
349 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
350 case NFA_MOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
351 case NFA_MOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
352 case NFA_MOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
353 case NFA_MOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
354 case NFA_MOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
355 case NFA_MOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
356 case NFA_MOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
357 case NFA_MOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
358 case NFA_MOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
359 case NFA_MOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
360 case NFA_NOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
361 #ifdef FEAT_SYN_HL |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
362 case NFA_ZOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
363 case NFA_ZOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
364 case NFA_ZOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
365 case NFA_ZOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
366 case NFA_ZOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
367 case NFA_ZOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
368 case NFA_ZOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
369 case NFA_ZOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
370 case NFA_ZOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
371 case NFA_ZOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
372 #endif |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
373 p = p->out; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
374 break; |
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 case NFA_SPLIT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
377 return nfa_get_reganch(p->out, depth + 1) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
378 && nfa_get_reganch(p->out1, depth + 1); |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
379 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
380 default: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
381 return 0; // noooo |
4772
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 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
384 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
385 } |
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 /* |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
388 * 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
|
389 * at start of the match. |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
390 */ |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
391 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
392 nfa_get_regstart(nfa_state_T *start, int depth) |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
393 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
394 nfa_state_T *p = start; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
395 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
396 if (depth > 4) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
397 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
398 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
399 while (p != NULL) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
400 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
401 switch (p->c) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
402 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
403 // all kinds of zero-width matches |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
404 case NFA_BOL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
405 case NFA_BOF: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
406 case NFA_BOW: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
407 case NFA_EOW: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
408 case NFA_ZSTART: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
409 case NFA_ZEND: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
410 case NFA_CURSOR: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
411 case NFA_VISUAL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
412 case NFA_LNUM: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
413 case NFA_LNUM_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
414 case NFA_LNUM_LT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
415 case NFA_COL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
416 case NFA_COL_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
417 case NFA_COL_LT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
418 case NFA_VCOL: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
419 case NFA_VCOL_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
420 case NFA_VCOL_LT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
421 case NFA_MARK: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
422 case NFA_MARK_GT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
423 case NFA_MARK_LT: |
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 case NFA_MOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
426 case NFA_MOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
427 case NFA_MOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
428 case NFA_MOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
429 case NFA_MOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
430 case NFA_MOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
431 case NFA_MOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
432 case NFA_MOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
433 case NFA_MOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
434 case NFA_MOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
435 case NFA_NOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
436 #ifdef FEAT_SYN_HL |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
437 case NFA_ZOPEN: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
438 case NFA_ZOPEN1: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
439 case NFA_ZOPEN2: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
440 case NFA_ZOPEN3: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
441 case NFA_ZOPEN4: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
442 case NFA_ZOPEN5: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
443 case NFA_ZOPEN6: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
444 case NFA_ZOPEN7: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
445 case NFA_ZOPEN8: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
446 case NFA_ZOPEN9: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
447 #endif |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
448 p = p->out; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
449 break; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
450 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
451 case NFA_SPLIT: |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
452 { |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
453 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
|
454 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
|
455 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
456 if (c1 == c2) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
457 return c1; // yes! |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
458 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
459 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
460 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
461 default: |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
462 if (p->c > 0) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
463 return p->c; // yes! |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
464 return 0; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
465 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
466 } |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
467 return 0; |
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 |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
470 /* |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
471 * 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
|
472 * 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
|
473 * regstart. Otherwise return NULL. |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
474 */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
475 static char_u * |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
476 nfa_get_match_text(nfa_state_T *start) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
477 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
478 nfa_state_T *p = start; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
479 int len = 0; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
480 char_u *ret; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
481 char_u *s; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
482 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
483 if (p->c != NFA_MOPEN) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
484 return NULL; // just in case |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
485 p = p->out; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
486 while (p->c > 0) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
487 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
488 len += MB_CHAR2LEN(p->c); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
489 p = p->out; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
490 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
491 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
|
492 return NULL; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
493 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
494 ret = alloc(len); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
495 if (ret != NULL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
496 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
497 p = start->out->out; // skip first char, it goes into regstart |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
498 s = ret; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
499 while (p->c > 0) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
500 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
501 if (has_mbyte) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
502 s += (*mb_char2bytes)(p->c, s); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
503 else |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
504 *s++ = p->c; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
505 p = p->out; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
506 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
507 *s = NUL; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
508 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
509 return ret; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
510 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
511 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
512 /* |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
513 * Allocate more space for post_start. Called when |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
514 * running above the estimated number of states. |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
515 */ |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
516 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
517 realloc_post_list(void) |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
518 { |
4667
9e7ef781d494
updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents:
4661
diff
changeset
|
519 int nstate_max = (int)(post_end - post_start); |
15904
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15876
diff
changeset
|
520 int new_max; |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
521 int *new_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
522 int *old_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
523 |
15904
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15876
diff
changeset
|
524 // For weird patterns the number of states can be very high. Increasing by |
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15876
diff
changeset
|
525 // 50% seems a reasonable compromise between memory use and speed. |
fec4416adb80
patch 8.1.0958: compiling weird regexp pattern is very slow
Bram Moolenaar <Bram@vim.org>
parents:
15876
diff
changeset
|
526 new_max = nstate_max * 3 / 2; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
527 new_start = ALLOC_MULT(int, new_max); |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
528 if (new_start == NULL) |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
529 return FAIL; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
530 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
|
531 old_start = post_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
532 post_start = new_start; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
533 post_ptr = new_start + (post_ptr - old_start); |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
534 post_end = post_start + new_max; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
535 vim_free(old_start); |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
536 return OK; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
537 } |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
538 |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
539 /* |
4444 | 540 * Search between "start" and "end" and try to recognize a |
541 * character class in expanded form. For example [0-9]. | |
542 * On success, return the id the character class to be emitted. | |
543 * On failure, return 0 (=FAIL) | |
544 * Start points to the first char of the range, while end should point | |
545 * to the closing brace. | |
5296 | 546 * Keep in mind that 'ignorecase' applies at execution time, thus [a-z] may |
547 * need to be interpreted as [a-zA-Z]. | |
4444 | 548 */ |
549 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
550 nfa_recognize_char_class(char_u *start, char_u *end, int extra_newl) |
4444 | 551 { |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
552 # define CLASS_not 0x80 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
553 # define CLASS_af 0x40 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
554 # define CLASS_AF 0x20 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
555 # define CLASS_az 0x10 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
556 # define CLASS_AZ 0x08 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
557 # define CLASS_o7 0x04 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
558 # define CLASS_o9 0x02 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
559 # define CLASS_underscore 0x01 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
560 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
561 int newl = FALSE; |
4444 | 562 char_u *p; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
563 int config = 0; |
4444 | 564 |
565 if (extra_newl == TRUE) | |
566 newl = TRUE; | |
567 | |
568 if (*end != ']') | |
569 return FAIL; | |
570 p = start; | |
571 if (*p == '^') | |
572 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
573 config |= CLASS_not; |
4720
bd6bef0bd0fb
updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents:
4718
diff
changeset
|
574 p++; |
4444 | 575 } |
576 | |
577 while (p < end) | |
578 { | |
579 if (p + 2 < end && *(p + 1) == '-') | |
580 { | |
581 switch (*p) | |
582 { | |
583 case '0': | |
584 if (*(p + 2) == '9') | |
585 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
586 config |= CLASS_o9; |
4444 | 587 break; |
588 } | |
589 if (*(p + 2) == '7') | |
590 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
591 config |= CLASS_o7; |
4444 | 592 break; |
593 } | |
11469
0ade9dd85156
patch 8.0.0618: NFA regex engine handles [0-z] incorrectly
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
594 return FAIL; |
0ade9dd85156
patch 8.0.0618: NFA regex engine handles [0-z] incorrectly
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
595 |
4444 | 596 case 'a': |
597 if (*(p + 2) == 'z') | |
598 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
599 config |= CLASS_az; |
4444 | 600 break; |
601 } | |
602 if (*(p + 2) == 'f') | |
603 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
604 config |= CLASS_af; |
4444 | 605 break; |
606 } | |
11469
0ade9dd85156
patch 8.0.0618: NFA regex engine handles [0-z] incorrectly
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
607 return FAIL; |
0ade9dd85156
patch 8.0.0618: NFA regex engine handles [0-z] incorrectly
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
608 |
4444 | 609 case 'A': |
610 if (*(p + 2) == 'Z') | |
611 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
612 config |= CLASS_AZ; |
4444 | 613 break; |
614 } | |
615 if (*(p + 2) == 'F') | |
616 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
617 config |= CLASS_AF; |
4444 | 618 break; |
619 } | |
11469
0ade9dd85156
patch 8.0.0618: NFA regex engine handles [0-z] incorrectly
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
620 return FAIL; |
0ade9dd85156
patch 8.0.0618: NFA regex engine handles [0-z] incorrectly
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
621 |
4444 | 622 default: |
623 return FAIL; | |
624 } | |
625 p += 3; | |
626 } | |
627 else if (p + 1 < end && *p == '\\' && *(p + 1) == 'n') | |
628 { | |
629 newl = TRUE; | |
630 p += 2; | |
631 } | |
632 else if (*p == '_') | |
633 { | |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
634 config |= CLASS_underscore; |
4444 | 635 p ++; |
636 } | |
637 else if (*p == '\n') | |
638 { | |
639 newl = TRUE; | |
640 p ++; | |
641 } | |
642 else | |
643 return FAIL; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
644 } // while (p < end) |
4444 | 645 |
646 if (p != end) | |
647 return FAIL; | |
648 | |
649 if (newl == TRUE) | |
5296 | 650 extra_newl = NFA_ADD_NL; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
651 |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
652 switch (config) |
4444 | 653 { |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
654 case CLASS_o9: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
655 return extra_newl + NFA_DIGIT; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
656 case CLASS_not | CLASS_o9: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
657 return extra_newl + NFA_NDIGIT; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
658 case CLASS_af | CLASS_AF | CLASS_o9: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
659 return extra_newl + NFA_HEX; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
660 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
|
661 return extra_newl + NFA_NHEX; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
662 case CLASS_o7: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
663 return extra_newl + NFA_OCTAL; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
664 case CLASS_not | CLASS_o7: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
665 return extra_newl + NFA_NOCTAL; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
666 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
|
667 return extra_newl + NFA_WORD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
668 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
|
669 return extra_newl + NFA_NWORD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
670 case CLASS_az | CLASS_AZ | CLASS_underscore: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
671 return extra_newl + NFA_HEAD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
672 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
|
673 return extra_newl + NFA_NHEAD; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
674 case CLASS_az | CLASS_AZ: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
675 return extra_newl + NFA_ALPHA; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
676 case CLASS_not | CLASS_az | CLASS_AZ: |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
677 return extra_newl + NFA_NALPHA; |
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
678 case CLASS_az: |
5296 | 679 return extra_newl + NFA_LOWER_IC; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
680 case CLASS_not | CLASS_az: |
5296 | 681 return extra_newl + NFA_NLOWER_IC; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
682 case CLASS_AZ: |
5296 | 683 return extra_newl + NFA_UPPER_IC; |
4728
43de4ebbe7ad
updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents:
4726
diff
changeset
|
684 case CLASS_not | CLASS_AZ: |
5296 | 685 return extra_newl + NFA_NUPPER_IC; |
4444 | 686 } |
687 return FAIL; | |
688 } | |
689 | |
690 /* | |
691 * Produce the bytes for equivalence class "c". | |
692 * Currently only handles latin1, latin9 and utf-8. | |
693 * Emits bytes in postfix notation: 'a,b,NFA_OR,c,NFA_OR' is | |
694 * equivalent to 'a OR b OR c' | |
695 * | |
696 * NOTE! When changing this function, also update reg_equi_class() | |
697 */ | |
698 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
699 nfa_emit_equi_class(int c) |
4444 | 700 { |
5351 | 701 #define EMIT2(c) EMIT(c); EMIT(NFA_CONCAT); |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
702 #define EMITMBC(c) EMIT(c); EMIT(NFA_CONCAT); |
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
703 |
4444 | 704 if (enc_utf8 || STRCMP(p_enc, "latin1") == 0 |
705 || STRCMP(p_enc, "iso-8859-15") == 0) | |
706 { | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
707 #ifdef EBCDIC |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
708 # define A_circumflex 0x62 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
709 # define A_diaeresis 0x63 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
710 # define A_grave 0x64 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
711 # define A_acute 0x65 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
712 # define A_virguilla 0x66 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
713 # define A_ring 0x67 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
714 # define C_cedilla 0x68 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
715 # define E_acute 0x71 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
716 # define E_circumflex 0x72 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
717 # define E_diaeresis 0x73 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
718 # define E_grave 0x74 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
719 # define I_acute 0x75 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
720 # define I_circumflex 0x76 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
721 # define I_diaeresis 0x77 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
722 # define I_grave 0x78 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
723 # define N_virguilla 0x69 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
724 # define O_circumflex 0xeb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
725 # define O_diaeresis 0xec |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
726 # define O_grave 0xed |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
727 # define O_acute 0xee |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
728 # define O_virguilla 0xef |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
729 # define O_slash 0x80 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
730 # define U_circumflex 0xfb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
731 # define U_diaeresis 0xfc |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
732 # define U_grave 0xfd |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
733 # define U_acute 0xfe |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
734 # define Y_acute 0xba |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
735 # define a_grave 0x42 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
736 # define a_acute 0x43 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
737 # define a_circumflex 0x44 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
738 # define a_virguilla 0x45 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
739 # define a_diaeresis 0x46 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
740 # define a_ring 0x47 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
741 # define c_cedilla 0x48 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
742 # define e_grave 0x51 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
743 # define e_acute 0x52 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
744 # define e_circumflex 0x53 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
745 # define e_diaeresis 0x54 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
746 # define i_grave 0x55 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
747 # define i_acute 0x56 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
748 # define i_circumflex 0x57 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
749 # define i_diaeresis 0x58 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
750 # define n_virguilla 0x49 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
751 # define o_grave 0xcb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
752 # define o_acute 0xcc |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
753 # define o_circumflex 0xcd |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
754 # define o_virguilla 0xce |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
755 # define o_diaeresis 0xcf |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
756 # define o_slash 0x70 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
757 # define u_grave 0xdb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
758 # define u_acute 0xdc |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
759 # define u_circumflex 0xdd |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
760 # define u_diaeresis 0xde |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
761 # define y_acute 0x8d |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
762 # define y_diaeresis 0xdf |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
763 #else |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
764 # define A_grave 0xc0 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
765 # define A_acute 0xc1 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
766 # define A_circumflex 0xc2 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
767 # define A_virguilla 0xc3 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
768 # define A_diaeresis 0xc4 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
769 # define A_ring 0xc5 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
770 # define C_cedilla 0xc7 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
771 # define E_grave 0xc8 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
772 # define E_acute 0xc9 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
773 # define E_circumflex 0xca |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
774 # define E_diaeresis 0xcb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
775 # define I_grave 0xcc |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
776 # define I_acute 0xcd |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
777 # define I_circumflex 0xce |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
778 # define I_diaeresis 0xcf |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
779 # define N_virguilla 0xd1 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
780 # define O_grave 0xd2 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
781 # define O_acute 0xd3 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
782 # define O_circumflex 0xd4 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
783 # define O_virguilla 0xd5 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
784 # define O_diaeresis 0xd6 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
785 # define O_slash 0xd8 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
786 # define U_grave 0xd9 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
787 # define U_acute 0xda |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
788 # define U_circumflex 0xdb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
789 # define U_diaeresis 0xdc |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
790 # define Y_acute 0xdd |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
791 # define a_grave 0xe0 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
792 # define a_acute 0xe1 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
793 # define a_circumflex 0xe2 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
794 # define a_virguilla 0xe3 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
795 # define a_diaeresis 0xe4 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
796 # define a_ring 0xe5 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
797 # define c_cedilla 0xe7 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
798 # define e_grave 0xe8 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
799 # define e_acute 0xe9 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
800 # define e_circumflex 0xea |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
801 # define e_diaeresis 0xeb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
802 # define i_grave 0xec |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
803 # define i_acute 0xed |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
804 # define i_circumflex 0xee |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
805 # define i_diaeresis 0xef |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
806 # define n_virguilla 0xf1 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
807 # define o_grave 0xf2 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
808 # define o_acute 0xf3 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
809 # define o_circumflex 0xf4 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
810 # define o_virguilla 0xf5 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
811 # define o_diaeresis 0xf6 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
812 # define o_slash 0xf8 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
813 # define u_grave 0xf9 |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
814 # define u_acute 0xfa |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
815 # define u_circumflex 0xfb |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
816 # define u_diaeresis 0xfc |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
817 # define y_acute 0xfd |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
818 # define y_diaeresis 0xff |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
819 #endif |
4444 | 820 switch (c) |
821 { | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
822 case 'A': case A_grave: case A_acute: case A_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
823 case A_virguilla: case A_diaeresis: case A_ring: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
824 CASEMBC(0x100) CASEMBC(0x102) CASEMBC(0x104) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
825 CASEMBC(0x1cd) CASEMBC(0x1de) CASEMBC(0x1e0) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
826 CASEMBC(0x1ea2) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
827 EMIT2('A'); EMIT2(A_grave); EMIT2(A_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
828 EMIT2(A_circumflex); EMIT2(A_virguilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
829 EMIT2(A_diaeresis); EMIT2(A_ring); |
5351 | 830 EMITMBC(0x100) EMITMBC(0x102) EMITMBC(0x104) |
831 EMITMBC(0x1cd) EMITMBC(0x1de) EMITMBC(0x1e0) | |
832 EMITMBC(0x1ea2) | |
833 return OK; | |
834 | |
835 case 'B': CASEMBC(0x1e02) CASEMBC(0x1e06) | |
836 EMIT2('B'); EMITMBC(0x1e02) EMITMBC(0x1e06) | |
4444 | 837 return OK; |
838 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
839 case 'C': case C_cedilla: CASEMBC(0x106) CASEMBC(0x108) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
840 CASEMBC(0x10a) CASEMBC(0x10c) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
841 EMIT2('C'); EMIT2(C_cedilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
842 EMITMBC(0x106) EMITMBC(0x108) |
5351 | 843 EMITMBC(0x10a) EMITMBC(0x10c) |
844 return OK; | |
845 | |
846 case 'D': CASEMBC(0x10e) CASEMBC(0x110) CASEMBC(0x1e0a) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
847 CASEMBC(0x1e0e) CASEMBC(0x1e10) |
5351 | 848 EMIT2('D'); EMITMBC(0x10e) EMITMBC(0x110) EMITMBC(0x1e0a) |
849 EMITMBC(0x1e0e) EMITMBC(0x1e10) | |
4444 | 850 return OK; |
851 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
852 case 'E': case E_grave: case E_acute: case E_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
853 case E_diaeresis: CASEMBC(0x112) CASEMBC(0x114) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
854 CASEMBC(0x116) CASEMBC(0x118) CASEMBC(0x11a) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
855 CASEMBC(0x1eba) CASEMBC(0x1ebc) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
856 EMIT2('E'); EMIT2(E_grave); EMIT2(E_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
857 EMIT2(E_circumflex); EMIT2(E_diaeresis); |
5351 | 858 EMITMBC(0x112) EMITMBC(0x114) EMITMBC(0x116) |
859 EMITMBC(0x118) EMITMBC(0x11a) EMITMBC(0x1eba) | |
860 EMITMBC(0x1ebc) | |
861 return OK; | |
862 | |
863 case 'F': CASEMBC(0x1e1e) | |
864 EMIT2('F'); EMITMBC(0x1e1e) | |
865 return OK; | |
866 | |
867 case 'G': CASEMBC(0x11c) CASEMBC(0x11e) CASEMBC(0x120) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
868 CASEMBC(0x122) CASEMBC(0x1e4) CASEMBC(0x1e6) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
869 CASEMBC(0x1f4) CASEMBC(0x1e20) |
5351 | 870 EMIT2('G'); EMITMBC(0x11c) EMITMBC(0x11e) EMITMBC(0x120) |
871 EMITMBC(0x122) EMITMBC(0x1e4) EMITMBC(0x1e6) | |
872 EMITMBC(0x1f4) EMITMBC(0x1e20) | |
873 return OK; | |
874 | |
875 case 'H': CASEMBC(0x124) CASEMBC(0x126) CASEMBC(0x1e22) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
876 CASEMBC(0x1e26) CASEMBC(0x1e28) |
5351 | 877 EMIT2('H'); EMITMBC(0x124) EMITMBC(0x126) EMITMBC(0x1e22) |
878 EMITMBC(0x1e26) EMITMBC(0x1e28) | |
4444 | 879 return OK; |
880 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
881 case 'I': case I_grave: case I_acute: case I_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
882 case I_diaeresis: CASEMBC(0x128) CASEMBC(0x12a) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
883 CASEMBC(0x12c) CASEMBC(0x12e) CASEMBC(0x130) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
884 CASEMBC(0x1cf) CASEMBC(0x1ec8) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
885 EMIT2('I'); EMIT2(I_grave); EMIT2(I_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
886 EMIT2(I_circumflex); EMIT2(I_diaeresis); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
887 EMITMBC(0x128) EMITMBC(0x12a) |
5351 | 888 EMITMBC(0x12c) EMITMBC(0x12e) EMITMBC(0x130) |
889 EMITMBC(0x1cf) EMITMBC(0x1ec8) | |
890 return OK; | |
891 | |
892 case 'J': CASEMBC(0x134) | |
893 EMIT2('J'); EMITMBC(0x134) | |
894 return OK; | |
895 | |
896 case 'K': CASEMBC(0x136) CASEMBC(0x1e8) CASEMBC(0x1e30) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
897 CASEMBC(0x1e34) |
5351 | 898 EMIT2('K'); EMITMBC(0x136) EMITMBC(0x1e8) EMITMBC(0x1e30) |
899 EMITMBC(0x1e34) | |
900 return OK; | |
901 | |
902 case 'L': CASEMBC(0x139) CASEMBC(0x13b) CASEMBC(0x13d) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
903 CASEMBC(0x13f) CASEMBC(0x141) CASEMBC(0x1e3a) |
5351 | 904 EMIT2('L'); EMITMBC(0x139) EMITMBC(0x13b) EMITMBC(0x13d) |
905 EMITMBC(0x13f) EMITMBC(0x141) EMITMBC(0x1e3a) | |
906 return OK; | |
907 | |
908 case 'M': CASEMBC(0x1e3e) CASEMBC(0x1e40) | |
909 EMIT2('M'); EMITMBC(0x1e3e) EMITMBC(0x1e40) | |
4444 | 910 return OK; |
911 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
912 case 'N': case N_virguilla: CASEMBC(0x143) CASEMBC(0x145) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
913 CASEMBC(0x147) CASEMBC(0x1e44) CASEMBC(0x1e48) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
914 EMIT2('N'); EMIT2(N_virguilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
915 EMITMBC(0x143) EMITMBC(0x145) |
5351 | 916 EMITMBC(0x147) EMITMBC(0x1e44) EMITMBC(0x1e48) |
4444 | 917 return OK; |
918 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
919 case 'O': case O_grave: case O_acute: case O_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
920 case O_virguilla: case O_diaeresis: case O_slash: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
921 CASEMBC(0x14c) CASEMBC(0x14e) CASEMBC(0x150) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
922 CASEMBC(0x1a0) CASEMBC(0x1d1) CASEMBC(0x1ea) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
923 CASEMBC(0x1ec) CASEMBC(0x1ece) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
924 EMIT2('O'); EMIT2(O_grave); EMIT2(O_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
925 EMIT2(O_circumflex); EMIT2(O_virguilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
926 EMIT2(O_diaeresis); EMIT2(O_slash); |
5351 | 927 EMITMBC(0x14c) EMITMBC(0x14e) EMITMBC(0x150) |
928 EMITMBC(0x1a0) EMITMBC(0x1d1) EMITMBC(0x1ea) | |
929 EMITMBC(0x1ec) EMITMBC(0x1ece) | |
930 return OK; | |
931 | |
932 case 'P': case 0x1e54: case 0x1e56: | |
933 EMIT2('P'); EMITMBC(0x1e54) EMITMBC(0x1e56) | |
934 return OK; | |
935 | |
936 case 'R': CASEMBC(0x154) CASEMBC(0x156) CASEMBC(0x158) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
937 CASEMBC(0x1e58) CASEMBC(0x1e5e) |
5351 | 938 EMIT2('R'); EMITMBC(0x154) EMITMBC(0x156) EMITMBC(0x158) |
939 EMITMBC(0x1e58) EMITMBC(0x1e5e) | |
940 return OK; | |
941 | |
942 case 'S': CASEMBC(0x15a) CASEMBC(0x15c) CASEMBC(0x15e) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
943 CASEMBC(0x160) CASEMBC(0x1e60) |
5351 | 944 EMIT2('S'); EMITMBC(0x15a) EMITMBC(0x15c) EMITMBC(0x15e) |
945 EMITMBC(0x160) EMITMBC(0x1e60) | |
946 return OK; | |
947 | |
948 case 'T': CASEMBC(0x162) CASEMBC(0x164) CASEMBC(0x166) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
949 CASEMBC(0x1e6a) CASEMBC(0x1e6e) |
5351 | 950 EMIT2('T'); EMITMBC(0x162) EMITMBC(0x164) EMITMBC(0x166) |
951 EMITMBC(0x1e6a) EMITMBC(0x1e6e) | |
4444 | 952 return OK; |
953 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
954 case 'U': case U_grave: case U_acute: case U_diaeresis: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
955 case U_circumflex: CASEMBC(0x168) CASEMBC(0x16a) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
956 CASEMBC(0x16c) CASEMBC(0x16e) CASEMBC(0x170) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
957 CASEMBC(0x172) CASEMBC(0x1af) CASEMBC(0x1d3) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
958 CASEMBC(0x1ee6) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
959 EMIT2('U'); EMIT2(U_grave); EMIT2(U_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
960 EMIT2(U_diaeresis); EMIT2(U_circumflex); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
961 EMITMBC(0x168) EMITMBC(0x16a) |
5351 | 962 EMITMBC(0x16c) EMITMBC(0x16e) EMITMBC(0x170) |
963 EMITMBC(0x172) EMITMBC(0x1af) EMITMBC(0x1d3) | |
964 EMITMBC(0x1ee6) | |
965 return OK; | |
966 | |
967 case 'V': CASEMBC(0x1e7c) | |
968 EMIT2('V'); EMITMBC(0x1e7c) | |
969 return OK; | |
970 | |
971 case 'W': CASEMBC(0x174) CASEMBC(0x1e80) CASEMBC(0x1e82) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
972 CASEMBC(0x1e84) CASEMBC(0x1e86) |
5351 | 973 EMIT2('W'); EMITMBC(0x174) EMITMBC(0x1e80) EMITMBC(0x1e82) |
974 EMITMBC(0x1e84) EMITMBC(0x1e86) | |
975 return OK; | |
976 | |
977 case 'X': CASEMBC(0x1e8a) CASEMBC(0x1e8c) | |
978 EMIT2('X'); EMITMBC(0x1e8a) EMITMBC(0x1e8c) | |
4444 | 979 return OK; |
980 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
981 case 'Y': case Y_acute: CASEMBC(0x176) CASEMBC(0x178) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
982 CASEMBC(0x1e8e) CASEMBC(0x1ef2) CASEMBC(0x1ef6) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
983 CASEMBC(0x1ef8) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
984 EMIT2('Y'); EMIT2(Y_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
985 EMITMBC(0x176) EMITMBC(0x178) |
5351 | 986 EMITMBC(0x1e8e) EMITMBC(0x1ef2) EMITMBC(0x1ef6) |
987 EMITMBC(0x1ef8) | |
988 return OK; | |
989 | |
990 case 'Z': CASEMBC(0x179) CASEMBC(0x17b) CASEMBC(0x17d) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
991 CASEMBC(0x1b5) CASEMBC(0x1e90) CASEMBC(0x1e94) |
5351 | 992 EMIT2('Z'); EMITMBC(0x179) EMITMBC(0x17b) EMITMBC(0x17d) |
993 EMITMBC(0x1b5) EMITMBC(0x1e90) EMITMBC(0x1e94) | |
4444 | 994 return OK; |
995 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
996 case 'a': case a_grave: case a_acute: case a_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
997 case a_virguilla: case a_diaeresis: case a_ring: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
998 CASEMBC(0x101) CASEMBC(0x103) CASEMBC(0x105) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
999 CASEMBC(0x1ce) CASEMBC(0x1df) CASEMBC(0x1e1) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1000 CASEMBC(0x1ea3) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1001 EMIT2('a'); EMIT2(a_grave); EMIT2(a_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1002 EMIT2(a_circumflex); EMIT2(a_virguilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1003 EMIT2(a_diaeresis); EMIT2(a_ring); |
5351 | 1004 EMITMBC(0x101) EMITMBC(0x103) EMITMBC(0x105) |
1005 EMITMBC(0x1ce) EMITMBC(0x1df) EMITMBC(0x1e1) | |
1006 EMITMBC(0x1ea3) | |
1007 return OK; | |
1008 | |
1009 case 'b': CASEMBC(0x1e03) CASEMBC(0x1e07) | |
1010 EMIT2('b'); EMITMBC(0x1e03) EMITMBC(0x1e07) | |
4444 | 1011 return OK; |
1012 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1013 case 'c': case c_cedilla: CASEMBC(0x107) CASEMBC(0x109) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1014 CASEMBC(0x10b) CASEMBC(0x10d) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1015 EMIT2('c'); EMIT2(c_cedilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1016 EMITMBC(0x107) EMITMBC(0x109) |
5351 | 1017 EMITMBC(0x10b) EMITMBC(0x10d) |
1018 return OK; | |
1019 | |
6914 | 1020 case 'd': CASEMBC(0x10f) CASEMBC(0x111) CASEMBC(0x1e0b) |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1021 CASEMBC(0x1e0f) CASEMBC(0x1e11) |
6914 | 1022 EMIT2('d'); EMITMBC(0x10f) EMITMBC(0x111) |
1023 EMITMBC(0x1e0b) EMITMBC(0x1e0f) EMITMBC(0x1e11) | |
4444 | 1024 return OK; |
1025 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1026 case 'e': case e_grave: case e_acute: case e_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1027 case e_diaeresis: CASEMBC(0x113) CASEMBC(0x115) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1028 CASEMBC(0x117) CASEMBC(0x119) CASEMBC(0x11b) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1029 CASEMBC(0x1ebb) CASEMBC(0x1ebd) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1030 EMIT2('e'); EMIT2(e_grave); EMIT2(e_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1031 EMIT2(e_circumflex); EMIT2(e_diaeresis); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1032 EMITMBC(0x113) EMITMBC(0x115) |
5351 | 1033 EMITMBC(0x117) EMITMBC(0x119) EMITMBC(0x11b) |
1034 EMITMBC(0x1ebb) EMITMBC(0x1ebd) | |
1035 return OK; | |
1036 | |
1037 case 'f': CASEMBC(0x1e1f) | |
1038 EMIT2('f'); EMITMBC(0x1e1f) | |
1039 return OK; | |
1040 | |
1041 case 'g': CASEMBC(0x11d) CASEMBC(0x11f) CASEMBC(0x121) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1042 CASEMBC(0x123) CASEMBC(0x1e5) CASEMBC(0x1e7) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1043 CASEMBC(0x1f5) CASEMBC(0x1e21) |
5351 | 1044 EMIT2('g'); EMITMBC(0x11d) EMITMBC(0x11f) EMITMBC(0x121) |
1045 EMITMBC(0x123) EMITMBC(0x1e5) EMITMBC(0x1e7) | |
1046 EMITMBC(0x1f5) EMITMBC(0x1e21) | |
1047 return OK; | |
1048 | |
1049 case 'h': CASEMBC(0x125) CASEMBC(0x127) CASEMBC(0x1e23) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1050 CASEMBC(0x1e27) CASEMBC(0x1e29) CASEMBC(0x1e96) |
5351 | 1051 EMIT2('h'); EMITMBC(0x125) EMITMBC(0x127) EMITMBC(0x1e23) |
1052 EMITMBC(0x1e27) EMITMBC(0x1e29) EMITMBC(0x1e96) | |
4444 | 1053 return OK; |
1054 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1055 case 'i': case i_grave: case i_acute: case i_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1056 case i_diaeresis: CASEMBC(0x129) CASEMBC(0x12b) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1057 CASEMBC(0x12d) CASEMBC(0x12f) CASEMBC(0x1d0) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1058 CASEMBC(0x1ec9) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1059 EMIT2('i'); EMIT2(i_grave); EMIT2(i_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1060 EMIT2(i_circumflex); EMIT2(i_diaeresis); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1061 EMITMBC(0x129) EMITMBC(0x12b) |
5351 | 1062 EMITMBC(0x12d) EMITMBC(0x12f) EMITMBC(0x1d0) |
1063 EMITMBC(0x1ec9) | |
1064 return OK; | |
1065 | |
1066 case 'j': CASEMBC(0x135) CASEMBC(0x1f0) | |
1067 EMIT2('j'); EMITMBC(0x135) EMITMBC(0x1f0) | |
1068 return OK; | |
1069 | |
1070 case 'k': CASEMBC(0x137) CASEMBC(0x1e9) CASEMBC(0x1e31) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1071 CASEMBC(0x1e35) |
5351 | 1072 EMIT2('k'); EMITMBC(0x137) EMITMBC(0x1e9) EMITMBC(0x1e31) |
1073 EMITMBC(0x1e35) | |
1074 return OK; | |
1075 | |
1076 case 'l': CASEMBC(0x13a) CASEMBC(0x13c) CASEMBC(0x13e) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1077 CASEMBC(0x140) CASEMBC(0x142) CASEMBC(0x1e3b) |
5351 | 1078 EMIT2('l'); EMITMBC(0x13a) EMITMBC(0x13c) EMITMBC(0x13e) |
1079 EMITMBC(0x140) EMITMBC(0x142) EMITMBC(0x1e3b) | |
1080 return OK; | |
1081 | |
1082 case 'm': CASEMBC(0x1e3f) CASEMBC(0x1e41) | |
1083 EMIT2('m'); EMITMBC(0x1e3f) EMITMBC(0x1e41) | |
4444 | 1084 return OK; |
1085 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1086 case 'n': case n_virguilla: CASEMBC(0x144) CASEMBC(0x146) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1087 CASEMBC(0x148) CASEMBC(0x149) CASEMBC(0x1e45) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1088 CASEMBC(0x1e49) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1089 EMIT2('n'); EMIT2(n_virguilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1090 EMITMBC(0x144) EMITMBC(0x146) |
5351 | 1091 EMITMBC(0x148) EMITMBC(0x149) EMITMBC(0x1e45) |
1092 EMITMBC(0x1e49) | |
4444 | 1093 return OK; |
1094 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1095 case 'o': case o_grave: case o_acute: case o_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1096 case o_virguilla: case o_diaeresis: case o_slash: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1097 CASEMBC(0x14d) CASEMBC(0x14f) CASEMBC(0x151) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1098 CASEMBC(0x1a1) CASEMBC(0x1d2) CASEMBC(0x1eb) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1099 CASEMBC(0x1ed) CASEMBC(0x1ecf) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1100 EMIT2('o'); EMIT2(o_grave); EMIT2(o_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1101 EMIT2(o_circumflex); EMIT2(o_virguilla); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1102 EMIT2(o_diaeresis); EMIT2(o_slash); |
5351 | 1103 EMITMBC(0x14d) EMITMBC(0x14f) EMITMBC(0x151) |
1104 EMITMBC(0x1a1) EMITMBC(0x1d2) EMITMBC(0x1eb) | |
1105 EMITMBC(0x1ed) EMITMBC(0x1ecf) | |
1106 return OK; | |
1107 | |
1108 case 'p': CASEMBC(0x1e55) CASEMBC(0x1e57) | |
1109 EMIT2('p'); EMITMBC(0x1e55) EMITMBC(0x1e57) | |
1110 return OK; | |
1111 | |
1112 case 'r': CASEMBC(0x155) CASEMBC(0x157) CASEMBC(0x159) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1113 CASEMBC(0x1e59) CASEMBC(0x1e5f) |
5351 | 1114 EMIT2('r'); EMITMBC(0x155) EMITMBC(0x157) EMITMBC(0x159) |
1115 EMITMBC(0x1e59) EMITMBC(0x1e5f) | |
1116 return OK; | |
1117 | |
1118 case 's': CASEMBC(0x15b) CASEMBC(0x15d) CASEMBC(0x15f) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1119 CASEMBC(0x161) CASEMBC(0x1e61) |
5351 | 1120 EMIT2('s'); EMITMBC(0x15b) EMITMBC(0x15d) EMITMBC(0x15f) |
1121 EMITMBC(0x161) EMITMBC(0x1e61) | |
1122 return OK; | |
1123 | |
1124 case 't': CASEMBC(0x163) CASEMBC(0x165) CASEMBC(0x167) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1125 CASEMBC(0x1e6b) CASEMBC(0x1e6f) CASEMBC(0x1e97) |
5351 | 1126 EMIT2('t'); EMITMBC(0x163) EMITMBC(0x165) EMITMBC(0x167) |
1127 EMITMBC(0x1e6b) EMITMBC(0x1e6f) EMITMBC(0x1e97) | |
4444 | 1128 return OK; |
1129 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1130 case 'u': case u_grave: case u_acute: case u_circumflex: |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1131 case u_diaeresis: CASEMBC(0x169) CASEMBC(0x16b) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1132 CASEMBC(0x16d) CASEMBC(0x16f) CASEMBC(0x171) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1133 CASEMBC(0x173) CASEMBC(0x1b0) CASEMBC(0x1d4) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1134 CASEMBC(0x1ee7) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1135 EMIT2('u'); EMIT2(u_grave); EMIT2(u_acute); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1136 EMIT2(u_circumflex); EMIT2(u_diaeresis); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1137 EMITMBC(0x169) EMITMBC(0x16b) |
5351 | 1138 EMITMBC(0x16d) EMITMBC(0x16f) EMITMBC(0x171) |
1139 EMITMBC(0x173) EMITMBC(0x1b0) EMITMBC(0x1d4) | |
1140 EMITMBC(0x1ee7) | |
1141 return OK; | |
1142 | |
1143 case 'v': CASEMBC(0x1e7d) | |
1144 EMIT2('v'); EMITMBC(0x1e7d) | |
1145 return OK; | |
1146 | |
1147 case 'w': CASEMBC(0x175) CASEMBC(0x1e81) CASEMBC(0x1e83) | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1148 CASEMBC(0x1e85) CASEMBC(0x1e87) CASEMBC(0x1e98) |
5351 | 1149 EMIT2('w'); EMITMBC(0x175) EMITMBC(0x1e81) EMITMBC(0x1e83) |
1150 EMITMBC(0x1e85) EMITMBC(0x1e87) EMITMBC(0x1e98) | |
1151 return OK; | |
1152 | |
1153 case 'x': CASEMBC(0x1e8b) CASEMBC(0x1e8d) | |
1154 EMIT2('x'); EMITMBC(0x1e8b) EMITMBC(0x1e8d) | |
4444 | 1155 return OK; |
1156 | |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1157 case 'y': case y_acute: case y_diaeresis: CASEMBC(0x177) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1158 CASEMBC(0x1e8f) CASEMBC(0x1e99) CASEMBC(0x1ef3) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1159 CASEMBC(0x1ef7) CASEMBC(0x1ef9) |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1160 EMIT2('y'); EMIT2(y_acute); EMIT2(y_diaeresis); |
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1161 EMITMBC(0x177) |
5351 | 1162 EMITMBC(0x1e8f) EMITMBC(0x1e99) EMITMBC(0x1ef3) |
1163 EMITMBC(0x1ef7) EMITMBC(0x1ef9) | |
4444 | 1164 return OK; |
1165 | |
5351 | 1166 case 'z': CASEMBC(0x17a) CASEMBC(0x17c) CASEMBC(0x17e) |
8841
f196308a2813
commit https://github.com/vim/vim/commit/2a6fa564a3b5061c14ff63b8b0f12801df0b0ac2
Christian Brabandt <cb@256bit.org>
parents:
8021
diff
changeset
|
1167 CASEMBC(0x1b6) CASEMBC(0x1e91) CASEMBC(0x1e95) |
5351 | 1168 EMIT2('z'); EMITMBC(0x17a) EMITMBC(0x17c) EMITMBC(0x17e) |
1169 EMITMBC(0x1b6) EMITMBC(0x1e91) EMITMBC(0x1e95) | |
1170 return OK; | |
1171 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1172 // default: character itself |
4444 | 1173 } |
1174 } | |
1175 | |
5351 | 1176 EMIT2(c); |
4444 | 1177 return OK; |
1178 #undef EMIT2 | |
5351 | 1179 #undef EMITMBC |
4444 | 1180 } |
1181 | |
1182 /* | |
1183 * Code to parse regular expression. | |
1184 * | |
1185 * We try to reuse parsing functions in regexp.c to | |
1186 * minimize surprise and keep the syntax consistent. | |
1187 */ | |
1188 | |
1189 /* | |
1190 * Parse the lowest level. | |
1191 * | |
1192 * An atom can be one of a long list of items. Many atoms match one character | |
1193 * in the text. It is often an ordinary character or a character class. | |
1194 * Braces can be used to make a pattern into an atom. The "\z(\)" construct | |
1195 * is only for syntax highlighting. | |
1196 * | |
1197 * atom ::= ordinary-atom | |
1198 * or \( pattern \) | |
1199 * or \%( pattern \) | |
1200 * or \z( pattern \) | |
1201 */ | |
1202 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1203 nfa_regatom(void) |
4444 | 1204 { |
1205 int c; | |
1206 int charclass; | |
1207 int equiclass; | |
1208 int collclass; | |
1209 int got_coll_char; | |
1210 char_u *p; | |
1211 char_u *endp; | |
1212 char_u *old_regparse = regparse; | |
1213 int extra = 0; | |
1214 int emit_range; | |
1215 int negated; | |
1216 int result; | |
1217 int startc = -1; | |
1218 int endc = -1; | |
1219 int oldstartc = -1; | |
8021
b6b4f354df23
commit https://github.com/vim/vim/commit/7c29f387819b5817b003d2ba73e2b5cf3cb3d0dd
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1220 int save_prev_at_start = prev_at_start; |
4444 | 1221 |
1222 c = getchr(); | |
1223 switch (c) | |
1224 { | |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1225 case NUL: |
5511 | 1226 EMSG_RET_FAIL(_(e_nul_found)); |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1227 |
4444 | 1228 case Magic('^'): |
1229 EMIT(NFA_BOL); | |
1230 break; | |
1231 | |
1232 case Magic('$'): | |
1233 EMIT(NFA_EOL); | |
1234 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
1235 had_eol = TRUE; | |
1236 #endif | |
1237 break; | |
1238 | |
1239 case Magic('<'): | |
1240 EMIT(NFA_BOW); | |
1241 break; | |
1242 | |
1243 case Magic('>'): | |
1244 EMIT(NFA_EOW); | |
1245 break; | |
1246 | |
1247 case Magic('_'): | |
1248 c = no_Magic(getchr()); | |
5511 | 1249 if (c == NUL) |
1250 EMSG_RET_FAIL(_(e_nul_found)); | |
1251 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1252 if (c == '^') // "\_^" is start-of-line |
4444 | 1253 { |
1254 EMIT(NFA_BOL); | |
1255 break; | |
1256 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1257 if (c == '$') // "\_$" is end-of-line |
4444 | 1258 { |
1259 EMIT(NFA_EOL); | |
1260 #if defined(FEAT_SYN_HL) || defined(PROTO) | |
1261 had_eol = TRUE; | |
1262 #endif | |
1263 break; | |
1264 } | |
1265 | |
5296 | 1266 extra = NFA_ADD_NL; |
4444 | 1267 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1268 // "\_[" is collection plus newline |
4444 | 1269 if (c == '[') |
4517
9a2183bd8295
updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents:
4515
diff
changeset
|
1270 goto collection; |
4444 | 1271 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1272 // "\_x" is character class plus newline |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1273 // FALLTHROUGH |
4444 | 1274 |
1275 /* | |
1276 * Character classes. | |
1277 */ | |
1278 case Magic('.'): | |
1279 case Magic('i'): | |
1280 case Magic('I'): | |
1281 case Magic('k'): | |
1282 case Magic('K'): | |
1283 case Magic('f'): | |
1284 case Magic('F'): | |
1285 case Magic('p'): | |
1286 case Magic('P'): | |
1287 case Magic('s'): | |
1288 case Magic('S'): | |
1289 case Magic('d'): | |
1290 case Magic('D'): | |
1291 case Magic('x'): | |
1292 case Magic('X'): | |
1293 case Magic('o'): | |
1294 case Magic('O'): | |
1295 case Magic('w'): | |
1296 case Magic('W'): | |
1297 case Magic('h'): | |
1298 case Magic('H'): | |
1299 case Magic('a'): | |
1300 case Magic('A'): | |
1301 case Magic('l'): | |
1302 case Magic('L'): | |
1303 case Magic('u'): | |
1304 case Magic('U'): | |
1305 p = vim_strchr(classchars, no_Magic(c)); | |
1306 if (p == NULL) | |
1307 { | |
5511 | 1308 if (extra == NFA_ADD_NL) |
1309 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
1310 semsg(_(e_ill_char_class), c); |
5511 | 1311 rc_did_emsg = TRUE; |
1312 return FAIL; | |
1313 } | |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1314 siemsg("INTERNAL: Unknown character class char: %d", c); |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1315 return FAIL; |
4444 | 1316 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
1317 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1318 // When '.' is followed by a composing char ignore the dot, so that |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1319 // the composing char is matched here. |
4444 | 1320 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr())) |
1321 { | |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
1322 old_regparse = regparse; |
4444 | 1323 c = getchr(); |
1324 goto nfa_do_multibyte; | |
1325 } | |
1326 EMIT(nfa_classcodes[p - classchars]); | |
5296 | 1327 if (extra == NFA_ADD_NL) |
4444 | 1328 { |
1329 EMIT(NFA_NEWL); | |
1330 EMIT(NFA_OR); | |
1331 regflags |= RF_HASNL; | |
1332 } | |
1333 break; | |
1334 | |
1335 case Magic('n'): | |
1336 if (reg_string) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1337 // In a string "\n" matches a newline character. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1338 EMIT(NL); |
4444 | 1339 else |
1340 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1341 // In buffer text "\n" matches the end of a line. |
4444 | 1342 EMIT(NFA_NEWL); |
1343 regflags |= RF_HASNL; | |
1344 } | |
1345 break; | |
1346 | |
1347 case Magic('('): | |
1348 if (nfa_reg(REG_PAREN) == FAIL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1349 return FAIL; // cascaded error |
4444 | 1350 break; |
1351 | |
1352 case Magic('|'): | |
1353 case Magic('&'): | |
1354 case Magic(')'): | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
1355 semsg(_(e_misplaced), no_Magic(c)); |
4444 | 1356 return FAIL; |
1357 | |
1358 case Magic('='): | |
1359 case Magic('?'): | |
1360 case Magic('+'): | |
1361 case Magic('@'): | |
1362 case Magic('*'): | |
1363 case Magic('{'): | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1364 // these should follow an atom, not form an atom |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
1365 semsg(_(e_misplaced), no_Magic(c)); |
4444 | 1366 return FAIL; |
1367 | |
4714
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1368 case Magic('~'): |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1369 { |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1370 char_u *lp; |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1371 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1372 // Previous substitute pattern. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1373 // Generated as "\%(pattern\)". |
4714
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1374 if (reg_prev_sub == NULL) |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1375 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
1376 emsg(_(e_nopresub)); |
4714
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1377 return FAIL; |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1378 } |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1379 for (lp = reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) |
4714
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1380 { |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1381 EMIT(PTR2CHAR(lp)); |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1382 if (lp != reg_prev_sub) |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1383 EMIT(NFA_CONCAT); |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1384 } |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1385 EMIT(NFA_NOPEN); |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1386 break; |
fc4d7f02ea3a
updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents:
4712
diff
changeset
|
1387 } |
4444 | 1388 |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1389 case Magic('1'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1390 case Magic('2'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1391 case Magic('3'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1392 case Magic('4'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1393 case Magic('5'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1394 case Magic('6'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1395 case Magic('7'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1396 case Magic('8'): |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1397 case Magic('9'): |
11525
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1398 { |
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1399 int refnum = no_Magic(c) - '1'; |
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1400 |
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1401 if (!seen_endbrace(refnum + 1)) |
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1402 return FAIL; |
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1403 EMIT(NFA_BACKREF1 + refnum); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
1404 rex.nfa_has_backref = TRUE; |
11525
14b6b79d685b
patch 8.0.0645: no error for illegal back reference in NFA engine
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1405 } |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
1406 break; |
4444 | 1407 |
1408 case Magic('z'): | |
1409 c = no_Magic(getchr()); | |
1410 switch (c) | |
1411 { | |
1412 case 's': | |
1413 EMIT(NFA_ZSTART); | |
6170 | 1414 if (re_mult_next("\\zs") == FAIL) |
1415 return FAIL; | |
4444 | 1416 break; |
1417 case 'e': | |
1418 EMIT(NFA_ZEND); | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
1419 rex.nfa_has_zend = TRUE; |
6170 | 1420 if (re_mult_next("\\ze") == FAIL) |
1421 return FAIL; | |
4569
f262fb02889d
updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents:
4567
diff
changeset
|
1422 break; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1423 #ifdef FEAT_SYN_HL |
4444 | 1424 case '1': |
1425 case '2': | |
1426 case '3': | |
1427 case '4': | |
1428 case '5': | |
1429 case '6': | |
1430 case '7': | |
1431 case '8': | |
1432 case '9': | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1433 // \z1...\z9 |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
14159
diff
changeset
|
1434 if ((reg_do_extmatch & REX_USE) == 0) |
4688
371cc0c44097
updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
1435 EMSG_RET_FAIL(_(e_z1_not_allowed)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1436 EMIT(NFA_ZREF1 + (no_Magic(c) - '1')); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1437 // No need to set rex.nfa_has_backref, the sub-matches don't |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1438 // change when \z1 .. \z9 matches or not. |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1439 re_has_z = REX_USE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1440 break; |
4444 | 1441 case '(': |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1442 // \z( |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
14159
diff
changeset
|
1443 if ((reg_do_extmatch & REX_SET) == 0) |
4688
371cc0c44097
updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents:
4686
diff
changeset
|
1444 EMSG_RET_FAIL(_(e_z_not_allowed)); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1445 if (nfa_reg(REG_ZPAREN) == FAIL) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1446 return FAIL; // cascaded error |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1447 re_has_z = REX_SET; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1448 break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
1449 #endif |
4444 | 1450 default: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
1451 semsg(_("E867: (NFA) Unknown operator '\\z%c'"), |
4444 | 1452 no_Magic(c)); |
1453 return FAIL; | |
1454 } | |
1455 break; | |
1456 | |
1457 case Magic('%'): | |
1458 c = no_Magic(getchr()); | |
1459 switch (c) | |
1460 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1461 // () without a back reference |
4444 | 1462 case '(': |
1463 if (nfa_reg(REG_NPAREN) == FAIL) | |
1464 return FAIL; | |
1465 EMIT(NFA_NOPEN); | |
1466 break; | |
1467 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1468 case 'd': // %d123 decimal |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1469 case 'o': // %o123 octal |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1470 case 'x': // %xab hex 2 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1471 case 'u': // %uabcd hex 4 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1472 case 'U': // %U1234abcd hex 8 |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1473 { |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1474 long nr; |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1475 |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1476 switch (c) |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1477 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1478 case 'd': nr = getdecchrs(); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1479 case 'o': nr = getoctchrs(); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1480 case 'x': nr = gethexchrs(2); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1481 case 'u': nr = gethexchrs(4); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1482 case 'U': nr = gethexchrs(8); break; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1483 default: nr = -1; break; |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1484 } |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1485 |
15924
98d315176d48
patch 8.1.0968: crash when using search pattern %Ufffffc23
Bram Moolenaar <Bram@vim.org>
parents:
15904
diff
changeset
|
1486 if (nr < 0 || nr > INT_MAX) |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1487 EMSG2_RET_FAIL( |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1488 _("E678: Invalid character after %s%%[dxouU]"), |
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1489 reg_magic == MAGIC_ALL); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1490 // A NUL is stored in the text as NL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1491 // TODO: what if a composing character follows? |
5360 | 1492 EMIT(nr == 0 ? 0x0a : nr); |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1493 } |
4444 | 1494 break; |
1495 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1496 // Catch \%^ and \%$ regardless of where they appear in the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1497 // pattern -- regardless of whether or not it makes sense. |
4444 | 1498 case '^': |
1499 EMIT(NFA_BOF); | |
1500 break; | |
1501 | |
1502 case '$': | |
1503 EMIT(NFA_EOF); | |
1504 break; | |
1505 | |
1506 case '#': | |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1507 EMIT(NFA_CURSOR); |
4444 | 1508 break; |
1509 | |
1510 case 'V': | |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
1511 EMIT(NFA_VISUAL); |
4444 | 1512 break; |
1513 | |
5901 | 1514 case 'C': |
1515 EMIT(NFA_ANY_COMPOSING); | |
1516 break; | |
1517 | |
4444 | 1518 case '[': |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1519 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1520 int n; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1521 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1522 // \%[abc] |
4944
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1523 for (n = 0; (c = peekchr()) != ']'; ++n) |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1524 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1525 if (c == NUL) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1526 EMSG2_RET_FAIL(_(e_missing_sb), |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1527 reg_magic == MAGIC_ALL); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1528 // recursive call! |
4944
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1529 if (nfa_regatom() == FAIL) |
613651492c19
updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents:
4938
diff
changeset
|
1530 return FAIL; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1531 } |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1532 getchr(); // get the ] |
4760
532a9855bd30
updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents:
4758
diff
changeset
|
1533 if (n == 0) |
532a9855bd30
updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents:
4758
diff
changeset
|
1534 EMSG2_RET_FAIL(_(e_empty_sb), |
532a9855bd30
updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents:
4758
diff
changeset
|
1535 reg_magic == MAGIC_ALL); |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1536 EMIT(NFA_OPT_CHARS); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1537 EMIT(n); |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1538 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1539 // Emit as "\%(\%[abc]\)" to be able to handle |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1540 // "\%[abc]*" which would cause the empty string to be |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1541 // matched an unlimited number of times. NFA_NOPEN is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1542 // added only once at a position, while NFA_SPLIT is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1543 // added multiple times. This is more efficient than |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1544 // not allowing NFA_SPLIT multiple times, it is used |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1545 // a lot. |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
1546 EMIT(NFA_NOPEN); |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1547 break; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1548 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1549 |
4444 | 1550 default: |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1551 { |
20677
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1552 long_u n = 0; |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1553 int cmp = c; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1554 |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1555 if (c == '<' || c == '>') |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1556 c = getchr(); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1557 while (VIM_ISDIGIT(c)) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1558 { |
20677
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1559 long_u tmp = n * 10 + (c - '0'); |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1560 |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1561 if (tmp < n) |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1562 { |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1563 // overflow. |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1564 emsg(_(e_value_too_large)); |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1565 return FAIL; |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1566 } |
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1567 n = tmp; |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1568 c = getchr(); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1569 } |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1570 if (c == 'l' || c == 'c' || c == 'v') |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1571 { |
20677
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1572 long_u limit = INT_MAX; |
15802
f043c8931585
patch 8.1.0908: can't handle large value for %{nr}v in regexp
Bram Moolenaar <Bram@vim.org>
parents:
15800
diff
changeset
|
1573 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1574 if (c == 'l') |
8021
b6b4f354df23
commit https://github.com/vim/vim/commit/7c29f387819b5817b003d2ba73e2b5cf3cb3d0dd
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1575 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1576 // \%{n}l \%{n}<l \%{n}>l |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1577 EMIT(cmp == '<' ? NFA_LNUM_LT : |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1578 cmp == '>' ? NFA_LNUM_GT : NFA_LNUM); |
8021
b6b4f354df23
commit https://github.com/vim/vim/commit/7c29f387819b5817b003d2ba73e2b5cf3cb3d0dd
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1579 if (save_prev_at_start) |
b6b4f354df23
commit https://github.com/vim/vim/commit/7c29f387819b5817b003d2ba73e2b5cf3cb3d0dd
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1580 at_start = TRUE; |
b6b4f354df23
commit https://github.com/vim/vim/commit/7c29f387819b5817b003d2ba73e2b5cf3cb3d0dd
Christian Brabandt <cb@256bit.org>
parents:
7833
diff
changeset
|
1581 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1582 else if (c == 'c') |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1583 // \%{n}c \%{n}<c \%{n}>c |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1584 EMIT(cmp == '<' ? NFA_COL_LT : |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1585 cmp == '>' ? NFA_COL_GT : NFA_COL); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1586 else |
15802
f043c8931585
patch 8.1.0908: can't handle large value for %{nr}v in regexp
Bram Moolenaar <Bram@vim.org>
parents:
15800
diff
changeset
|
1587 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1588 // \%{n}v \%{n}<v \%{n}>v |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1589 EMIT(cmp == '<' ? NFA_VCOL_LT : |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1590 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); |
15802
f043c8931585
patch 8.1.0908: can't handle large value for %{nr}v in regexp
Bram Moolenaar <Bram@vim.org>
parents:
15800
diff
changeset
|
1591 limit = INT_MAX / MB_MAXBYTES; |
f043c8931585
patch 8.1.0908: can't handle large value for %{nr}v in regexp
Bram Moolenaar <Bram@vim.org>
parents:
15800
diff
changeset
|
1592 } |
f043c8931585
patch 8.1.0908: can't handle large value for %{nr}v in regexp
Bram Moolenaar <Bram@vim.org>
parents:
15800
diff
changeset
|
1593 if (n >= limit) |
13192
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
1594 { |
20677
ab0dc036f586
patch 8.2.0892: ubsan warns for undefined behavior
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
1595 emsg(_(e_value_too_large)); |
13192
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
1596 return FAIL; |
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
1597 } |
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
1598 EMIT((int)n); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1599 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1600 } |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1601 else if (c == '\'' && n == 0) |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1602 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1603 // \%'m \%<'m \%>'m |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1604 EMIT(cmp == '<' ? NFA_MARK_LT : |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1605 cmp == '>' ? NFA_MARK_GT : NFA_MARK); |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
1606 EMIT(getchr()); |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1607 break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
1608 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
1609 } |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
1610 semsg(_("E867: (NFA) Unknown operator '\\%%%c'"), |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
1611 no_Magic(c)); |
4444 | 1612 return FAIL; |
1613 } | |
1614 break; | |
1615 | |
1616 case Magic('['): | |
4517
9a2183bd8295
updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents:
4515
diff
changeset
|
1617 collection: |
4444 | 1618 /* |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1619 * [abc] uses NFA_START_COLL - NFA_END_COLL |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1620 * [^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
|
1621 * 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
|
1622 * NFA_CONCAT to bind them together. |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1623 * Besides normal characters there can be: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1624 * - character classes NFA_CLASS_* |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1625 * - ranges, two characters followed by NFA_RANGE. |
4444 | 1626 */ |
1627 | |
1628 p = regparse; | |
1629 endp = skip_anyof(p); | |
1630 if (*endp == ']') | |
1631 { | |
1632 /* | |
1633 * Try to reverse engineer character classes. For example, | |
5296 | 1634 * recognize that [0-9] stands for \d and [A-Za-z_] for \h, |
4444 | 1635 * and perform the necessary substitutions in the NFA. |
1636 */ | |
1637 result = nfa_recognize_char_class(regparse, endp, | |
5296 | 1638 extra == NFA_ADD_NL); |
4444 | 1639 if (result != FAIL) |
1640 { | |
5296 | 1641 if (result >= NFA_FIRST_NL && result <= NFA_LAST_NL) |
4444 | 1642 { |
5296 | 1643 EMIT(result - NFA_ADD_NL); |
4444 | 1644 EMIT(NFA_NEWL); |
1645 EMIT(NFA_OR); | |
1646 } | |
5296 | 1647 else |
1648 EMIT(result); | |
4444 | 1649 regparse = endp; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1650 MB_PTR_ADV(regparse); |
4444 | 1651 return OK; |
1652 } | |
1653 /* | |
1654 * Failed to recognize a character class. Use the simple | |
1655 * version that turns [abc] into 'a' OR 'b' OR 'c' | |
1656 */ | |
1657 startc = endc = oldstartc = -1; | |
1658 negated = FALSE; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1659 if (*regparse == '^') // negated range |
4444 | 1660 { |
1661 negated = TRUE; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1662 MB_PTR_ADV(regparse); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1663 EMIT(NFA_START_NEG_COLL); |
4444 | 1664 } |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1665 else |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1666 EMIT(NFA_START_COLL); |
4444 | 1667 if (*regparse == '-') |
1668 { | |
1669 startc = '-'; | |
1670 EMIT(startc); | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1671 EMIT(NFA_CONCAT); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1672 MB_PTR_ADV(regparse); |
4444 | 1673 } |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1674 // Emit the OR branches for each character in the [] |
4444 | 1675 emit_range = FALSE; |
1676 while (regparse < endp) | |
1677 { | |
1678 oldstartc = startc; | |
1679 startc = -1; | |
1680 got_coll_char = FALSE; | |
1681 if (*regparse == '[') | |
1682 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1683 // Check for [: :], [= =], [. .] |
4444 | 1684 equiclass = collclass = 0; |
1685 charclass = get_char_class(®parse); | |
1686 if (charclass == CLASS_NONE) | |
1687 { | |
1688 equiclass = get_equi_class(®parse); | |
1689 if (equiclass == 0) | |
1690 collclass = get_coll_element(®parse); | |
1691 } | |
1692 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1693 // Character class like [:alpha:] |
4444 | 1694 if (charclass != CLASS_NONE) |
1695 { | |
1696 switch (charclass) | |
1697 { | |
1698 case CLASS_ALNUM: | |
1699 EMIT(NFA_CLASS_ALNUM); | |
1700 break; | |
1701 case CLASS_ALPHA: | |
1702 EMIT(NFA_CLASS_ALPHA); | |
1703 break; | |
1704 case CLASS_BLANK: | |
1705 EMIT(NFA_CLASS_BLANK); | |
1706 break; | |
1707 case CLASS_CNTRL: | |
1708 EMIT(NFA_CLASS_CNTRL); | |
1709 break; | |
1710 case CLASS_DIGIT: | |
1711 EMIT(NFA_CLASS_DIGIT); | |
1712 break; | |
1713 case CLASS_GRAPH: | |
1714 EMIT(NFA_CLASS_GRAPH); | |
1715 break; | |
1716 case CLASS_LOWER: | |
23471
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
1717 wants_nfa = TRUE; |
4444 | 1718 EMIT(NFA_CLASS_LOWER); |
1719 break; | |
1720 case CLASS_PRINT: | |
1721 EMIT(NFA_CLASS_PRINT); | |
1722 break; | |
1723 case CLASS_PUNCT: | |
1724 EMIT(NFA_CLASS_PUNCT); | |
1725 break; | |
1726 case CLASS_SPACE: | |
1727 EMIT(NFA_CLASS_SPACE); | |
1728 break; | |
1729 case CLASS_UPPER: | |
23471
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
1730 wants_nfa = TRUE; |
4444 | 1731 EMIT(NFA_CLASS_UPPER); |
1732 break; | |
1733 case CLASS_XDIGIT: | |
1734 EMIT(NFA_CLASS_XDIGIT); | |
1735 break; | |
1736 case CLASS_TAB: | |
1737 EMIT(NFA_CLASS_TAB); | |
1738 break; | |
1739 case CLASS_RETURN: | |
1740 EMIT(NFA_CLASS_RETURN); | |
1741 break; | |
1742 case CLASS_BACKSPACE: | |
1743 EMIT(NFA_CLASS_BACKSPACE); | |
1744 break; | |
1745 case CLASS_ESCAPE: | |
1746 EMIT(NFA_CLASS_ESCAPE); | |
1747 break; | |
15709
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1748 case CLASS_IDENT: |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1749 EMIT(NFA_CLASS_IDENT); |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1750 break; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1751 case CLASS_KEYWORD: |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1752 EMIT(NFA_CLASS_KEYWORD); |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1753 break; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1754 case CLASS_FNAME: |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1755 EMIT(NFA_CLASS_FNAME); |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
1756 break; |
4444 | 1757 } |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1758 EMIT(NFA_CONCAT); |
4444 | 1759 continue; |
1760 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1761 // Try equivalence class [=a=] and the like |
4444 | 1762 if (equiclass != 0) |
1763 { | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1764 result = nfa_emit_equi_class(equiclass); |
4444 | 1765 if (result == FAIL) |
1766 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1767 // should never happen |
4444 | 1768 EMSG_RET_FAIL(_("E868: Error building NFA with equivalence class!")); |
1769 } | |
1770 continue; | |
1771 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1772 // Try collating class like [. .] |
4444 | 1773 if (collclass != 0) |
1774 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1775 startc = collclass; // allow [.a.]-x as a range |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1776 // Will emit the proper atom at the end of the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1777 // while loop. |
4444 | 1778 } |
1779 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1780 // Try a range like 'a-x' or '\t-z'. Also allows '-' as a |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1781 // start character. |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1782 if (*regparse == '-' && oldstartc != -1) |
4444 | 1783 { |
1784 emit_range = TRUE; | |
1785 startc = oldstartc; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1786 MB_PTR_ADV(regparse); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1787 continue; // reading the end of the range |
4444 | 1788 } |
1789 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1790 // Now handle simple and escaped characters. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1791 // Only "\]", "\^", "\]" and "\\" are special in Vi. Vim |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1792 // accepts "\t", "\e", etc., but only when the 'l' flag in |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1793 // 'cpoptions' is not included. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1794 // Posix doesn't recognize backslash at all. |
4444 | 1795 if (*regparse == '\\' |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4742
diff
changeset
|
1796 && !reg_cpo_bsl |
4444 | 1797 && regparse + 1 <= endp |
1798 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL | |
4744
a62695305e03
updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents:
4742
diff
changeset
|
1799 || (!reg_cpo_lit |
4444 | 1800 && vim_strchr(REGEXP_ABBR, regparse[1]) |
1801 != NULL) | |
1802 ) | |
1803 ) | |
1804 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1805 MB_PTR_ADV(regparse); |
4444 | 1806 |
4507
9dbbddb2ed10
updated for version 7.3.1001
Bram Moolenaar <bram@vim.org>
parents:
4503
diff
changeset
|
1807 if (*regparse == 'n') |
15876
0c49755f460e
patch 8.1.0945: internal error when using pattern with NL in the range
Bram Moolenaar <Bram@vim.org>
parents:
15824
diff
changeset
|
1808 startc = (reg_string || emit_range |
0c49755f460e
patch 8.1.0945: internal error when using pattern with NL in the range
Bram Moolenaar <Bram@vim.org>
parents:
15824
diff
changeset
|
1809 || regparse[1] == '-') ? NL : NFA_NEWL; |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
15935
diff
changeset
|
1810 else if (*regparse == 'd' |
4444 | 1811 || *regparse == 'o' |
1812 || *regparse == 'x' | |
1813 || *regparse == 'u' | |
1814 || *regparse == 'U' | |
1815 ) | |
1816 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1817 // TODO(RE) This needs more testing |
4444 | 1818 startc = coll_get_char(); |
1819 got_coll_char = TRUE; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1820 MB_PTR_BACK(old_regparse, regparse); |
4444 | 1821 } |
1822 else | |
1823 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1824 // \r,\t,\e,\b |
4444 | 1825 startc = backslash_trans(*regparse); |
1826 } | |
1827 } | |
1828 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1829 // Normal printable char |
4444 | 1830 if (startc == -1) |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1831 startc = PTR2CHAR(regparse); |
4444 | 1832 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1833 // Previous char was '-', so this char is end of range. |
4444 | 1834 if (emit_range) |
1835 { | |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1836 endc = startc; |
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1837 startc = oldstartc; |
4444 | 1838 if (startc > endc) |
11480
99ce30ac4226
patch 8.0.0623: error for invalid regexp is not very informative
Christian Brabandt <cb@256bit.org>
parents:
11469
diff
changeset
|
1839 EMSG_RET_FAIL(_(e_reverse_range)); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1840 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1841 if (endc > startc + 2) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1842 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1843 // Emit a range instead of the sequence of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1844 // individual characters. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1845 if (startc == 0) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1846 // \x00 is translated to \x0a, start at \x01. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1847 EMIT(1); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1848 else |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1849 --post_ptr; // remove NFA_CONCAT |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1850 EMIT(endc); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1851 EMIT(NFA_RANGE); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1852 EMIT(NFA_CONCAT); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1853 } |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
1854 else if (has_mbyte && ((*mb_char2len)(startc) > 1 |
4444 | 1855 || (*mb_char2len)(endc) > 1)) |
1856 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1857 // Emit the characters in the range. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1858 // "startc" was already emitted, so skip it. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1859 // |
4444 | 1860 for (c = startc + 1; c <= endc; c++) |
1861 { | |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1862 EMIT(c); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1863 EMIT(NFA_CONCAT); |
4444 | 1864 } |
1865 } | |
1866 else | |
1867 { | |
1868 #ifdef EBCDIC | |
1869 int alpha_only = FALSE; | |
1870 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1871 // for alphabetical range skip the gaps |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1872 // 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. |
4444 | 1873 if (isalpha(startc) && isalpha(endc)) |
1874 alpha_only = TRUE; | |
1875 #endif | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1876 // Emit the range. "startc" was already emitted, so |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1877 // skip it. |
4444 | 1878 for (c = startc + 1; c <= endc; c++) |
1879 #ifdef EBCDIC | |
1880 if (!alpha_only || isalpha(startc)) | |
1881 #endif | |
1882 { | |
1883 EMIT(c); | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1884 EMIT(NFA_CONCAT); |
4444 | 1885 } |
1886 } | |
4677
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1887 emit_range = FALSE; |
c1622ff9ed8d
updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents:
4675
diff
changeset
|
1888 startc = -1; |
4444 | 1889 } |
1890 else | |
1891 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1892 // This char (startc) is not part of a range. Just |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1893 // emit it. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1894 // Normally, simply emit startc. But if we get char |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1895 // code=0 from a collating char, then replace it with |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1896 // 0x0a. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1897 // This is needed to completely mimic the behaviour of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1898 // the backtracking engine. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1899 if (startc == NFA_NEWL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1900 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1901 // Line break can't be matched as part of the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1902 // collection, add an OR below. But not for negated |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1903 // range. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1904 if (!negated) |
5296 | 1905 extra = NFA_ADD_NL; |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1906 } |
4444 | 1907 else |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1908 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1909 if (got_coll_char == TRUE && startc == 0) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1910 EMIT(0x0a); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1911 else |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1912 EMIT(startc); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1913 EMIT(NFA_CONCAT); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1914 } |
4444 | 1915 } |
1916 | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1917 MB_PTR_ADV(regparse); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1918 } // while (p < endp) |
4444 | 1919 |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1920 MB_PTR_BACK(old_regparse, regparse); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1921 if (*regparse == '-') // if last, '-' is just a char |
4444 | 1922 { |
1923 EMIT('-'); | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1924 EMIT(NFA_CONCAT); |
4444 | 1925 } |
1926 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1927 // skip the trailing ] |
4444 | 1928 regparse = endp; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10551
diff
changeset
|
1929 MB_PTR_ADV(regparse); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1930 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1931 // Mark end of the collection. |
4444 | 1932 if (negated == TRUE) |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1933 EMIT(NFA_END_NEG_COLL); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1934 else |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
1935 EMIT(NFA_END_COLL); |
4615
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1936 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1937 // \_[] also matches \n but it's not negated |
5296 | 1938 if (extra == NFA_ADD_NL) |
4615
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1939 { |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1940 EMIT(reg_string ? NL : NFA_NEWL); |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1941 EMIT(NFA_OR); |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1942 } |
5679b8ddd8cc
updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents:
4583
diff
changeset
|
1943 |
4444 | 1944 return OK; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1945 } // if exists closing ] |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1946 |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1947 if (reg_strict) |
4444 | 1948 EMSG_RET_FAIL(_(e_missingbracket)); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1949 // FALLTHROUGH |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1950 |
4444 | 1951 default: |
1952 { | |
1953 int plen; | |
1954 | |
1955 nfa_do_multibyte: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1956 // plen is length of current char with composing chars |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1957 if (enc_utf8 && ((*mb_char2len)(c) |
11269
121d29004998
patch 8.0.0520: using a function pointer while the function is known
Christian Brabandt <cb@256bit.org>
parents:
11267
diff
changeset
|
1958 != (plen = utfc_ptr2len(old_regparse)) |
4543
08ac46980953
updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents:
4541
diff
changeset
|
1959 || utf_iscomposing(c))) |
4444 | 1960 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1961 int i = 0; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
1962 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1963 // A base character plus composing characters, or just one |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1964 // or more composing characters. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1965 // This requires creating a separate atom as if enclosing |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1966 // the characters in (), where NFA_COMPOSING is the ( and |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1967 // NFA_END_COMPOSING is the ). Note that right now we are |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1968 // building the postfix form, not the NFA itself; |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1969 // a composing char could be: a, b, c, NFA_COMPOSING |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1970 // where 'b' and 'c' are chars with codes > 256. |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1971 for (;;) |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1972 { |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1973 EMIT(c); |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1974 if (i > 0) |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1975 EMIT(NFA_CONCAT); |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
1976 if ((i += utf_char2len(c)) >= plen) |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1977 break; |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1978 c = utf_ptr2char(old_regparse + i); |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1979 } |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
1980 EMIT(NFA_COMPOSING); |
4444 | 1981 regparse = old_regparse + plen; |
1982 } | |
1983 else | |
1984 { | |
1985 c = no_Magic(c); | |
1986 EMIT(c); | |
1987 } | |
1988 return OK; | |
1989 } | |
1990 } | |
1991 | |
1992 return OK; | |
1993 } | |
1994 | |
1995 /* | |
1996 * Parse something followed by possible [*+=]. | |
1997 * | |
1998 * A piece is an atom, possibly followed by a multi, an indication of how many | |
1999 * times the atom can be matched. Example: "a*" matches any sequence of "a" | |
2000 * characters: "", "a", "aa", etc. | |
2001 * | |
2002 * piece ::= atom | |
2003 * or atom multi | |
2004 */ | |
2005 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2006 nfa_regpiece(void) |
4444 | 2007 { |
2008 int i; | |
2009 int op; | |
2010 int ret; | |
2011 long minval, maxval; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2012 int greedy = TRUE; // Braces are prefixed with '-' ? |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2013 parse_state_T old_state; |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2014 parse_state_T new_state; |
12752
09c856605191
patch 8.0.1254: undefined left shift in gethexchrs()
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2015 long c2; |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2016 int old_post_pos; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2017 int my_post_start; |
4444 | 2018 int quest; |
2019 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2020 // Save the current parse state, so that we can use it if <atom>{m,n} is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2021 // next. |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2022 save_parse_state(&old_state); |
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2023 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2024 // 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
|
2025 my_post_start = (int)(post_ptr - post_start); |
4444 | 2026 |
2027 ret = nfa_regatom(); | |
2028 if (ret == FAIL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2029 return FAIL; // cascaded error |
4444 | 2030 |
2031 op = peekchr(); | |
2032 if (re_multi_type(op) == NOT_MULTI) | |
2033 return OK; | |
2034 | |
2035 skipchr(); | |
2036 switch (op) | |
2037 { | |
2038 case Magic('*'): | |
2039 EMIT(NFA_STAR); | |
2040 break; | |
2041 | |
2042 case Magic('+'): | |
2043 /* | |
2044 * Trick: Normally, (a*)\+ would match the whole input "aaa". The | |
2045 * first and only submatch would be "aaa". But the backtracking | |
2046 * engine interprets the plus as "try matching one more time", and | |
2047 * a* matches a second time at the end of the input, the empty | |
2048 * string. | |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
2049 * The submatch will be the empty string. |
4444 | 2050 * |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2051 * 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
|
2052 * <atom>+ with <atom><atom>* |
4444 | 2053 */ |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2054 restore_parse_state(&old_state); |
4444 | 2055 curchr = -1; |
2056 if (nfa_regatom() == FAIL) | |
2057 return FAIL; | |
2058 EMIT(NFA_STAR); | |
2059 EMIT(NFA_CONCAT); | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2060 skipchr(); // skip the \+ |
4444 | 2061 break; |
2062 | |
2063 case Magic('@'): | |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2064 c2 = getdecchrs(); |
4444 | 2065 op = no_Magic(getchr()); |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2066 i = 0; |
4444 | 2067 switch(op) |
2068 { | |
2069 case '=': | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2070 // \@= |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2071 i = NFA_PREV_ATOM_NO_WIDTH; |
4444 | 2072 break; |
4661
0dce3d812e7a
updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents:
4657
diff
changeset
|
2073 case '!': |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2074 // \@! |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2075 i = NFA_PREV_ATOM_NO_WIDTH_NEG; |
4661
0dce3d812e7a
updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents:
4657
diff
changeset
|
2076 break; |
4444 | 2077 case '<': |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2078 op = no_Magic(getchr()); |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2079 if (op == '=') |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2080 // \@<= |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2081 i = NFA_PREV_ATOM_JUST_BEFORE; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2082 else if (op == '!') |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2083 // \@<! |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2084 i = NFA_PREV_ATOM_JUST_BEFORE_NEG; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2085 break; |
4444 | 2086 case '>': |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2087 // \@> |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2088 i = NFA_PREV_ATOM_LIKE_PATTERN; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2089 break; |
4444 | 2090 } |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2091 if (i == 0) |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2092 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
2093 semsg(_("E869: (NFA) Unknown operator '\\@%c'"), op); |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2094 return FAIL; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2095 } |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2096 EMIT(i); |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2097 if (i == NFA_PREV_ATOM_JUST_BEFORE |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2098 || i == NFA_PREV_ATOM_JUST_BEFORE_NEG) |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2099 EMIT(c2); |
4444 | 2100 break; |
2101 | |
2102 case Magic('?'): | |
2103 case Magic('='): | |
2104 EMIT(NFA_QUEST); | |
2105 break; | |
2106 | |
2107 case Magic('{'): | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2108 // a{2,5} will expand to 'aaa?a?a?' |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2109 // a{-1,3} will expand to 'aa??a??', where ?? is the nongreedy |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2110 // version of '?' |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2111 // \v(ab){2,3} will expand to '(ab)(ab)(ab)?', where all the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2112 // parenthesis have the same id |
4444 | 2113 |
2114 greedy = TRUE; | |
2115 c2 = peekchr(); | |
2116 if (c2 == '-' || c2 == Magic('-')) | |
2117 { | |
2118 skipchr(); | |
2119 greedy = FALSE; | |
2120 } | |
2121 if (!read_limits(&minval, &maxval)) | |
2122 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
|
2123 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2124 // <atom>{0,inf}, <atom>{0,} and <atom>{} are equivalent to |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2125 // <atom>* |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2126 if (minval == 0 && maxval == MAX_LIMIT) |
4444 | 2127 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2128 if (greedy) // { { (match the braces) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2129 // \{}, \{0,} |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2130 EMIT(NFA_STAR); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2131 else // { { (match the braces) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2132 // \{-}, \{-0,} |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2133 EMIT(NFA_STAR_NONGREEDY); |
4444 | 2134 break; |
2135 } | |
2136 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2137 // Special case: x{0} or x{-0} |
4444 | 2138 if (maxval == 0) |
2139 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2140 // 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
|
2141 post_ptr = post_start + my_post_start; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2142 // NFA_EMPTY is 0-length and works everywhere |
5370 | 2143 EMIT(NFA_EMPTY); |
4444 | 2144 return OK; |
2145 } | |
2146 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2147 // The engine is very inefficient (uses too many states) when the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2148 // maximum is much larger than the minimum and when the maximum is |
23471
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2149 // large. However, when maxval is MAX_LIMIT, it is okay, as this |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2150 // will emit NFA_STAR. |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2151 // Bail out if we can use the other engine, but only, when the |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2152 // pattern does not need the NFA engine like (e.g. [[:upper:]]\{2,\} |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2153 // does not work with with characters > 8 bit with the BT engine) |
6594 | 2154 if ((nfa_re_flags & RE_AUTO) |
23471
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2155 && (maxval > 500 || maxval > minval + 200) |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2156 && (maxval != MAX_LIMIT && minval < 200) |
a7cdfc8e4b6e
patch 8.2.2278: falling back to old regexp engine can some patterns
Bram Moolenaar <Bram@vim.org>
parents:
23270
diff
changeset
|
2157 && !wants_nfa) |
6533 | 2158 return FAIL; |
2159 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2160 // Ignore previous call to nfa_regatom() |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2161 post_ptr = post_start + my_post_start; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2162 // Save parse state after the repeated atom and the \{} |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2163 save_parse_state(&new_state); |
4444 | 2164 |
2165 quest = (greedy == TRUE? NFA_QUEST : NFA_QUEST_NONGREEDY); | |
2166 for (i = 0; i < maxval; i++) | |
2167 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2168 // Goto beginning of the repeated atom |
4679
4d92b873acef
updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents:
4677
diff
changeset
|
2169 restore_parse_state(&old_state); |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2170 old_post_pos = (int)(post_ptr - post_start); |
4444 | 2171 if (nfa_regatom() == FAIL) |
2172 return FAIL; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2173 // after "minval" times, atoms are optional |
4444 | 2174 if (i + 1 > minval) |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2175 { |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2176 if (maxval == MAX_LIMIT) |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2177 { |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2178 if (greedy) |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2179 EMIT(NFA_STAR); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2180 else |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2181 EMIT(NFA_STAR_NONGREEDY); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2182 } |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2183 else |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2184 EMIT(quest); |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2185 } |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2186 if (old_post_pos != my_post_start) |
4444 | 2187 EMIT(NFA_CONCAT); |
4673
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2188 if (i + 1 > minval && maxval == MAX_LIMIT) |
05d57d7c2d55
updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents:
4671
diff
changeset
|
2189 break; |
4444 | 2190 } |
2191 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2192 // 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
|
2193 restore_parse_state(&new_state); |
4444 | 2194 curchr = -1; |
2195 | |
2196 break; | |
2197 | |
2198 | |
2199 default: | |
2200 break; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2201 } // end switch |
4444 | 2202 |
2203 if (re_multi_type(peekchr()) != NOT_MULTI) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2204 // Can't have a multi follow a multi. |
14163
99a96be12254
patch 8.1.0099: exclamation mark in error message not needed
Christian Brabandt <cb@256bit.org>
parents:
14161
diff
changeset
|
2205 EMSG_RET_FAIL(_("E871: (NFA regexp) Can't have a multi follow a multi")); |
4444 | 2206 |
2207 return OK; | |
2208 } | |
2209 | |
2210 /* | |
2211 * Parse one or more pieces, concatenated. It matches a match for the | |
2212 * first piece, followed by a match for the second piece, etc. Example: | |
2213 * "f[0-9]b", first matches "f", then a digit and then "b". | |
2214 * | |
2215 * concat ::= piece | |
2216 * or piece piece | |
2217 * or piece piece piece | |
2218 * etc. | |
2219 */ | |
2220 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2221 nfa_regconcat(void) |
4444 | 2222 { |
2223 int cont = TRUE; | |
2224 int first = TRUE; | |
2225 | |
2226 while (cont) | |
2227 { | |
2228 switch (peekchr()) | |
2229 { | |
2230 case NUL: | |
2231 case Magic('|'): | |
2232 case Magic('&'): | |
2233 case Magic(')'): | |
2234 cont = FALSE; | |
2235 break; | |
2236 | |
2237 case Magic('Z'): | |
2238 regflags |= RF_ICOMBINE; | |
2239 skipchr_keepstart(); | |
2240 break; | |
2241 case Magic('c'): | |
2242 regflags |= RF_ICASE; | |
2243 skipchr_keepstart(); | |
2244 break; | |
2245 case Magic('C'): | |
2246 regflags |= RF_NOICASE; | |
2247 skipchr_keepstart(); | |
2248 break; | |
2249 case Magic('v'): | |
2250 reg_magic = MAGIC_ALL; | |
2251 skipchr_keepstart(); | |
2252 curchr = -1; | |
2253 break; | |
2254 case Magic('m'): | |
2255 reg_magic = MAGIC_ON; | |
2256 skipchr_keepstart(); | |
2257 curchr = -1; | |
2258 break; | |
2259 case Magic('M'): | |
2260 reg_magic = MAGIC_OFF; | |
2261 skipchr_keepstart(); | |
2262 curchr = -1; | |
2263 break; | |
2264 case Magic('V'): | |
2265 reg_magic = MAGIC_NONE; | |
2266 skipchr_keepstart(); | |
2267 curchr = -1; | |
2268 break; | |
2269 | |
2270 default: | |
2271 if (nfa_regpiece() == FAIL) | |
2272 return FAIL; | |
2273 if (first == FALSE) | |
2274 EMIT(NFA_CONCAT); | |
2275 else | |
2276 first = FALSE; | |
2277 break; | |
2278 } | |
2279 } | |
2280 | |
2281 return OK; | |
2282 } | |
2283 | |
2284 /* | |
2285 * Parse a branch, one or more concats, separated by "\&". It matches the | |
2286 * last concat, but only if all the preceding concats also match at the same | |
2287 * position. Examples: | |
2288 * "foobeep\&..." matches "foo" in "foobeep". | |
2289 * ".*Peter\&.*Bob" matches in a line containing both "Peter" and "Bob" | |
2290 * | |
2291 * branch ::= concat | |
2292 * or concat \& concat | |
2293 * or concat \& concat \& concat | |
2294 * etc. | |
2295 */ | |
2296 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2297 nfa_regbranch(void) |
4444 | 2298 { |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2299 int old_post_pos; |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2300 |
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2301 old_post_pos = (int)(post_ptr - post_start); |
4444 | 2302 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2303 // First branch, possibly the only one |
4444 | 2304 if (nfa_regconcat() == FAIL) |
2305 return FAIL; | |
2306 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2307 // Try next concats |
13043
307f2622826f
patch 8.0.1397: pattern with & following nothing gives an error
Christian Brabandt <cb@256bit.org>
parents:
12752
diff
changeset
|
2308 while (peekchr() == Magic('&')) |
4444 | 2309 { |
2310 skipchr(); | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2311 // if concat is empty do emit a node |
13043
307f2622826f
patch 8.0.1397: pattern with & following nothing gives an error
Christian Brabandt <cb@256bit.org>
parents:
12752
diff
changeset
|
2312 if (old_post_pos == (int)(post_ptr - post_start)) |
307f2622826f
patch 8.0.1397: pattern with & following nothing gives an error
Christian Brabandt <cb@256bit.org>
parents:
12752
diff
changeset
|
2313 EMIT(NFA_EMPTY); |
4444 | 2314 EMIT(NFA_NOPEN); |
2315 EMIT(NFA_PREV_ATOM_NO_WIDTH); | |
4651
f10f63aaec5c
updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents:
4649
diff
changeset
|
2316 old_post_pos = (int)(post_ptr - post_start); |
4444 | 2317 if (nfa_regconcat() == FAIL) |
2318 return FAIL; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2319 // 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
|
2320 if (old_post_pos == (int)(post_ptr - post_start)) |
5370 | 2321 EMIT(NFA_EMPTY); |
4444 | 2322 EMIT(NFA_CONCAT); |
2323 } | |
2324 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2325 // 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
|
2326 if (old_post_pos == (int)(post_ptr - post_start)) |
5370 | 2327 EMIT(NFA_EMPTY); |
4444 | 2328 |
2329 return OK; | |
2330 } | |
2331 | |
2332 /* | |
2333 * Parse a pattern, one or more branches, separated by "\|". It matches | |
2334 * anything that matches one of the branches. Example: "foo\|beep" matches | |
2335 * "foo" and matches "beep". If more than one branch matches, the first one | |
2336 * is used. | |
2337 * | |
2338 * pattern ::= branch | |
2339 * or branch \| branch | |
2340 * or branch \| branch \| branch | |
2341 * etc. | |
2342 */ | |
2343 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2344 nfa_reg( |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2345 int paren) // REG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN |
4444 | 2346 { |
2347 int parno = 0; | |
2348 | |
2349 if (paren == REG_PAREN) | |
2350 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2351 if (regnpar >= NSUBEXP) // Too many `(' |
4444 | 2352 EMSG_RET_FAIL(_("E872: (NFA regexp) Too many '('")); |
2353 parno = regnpar++; | |
2354 } | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2355 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2356 else if (paren == REG_ZPAREN) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2357 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2358 // Make a ZOPEN node. |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2359 if (regnzpar >= NSUBEXP) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2360 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
|
2361 parno = regnzpar++; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2362 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2363 #endif |
4444 | 2364 |
2365 if (nfa_regbranch() == FAIL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2366 return FAIL; // cascaded error |
4444 | 2367 |
2368 while (peekchr() == Magic('|')) | |
2369 { | |
2370 skipchr(); | |
2371 if (nfa_regbranch() == FAIL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2372 return FAIL; // cascaded error |
4444 | 2373 EMIT(NFA_OR); |
2374 } | |
2375 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2376 // Check for proper termination. |
4444 | 2377 if (paren != REG_NOPAREN && getchr() != Magic(')')) |
2378 { | |
2379 if (paren == REG_NPAREN) | |
2380 EMSG2_RET_FAIL(_(e_unmatchedpp), reg_magic == MAGIC_ALL); | |
2381 else | |
2382 EMSG2_RET_FAIL(_(e_unmatchedp), reg_magic == MAGIC_ALL); | |
2383 } | |
2384 else if (paren == REG_NOPAREN && peekchr() != NUL) | |
2385 { | |
2386 if (peekchr() == Magic(')')) | |
2387 EMSG2_RET_FAIL(_(e_unmatchedpar), reg_magic == MAGIC_ALL); | |
2388 else | |
2389 EMSG_RET_FAIL(_("E873: (NFA regexp) proper termination error")); | |
2390 } | |
2391 /* | |
2392 * Here we set the flag allowing back references to this set of | |
2393 * parentheses. | |
2394 */ | |
2395 if (paren == REG_PAREN) | |
2396 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2397 had_endbrace[parno] = TRUE; // have seen the close paren |
4444 | 2398 EMIT(NFA_MOPEN + parno); |
2399 } | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2400 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2401 else if (paren == REG_ZPAREN) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2402 EMIT(NFA_ZOPEN + parno); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2403 #endif |
4444 | 2404 |
2405 return OK; | |
2406 } | |
2407 | |
2408 #ifdef DEBUG | |
2409 static char_u code[50]; | |
2410 | |
2411 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2412 nfa_set_code(int c) |
4444 | 2413 { |
2414 int addnl = FALSE; | |
2415 | |
2416 if (c >= NFA_FIRST_NL && c <= NFA_LAST_NL) | |
2417 { | |
2418 addnl = TRUE; | |
5296 | 2419 c -= NFA_ADD_NL; |
4444 | 2420 } |
2421 | |
2422 STRCPY(code, ""); | |
2423 switch (c) | |
2424 { | |
2425 case NFA_MATCH: STRCPY(code, "NFA_MATCH "); break; | |
2426 case NFA_SPLIT: STRCPY(code, "NFA_SPLIT "); break; | |
2427 case NFA_CONCAT: STRCPY(code, "NFA_CONCAT "); break; | |
2428 case NFA_NEWL: STRCPY(code, "NFA_NEWL "); break; | |
2429 case NFA_ZSTART: STRCPY(code, "NFA_ZSTART"); break; | |
2430 case NFA_ZEND: STRCPY(code, "NFA_ZEND"); break; | |
2431 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2432 case NFA_BACKREF1: STRCPY(code, "NFA_BACKREF1"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2433 case NFA_BACKREF2: STRCPY(code, "NFA_BACKREF2"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2434 case NFA_BACKREF3: STRCPY(code, "NFA_BACKREF3"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2435 case NFA_BACKREF4: STRCPY(code, "NFA_BACKREF4"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2436 case NFA_BACKREF5: STRCPY(code, "NFA_BACKREF5"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2437 case NFA_BACKREF6: STRCPY(code, "NFA_BACKREF6"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2438 case NFA_BACKREF7: STRCPY(code, "NFA_BACKREF7"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2439 case NFA_BACKREF8: STRCPY(code, "NFA_BACKREF8"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2440 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
|
2441 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2442 case NFA_ZREF1: STRCPY(code, "NFA_ZREF1"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2443 case NFA_ZREF2: STRCPY(code, "NFA_ZREF2"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2444 case NFA_ZREF3: STRCPY(code, "NFA_ZREF3"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2445 case NFA_ZREF4: STRCPY(code, "NFA_ZREF4"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2446 case NFA_ZREF5: STRCPY(code, "NFA_ZREF5"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2447 case NFA_ZREF6: STRCPY(code, "NFA_ZREF6"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2448 case NFA_ZREF7: STRCPY(code, "NFA_ZREF7"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2449 case NFA_ZREF8: STRCPY(code, "NFA_ZREF8"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2450 case NFA_ZREF9: STRCPY(code, "NFA_ZREF9"); break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2451 #endif |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2452 case NFA_SKIP: STRCPY(code, "NFA_SKIP"); break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
2453 |
4444 | 2454 case NFA_PREV_ATOM_NO_WIDTH: |
2455 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
|
2456 case NFA_PREV_ATOM_NO_WIDTH_NEG: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
2457 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
|
2458 case NFA_PREV_ATOM_JUST_BEFORE: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2459 STRCPY(code, "NFA_PREV_ATOM_JUST_BEFORE"); break; |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2460 case NFA_PREV_ATOM_JUST_BEFORE_NEG: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2461 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
|
2462 case NFA_PREV_ATOM_LIKE_PATTERN: |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2463 STRCPY(code, "NFA_PREV_ATOM_LIKE_PATTERN"); break; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
2464 |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
2465 case NFA_NOPEN: STRCPY(code, "NFA_NOPEN"); break; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
2466 case NFA_NCLOSE: STRCPY(code, "NFA_NCLOSE"); break; |
4444 | 2467 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
|
2468 case NFA_START_INVISIBLE_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2469 STRCPY(code, "NFA_START_INVISIBLE_FIRST"); break; |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2470 case NFA_START_INVISIBLE_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2471 STRCPY(code, "NFA_START_INVISIBLE_NEG"); break; |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2472 case NFA_START_INVISIBLE_NEG_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2473 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
|
2474 case NFA_START_INVISIBLE_BEFORE: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
2475 STRCPY(code, "NFA_START_INVISIBLE_BEFORE"); break; |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2476 case NFA_START_INVISIBLE_BEFORE_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2477 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
|
2478 case NFA_START_INVISIBLE_BEFORE_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2479 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
|
2480 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
2481 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
|
2482 case NFA_START_PATTERN: STRCPY(code, "NFA_START_PATTERN"); break; |
4444 | 2483 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
|
2484 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
|
2485 case NFA_END_PATTERN: STRCPY(code, "NFA_END_PATTERN"); break; |
4444 | 2486 |
2487 case NFA_COMPOSING: STRCPY(code, "NFA_COMPOSING"); break; | |
2488 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
|
2489 case NFA_OPT_CHARS: STRCPY(code, "NFA_OPT_CHARS"); break; |
4444 | 2490 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2491 case NFA_MOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2492 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2493 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2494 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2495 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2496 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2497 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2498 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2499 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2500 case NFA_MOPEN9: |
4444 | 2501 STRCPY(code, "NFA_MOPEN(x)"); |
2502 code[10] = c - NFA_MOPEN + '0'; | |
2503 break; | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2504 case NFA_MCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2505 case NFA_MCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2506 case NFA_MCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2507 case NFA_MCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2508 case NFA_MCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2509 case NFA_MCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2510 case NFA_MCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2511 case NFA_MCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2512 case NFA_MCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2513 case NFA_MCLOSE9: |
4444 | 2514 STRCPY(code, "NFA_MCLOSE(x)"); |
2515 code[11] = c - NFA_MCLOSE + '0'; | |
2516 break; | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2517 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2518 case NFA_ZOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2519 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2520 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2521 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2522 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2523 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2524 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2525 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2526 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2527 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2528 STRCPY(code, "NFA_ZOPEN(x)"); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2529 code[10] = c - NFA_ZOPEN + '0'; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2530 break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2531 case NFA_ZCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2532 case NFA_ZCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2533 case NFA_ZCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2534 case NFA_ZCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2535 case NFA_ZCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2536 case NFA_ZCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2537 case NFA_ZCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2538 case NFA_ZCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2539 case NFA_ZCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2540 case NFA_ZCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2541 STRCPY(code, "NFA_ZCLOSE(x)"); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2542 code[11] = c - NFA_ZCLOSE + '0'; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2543 break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
2544 #endif |
4444 | 2545 case NFA_EOL: STRCPY(code, "NFA_EOL "); break; |
2546 case NFA_BOL: STRCPY(code, "NFA_BOL "); break; | |
2547 case NFA_EOW: STRCPY(code, "NFA_EOW "); break; | |
2548 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
|
2549 case NFA_EOF: STRCPY(code, "NFA_EOF "); break; |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
2550 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
|
2551 case NFA_LNUM: STRCPY(code, "NFA_LNUM "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2552 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
|
2553 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
|
2554 case NFA_COL: STRCPY(code, "NFA_COL "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2555 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
|
2556 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
|
2557 case NFA_VCOL: STRCPY(code, "NFA_VCOL "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2558 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
|
2559 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
|
2560 case NFA_MARK: STRCPY(code, "NFA_MARK "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2561 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
|
2562 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
|
2563 case NFA_CURSOR: STRCPY(code, "NFA_CURSOR "); break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
2564 case NFA_VISUAL: STRCPY(code, "NFA_VISUAL "); break; |
5901 | 2565 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
|
2566 |
4444 | 2567 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
|
2568 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
|
2569 case NFA_QUEST: STRCPY(code, "NFA_QUEST"); break; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
2570 case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break; |
5370 | 2571 case NFA_EMPTY: STRCPY(code, "NFA_EMPTY"); break; |
4444 | 2572 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
|
2573 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2574 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
|
2575 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
|
2576 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
|
2577 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
|
2578 case NFA_RANGE: STRCPY(code, "NFA_RANGE"); break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2579 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
|
2580 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
|
2581 |
4444 | 2582 case NFA_CLASS_ALNUM: STRCPY(code, "NFA_CLASS_ALNUM"); break; |
2583 case NFA_CLASS_ALPHA: STRCPY(code, "NFA_CLASS_ALPHA"); break; | |
2584 case NFA_CLASS_BLANK: STRCPY(code, "NFA_CLASS_BLANK"); break; | |
2585 case NFA_CLASS_CNTRL: STRCPY(code, "NFA_CLASS_CNTRL"); break; | |
2586 case NFA_CLASS_DIGIT: STRCPY(code, "NFA_CLASS_DIGIT"); break; | |
2587 case NFA_CLASS_GRAPH: STRCPY(code, "NFA_CLASS_GRAPH"); break; | |
2588 case NFA_CLASS_LOWER: STRCPY(code, "NFA_CLASS_LOWER"); break; | |
2589 case NFA_CLASS_PRINT: STRCPY(code, "NFA_CLASS_PRINT"); break; | |
2590 case NFA_CLASS_PUNCT: STRCPY(code, "NFA_CLASS_PUNCT"); break; | |
2591 case NFA_CLASS_SPACE: STRCPY(code, "NFA_CLASS_SPACE"); break; | |
2592 case NFA_CLASS_UPPER: STRCPY(code, "NFA_CLASS_UPPER"); break; | |
2593 case NFA_CLASS_XDIGIT: STRCPY(code, "NFA_CLASS_XDIGIT"); break; | |
2594 case NFA_CLASS_TAB: STRCPY(code, "NFA_CLASS_TAB"); break; | |
2595 case NFA_CLASS_RETURN: STRCPY(code, "NFA_CLASS_RETURN"); break; | |
2596 case NFA_CLASS_BACKSPACE: STRCPY(code, "NFA_CLASS_BACKSPACE"); break; | |
2597 case NFA_CLASS_ESCAPE: STRCPY(code, "NFA_CLASS_ESCAPE"); break; | |
15709
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
2598 case NFA_CLASS_IDENT: STRCPY(code, "NFA_CLASS_IDENT"); break; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
2599 case NFA_CLASS_KEYWORD: STRCPY(code, "NFA_CLASS_KEYWORD"); break; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
2600 case NFA_CLASS_FNAME: STRCPY(code, "NFA_CLASS_FNAME"); break; |
4444 | 2601 |
2602 case NFA_ANY: STRCPY(code, "NFA_ANY"); break; | |
2603 case NFA_IDENT: STRCPY(code, "NFA_IDENT"); break; | |
2604 case NFA_SIDENT:STRCPY(code, "NFA_SIDENT"); break; | |
2605 case NFA_KWORD: STRCPY(code, "NFA_KWORD"); break; | |
2606 case NFA_SKWORD:STRCPY(code, "NFA_SKWORD"); break; | |
2607 case NFA_FNAME: STRCPY(code, "NFA_FNAME"); break; | |
2608 case NFA_SFNAME:STRCPY(code, "NFA_SFNAME"); break; | |
2609 case NFA_PRINT: STRCPY(code, "NFA_PRINT"); break; | |
2610 case NFA_SPRINT:STRCPY(code, "NFA_SPRINT"); break; | |
2611 case NFA_WHITE: STRCPY(code, "NFA_WHITE"); break; | |
2612 case NFA_NWHITE:STRCPY(code, "NFA_NWHITE"); break; | |
2613 case NFA_DIGIT: STRCPY(code, "NFA_DIGIT"); break; | |
2614 case NFA_NDIGIT:STRCPY(code, "NFA_NDIGIT"); break; | |
2615 case NFA_HEX: STRCPY(code, "NFA_HEX"); break; | |
2616 case NFA_NHEX: STRCPY(code, "NFA_NHEX"); break; | |
2617 case NFA_OCTAL: STRCPY(code, "NFA_OCTAL"); break; | |
2618 case NFA_NOCTAL:STRCPY(code, "NFA_NOCTAL"); break; | |
2619 case NFA_WORD: STRCPY(code, "NFA_WORD"); break; | |
2620 case NFA_NWORD: STRCPY(code, "NFA_NWORD"); break; | |
2621 case NFA_HEAD: STRCPY(code, "NFA_HEAD"); break; | |
2622 case NFA_NHEAD: STRCPY(code, "NFA_NHEAD"); break; | |
2623 case NFA_ALPHA: STRCPY(code, "NFA_ALPHA"); break; | |
2624 case NFA_NALPHA:STRCPY(code, "NFA_NALPHA"); break; | |
2625 case NFA_LOWER: STRCPY(code, "NFA_LOWER"); break; | |
2626 case NFA_NLOWER:STRCPY(code, "NFA_NLOWER"); break; | |
2627 case NFA_UPPER: STRCPY(code, "NFA_UPPER"); break; | |
2628 case NFA_NUPPER:STRCPY(code, "NFA_NUPPER"); break; | |
5296 | 2629 case NFA_LOWER_IC: STRCPY(code, "NFA_LOWER_IC"); break; |
2630 case NFA_NLOWER_IC: STRCPY(code, "NFA_NLOWER_IC"); break; | |
2631 case NFA_UPPER_IC: STRCPY(code, "NFA_UPPER_IC"); break; | |
2632 case NFA_NUPPER_IC: STRCPY(code, "NFA_NUPPER_IC"); break; | |
4444 | 2633 |
2634 default: | |
2635 STRCPY(code, "CHAR(x)"); | |
2636 code[5] = c; | |
2637 } | |
2638 | |
2639 if (addnl == TRUE) | |
2640 STRCAT(code, " + NEWLINE "); | |
2641 | |
2642 } | |
2643 | |
2644 #ifdef ENABLE_LOG | |
2645 static FILE *log_fd; | |
14145
1cf832945469
patch 8.1.0090: "..." used inconsistently in a message
Christian Brabandt <cb@256bit.org>
parents:
14121
diff
changeset
|
2646 static char_u e_log_open_failed[] = N_("Could not open temporary log file for writing, displaying on stderr... "); |
4444 | 2647 |
2648 /* | |
2649 * Print the postfix notation of the current regexp. | |
2650 */ | |
2651 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2652 nfa_postfix_dump(char_u *expr, int retval) |
4444 | 2653 { |
2654 int *p; | |
2655 FILE *f; | |
2656 | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2657 f = fopen(NFA_REGEXP_DUMP_LOG, "a"); |
4444 | 2658 if (f != NULL) |
2659 { | |
2660 fprintf(f, "\n-------------------------\n"); | |
2661 if (retval == FAIL) | |
14145
1cf832945469
patch 8.1.0090: "..." used inconsistently in a message
Christian Brabandt <cb@256bit.org>
parents:
14121
diff
changeset
|
2662 fprintf(f, ">>> NFA engine failed... \n"); |
4444 | 2663 else if (retval == OK) |
2664 fprintf(f, ">>> NFA engine succeeded !\n"); | |
2665 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
|
2666 for (p = post_start; *p && p < post_ptr; p++) |
4444 | 2667 { |
2668 nfa_set_code(*p); | |
2669 fprintf(f, "%s, ", code); | |
2670 } | |
2671 fprintf(f, "\"\nPostfix notation (int): "); | |
5255
3c6e2b89875f
updated for version 7.4b.004
Bram Moolenaar <bram@vim.org>
parents:
5253
diff
changeset
|
2672 for (p = post_start; *p && p < post_ptr; p++) |
4444 | 2673 fprintf(f, "%d ", *p); |
2674 fprintf(f, "\n\n"); | |
2675 fclose(f); | |
2676 } | |
2677 } | |
2678 | |
2679 /* | |
2680 * Print the NFA starting with a root node "state". | |
2681 */ | |
2682 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2683 nfa_print_state(FILE *debugf, nfa_state_T *state) |
4444 | 2684 { |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2685 garray_T indent; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2686 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2687 ga_init2(&indent, 1, 64); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2688 ga_append(&indent, '\0'); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2689 nfa_print_state2(debugf, state, &indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2690 ga_clear(&indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2691 } |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2692 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2693 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2694 nfa_print_state2(FILE *debugf, nfa_state_T *state, garray_T *indent) |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2695 { |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2696 char_u *p; |
4444 | 2697 |
2698 if (state == NULL) | |
2699 return; | |
2700 | |
2701 fprintf(debugf, "(%2d)", abs(state->id)); | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2702 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2703 // Output indent |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2704 p = (char_u *)indent->ga_data; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2705 if (indent->ga_len >= 3) |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2706 { |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2707 int last = indent->ga_len - 3; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2708 char_u save[2]; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2709 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2710 STRNCPY(save, &p[last], 2); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2711 STRNCPY(&p[last], "+-", 2); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2712 fprintf(debugf, " %s", p); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2713 STRNCPY(&p[last], save, 2); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2714 } |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2715 else |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2716 fprintf(debugf, " %s", p); |
4444 | 2717 |
2718 nfa_set_code(state->c); | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
2719 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
|
2720 code, |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2721 state->c, |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2722 abs(state->id), |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2723 state->val); |
4444 | 2724 if (state->id < 0) |
2725 return; | |
2726 | |
2727 state->id = abs(state->id) * -1; | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2728 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2729 // grow indent for state->out |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2730 indent->ga_len -= 1; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2731 if (state->out1) |
4537
5cc98a5898cf
updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents:
4535
diff
changeset
|
2732 ga_concat(indent, (char_u *)"| "); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2733 else |
4537
5cc98a5898cf
updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents:
4535
diff
changeset
|
2734 ga_concat(indent, (char_u *)" "); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2735 ga_append(indent, '\0'); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2736 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2737 nfa_print_state2(debugf, state->out, indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2738 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2739 // replace last part of indent for state->out1 |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2740 indent->ga_len -= 3; |
4537
5cc98a5898cf
updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents:
4535
diff
changeset
|
2741 ga_concat(indent, (char_u *)" "); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2742 ga_append(indent, '\0'); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2743 |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2744 nfa_print_state2(debugf, state->out1, indent); |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2745 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2746 // shrink indent |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2747 indent->ga_len -= 3; |
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2748 ga_append(indent, '\0'); |
4444 | 2749 } |
2750 | |
2751 /* | |
2752 * Print the NFA state machine. | |
2753 */ | |
2754 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2755 nfa_dump(nfa_regprog_T *prog) |
4444 | 2756 { |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2757 FILE *debugf = fopen(NFA_REGEXP_DUMP_LOG, "a"); |
4444 | 2758 |
2759 if (debugf != NULL) | |
2760 { | |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
2761 nfa_print_state(debugf, prog->start); |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
2762 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2763 if (prog->reganch) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2764 fprintf(debugf, "reganch: %d\n", prog->reganch); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2765 if (prog->regstart != NUL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2766 fprintf(debugf, "regstart: %c (decimal: %d)\n", |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2767 prog->regstart, prog->regstart); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2768 if (prog->match_text != NULL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
2769 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
|
2770 |
4444 | 2771 fclose(debugf); |
2772 } | |
2773 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2774 #endif // ENABLE_LOG |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2775 #endif // DEBUG |
4444 | 2776 |
2777 /* | |
2778 * Parse r.e. @expr and convert it into postfix form. | |
2779 * Return the postfix string on success, NULL otherwise. | |
2780 */ | |
2781 static int * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2782 re2post(void) |
4444 | 2783 { |
2784 if (nfa_reg(REG_NOPAREN) == FAIL) | |
2785 return NULL; | |
2786 EMIT(NFA_MOPEN); | |
2787 return post_start; | |
2788 } | |
2789 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2790 // NB. Some of the code below is inspired by Russ's. |
4444 | 2791 |
2792 /* | |
2793 * Represents an NFA state plus zero or one or two arrows exiting. | |
2794 * if c == MATCH, no arrows out; matching state. | |
2795 * If c == SPLIT, unlabeled arrows to out and out1 (if != NULL). | |
2796 * If c < 256, labeled arrow with character c to out. | |
2797 */ | |
2798 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2799 static nfa_state_T *state_ptr; // points to nfa_prog->state |
4444 | 2800 |
2801 /* | |
2802 * Allocate and initialize nfa_state_T. | |
2803 */ | |
2804 static nfa_state_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2805 alloc_state(int c, nfa_state_T *out, nfa_state_T *out1) |
4444 | 2806 { |
2807 nfa_state_T *s; | |
2808 | |
2809 if (istate >= nstate) | |
2810 return NULL; | |
2811 | |
2812 s = &state_ptr[istate++]; | |
2813 | |
2814 s->c = c; | |
2815 s->out = out; | |
2816 s->out1 = out1; | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
2817 s->val = 0; |
4444 | 2818 |
2819 s->id = istate; | |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
2820 s->lastlist[0] = 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
2821 s->lastlist[1] = 0; |
4444 | 2822 |
2823 return s; | |
2824 } | |
2825 | |
2826 /* | |
2827 * A partially built NFA without the matching state filled in. | |
2828 * Frag_T.start points at the start state. | |
2829 * Frag_T.out is a list of places that need to be set to the | |
2830 * next state for this fragment. | |
2831 */ | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2832 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2833 // Since the out pointers in the list are always |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2834 // uninitialized, we use the pointers themselves |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2835 // as storage for the Ptrlists. |
4444 | 2836 typedef union Ptrlist Ptrlist; |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2837 union Ptrlist |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2838 { |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2839 Ptrlist *next; |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2840 nfa_state_T *s; |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2841 }; |
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2842 |
4444 | 2843 struct Frag |
2844 { | |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
2845 nfa_state_T *start; |
4444 | 2846 Ptrlist *out; |
2847 }; | |
2848 typedef struct Frag Frag_T; | |
2849 | |
2850 /* | |
4456 | 2851 * Initialize a Frag_T struct and return it. |
4444 | 2852 */ |
2853 static Frag_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2854 frag(nfa_state_T *start, Ptrlist *out) |
4444 | 2855 { |
4456 | 2856 Frag_T n; |
2857 | |
2858 n.start = start; | |
2859 n.out = out; | |
4444 | 2860 return n; |
2861 } | |
2862 | |
2863 /* | |
2864 * Create singleton list containing just outp. | |
2865 */ | |
2866 static Ptrlist * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2867 list1( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2868 nfa_state_T **outp) |
4444 | 2869 { |
2870 Ptrlist *l; | |
2871 | |
2872 l = (Ptrlist *)outp; | |
2873 l->next = NULL; | |
2874 return l; | |
2875 } | |
2876 | |
2877 /* | |
2878 * Patch the list of states at out to point to start. | |
2879 */ | |
2880 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2881 patch(Ptrlist *l, nfa_state_T *s) |
4444 | 2882 { |
2883 Ptrlist *next; | |
2884 | |
2885 for (; l; l = next) | |
2886 { | |
2887 next = l->next; | |
2888 l->s = s; | |
2889 } | |
2890 } | |
2891 | |
2892 | |
2893 /* | |
2894 * Join the two lists l1 and l2, returning the combination. | |
2895 */ | |
2896 static Ptrlist * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2897 append(Ptrlist *l1, Ptrlist *l2) |
4444 | 2898 { |
2899 Ptrlist *oldl1; | |
2900 | |
2901 oldl1 = l1; | |
2902 while (l1->next) | |
2903 l1 = l1->next; | |
2904 l1->next = l2; | |
2905 return oldl1; | |
2906 } | |
2907 | |
2908 /* | |
2909 * Stack used for transforming postfix form into NFA. | |
2910 */ | |
2911 static Frag_T empty; | |
2912 | |
2913 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2914 st_error(int *postfix UNUSED, int *end UNUSED, int *p UNUSED) |
4444 | 2915 { |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2916 #ifdef NFA_REGEXP_ERROR_LOG |
4444 | 2917 FILE *df; |
2918 int *p2; | |
2919 | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2920 df = fopen(NFA_REGEXP_ERROR_LOG, "a"); |
4444 | 2921 if (df) |
2922 { | |
2923 fprintf(df, "Error popping the stack!\n"); | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
2924 # ifdef DEBUG |
4444 | 2925 fprintf(df, "Current regexp is \"%s\"\n", nfa_regengine.expr); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
2926 # endif |
4444 | 2927 fprintf(df, "Postfix form is: "); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
2928 # ifdef DEBUG |
4444 | 2929 for (p2 = postfix; p2 < end; p2++) |
2930 { | |
2931 nfa_set_code(*p2); | |
2932 fprintf(df, "%s, ", code); | |
2933 } | |
2934 nfa_set_code(*p); | |
2935 fprintf(df, "\nCurrent position is: "); | |
2936 for (p2 = postfix; p2 <= p; p2 ++) | |
2937 { | |
2938 nfa_set_code(*p2); | |
2939 fprintf(df, "%s, ", code); | |
2940 } | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
2941 # else |
4444 | 2942 for (p2 = postfix; p2 < end; p2++) |
2943 fprintf(df, "%d, ", *p2); | |
2944 fprintf(df, "\nCurrent position is: "); | |
2945 for (p2 = postfix; p2 <= p; p2 ++) | |
2946 fprintf(df, "%d, ", *p2); | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
2947 # endif |
4444 | 2948 fprintf(df, "\n--------------------------\n"); |
2949 fclose(df); | |
2950 } | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
2951 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
2952 emsg(_("E874: (NFA) Could not pop the stack!")); |
4444 | 2953 } |
2954 | |
2955 /* | |
2956 * Push an item onto the stack. | |
2957 */ | |
2958 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2959 st_push(Frag_T s, Frag_T **p, Frag_T *stack_end) |
4444 | 2960 { |
2961 Frag_T *stackp = *p; | |
2962 | |
2963 if (stackp >= stack_end) | |
2964 return; | |
2965 *stackp = s; | |
2966 *p = *p + 1; | |
2967 } | |
2968 | |
2969 /* | |
2970 * Pop an item from the stack. | |
2971 */ | |
2972 static Frag_T | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2973 st_pop(Frag_T **p, Frag_T *stack) |
4444 | 2974 { |
2975 Frag_T *stackp; | |
2976 | |
2977 *p = *p - 1; | |
2978 stackp = *p; | |
2979 if (stackp < stack) | |
2980 return empty; | |
2981 return **p; | |
2982 } | |
2983 | |
2984 /* | |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2985 * 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
|
2986 * When unknown or unlimited return -1. |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2987 */ |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2988 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2989 nfa_max_width(nfa_state_T *startstate, int depth) |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2990 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2991 int l, r; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2992 nfa_state_T *state = startstate; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2993 int len = 0; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2994 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
2995 // detect looping in a NFA_SPLIT |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2996 if (depth > 4) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2997 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2998 |
4958
0a379dea13c9
updated for version 7.3.1224
Bram Moolenaar <bram@vim.org>
parents:
4944
diff
changeset
|
2999 while (state != NULL) |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3000 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3001 switch (state->c) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3002 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3003 case NFA_END_INVISIBLE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3004 case NFA_END_INVISIBLE_NEG: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3005 // the end, return what we have |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3006 return len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3007 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3008 case NFA_SPLIT: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3009 // two alternatives, use the maximum |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3010 l = nfa_max_width(state->out, depth + 1); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3011 r = nfa_max_width(state->out1, depth + 1); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3012 if (l < 0 || r < 0) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3013 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3014 return len + (l > r ? l : r); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3015 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3016 case NFA_ANY: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3017 case NFA_START_COLL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3018 case NFA_START_NEG_COLL: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3019 // matches some character, including composing chars |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3020 if (enc_utf8) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3021 len += MB_MAXBYTES; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3022 else if (has_mbyte) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3023 len += 2; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3024 else |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3025 ++len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3026 if (state->c != NFA_ANY) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3027 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3028 // skip over the characters |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3029 state = state->out1->out; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3030 continue; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3031 } |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3032 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3033 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3034 case NFA_DIGIT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3035 case NFA_WHITE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3036 case NFA_HEX: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3037 case NFA_OCTAL: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3038 // ascii |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3039 ++len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3040 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3041 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3042 case NFA_IDENT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3043 case NFA_SIDENT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3044 case NFA_KWORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3045 case NFA_SKWORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3046 case NFA_FNAME: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3047 case NFA_SFNAME: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3048 case NFA_PRINT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3049 case NFA_SPRINT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3050 case NFA_NWHITE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3051 case NFA_NDIGIT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3052 case NFA_NHEX: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3053 case NFA_NOCTAL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3054 case NFA_WORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3055 case NFA_NWORD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3056 case NFA_HEAD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3057 case NFA_NHEAD: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3058 case NFA_ALPHA: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3059 case NFA_NALPHA: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3060 case NFA_LOWER: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3061 case NFA_NLOWER: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3062 case NFA_UPPER: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3063 case NFA_NUPPER: |
5296 | 3064 case NFA_LOWER_IC: |
3065 case NFA_NLOWER_IC: | |
3066 case NFA_UPPER_IC: | |
3067 case NFA_NUPPER_IC: | |
5901 | 3068 case NFA_ANY_COMPOSING: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3069 // possibly non-ascii |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3070 if (has_mbyte) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3071 len += 3; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3072 else |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3073 ++len; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3074 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3075 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3076 case NFA_START_INVISIBLE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3077 case NFA_START_INVISIBLE_NEG: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3078 case NFA_START_INVISIBLE_BEFORE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3079 case NFA_START_INVISIBLE_BEFORE_NEG: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3080 // zero-width, out1 points to the END state |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3081 state = state->out1->out; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3082 continue; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3083 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3084 case NFA_BACKREF1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3085 case NFA_BACKREF2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3086 case NFA_BACKREF3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3087 case NFA_BACKREF4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3088 case NFA_BACKREF5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3089 case NFA_BACKREF6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3090 case NFA_BACKREF7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3091 case NFA_BACKREF8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3092 case NFA_BACKREF9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3093 #ifdef FEAT_SYN_HL |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3094 case NFA_ZREF1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3095 case NFA_ZREF2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3096 case NFA_ZREF3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3097 case NFA_ZREF4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3098 case NFA_ZREF5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3099 case NFA_ZREF6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3100 case NFA_ZREF7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3101 case NFA_ZREF8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3102 case NFA_ZREF9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3103 #endif |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3104 case NFA_NEWL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3105 case NFA_SKIP: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3106 // unknown width |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3107 return -1; |
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 case NFA_BOL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3110 case NFA_EOL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3111 case NFA_BOF: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3112 case NFA_EOF: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3113 case NFA_BOW: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3114 case NFA_EOW: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3115 case NFA_MOPEN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3116 case NFA_MOPEN1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3117 case NFA_MOPEN2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3118 case NFA_MOPEN3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3119 case NFA_MOPEN4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3120 case NFA_MOPEN5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3121 case NFA_MOPEN6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3122 case NFA_MOPEN7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3123 case NFA_MOPEN8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3124 case NFA_MOPEN9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3125 #ifdef FEAT_SYN_HL |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3126 case NFA_ZOPEN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3127 case NFA_ZOPEN1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3128 case NFA_ZOPEN2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3129 case NFA_ZOPEN3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3130 case NFA_ZOPEN4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3131 case NFA_ZOPEN5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3132 case NFA_ZOPEN6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3133 case NFA_ZOPEN7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3134 case NFA_ZOPEN8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3135 case NFA_ZOPEN9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3136 case NFA_ZCLOSE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3137 case NFA_ZCLOSE1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3138 case NFA_ZCLOSE2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3139 case NFA_ZCLOSE3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3140 case NFA_ZCLOSE4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3141 case NFA_ZCLOSE5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3142 case NFA_ZCLOSE6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3143 case NFA_ZCLOSE7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3144 case NFA_ZCLOSE8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3145 case NFA_ZCLOSE9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3146 #endif |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3147 case NFA_MCLOSE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3148 case NFA_MCLOSE1: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3149 case NFA_MCLOSE2: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3150 case NFA_MCLOSE3: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3151 case NFA_MCLOSE4: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3152 case NFA_MCLOSE5: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3153 case NFA_MCLOSE6: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3154 case NFA_MCLOSE7: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3155 case NFA_MCLOSE8: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3156 case NFA_MCLOSE9: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3157 case NFA_NOPEN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3158 case NFA_NCLOSE: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3159 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3160 case NFA_LNUM_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3161 case NFA_LNUM_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3162 case NFA_COL_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3163 case NFA_COL_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3164 case NFA_VCOL_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3165 case NFA_VCOL_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3166 case NFA_MARK_GT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3167 case NFA_MARK_LT: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3168 case NFA_VISUAL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3169 case NFA_LNUM: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3170 case NFA_CURSOR: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3171 case NFA_COL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3172 case NFA_VCOL: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3173 case NFA_MARK: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3174 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3175 case NFA_ZSTART: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3176 case NFA_ZEND: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3177 case NFA_OPT_CHARS: |
5370 | 3178 case NFA_EMPTY: |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3179 case NFA_START_PATTERN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3180 case NFA_END_PATTERN: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3181 case NFA_COMPOSING: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3182 case NFA_END_COMPOSING: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3183 // zero-width |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3184 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3185 |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3186 default: |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3187 if (state->c < 0) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3188 // don't know what this is |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3189 return -1; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3190 // normal character |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3191 len += MB_CHAR2LEN(state->c); |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3192 break; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3193 } |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3194 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3195 // normal way to continue |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3196 state = state->out; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3197 } |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3198 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3199 // unrecognized, "cannot happen" |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3200 return -1; |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3201 } |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
3202 |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3203 /* |
4444 | 3204 * Convert a postfix form into its equivalent NFA. |
3205 * Return the NFA start state on success, NULL otherwise. | |
3206 */ | |
3207 static nfa_state_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3208 post2nfa(int *postfix, int *end, int nfa_calc_size) |
4444 | 3209 { |
3210 int *p; | |
3211 int mopen; | |
3212 int mclose; | |
3213 Frag_T *stack = NULL; | |
3214 Frag_T *stackp = NULL; | |
3215 Frag_T *stack_end = NULL; | |
3216 Frag_T e1; | |
3217 Frag_T e2; | |
3218 Frag_T e; | |
3219 nfa_state_T *s; | |
3220 nfa_state_T *s1; | |
3221 nfa_state_T *matchstate; | |
4484 | 3222 nfa_state_T *ret = NULL; |
4444 | 3223 |
3224 if (postfix == NULL) | |
3225 return NULL; | |
3226 | |
4456 | 3227 #define PUSH(s) st_push((s), &stackp, stack_end) |
4444 | 3228 #define POP() st_pop(&stackp, stack); \ |
3229 if (stackp < stack) \ | |
3230 { \ | |
3231 st_error(postfix, end, p); \ | |
6747 | 3232 vim_free(stack); \ |
4444 | 3233 return NULL; \ |
3234 } | |
3235 | |
3236 if (nfa_calc_size == FALSE) | |
3237 { | |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3238 // Allocate space for the stack. Max states on the stack: "nstate". |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3239 stack = ALLOC_MULT(Frag_T, nstate + 1); |
15265
a7d02a56b5d5
patch 8.1.0641: no check for out-of-memory when converting regexp
Bram Moolenaar <Bram@vim.org>
parents:
14354
diff
changeset
|
3240 if (stack == NULL) |
a7d02a56b5d5
patch 8.1.0641: no check for out-of-memory when converting regexp
Bram Moolenaar <Bram@vim.org>
parents:
14354
diff
changeset
|
3241 return NULL; |
4444 | 3242 stackp = stack; |
4462 | 3243 stack_end = stack + (nstate + 1); |
4444 | 3244 } |
3245 | |
3246 for (p = postfix; p < end; ++p) | |
3247 { | |
3248 switch (*p) | |
3249 { | |
3250 case NFA_CONCAT: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3251 // Concatenation. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3252 // Pay attention: this operator does not exist in the r.e. itself |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3253 // (it is implicit, really). It is added when r.e. is translated |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3254 // to postfix form in re2post(). |
4444 | 3255 if (nfa_calc_size == TRUE) |
3256 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3257 // nstate += 0; |
4444 | 3258 break; |
3259 } | |
3260 e2 = POP(); | |
3261 e1 = POP(); | |
3262 patch(e1.out, e2.start); | |
3263 PUSH(frag(e1.start, e2.out)); | |
3264 break; | |
3265 | |
3266 case NFA_OR: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3267 // Alternation |
4444 | 3268 if (nfa_calc_size == TRUE) |
3269 { | |
4458 | 3270 nstate++; |
4444 | 3271 break; |
3272 } | |
3273 e2 = POP(); | |
3274 e1 = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3275 s = alloc_state(NFA_SPLIT, e1.start, e2.start); |
4444 | 3276 if (s == NULL) |
4484 | 3277 goto theend; |
4444 | 3278 PUSH(frag(s, append(e1.out, e2.out))); |
3279 break; | |
3280 | |
3281 case NFA_STAR: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3282 // Zero or more, prefer more |
4444 | 3283 if (nfa_calc_size == TRUE) |
3284 { | |
4458 | 3285 nstate++; |
4444 | 3286 break; |
3287 } | |
3288 e = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3289 s = alloc_state(NFA_SPLIT, e.start, NULL); |
4444 | 3290 if (s == NULL) |
4484 | 3291 goto theend; |
4444 | 3292 patch(e.out, s); |
3293 PUSH(frag(s, list1(&s->out1))); | |
3294 break; | |
3295 | |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3296 case NFA_STAR_NONGREEDY: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3297 // Zero or more, prefer zero |
4675
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3298 if (nfa_calc_size == TRUE) |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3299 { |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3300 nstate++; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3301 break; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3302 } |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3303 e = POP(); |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3304 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
|
3305 if (s == NULL) |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3306 goto theend; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3307 patch(e.out, s); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3308 PUSH(frag(s, list1(&s->out))); |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3309 break; |
811a4c9b51d8
updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents:
4673
diff
changeset
|
3310 |
4444 | 3311 case NFA_QUEST: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3312 // one or zero atoms=> greedy match |
4444 | 3313 if (nfa_calc_size == TRUE) |
3314 { | |
4458 | 3315 nstate++; |
4444 | 3316 break; |
3317 } | |
3318 e = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3319 s = alloc_state(NFA_SPLIT, e.start, NULL); |
4444 | 3320 if (s == NULL) |
4484 | 3321 goto theend; |
4444 | 3322 PUSH(frag(s, append(e.out, list1(&s->out1)))); |
3323 break; | |
3324 | |
3325 case NFA_QUEST_NONGREEDY: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3326 // zero or one atoms => non-greedy match |
4444 | 3327 if (nfa_calc_size == TRUE) |
3328 { | |
4458 | 3329 nstate++; |
4444 | 3330 break; |
3331 } | |
3332 e = POP(); | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3333 s = alloc_state(NFA_SPLIT, NULL, e.start); |
4444 | 3334 if (s == NULL) |
4484 | 3335 goto theend; |
4444 | 3336 PUSH(frag(s, append(e.out, list1(&s->out)))); |
3337 break; | |
3338 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3339 case NFA_END_COLL: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3340 case NFA_END_NEG_COLL: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3341 // On the stack is the sequence starting with NFA_START_COLL or |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3342 // NFA_START_NEG_COLL and all possible characters. Patch it to |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3343 // add the output to the start. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3344 if (nfa_calc_size == TRUE) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3345 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3346 nstate++; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3347 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3348 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3349 e = POP(); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3350 s = alloc_state(NFA_END_COLL, NULL, NULL); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3351 if (s == NULL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3352 goto theend; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3353 patch(e.out, s); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3354 e.start->out1 = s; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3355 PUSH(frag(e.start, list1(&s->out))); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3356 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3357 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3358 case NFA_RANGE: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3359 // Before this are two characters, the low and high end of a |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3360 // range. Turn them into two states with MIN and MAX. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3361 if (nfa_calc_size == TRUE) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3362 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3363 // nstate += 0; |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3364 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3365 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3366 e2 = POP(); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3367 e1 = POP(); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3368 e2.start->val = e2.start->c; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3369 e2.start->c = NFA_RANGE_MAX; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3370 e1.start->val = e1.start->c; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3371 e1.start->c = NFA_RANGE_MIN; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3372 patch(e1.out, e2.start); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3373 PUSH(frag(e1.start, e2.out)); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3374 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3375 |
5370 | 3376 case NFA_EMPTY: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3377 // 0-length, used in a repetition with max/min count of 0 |
4444 | 3378 if (nfa_calc_size == TRUE) |
3379 { | |
4458 | 3380 nstate++; |
4444 | 3381 break; |
3382 } | |
5370 | 3383 s = alloc_state(NFA_EMPTY, NULL, NULL); |
4444 | 3384 if (s == NULL) |
4484 | 3385 goto theend; |
4444 | 3386 PUSH(frag(s, list1(&s->out))); |
3387 break; | |
3388 | |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3389 case NFA_OPT_CHARS: |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3390 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3391 int n; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3392 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3393 // \%[abc] implemented as: |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3394 // NFA_SPLIT |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3395 // +-CHAR(a) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3396 // | +-NFA_SPLIT |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3397 // | +-CHAR(b) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3398 // | | +-NFA_SPLIT |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3399 // | | +-CHAR(c) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3400 // | | | +-next |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3401 // | | +- next |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3402 // | +- next |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3403 // +- next |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3404 n = *++p; // get number of characters |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3405 if (nfa_calc_size == TRUE) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3406 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3407 nstate += n; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3408 break; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3409 } |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3410 s = NULL; // avoid compiler warning |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3411 e1.out = NULL; // stores list with out1's |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3412 s1 = NULL; // previous NFA_SPLIT to connect to |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3413 while (n-- > 0) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3414 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3415 e = POP(); // get character |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3416 s = alloc_state(NFA_SPLIT, e.start, NULL); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3417 if (s == NULL) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3418 goto theend; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3419 if (e1.out == NULL) |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3420 e1 = e; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3421 patch(e.out, s1); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3422 append(e1.out, list1(&s->out1)); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3423 s1 = s; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3424 } |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3425 PUSH(frag(s, e1.out)); |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3426 break; |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3427 } |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3428 |
4444 | 3429 case NFA_PREV_ATOM_NO_WIDTH: |
4661
0dce3d812e7a
updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents:
4657
diff
changeset
|
3430 case NFA_PREV_ATOM_NO_WIDTH_NEG: |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3431 case NFA_PREV_ATOM_JUST_BEFORE: |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3432 case NFA_PREV_ATOM_JUST_BEFORE_NEG: |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3433 case NFA_PREV_ATOM_LIKE_PATTERN: |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3434 { |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3435 int before = (*p == NFA_PREV_ATOM_JUST_BEFORE |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3436 || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG); |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3437 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
|
3438 int start_state; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3439 int end_state; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3440 int n = 0; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3441 nfa_state_T *zend; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3442 nfa_state_T *skip; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3443 |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3444 switch (*p) |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3445 { |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3446 case NFA_PREV_ATOM_NO_WIDTH: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3447 start_state = NFA_START_INVISIBLE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3448 end_state = NFA_END_INVISIBLE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3449 break; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3450 case NFA_PREV_ATOM_NO_WIDTH_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3451 start_state = NFA_START_INVISIBLE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3452 end_state = NFA_END_INVISIBLE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3453 break; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3454 case NFA_PREV_ATOM_JUST_BEFORE: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3455 start_state = NFA_START_INVISIBLE_BEFORE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3456 end_state = NFA_END_INVISIBLE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3457 break; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3458 case NFA_PREV_ATOM_JUST_BEFORE_NEG: |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3459 start_state = NFA_START_INVISIBLE_BEFORE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3460 end_state = NFA_END_INVISIBLE_NEG; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3461 break; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3462 default: // NFA_PREV_ATOM_LIKE_PATTERN: |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3463 start_state = NFA_START_PATTERN; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3464 end_state = NFA_END_PATTERN; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
3465 break; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3466 } |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3467 |
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3468 if (before) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3469 n = *++p; // get the count |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3470 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3471 // The \@= operator: match the preceding atom with zero width. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3472 // The \@! operator: no match for the preceding atom. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3473 // The \@<= operator: match for the preceding atom. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3474 // The \@<! operator: no match for the preceding atom. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3475 // Surrounds the preceding atom with START_INVISIBLE and |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3476 // END_INVISIBLE, similarly to MOPEN. |
4444 | 3477 |
3478 if (nfa_calc_size == TRUE) | |
3479 { | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3480 nstate += pattern ? 4 : 2; |
4444 | 3481 break; |
3482 } | |
3483 e = POP(); | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3484 s1 = alloc_state(end_state, NULL, NULL); |
4444 | 3485 if (s1 == NULL) |
4484 | 3486 goto theend; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3487 |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3488 s = alloc_state(start_state, e.start, s1); |
4444 | 3489 if (s == NULL) |
4484 | 3490 goto theend; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3491 if (pattern) |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3492 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3493 // NFA_ZEND -> NFA_END_PATTERN -> NFA_SKIP -> what follows. |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3494 skip = alloc_state(NFA_SKIP, NULL, NULL); |
11896
a941848d8c44
patch 8.0.0828: Coverity: may dereference NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11525
diff
changeset
|
3495 if (skip == NULL) |
a941848d8c44
patch 8.0.0828: Coverity: may dereference NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11525
diff
changeset
|
3496 goto theend; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3497 zend = alloc_state(NFA_ZEND, s1, NULL); |
11896
a941848d8c44
patch 8.0.0828: Coverity: may dereference NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11525
diff
changeset
|
3498 if (zend == NULL) |
a941848d8c44
patch 8.0.0828: Coverity: may dereference NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11525
diff
changeset
|
3499 goto theend; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3500 s1->out= skip; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3501 patch(e.out, zend); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3502 PUSH(frag(s, list1(&skip->out))); |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
3503 } |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3504 else |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3505 { |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3506 patch(e.out, s1); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3507 PUSH(frag(s, list1(&s1->out))); |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3508 if (before) |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3509 { |
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3510 if (n <= 0) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3511 // See if we can guess the maximum width, it avoids a |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3512 // lot of pointless tries. |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3513 n = nfa_max_width(e.start, 0); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3514 s->val = n; // store the count |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
3515 } |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3516 } |
4444 | 3517 break; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3518 } |
4444 | 3519 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3520 case NFA_COMPOSING: // char with composing char |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3521 #if 0 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3522 // TODO |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3523 if (regflags & RF_ICOMBINE) |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3524 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3525 // use the base character only |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3526 } |
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3527 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3528 // FALLTHROUGH |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3529 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3530 case NFA_MOPEN: // \( \) Submatch |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3531 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3532 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3533 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3534 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3535 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3536 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3537 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3538 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3539 case NFA_MOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3540 #ifdef FEAT_SYN_HL |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3541 case NFA_ZOPEN: // \z( \) Submatch |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3542 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3543 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3544 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3545 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3546 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3547 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3548 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3549 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3550 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3551 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3552 case NFA_NOPEN: // \%( \) "Invisible Submatch" |
4444 | 3553 if (nfa_calc_size == TRUE) |
3554 { | |
3555 nstate += 2; | |
3556 break; | |
3557 } | |
3558 | |
3559 mopen = *p; | |
3560 switch (*p) | |
3561 { | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3562 case NFA_NOPEN: mclose = NFA_NCLOSE; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3563 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3564 case NFA_ZOPEN: mclose = NFA_ZCLOSE; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3565 case NFA_ZOPEN1: mclose = NFA_ZCLOSE1; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3566 case NFA_ZOPEN2: mclose = NFA_ZCLOSE2; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3567 case NFA_ZOPEN3: mclose = NFA_ZCLOSE3; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3568 case NFA_ZOPEN4: mclose = NFA_ZCLOSE4; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3569 case NFA_ZOPEN5: mclose = NFA_ZCLOSE5; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3570 case NFA_ZOPEN6: mclose = NFA_ZCLOSE6; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3571 case NFA_ZOPEN7: mclose = NFA_ZCLOSE7; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3572 case NFA_ZOPEN8: mclose = NFA_ZCLOSE8; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3573 case NFA_ZOPEN9: mclose = NFA_ZCLOSE9; break; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3574 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3575 case NFA_COMPOSING: mclose = NFA_END_COMPOSING; break; |
4444 | 3576 default: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3577 // NFA_MOPEN, NFA_MOPEN1 .. NFA_MOPEN9 |
4444 | 3578 mclose = *p + NSUBEXP; |
3579 break; | |
3580 } | |
3581 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3582 // Allow "NFA_MOPEN" as a valid postfix representation for |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3583 // the empty regexp "". In this case, the NFA will be |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3584 // NFA_MOPEN -> NFA_MCLOSE. Note that this also allows |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3585 // empty groups of parenthesis, and empty mbyte chars |
4444 | 3586 if (stackp == stack) |
3587 { | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3588 s = alloc_state(mopen, NULL, NULL); |
4444 | 3589 if (s == NULL) |
4484 | 3590 goto theend; |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3591 s1 = alloc_state(mclose, NULL, NULL); |
4444 | 3592 if (s1 == NULL) |
4484 | 3593 goto theend; |
4444 | 3594 patch(list1(&s->out), s1); |
3595 PUSH(frag(s, list1(&s1->out))); | |
3596 break; | |
3597 } | |
3598 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3599 // At least one node was emitted before NFA_MOPEN, so |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3600 // at least one node will be between NFA_MOPEN and NFA_MCLOSE |
4444 | 3601 e = POP(); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3602 s = alloc_state(mopen, e.start, NULL); // `(' |
4444 | 3603 if (s == NULL) |
4484 | 3604 goto theend; |
4444 | 3605 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3606 s1 = alloc_state(mclose, NULL, NULL); // `)' |
4444 | 3607 if (s1 == NULL) |
4484 | 3608 goto theend; |
4444 | 3609 patch(e.out, s1); |
3610 | |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
3611 if (mopen == NFA_COMPOSING) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3612 // COMPOSING->out1 = END_COMPOSING |
4444 | 3613 patch(list1(&s->out1), s1); |
3614 | |
3615 PUSH(frag(s, list1(&s1->out))); | |
3616 break; | |
3617 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3618 case NFA_BACKREF1: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3619 case NFA_BACKREF2: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3620 case NFA_BACKREF3: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3621 case NFA_BACKREF4: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3622 case NFA_BACKREF5: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3623 case NFA_BACKREF6: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3624 case NFA_BACKREF7: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3625 case NFA_BACKREF8: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3626 case NFA_BACKREF9: |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3627 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3628 case NFA_ZREF1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3629 case NFA_ZREF2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3630 case NFA_ZREF3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3631 case NFA_ZREF4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3632 case NFA_ZREF5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3633 case NFA_ZREF6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3634 case NFA_ZREF7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3635 case NFA_ZREF8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3636 case NFA_ZREF9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3637 #endif |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3638 if (nfa_calc_size == TRUE) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3639 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3640 nstate += 2; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3641 break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3642 } |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3643 s = alloc_state(*p, NULL, NULL); |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3644 if (s == NULL) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3645 goto theend; |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3646 s1 = alloc_state(NFA_SKIP, NULL, NULL); |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3647 if (s1 == NULL) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3648 goto theend; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3649 patch(list1(&s->out), s1); |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3650 PUSH(frag(s, list1(&s1->out))); |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3651 break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3652 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3653 case NFA_LNUM: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3654 case NFA_LNUM_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3655 case NFA_LNUM_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3656 case NFA_VCOL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3657 case NFA_VCOL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3658 case NFA_VCOL_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3659 case NFA_COL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3660 case NFA_COL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3661 case NFA_COL_LT: |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
3662 case NFA_MARK: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
3663 case NFA_MARK_GT: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
3664 case NFA_MARK_LT: |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3665 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3666 int n = *++p; // lnum, col or mark name |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3667 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3668 if (nfa_calc_size == TRUE) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3669 { |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3670 nstate += 1; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3671 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3672 } |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3673 s = alloc_state(p[-1], NULL, NULL); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3674 if (s == NULL) |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3675 goto theend; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3676 s->val = n; |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3677 PUSH(frag(s, list1(&s->out))); |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3678 break; |
4740
97560c16ca99
updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents:
4738
diff
changeset
|
3679 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
3680 |
4444 | 3681 case NFA_ZSTART: |
3682 case NFA_ZEND: | |
3683 default: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3684 // Operands |
4444 | 3685 if (nfa_calc_size == TRUE) |
3686 { | |
4458 | 3687 nstate++; |
4444 | 3688 break; |
3689 } | |
4696
ed4e689bbea1
updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents:
4694
diff
changeset
|
3690 s = alloc_state(*p, NULL, NULL); |
4444 | 3691 if (s == NULL) |
4484 | 3692 goto theend; |
4444 | 3693 PUSH(frag(s, list1(&s->out))); |
3694 break; | |
3695 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3696 } // switch(*p) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3697 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3698 } // for(p = postfix; *p; ++p) |
4444 | 3699 |
3700 if (nfa_calc_size == TRUE) | |
3701 { | |
4458 | 3702 nstate++; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3703 goto theend; // Return value when counting size is ignored anyway |
4444 | 3704 } |
3705 | |
3706 e = POP(); | |
3707 if (stackp != stack) | |
6747 | 3708 { |
3709 vim_free(stack); | |
4444 | 3710 EMSG_RET_NULL(_("E875: (NFA regexp) (While converting from postfix to NFA), too many states left on stack")); |
6747 | 3711 } |
4444 | 3712 |
3713 if (istate >= nstate) | |
6747 | 3714 { |
3715 vim_free(stack); | |
4444 | 3716 EMSG_RET_NULL(_("E876: (NFA regexp) Not enough space to store the whole NFA ")); |
6747 | 3717 } |
4444 | 3718 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3719 matchstate = &state_ptr[istate++]; // the match state |
4444 | 3720 matchstate->c = NFA_MATCH; |
3721 matchstate->out = matchstate->out1 = NULL; | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
3722 matchstate->id = 0; |
4444 | 3723 |
3724 patch(e.out, matchstate); | |
4484 | 3725 ret = e.start; |
3726 | |
3727 theend: | |
3728 vim_free(stack); | |
3729 return ret; | |
4444 | 3730 |
3731 #undef POP1 | |
3732 #undef PUSH1 | |
3733 #undef POP2 | |
3734 #undef PUSH2 | |
3735 #undef POP | |
3736 #undef PUSH | |
3737 } | |
3738 | |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3739 /* |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3740 * 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
|
3741 */ |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3742 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3743 nfa_postprocess(nfa_regprog_T *prog) |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3744 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3745 int i; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3746 int c; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3747 |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3748 for (i = 0; i < prog->nstate; ++i) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3749 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3750 c = prog->state[i].c; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3751 if (c == NFA_START_INVISIBLE |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3752 || c == NFA_START_INVISIBLE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3753 || c == NFA_START_INVISIBLE_BEFORE |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3754 || c == NFA_START_INVISIBLE_BEFORE_NEG) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3755 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3756 int directly; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3757 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3758 // Do it directly when what follows is possibly the end of the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3759 // match. |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3760 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
|
3761 directly = TRUE; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3762 else |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3763 { |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3764 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
|
3765 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
|
3766 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3767 // Postpone when the invisible match is expensive or has a |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3768 // lower chance of failing. |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3769 if (c == NFA_START_INVISIBLE_BEFORE |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3770 || c == NFA_START_INVISIBLE_BEFORE_NEG) |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3771 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3772 // "before" matches are very expensive when |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3773 // unbounded, always prefer what follows then, |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3774 // unless what follows will always match. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3775 // Otherwise strongly prefer what follows. |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3776 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
|
3777 directly = FALSE; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3778 else |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3779 directly = ch_follows * 10 < ch_invisible; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3780 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3781 else |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3782 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3783 // normal invisible, first do the one with the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3784 // highest failure chance |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3785 directly = ch_follows < ch_invisible; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3786 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3787 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3788 if (directly) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3789 // switch to the _FIRST state |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3790 ++prog->state[i].c; |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3791 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3792 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3793 } |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
3794 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3795 ///////////////////////////////////////////////////////////////// |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3796 // NFA execution code. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3797 ///////////////////////////////////////////////////////////////// |
4444 | 3798 |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3799 typedef struct |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3800 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3801 int in_use; // number of subexpr with useful info |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3802 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3803 // 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
|
3804 union |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3805 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3806 struct multipos |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3807 { |
6547 | 3808 linenr_T start_lnum; |
3809 linenr_T end_lnum; | |
3810 colnr_T start_col; | |
3811 colnr_T end_col; | |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3812 } multi[NSUBEXP]; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3813 struct linepos |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3814 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3815 char_u *start; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3816 char_u *end; |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3817 } line[NSUBEXP]; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
3818 } list; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3819 } regsub_T; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
3820 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3821 typedef struct |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3822 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3823 regsub_T norm; // \( .. \) matches |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3824 #ifdef FEAT_SYN_HL |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3825 regsub_T synt; // \z( .. \) matches |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3826 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3827 } regsubs_T; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3828 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3829 // nfa_pim_T stores a Postponed Invisible Match. |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3830 typedef struct nfa_pim_S nfa_pim_T; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3831 struct nfa_pim_S |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3832 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3833 int result; // NFA_PIM_*, see below |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3834 nfa_state_T *state; // the invisible match start state |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3835 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
|
3836 union |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3837 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3838 lpos_T pos; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3839 char_u *ptr; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3840 } end; // where the match must end |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3841 }; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
3842 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3843 // Values for done in nfa_pim_T. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3844 #define NFA_PIM_UNUSED 0 // pim not used |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3845 #define NFA_PIM_TODO 1 // pim not done yet |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3846 #define NFA_PIM_MATCH 2 // pim executed, matches |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3847 #define NFA_PIM_NOMATCH 3 // pim executed, no match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3848 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3849 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3850 // 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
|
3851 typedef struct |
4444 | 3852 { |
3853 nfa_state_T *state; | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3854 int count; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3855 nfa_pim_T pim; // if pim.result != NFA_PIM_UNUSED: postponed |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3856 // invisible match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3857 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
|
3858 } nfa_thread_T; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
3859 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3860 // nfa_list_T contains the alternative NFA execution states. |
4444 | 3861 typedef struct |
3862 { | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3863 nfa_thread_T *t; // allocated array of states |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3864 int n; // nr of states currently in "t" |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3865 int len; // max nr of states in "t" |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3866 int id; // ID of the list |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3867 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
|
3868 } nfa_list_T; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
3869 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3870 #ifdef ENABLE_LOG |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
3871 static void log_subexpr(regsub_T *sub); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3872 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3873 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3874 log_subsexpr(regsubs_T *subs) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3875 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3876 log_subexpr(&subs->norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3877 # ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
3878 if (rex.nfa_has_zsubexpr) |
4770
b20dbf3a5370
updated for version 7.3.1132
Bram Moolenaar <bram@vim.org>
parents:
4768
diff
changeset
|
3879 log_subexpr(&subs->synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3880 # endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3881 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3882 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3883 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3884 log_subexpr(regsub_T *sub) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3885 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3886 int j; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3887 |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3888 for (j = 0; j < sub->in_use; j++) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3889 if (REG_MULTI) |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3890 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
|
3891 j, |
6547 | 3892 sub->list.multi[j].start_col, |
3893 (int)sub->list.multi[j].start_lnum, | |
3894 sub->list.multi[j].end_col, | |
3895 (int)sub->list.multi[j].end_lnum); | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3896 else |
4746
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3897 { |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3898 char *s = (char *)sub->list.line[j].start; |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3899 char *e = (char *)sub->list.line[j].end; |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3900 |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
3901 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
|
3902 j, |
4746
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3903 s == NULL ? "NULL" : s, |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3904 e == NULL ? "NULL" : e); |
d1376091d18b
updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents:
4744
diff
changeset
|
3905 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3906 } |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3907 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3908 static char * |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3909 pim_info(nfa_pim_T *pim) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3910 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3911 static char buf[30]; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3912 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3913 if (pim == NULL || pim->result == NFA_PIM_UNUSED) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3914 buf[0] = NUL; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3915 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3916 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3917 sprintf(buf, " PIM col %d", REG_MULTI ? (int)pim->end.pos.col |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
3918 : (int)(pim->end.ptr - rex.input)); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3919 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3920 return buf; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3921 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3922 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3923 #endif |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
3924 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3925 // Used during execution: whether a match has been found. |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
3926 static int nfa_match; |
6573 | 3927 #ifdef FEAT_RELTIME |
3928 static proftime_T *nfa_time_limit; | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
3929 static int *nfa_timed_out; |
13192
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
3930 static int nfa_time_count; |
6573 | 3931 #endif |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
3932 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
3933 static void copy_sub(regsub_T *to, regsub_T *from); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
3934 static int pim_equal(nfa_pim_T *one, nfa_pim_T *two); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3935 |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3936 /* |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3937 * 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
|
3938 */ |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3939 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3940 copy_pim(nfa_pim_T *to, nfa_pim_T *from) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3941 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3942 to->result = from->result; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3943 to->state = from->state; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3944 copy_sub(&to->subs.norm, &from->subs.norm); |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3945 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
3946 if (rex.nfa_has_zsubexpr) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3947 copy_sub(&to->subs.synt, &from->subs.synt); |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3948 #endif |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3949 to->end = from->end; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3950 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
3951 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3952 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3953 clear_sub(regsub_T *sub) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3954 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3955 if (REG_MULTI) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3956 // Use 0xff to set lnum to -1 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3957 vim_memset(sub->list.multi, 0xff, |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
3958 sizeof(struct multipos) * rex.nfa_nsubexpr); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3959 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
3960 vim_memset(sub->list.line, 0, |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
3961 sizeof(struct linepos) * rex.nfa_nsubexpr); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3962 sub->in_use = 0; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3963 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3964 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3965 /* |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3966 * Copy the submatches from "from" to "to". |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3967 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3968 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3969 copy_sub(regsub_T *to, regsub_T *from) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3970 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3971 to->in_use = from->in_use; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3972 if (from->in_use > 0) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3973 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3974 // Copy the match start and end positions. |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3975 if (REG_MULTI) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3976 mch_memmove(&to->list.multi[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3977 &from->list.multi[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3978 sizeof(struct multipos) * from->in_use); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3979 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3980 mch_memmove(&to->list.line[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3981 &from->list.line[0], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3982 sizeof(struct linepos) * from->in_use); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3983 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3984 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3985 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3986 /* |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3987 * Like copy_sub() but exclude the main match. |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3988 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3989 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3990 copy_sub_off(regsub_T *to, regsub_T *from) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3991 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3992 if (to->in_use < from->in_use) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3993 to->in_use = from->in_use; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3994 if (from->in_use > 1) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3995 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3996 // Copy the match start and end positions. |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3997 if (REG_MULTI) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3998 mch_memmove(&to->list.multi[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
3999 &from->list.multi[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4000 sizeof(struct multipos) * (from->in_use - 1)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4001 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4002 mch_memmove(&to->list.line[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4003 &from->list.line[1], |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4004 sizeof(struct linepos) * (from->in_use - 1)); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4005 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4006 } |
4444 | 4007 |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4008 /* |
5372 | 4009 * Like copy_sub() but only do the end of the main match if \ze is present. |
4010 */ | |
4011 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4012 copy_ze_off(regsub_T *to, regsub_T *from) |
5372 | 4013 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4014 if (rex.nfa_has_zend) |
5372 | 4015 { |
4016 if (REG_MULTI) | |
4017 { | |
6547 | 4018 if (from->list.multi[0].end_lnum >= 0) |
13192
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
4019 { |
6547 | 4020 to->list.multi[0].end_lnum = from->list.multi[0].end_lnum; |
4021 to->list.multi[0].end_col = from->list.multi[0].end_col; | |
13192
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
4022 } |
5372 | 4023 } |
4024 else | |
4025 { | |
4026 if (from->list.line[0].end != NULL) | |
4027 to->list.line[0].end = from->list.line[0].end; | |
4028 } | |
4029 } | |
4030 } | |
4031 | |
4032 /* | |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4033 * Return TRUE if "sub1" and "sub2" have the same start positions. |
5893 | 4034 * 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
|
4035 */ |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4036 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4037 sub_equal(regsub_T *sub1, regsub_T *sub2) |
4647
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 int i; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4040 int todo; |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4041 linenr_T s1; |
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4042 linenr_T s2; |
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4043 char_u *sp1; |
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4044 char_u *sp2; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4045 |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4046 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
|
4047 if (REG_MULTI) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4048 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4049 for (i = 0; i < todo; ++i) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4050 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4051 if (i < sub1->in_use) |
6547 | 4052 s1 = sub1->list.multi[i].start_lnum; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4053 else |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
4054 s1 = -1; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4055 if (i < sub2->in_use) |
6547 | 4056 s2 = sub2->list.multi[i].start_lnum; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4057 else |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
4058 s2 = -1; |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4059 if (s1 != s2) |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4060 return FALSE; |
6547 | 4061 if (s1 != -1 && sub1->list.multi[i].start_col |
4062 != sub2->list.multi[i].start_col) | |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4063 return FALSE; |
5893 | 4064 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4065 if (rex.nfa_has_backref) |
5893 | 4066 { |
4067 if (i < sub1->in_use) | |
6547 | 4068 s1 = sub1->list.multi[i].end_lnum; |
5893 | 4069 else |
4070 s1 = -1; | |
4071 if (i < sub2->in_use) | |
6547 | 4072 s2 = sub2->list.multi[i].end_lnum; |
5893 | 4073 else |
4074 s2 = -1; | |
4075 if (s1 != s2) | |
4076 return FALSE; | |
6547 | 4077 if (s1 != -1 && sub1->list.multi[i].end_col |
4078 != sub2->list.multi[i].end_col) | |
5893 | 4079 return FALSE; |
4080 } | |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4081 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4082 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4083 else |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4084 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4085 for (i = 0; i < todo; ++i) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4086 { |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4087 if (i < sub1->in_use) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4088 sp1 = sub1->list.line[i].start; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4089 else |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4090 sp1 = NULL; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4091 if (i < sub2->in_use) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4092 sp2 = sub2->list.line[i].start; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4093 else |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4094 sp2 = NULL; |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4095 if (sp1 != sp2) |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4096 return FALSE; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4097 if (rex.nfa_has_backref) |
5893 | 4098 { |
4099 if (i < sub1->in_use) | |
4100 sp1 = sub1->list.line[i].end; | |
4101 else | |
4102 sp1 = NULL; | |
4103 if (i < sub2->in_use) | |
4104 sp2 = sub2->list.line[i].end; | |
4105 else | |
4106 sp2 = NULL; | |
4107 if (sp1 != sp2) | |
4108 return FALSE; | |
4109 } | |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4110 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4111 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4112 |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4113 return TRUE; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4114 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4115 |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4116 #ifdef ENABLE_LOG |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4117 static void |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4118 report_state(char *action, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4119 regsub_T *sub, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4120 nfa_state_T *state, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4121 int lid, |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4122 nfa_pim_T *pim) |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4123 { |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4124 int col; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4125 |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4126 if (sub->in_use <= 0) |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4127 col = -1; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4128 else if (REG_MULTI) |
6547 | 4129 col = sub->list.multi[0].start_col; |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4130 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4131 col = (int)(sub->list.line[0].start - rex.line); |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4132 nfa_set_code(state->c); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4133 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
|
4134 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
|
4135 pim_info(pim)); |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4136 } |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4137 #endif |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4138 |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4139 /* |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4140 * 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
|
4141 * positions as "subs". |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4142 */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4143 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4144 has_state_with_pos( |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4145 nfa_list_T *l, // runtime state list |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4146 nfa_state_T *state, // state to update |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4147 regsubs_T *subs, // pointers to subexpressions |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4148 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
|
4149 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4150 nfa_thread_T *thread; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4151 int i; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4152 |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4153 for (i = 0; i < l->n; ++i) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4154 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4155 thread = &l->t[i]; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4156 if (thread->state->id == state->id |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4157 && sub_equal(&thread->subs.norm, &subs->norm) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4158 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4159 && (!rex.nfa_has_zsubexpr |
4893
07b9c48a30e9
updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents:
4891
diff
changeset
|
4160 || sub_equal(&thread->subs.synt, &subs->synt)) |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4161 #endif |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4162 && pim_equal(&thread->pim, pim)) |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4163 return TRUE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4164 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4165 return FALSE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4166 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4167 |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4168 /* |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4169 * 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
|
4170 * set. |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4171 */ |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4172 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4173 pim_equal(nfa_pim_T *one, nfa_pim_T *two) |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4174 { |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4175 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
|
4176 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
|
4177 |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4178 if (one_unused) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4179 // one is unused: equal when two is also unused |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4180 return two_unused; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4181 if (two_unused) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4182 // one is used and two is not: not equal |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4183 return FALSE; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4184 // compare the state id |
5298 | 4185 if (one->state->id != two->state->id) |
4186 return FALSE; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4187 // compare the position |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4188 if (REG_MULTI) |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4189 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
|
4190 && one->end.pos.col == two->end.pos.col; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4191 return one->end.ptr == two->end.ptr; |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4192 } |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4193 |
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4194 /* |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4195 * 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
|
4196 */ |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4197 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4198 match_follows(nfa_state_T *startstate, int depth) |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4199 { |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4200 nfa_state_T *state = startstate; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4201 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4202 // avoid too much recursion |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4203 if (depth > 10) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4204 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4205 |
5184
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5074
diff
changeset
|
4206 while (state != NULL) |
4809
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 switch (state->c) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4209 { |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4210 case NFA_MATCH: |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4211 case NFA_MCLOSE: |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4212 case NFA_END_INVISIBLE: |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4213 case NFA_END_INVISIBLE_NEG: |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4214 case NFA_END_PATTERN: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4215 return TRUE; |
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 case NFA_SPLIT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4218 return match_follows(state->out, depth + 1) |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4219 || match_follows(state->out1, depth + 1); |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4220 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4221 case NFA_START_INVISIBLE: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4222 case NFA_START_INVISIBLE_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4223 case NFA_START_INVISIBLE_BEFORE: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4224 case NFA_START_INVISIBLE_BEFORE_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4225 case NFA_START_INVISIBLE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4226 case NFA_START_INVISIBLE_NEG_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4227 case NFA_START_INVISIBLE_BEFORE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
4228 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4229 case NFA_COMPOSING: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4230 // skip ahead to next state |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4231 state = state->out1->out; |
5184
c6dd0c545e5c
updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents:
5074
diff
changeset
|
4232 continue; |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4233 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4234 case NFA_ANY: |
5901 | 4235 case NFA_ANY_COMPOSING: |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4236 case NFA_IDENT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4237 case NFA_SIDENT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4238 case NFA_KWORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4239 case NFA_SKWORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4240 case NFA_FNAME: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4241 case NFA_SFNAME: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4242 case NFA_PRINT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4243 case NFA_SPRINT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4244 case NFA_WHITE: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4245 case NFA_NWHITE: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4246 case NFA_DIGIT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4247 case NFA_NDIGIT: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4248 case NFA_HEX: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4249 case NFA_NHEX: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4250 case NFA_OCTAL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4251 case NFA_NOCTAL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4252 case NFA_WORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4253 case NFA_NWORD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4254 case NFA_HEAD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4255 case NFA_NHEAD: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4256 case NFA_ALPHA: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4257 case NFA_NALPHA: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4258 case NFA_LOWER: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4259 case NFA_NLOWER: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4260 case NFA_UPPER: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4261 case NFA_NUPPER: |
5296 | 4262 case NFA_LOWER_IC: |
4263 case NFA_NLOWER_IC: | |
4264 case NFA_UPPER_IC: | |
4265 case NFA_NUPPER_IC: | |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4266 case NFA_START_COLL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4267 case NFA_START_NEG_COLL: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4268 case NFA_NEWL: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4269 // state will advance input |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4270 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4271 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4272 default: |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4273 if (state->c > 0) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4274 // state will advance input |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4275 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4276 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4277 // Others: zero-width or possibly zero-width, might still find |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4278 // a match at the same position, keep looking. |
4809
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4279 break; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4280 } |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4281 state = state->out; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4282 } |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4283 return FALSE; |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4284 } |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4285 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4286 |
4d7e3df04256
updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents:
4807
diff
changeset
|
4287 /* |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4288 * 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
|
4289 */ |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4290 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4291 state_in_list( |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4292 nfa_list_T *l, // runtime state list |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4293 nfa_state_T *state, // state to update |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4294 regsubs_T *subs) // pointers to subexpressions |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4295 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4296 if (state->lastlist[nfa_ll_index] == l->id) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4297 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4298 if (!rex.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
|
4299 return TRUE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4300 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4301 return FALSE; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4302 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
4303 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4304 // Offset used for "off" by addstate_here(). |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4305 #define ADDSTATE_HERE_OFFSET 10 |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4306 |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4307 /* |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4308 * 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
|
4309 * Returns "subs_arg", possibly copied into temp_subs. |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4310 * Returns NULL when recursiveness is too deep. |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4311 */ |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4312 static regsubs_T * |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4313 addstate( |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4314 nfa_list_T *l, // runtime state list |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4315 nfa_state_T *state, // state to update |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4316 regsubs_T *subs_arg, // pointers to subexpressions |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4317 nfa_pim_T *pim, // postponed look-behind match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4318 int off_arg) // byte offset, when -1 go to next line |
4444 | 4319 { |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4320 int subidx; |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4321 int off = off_arg; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4322 int add_here = FALSE; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4323 int listindex = 0; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4324 int k; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4325 int found = FALSE; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4326 nfa_thread_T *thread; |
10168
3c37899baa8d
commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4327 struct multipos save_multipos; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4328 int save_in_use; |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4329 char_u *save_ptr; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4330 int i; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4331 regsub_T *sub; |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4332 regsubs_T *subs = subs_arg; |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4333 static regsubs_T temp_subs; |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4334 #ifdef ENABLE_LOG |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4335 int did_print = FALSE; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4336 #endif |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4337 static int depth = 0; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4338 |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4339 // This function is called recursively. When the depth is too much we run |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4340 // out of stack and crash, limit recursiveness here. |
15800
483fda269100
patch 8.1.0907: CI tests on AppVeyor are failing
Bram Moolenaar <Bram@vim.org>
parents:
15796
diff
changeset
|
4341 if (++depth >= 5000 || subs == NULL) |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4342 { |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4343 --depth; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4344 return NULL; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4345 } |
4444 | 4346 |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4347 if (off_arg <= -ADDSTATE_HERE_OFFSET) |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4348 { |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4349 add_here = TRUE; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4350 off = 0; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4351 listindex = -(off_arg + ADDSTATE_HERE_OFFSET); |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4352 } |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4353 |
4444 | 4354 switch (state->c) |
4355 { | |
4356 case NFA_NCLOSE: | |
4357 case NFA_MCLOSE: | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4358 case NFA_MCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4359 case NFA_MCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4360 case NFA_MCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4361 case NFA_MCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4362 case NFA_MCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4363 case NFA_MCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4364 case NFA_MCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4365 case NFA_MCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4366 case NFA_MCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4367 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4368 case NFA_ZCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4369 case NFA_ZCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4370 case NFA_ZCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4371 case NFA_ZCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4372 case NFA_ZCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4373 case NFA_ZCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4374 case NFA_ZCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4375 case NFA_ZCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4376 case NFA_ZCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4377 case NFA_ZCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4378 #endif |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4379 case NFA_MOPEN: |
4748
4b9503f0c7d3
updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents:
4746
diff
changeset
|
4380 case NFA_ZEND: |
4815
6419ee8098c8
updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents:
4813
diff
changeset
|
4381 case NFA_SPLIT: |
5370 | 4382 case NFA_EMPTY: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4383 // These nodes are not added themselves but their "out" and/or |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4384 // "out1" may be added below. |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4385 break; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4386 |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4387 case NFA_BOL: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4388 case NFA_BOF: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4389 // "^" won't match past end-of-line, don't bother trying. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4390 // Except when at the end of the line, or when we are going to the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4391 // next line for a look-behind match. |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4392 if (rex.input > rex.line |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4393 && *rex.input != NUL |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4394 && (nfa_endp == NULL |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4395 || !REG_MULTI |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4396 || rex.lnum == nfa_endp->se_u.pos.lnum)) |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4397 goto skip_add; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4398 // FALLTHROUGH |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4399 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4400 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4401 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4402 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4403 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4404 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4405 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4406 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4407 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4408 case NFA_MOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4409 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4410 case NFA_ZOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4411 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4412 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4413 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4414 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4415 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4416 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4417 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4418 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4419 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4420 #endif |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
4421 case NFA_NOPEN: |
4748
4b9503f0c7d3
updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents:
4746
diff
changeset
|
4422 case NFA_ZSTART: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4423 // These nodes need to be added so that we can bail out when it |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4424 // was added to this list before at the same position to avoid an |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4425 // endless loop for "\(\)*" |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
4426 |
4444 | 4427 default: |
5502 | 4428 if (state->lastlist[nfa_ll_index] == l->id && state->c != NFA_SKIP) |
4444 | 4429 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4430 // This state is already in the list, don't add it again, |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4431 // unless it is an MOPEN that is used for a backreference or |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4432 // when there is a PIM. For NFA_MATCH check the position, |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4433 // lower position is preferred. |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4434 if (!rex.nfa_has_backref && pim == NULL && !l->has_pim |
5895 | 4435 && state->c != NFA_MATCH) |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4436 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4437 // When called from addstate_here() do insert before |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4438 // existing states. |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4439 if (add_here) |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4440 { |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4441 for (k = 0; k < l->n && k < listindex; ++k) |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4442 if (l->t[k].state->id == state->id) |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4443 { |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4444 found = TRUE; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4445 break; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4446 } |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4447 } |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4448 if (!add_here || found) |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4449 { |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4450 skip_add: |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4451 #ifdef ENABLE_LOG |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4452 nfa_set_code(state->c); |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4453 fprintf(log_fd, "> Not adding state %d to list %d. char %d: %s pim: %s has_pim: %d found: %d\n", |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4454 abs(state->id), l->id, state->c, code, |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4455 pim == NULL ? "NULL" : "yes", l->has_pim, found); |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4456 #endif |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4457 --depth; |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4458 return subs; |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4459 } |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4460 } |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4461 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4462 // Do not add the state again when it exists with the same |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4463 // positions. |
5212
2741b46e96bf
updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents:
5210
diff
changeset
|
4464 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
|
4465 goto skip_add; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4466 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4467 |
15812
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4468 // When there are backreferences or PIMs the number of states may |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4469 // be (a lot) bigger than anticipated. |
5006
f451d60ab8ec
updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents:
4997
diff
changeset
|
4470 if (l->n == l->len) |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4471 { |
15806
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4472 int newlen = l->len * 3 / 2 + 50; |
15812
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4473 size_t newsize = newlen * sizeof(nfa_thread_T); |
15806
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4474 nfa_thread_T *newt; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4475 |
15812
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4476 if ((long)(newsize >> 10) >= p_mmp) |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4477 { |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4478 emsg(_(e_maxmempat)); |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4479 --depth; |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4480 return NULL; |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4481 } |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4482 if (subs != &temp_subs) |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4483 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4484 // "subs" may point into the current array, need to make a |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4485 // copy before it becomes invalid. |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4486 copy_sub(&temp_subs.norm, &subs->norm); |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4487 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4488 if (rex.nfa_has_zsubexpr) |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4489 copy_sub(&temp_subs.synt, &subs->synt); |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4490 #endif |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4491 subs = &temp_subs; |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4492 } |
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4493 |
15812
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4494 newt = vim_realloc(l->t, newsize); |
15806
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4495 if (newt == NULL) |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4496 { |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4497 // out of memory |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4498 --depth; |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4499 return NULL; |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4500 } |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4501 l->t = newt; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4502 l->len = newlen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4503 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4504 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4505 // add the state to the list |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
4506 state->lastlist[nfa_ll_index] = l->id; |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4507 thread = &l->t[l->n++]; |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4508 thread->state = state; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4509 if (pim == NULL) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4510 thread->pim.result = NFA_PIM_UNUSED; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4511 else |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
4512 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4513 copy_pim(&thread->pim, pim); |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
4514 l->has_pim = TRUE; |
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
4515 } |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4516 copy_sub(&thread->subs.norm, &subs->norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4517 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4518 if (rex.nfa_has_zsubexpr) |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
4519 copy_sub(&thread->subs.synt, &subs->synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4520 #endif |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4521 #ifdef ENABLE_LOG |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4522 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
|
4523 did_print = TRUE; |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4524 #endif |
4444 | 4525 } |
4526 | |
4527 #ifdef ENABLE_LOG | |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
4528 if (!did_print) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
4529 report_state("Processing", &subs->norm, state, l->id, pim); |
4444 | 4530 #endif |
4531 switch (state->c) | |
4532 { | |
4533 case NFA_MATCH: | |
4534 break; | |
4535 | |
4536 case NFA_SPLIT: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4537 // order matters here |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4538 subs = addstate(l, state->out, subs, pim, off_arg); |
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4539 subs = addstate(l, state->out1, subs, pim, off_arg); |
4444 | 4540 break; |
4541 | |
5370 | 4542 case NFA_EMPTY: |
4444 | 4543 case NFA_NOPEN: |
4544 case NFA_NCLOSE: | |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4545 subs = addstate(l, state->out, subs, pim, off_arg); |
4444 | 4546 break; |
4547 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4548 case NFA_MOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4549 case NFA_MOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4550 case NFA_MOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4551 case NFA_MOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4552 case NFA_MOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4553 case NFA_MOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4554 case NFA_MOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4555 case NFA_MOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4556 case NFA_MOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4557 case NFA_MOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4558 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4559 case NFA_ZOPEN: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4560 case NFA_ZOPEN1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4561 case NFA_ZOPEN2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4562 case NFA_ZOPEN3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4563 case NFA_ZOPEN4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4564 case NFA_ZOPEN5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4565 case NFA_ZOPEN6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4566 case NFA_ZOPEN7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4567 case NFA_ZOPEN8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4568 case NFA_ZOPEN9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4569 #endif |
4444 | 4570 case NFA_ZSTART: |
4571 if (state->c == NFA_ZSTART) | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4572 { |
4444 | 4573 subidx = 0; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4574 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4575 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4576 #ifdef FEAT_SYN_HL |
5300 | 4577 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
|
4578 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4579 subidx = state->c - NFA_ZOPEN; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4580 sub = &subs->synt; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4581 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4582 #endif |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4583 else |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4584 { |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4585 subidx = state->c - NFA_MOPEN; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4586 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4587 } |
4444 | 4588 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4589 // avoid compiler warnings |
5210
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4590 save_ptr = NULL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
4591 CLEAR_FIELD(save_multipos); |
5210
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4592 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4593 // Set the position (with "off" added) in the subexpression. Save |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4594 // and restore it when it was in use. Otherwise fill any gap. |
4444 | 4595 if (REG_MULTI) |
4596 { | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4597 if (subidx < sub->in_use) |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4598 { |
10168
3c37899baa8d
commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4599 save_multipos = sub->list.multi[subidx]; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4600 save_in_use = -1; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4601 } |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4602 else |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4603 { |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4604 save_in_use = sub->in_use; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4605 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
|
4606 { |
6547 | 4607 sub->list.multi[i].start_lnum = -1; |
4608 sub->list.multi[i].end_lnum = -1; | |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4609 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4610 sub->in_use = subidx + 1; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4611 } |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4612 if (off == -1) |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4613 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4614 sub->list.multi[subidx].start_lnum = rex.lnum + 1; |
6547 | 4615 sub->list.multi[subidx].start_col = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4616 } |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4617 else |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4618 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4619 sub->list.multi[subidx].start_lnum = rex.lnum; |
6547 | 4620 sub->list.multi[subidx].start_col = |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4621 (colnr_T)(rex.input - rex.line + off); |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4622 } |
7152
cbdc02d71a18
commit https://github.com/vim/vim/commit/c2b717ebd6719e722dcb5f10e4c74033a53ff7c7
Christian Brabandt <cb@256bit.org>
parents:
6914
diff
changeset
|
4623 sub->list.multi[subidx].end_lnum = -1; |
4444 | 4624 } |
4625 else | |
4626 { | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4627 if (subidx < sub->in_use) |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4628 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4629 save_ptr = sub->list.line[subidx].start; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4630 save_in_use = -1; |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4631 } |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4632 else |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4633 { |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4634 save_in_use = sub->in_use; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4635 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
|
4636 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4637 sub->list.line[i].start = NULL; |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4638 sub->list.line[i].end = NULL; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4639 } |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4640 sub->in_use = subidx + 1; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4641 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4642 sub->list.line[subidx].start = rex.input + off; |
4444 | 4643 } |
4644 | |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4645 subs = addstate(l, state->out, subs, pim, off_arg); |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4646 if (subs == NULL) |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4647 break; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4648 // "subs" may have changed, need to set "sub" again |
5300 | 4649 #ifdef FEAT_SYN_HL |
4650 if (state->c >= NFA_ZOPEN && state->c <= NFA_ZOPEN9) | |
4651 sub = &subs->synt; | |
4652 else | |
4653 #endif | |
4654 sub = &subs->norm; | |
4444 | 4655 |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4656 if (save_in_use == -1) |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4657 { |
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4658 if (REG_MULTI) |
10168
3c37899baa8d
commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4659 sub->list.multi[subidx] = save_multipos; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4660 else |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4661 sub->list.line[subidx].start = save_ptr; |
4563
e7016af0cbf9
updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents:
4561
diff
changeset
|
4662 } |
4444 | 4663 else |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4664 sub->in_use = save_in_use; |
4444 | 4665 break; |
4666 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4667 case NFA_MCLOSE: |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4668 if (rex.nfa_has_zend && (REG_MULTI |
6547 | 4669 ? subs->norm.list.multi[0].end_lnum >= 0 |
5336 | 4670 : subs->norm.list.line[0].end != NULL)) |
4444 | 4671 { |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4672 // Do not overwrite the position set by \ze. |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4673 subs = addstate(l, state->out, subs, pim, off_arg); |
4444 | 4674 break; |
4675 } | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4676 // FALLTHROUGH |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4677 case NFA_MCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4678 case NFA_MCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4679 case NFA_MCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4680 case NFA_MCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4681 case NFA_MCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4682 case NFA_MCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4683 case NFA_MCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4684 case NFA_MCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4685 case NFA_MCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4686 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4687 case NFA_ZCLOSE: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4688 case NFA_ZCLOSE1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4689 case NFA_ZCLOSE2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4690 case NFA_ZCLOSE3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4691 case NFA_ZCLOSE4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4692 case NFA_ZCLOSE5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4693 case NFA_ZCLOSE6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4694 case NFA_ZCLOSE7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4695 case NFA_ZCLOSE8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4696 case NFA_ZCLOSE9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4697 #endif |
4444 | 4698 case NFA_ZEND: |
4699 if (state->c == NFA_ZEND) | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4700 { |
4444 | 4701 subidx = 0; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4702 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4703 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4704 #ifdef FEAT_SYN_HL |
5300 | 4705 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
|
4706 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4707 subidx = state->c - NFA_ZCLOSE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4708 sub = &subs->synt; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4709 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4710 #endif |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4711 else |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4712 { |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
4713 subidx = state->c - NFA_MCLOSE; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4714 sub = &subs->norm; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4715 } |
4444 | 4716 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4717 // We don't fill in gaps here, there must have been an MOPEN that |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4718 // has done that. |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4719 save_in_use = sub->in_use; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4720 if (sub->in_use <= subidx) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4721 sub->in_use = subidx + 1; |
4444 | 4722 if (REG_MULTI) |
4723 { | |
10168
3c37899baa8d
commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4724 save_multipos = sub->list.multi[subidx]; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4725 if (off == -1) |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4726 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4727 sub->list.multi[subidx].end_lnum = rex.lnum + 1; |
6547 | 4728 sub->list.multi[subidx].end_col = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4729 } |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4730 else |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4731 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4732 sub->list.multi[subidx].end_lnum = rex.lnum; |
6547 | 4733 sub->list.multi[subidx].end_col = |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4734 (colnr_T)(rex.input - rex.line + off); |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
4735 } |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4736 // avoid compiler warnings |
5210
839ebe7c1b2f
updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents:
5188
diff
changeset
|
4737 save_ptr = NULL; |
4444 | 4738 } |
4739 else | |
4740 { | |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4741 save_ptr = sub->list.line[subidx].end; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4742 sub->list.line[subidx].end = rex.input + off; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4743 // avoid compiler warnings |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19405
diff
changeset
|
4744 CLEAR_FIELD(save_multipos); |
4444 | 4745 } |
4746 | |
10170
4acacf4081ce
commit https://github.com/vim/vim/commit/16b3578f355282846f2600ce77fb344950f0b9ce
Christian Brabandt <cb@256bit.org>
parents:
10168
diff
changeset
|
4747 subs = addstate(l, state->out, subs, pim, off_arg); |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4748 if (subs == NULL) |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4749 break; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4750 // "subs" may have changed, need to set "sub" again |
5300 | 4751 #ifdef FEAT_SYN_HL |
4752 if (state->c >= NFA_ZCLOSE && state->c <= NFA_ZCLOSE9) | |
4753 sub = &subs->synt; | |
4754 else | |
4755 #endif | |
4756 sub = &subs->norm; | |
4444 | 4757 |
4758 if (REG_MULTI) | |
10168
3c37899baa8d
commit https://github.com/vim/vim/commit/d563883a1fb5ec6cf4a2758c5e36ac1ff4e9bb3d
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4759 sub->list.multi[subidx] = save_multipos; |
4444 | 4760 else |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
4761 sub->list.line[subidx].end = save_ptr; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4762 sub->in_use = save_in_use; |
4444 | 4763 break; |
4764 } | |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4765 --depth; |
5074
1cacf785299e
updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents:
5058
diff
changeset
|
4766 return subs; |
4444 | 4767 } |
4768 | |
4769 /* | |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4770 * 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
|
4771 * 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
|
4772 * 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
|
4773 * matters for alternatives. |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4774 */ |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4775 static regsubs_T * |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4776 addstate_here( |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4777 nfa_list_T *l, // runtime state list |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4778 nfa_state_T *state, // state to update |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4779 regsubs_T *subs, // pointers to subexpressions |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4780 nfa_pim_T *pim, // postponed look-behind match |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4781 int *ip) |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4782 { |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4783 int tlen = l->n; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4784 int count; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4785 int listidx = *ip; |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4786 regsubs_T *r; |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4787 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4788 // First add the state(s) at the end, so that we know how many there are. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4789 // Pass the listidx as offset (avoids adding another argument to |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4790 // addstate(). |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4791 r = addstate(l, state, subs, pim, -listidx - ADDSTATE_HERE_OFFSET); |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4792 if (r == NULL) |
15806
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4793 return NULL; |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4794 |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4795 // 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
|
4796 if (listidx + 1 == tlen) |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4797 return r; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4798 |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4799 // re-order to put the new state at the current position |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4800 count = l->n - tlen; |
4924
6ae32a64e153
updated for version 7.3.1207
Bram Moolenaar <bram@vim.org>
parents:
4897
diff
changeset
|
4801 if (count == 0) |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4802 return r; // no state got added |
4647
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4803 if (count == 1) |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4804 { |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4805 // overwrite the current state |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4806 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
|
4807 } |
857f6c53f117
updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents:
4615
diff
changeset
|
4808 else if (count > 1) |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4809 { |
5058
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4810 if (l->n + count - 1 >= l->len) |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4811 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4812 // not enough space to move the new states, reallocate the list |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4813 // and move the states to the right position |
15806
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4814 int newlen = l->len * 3 / 2 + 50; |
15812
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4815 size_t newsize = newlen * sizeof(nfa_thread_T); |
15806
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4816 nfa_thread_T *newl; |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4817 |
15812
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4818 if ((long)(newsize >> 10) >= p_mmp) |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4819 { |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4820 emsg(_(e_maxmempat)); |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4821 return NULL; |
3808b583889e
patch 8.1.0913: CI crashes when running out of memory
Bram Moolenaar <Bram@vim.org>
parents:
15806
diff
changeset
|
4822 } |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
4823 newl = alloc(newsize); |
5058
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4824 if (newl == NULL) |
15806
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4825 return NULL; |
6a4e9d9f1d66
patch 8.1.0910: crash with tricky search pattern
Bram Moolenaar <Bram@vim.org>
parents:
15802
diff
changeset
|
4826 l->len = newlen; |
5058
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4827 mch_memmove(&(newl[0]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4828 &(l->t[0]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4829 sizeof(nfa_thread_T) * listidx); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4830 mch_memmove(&(newl[listidx]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4831 &(l->t[l->n - count]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4832 sizeof(nfa_thread_T) * count); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4833 mch_memmove(&(newl[listidx + count]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4834 &(l->t[listidx + 1]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4835 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
|
4836 vim_free(l->t); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4837 l->t = newl; |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4838 } |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4839 else |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4840 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4841 // make space for new states, then move them from the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4842 // end to the current position |
5058
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4843 mch_memmove(&(l->t[listidx + count]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4844 &(l->t[listidx + 1]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4845 sizeof(nfa_thread_T) * (l->n - listidx - 1)); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4846 mch_memmove(&(l->t[listidx]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4847 &(l->t[l->n - 1]), |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4848 sizeof(nfa_thread_T) * count); |
a00cd1839ac4
updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents:
5029
diff
changeset
|
4849 } |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4850 } |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4851 --l->n; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
4852 *ip = listidx - 1; |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4853 |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
4854 return r; |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4855 } |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4856 |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
4857 /* |
4444 | 4858 * Check character class "class" against current character c. |
4859 */ | |
4860 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4861 check_char_class(int class, int c) |
4444 | 4862 { |
4863 switch (class) | |
4864 { | |
4865 case NFA_CLASS_ALNUM: | |
9015
42b228c8701b
commit https://github.com/vim/vim/commit/e8aee7dcf9b12becff86e8ce1783a86801c5f9f6
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4866 if (c >= 1 && c < 128 && isalnum(c)) |
4444 | 4867 return OK; |
4868 break; | |
4869 case NFA_CLASS_ALPHA: | |
9015
42b228c8701b
commit https://github.com/vim/vim/commit/e8aee7dcf9b12becff86e8ce1783a86801c5f9f6
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4870 if (c >= 1 && c < 128 && isalpha(c)) |
4444 | 4871 return OK; |
4872 break; | |
4873 case NFA_CLASS_BLANK: | |
4874 if (c == ' ' || c == '\t') | |
4875 return OK; | |
4876 break; | |
4877 case NFA_CLASS_CNTRL: | |
11267
588de97b40e7
patch 8.0.0519: character classes are not well tested
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4878 if (c >= 1 && c <= 127 && iscntrl(c)) |
4444 | 4879 return OK; |
4880 break; | |
4881 case NFA_CLASS_DIGIT: | |
4882 if (VIM_ISDIGIT(c)) | |
4883 return OK; | |
4884 break; | |
4885 case NFA_CLASS_GRAPH: | |
11267
588de97b40e7
patch 8.0.0519: character classes are not well tested
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4886 if (c >= 1 && c <= 127 && isgraph(c)) |
4444 | 4887 return OK; |
4888 break; | |
4889 case NFA_CLASS_LOWER: | |
9015
42b228c8701b
commit https://github.com/vim/vim/commit/e8aee7dcf9b12becff86e8ce1783a86801c5f9f6
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4890 if (MB_ISLOWER(c) && c != 170 && c != 186) |
4444 | 4891 return OK; |
4892 break; | |
4893 case NFA_CLASS_PRINT: | |
4894 if (vim_isprintc(c)) | |
4895 return OK; | |
4896 break; | |
4897 case NFA_CLASS_PUNCT: | |
9015
42b228c8701b
commit https://github.com/vim/vim/commit/e8aee7dcf9b12becff86e8ce1783a86801c5f9f6
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4898 if (c >= 1 && c < 128 && ispunct(c)) |
4444 | 4899 return OK; |
4900 break; | |
4901 case NFA_CLASS_SPACE: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
4902 if ((c >= 9 && c <= 13) || (c == ' ')) |
4444 | 4903 return OK; |
4904 break; | |
4905 case NFA_CLASS_UPPER: | |
4906 if (MB_ISUPPER(c)) | |
4907 return OK; | |
4908 break; | |
4909 case NFA_CLASS_XDIGIT: | |
4910 if (vim_isxdigit(c)) | |
4911 return OK; | |
4912 break; | |
4913 case NFA_CLASS_TAB: | |
4914 if (c == '\t') | |
4915 return OK; | |
4916 break; | |
4917 case NFA_CLASS_RETURN: | |
4918 if (c == '\r') | |
4919 return OK; | |
4920 break; | |
4921 case NFA_CLASS_BACKSPACE: | |
4922 if (c == '\b') | |
4923 return OK; | |
4924 break; | |
4925 case NFA_CLASS_ESCAPE: | |
4926 if (c == '\033') | |
4927 return OK; | |
4928 break; | |
15709
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4929 case NFA_CLASS_IDENT: |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4930 if (vim_isIDc(c)) |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4931 return OK; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4932 break; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4933 case NFA_CLASS_KEYWORD: |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4934 if (reg_iswordc(c)) |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4935 return OK; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4936 break; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4937 case NFA_CLASS_FNAME: |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4938 if (vim_isfilec(c)) |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4939 return OK; |
2e2f07561f4b
patch 8.1.0862: no verbose version of character classes
Bram Moolenaar <Bram@vim.org>
parents:
15603
diff
changeset
|
4940 break; |
4444 | 4941 |
4942 default: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4943 // should not be here :P |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
4944 siemsg(_(e_ill_char_class), class); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
4945 return FAIL; |
4444 | 4946 } |
4947 return FAIL; | |
4948 } | |
4949 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4950 /* |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4951 * Check for a match with subexpression "subidx". |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
4952 * Return TRUE if it matches. |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4953 */ |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4954 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4955 match_backref( |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4956 regsub_T *sub, // pointers to subexpressions |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4957 int subidx, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4958 int *bytelen) // out: length of match in bytes |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4959 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4960 int len; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4961 |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4962 if (sub->in_use <= subidx) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4963 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4964 retempty: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
4965 // backref was not set, match an empty string |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4966 *bytelen = 0; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4967 return TRUE; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4968 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4969 |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4970 if (REG_MULTI) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4971 { |
6547 | 4972 if (sub->list.multi[subidx].start_lnum < 0 |
4973 || sub->list.multi[subidx].end_lnum < 0) | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4974 goto retempty; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4975 if (sub->list.multi[subidx].start_lnum == rex.lnum |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4976 && sub->list.multi[subidx].end_lnum == rex.lnum) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4977 { |
6547 | 4978 len = sub->list.multi[subidx].end_col |
4979 - sub->list.multi[subidx].start_col; | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4980 if (cstrncmp(rex.line + sub->list.multi[subidx].start_col, |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
4981 rex.input, &len) == 0) |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4982 { |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4983 *bytelen = len; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4984 return TRUE; |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4985 } |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4986 } |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4987 else |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4988 { |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4989 if (match_with_backref( |
6547 | 4990 sub->list.multi[subidx].start_lnum, |
4991 sub->list.multi[subidx].start_col, | |
4992 sub->list.multi[subidx].end_lnum, | |
4993 sub->list.multi[subidx].end_col, | |
4891
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4994 bytelen) == RA_MATCH) |
4c42efb4c098
updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents:
4887
diff
changeset
|
4995 return TRUE; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4996 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4997 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4998 else |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
4999 { |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
5000 if (sub->list.line[subidx].start == NULL |
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
5001 || sub->list.line[subidx].end == NULL) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5002 goto retempty; |
4577
b22bff1a6af8
updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents:
4573
diff
changeset
|
5003 len = (int)(sub->list.line[subidx].end - sub->list.line[subidx].start); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5004 if (cstrncmp(sub->list.line[subidx].start, rex.input, &len) == 0) |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5005 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5006 *bytelen = len; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5007 return TRUE; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5008 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5009 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5010 return FALSE; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5011 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
5012 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5013 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5014 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5015 /* |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5016 * Check for a match with \z subexpression "subidx". |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5017 * Return TRUE if it matches. |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5018 */ |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5019 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5020 match_zref( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5021 int subidx, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5022 int *bytelen) // out: length of match in bytes |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5023 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5024 int len; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5025 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5026 cleanup_zsubexpr(); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5027 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
|
5028 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5029 // backref was not set, match an empty string |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5030 *bytelen = 0; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5031 return TRUE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5032 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5033 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5034 len = (int)STRLEN(re_extmatch_in->matches[subidx]); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5035 if (cstrncmp(re_extmatch_in->matches[subidx], rex.input, &len) == 0) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5036 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5037 *bytelen = len; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5038 return TRUE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5039 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5040 return FALSE; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5041 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5042 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5043 |
4444 | 5044 /* |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5045 * 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
|
5046 * Also reset the IDs to zero. |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5047 * Only used for the recursive value lastlist[1]. |
4444 | 5048 */ |
5049 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5050 nfa_save_listids(nfa_regprog_T *prog, int *list) |
4444 | 5051 { |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5052 int i; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5053 nfa_state_T *p; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5054 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5055 // Order in the list is reverse, it's a bit faster that way. |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5056 p = &prog->state[0]; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5057 for (i = prog->nstate; --i >= 0; ) |
4444 | 5058 { |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5059 list[i] = p->lastlist[1]; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5060 p->lastlist[1] = 0; |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5061 ++p; |
4444 | 5062 } |
5063 } | |
5064 | |
5065 /* | |
5066 * Restore list IDs from "list" to all NFA states. | |
5067 */ | |
5068 static void | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5069 nfa_restore_listids(nfa_regprog_T *prog, int *list) |
4444 | 5070 { |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5071 int i; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5072 nfa_state_T *p; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5073 |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5074 p = &prog->state[0]; |
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5075 for (i = prog->nstate; --i >= 0; ) |
4444 | 5076 { |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5077 p->lastlist[1] = list[i]; |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5078 ++p; |
4444 | 5079 } |
5080 } | |
5081 | |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
5082 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5083 nfa_re_num_cmp(long_u val, int op, long_u pos) |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
5084 { |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
5085 if (op == 1) return pos > val; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
5086 if (op == 2) return pos < val; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
5087 return val == pos; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
5088 } |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
5089 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7258
diff
changeset
|
5090 static int nfa_regmatch(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
|
5091 |
4444 | 5092 /* |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5093 * Recursively call nfa_regmatch() |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5094 * "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
|
5095 * position). |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5096 */ |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5097 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5098 recursive_regmatch( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5099 nfa_state_T *state, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5100 nfa_pim_T *pim, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5101 nfa_regprog_T *prog, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5102 regsubs_T *submatch, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5103 regsubs_T *m, |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
5104 int **listids, |
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
5105 int *listids_len) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5106 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5107 int save_reginput_col = (int)(rex.input - rex.line); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5108 int save_reglnum = rex.lnum; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5109 int save_nfa_match = nfa_match; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5110 int save_nfa_listid = rex.nfa_listid; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5111 save_se_T *save_nfa_endp = nfa_endp; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5112 save_se_T endpos; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5113 save_se_T *endposp = NULL; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5114 int result; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5115 int need_restore = FALSE; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5116 |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5117 if (pim != NULL) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5118 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5119 // start at the position where the postponed match was |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5120 if (REG_MULTI) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5121 rex.input = rex.line + pim->end.pos.col; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5122 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5123 rex.input = pim->end.ptr; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5124 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5125 |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5126 if (state->c == NFA_START_INVISIBLE_BEFORE |
13192
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
5127 || state->c == NFA_START_INVISIBLE_BEFORE_FIRST |
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
5128 || state->c == NFA_START_INVISIBLE_BEFORE_NEG |
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
5129 || 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
|
5130 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5131 // The recursive match must end at the current position. When "pim" is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5132 // not NULL it specifies the current position. |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5133 endposp = &endpos; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5134 if (REG_MULTI) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5135 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5136 if (pim == NULL) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5137 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5138 endpos.se_u.pos.col = (int)(rex.input - rex.line); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5139 endpos.se_u.pos.lnum = rex.lnum; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5140 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5141 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5142 endpos.se_u.pos = pim->end.pos; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5143 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5144 else |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5145 { |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5146 if (pim == NULL) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5147 endpos.se_u.ptr = rex.input; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5148 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5149 endpos.se_u.ptr = pim->end.ptr; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5150 } |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5151 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5152 // Go back the specified number of bytes, or as far as the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5153 // start of the previous line, to try matching "\@<=" or |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5154 // not matching "\@<!". This is very inefficient, limit the number of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5155 // bytes if possible. |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5156 if (state->val <= 0) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5157 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5158 if (REG_MULTI) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5159 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5160 rex.line = reg_getline(--rex.lnum); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5161 if (rex.line == NULL) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5162 // can't go before the first line |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5163 rex.line = reg_getline(++rex.lnum); |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5164 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5165 rex.input = rex.line; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5166 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5167 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5168 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5169 if (REG_MULTI && (int)(rex.input - rex.line) < state->val) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5170 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5171 // Not enough bytes in this line, go to end of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5172 // previous line. |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5173 rex.line = reg_getline(--rex.lnum); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5174 if (rex.line == NULL) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5175 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5176 // can't go before the first line |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5177 rex.line = reg_getline(++rex.lnum); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5178 rex.input = rex.line; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5179 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5180 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5181 rex.input = rex.line + STRLEN(rex.line); |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5182 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5183 if ((int)(rex.input - rex.line) >= state->val) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5184 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5185 rex.input -= state->val; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5186 if (has_mbyte) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5187 rex.input -= mb_head_off(rex.line, rex.input); |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5188 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5189 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5190 rex.input = rex.line; |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5191 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5192 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5193 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5194 #ifdef ENABLE_LOG |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5195 if (log_fd != stderr) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5196 fclose(log_fd); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5197 log_fd = NULL; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5198 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5199 // Have to clear the lastlist field of the NFA nodes, so that |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5200 // nfa_regmatch() and addstate() can run properly after recursion. |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5201 if (nfa_ll_index == 1) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5202 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5203 // Already calling nfa_regmatch() recursively. Save the lastlist[1] |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5204 // values and clear them. |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5205 if (*listids == NULL || *listids_len < prog->nstate) |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5206 { |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
5207 vim_free(*listids); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5208 *listids = ALLOC_MULT(int, prog->nstate); |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5209 if (*listids == NULL) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5210 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
5211 emsg(_("E878: (NFA) Could not allocate memory for branch traversal!")); |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5212 return 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5213 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5214 *listids_len = prog->nstate; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5215 } |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5216 nfa_save_listids(prog, *listids); |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5217 need_restore = TRUE; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5218 // any value of rex.nfa_listid will do |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5219 } |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5220 else |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5221 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5222 // First recursive nfa_regmatch() call, switch to the second lastlist |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5223 // entry. Make sure rex.nfa_listid is different from a previous |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5224 // recursive call, because some states may still have this ID. |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5225 ++nfa_ll_index; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5226 if (rex.nfa_listid <= rex.nfa_alt_listid) |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5227 rex.nfa_listid = rex.nfa_alt_listid; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5228 } |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5229 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5230 // Call nfa_regmatch() to check if the current concat matches at this |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5231 // 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
|
5232 nfa_endp = endposp; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5233 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
|
5234 |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5235 if (need_restore) |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5236 nfa_restore_listids(prog, *listids); |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5237 else |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5238 { |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5239 --nfa_ll_index; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5240 rex.nfa_alt_listid = rex.nfa_listid; |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
5241 } |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5242 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5243 // restore position in input text |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5244 rex.lnum = save_reglnum; |
4877
9e36c6b1ebf4
updated for version 7.3.1184
Bram Moolenaar <bram@vim.org>
parents:
4845
diff
changeset
|
5245 if (REG_MULTI) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5246 rex.line = reg_getline(rex.lnum); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5247 rex.input = rex.line + save_reginput_col; |
9371
3666915cac0b
commit https://github.com/vim/vim/commit/6747fabc7348bf5f41ccfe851e2be3e900ec8ee0
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
5248 if (result != NFA_TOO_EXPENSIVE) |
3666915cac0b
commit https://github.com/vim/vim/commit/6747fabc7348bf5f41ccfe851e2be3e900ec8ee0
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
5249 { |
3666915cac0b
commit https://github.com/vim/vim/commit/6747fabc7348bf5f41ccfe851e2be3e900ec8ee0
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
5250 nfa_match = save_nfa_match; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5251 rex.nfa_listid = save_nfa_listid; |
9371
3666915cac0b
commit https://github.com/vim/vim/commit/6747fabc7348bf5f41ccfe851e2be3e900ec8ee0
Christian Brabandt <cb@256bit.org>
parents:
9015
diff
changeset
|
5252 } |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5253 nfa_endp = save_nfa_endp; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5254 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5255 #ifdef ENABLE_LOG |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5256 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5257 if (log_fd != NULL) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5258 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5259 fprintf(log_fd, "****************************\n"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5260 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
|
5261 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
|
5262 fprintf(log_fd, "****************************\n"); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5263 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5264 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5265 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
5266 emsg(_(e_log_open_failed)); |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5267 log_fd = stderr; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5268 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5269 #endif |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5270 |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5271 return result; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5272 } |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5273 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5274 /* |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5275 * 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
|
5276 * empty match: 0 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5277 * NFA_ANY: 1 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5278 * specific character: 99 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5279 */ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5280 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5281 failure_chance(nfa_state_T *state, int depth) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5282 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5283 int c = state->c; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5284 int l, r; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5285 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5286 // detect looping |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5287 if (depth > 4) |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5288 return 1; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5289 |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5290 switch (c) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5291 { |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5292 case NFA_SPLIT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5293 if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5294 // avoid recursive stuff |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5295 return 1; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5296 // two alternatives, use the lowest failure chance |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5297 l = failure_chance(state->out, depth + 1); |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5298 r = failure_chance(state->out1, depth + 1); |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5299 return l < r ? l : r; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5300 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5301 case NFA_ANY: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5302 // matches anything, unlikely to fail |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5303 return 1; |
4821
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5304 |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5305 case NFA_MATCH: |
4821
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5306 case NFA_MCLOSE: |
5901 | 5307 case NFA_ANY_COMPOSING: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5308 // empty match works always |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5309 return 0; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5310 |
4897
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5311 case NFA_START_INVISIBLE: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5312 case NFA_START_INVISIBLE_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5313 case NFA_START_INVISIBLE_NEG: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5314 case NFA_START_INVISIBLE_NEG_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5315 case NFA_START_INVISIBLE_BEFORE: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5316 case NFA_START_INVISIBLE_BEFORE_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5317 case NFA_START_INVISIBLE_BEFORE_NEG: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5318 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5319 case NFA_START_PATTERN: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5320 // recursive regmatch is expensive, use low failure chance |
4897
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5321 return 5; |
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5322 |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5323 case NFA_BOL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5324 case NFA_EOL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5325 case NFA_BOF: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5326 case NFA_EOF: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5327 case NFA_NEWL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5328 return 99; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5329 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5330 case NFA_BOW: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5331 case NFA_EOW: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5332 return 90; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5333 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5334 case NFA_MOPEN: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5335 case NFA_MOPEN1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5336 case NFA_MOPEN2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5337 case NFA_MOPEN3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5338 case NFA_MOPEN4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5339 case NFA_MOPEN5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5340 case NFA_MOPEN6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5341 case NFA_MOPEN7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5342 case NFA_MOPEN8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5343 case NFA_MOPEN9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5344 #ifdef FEAT_SYN_HL |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5345 case NFA_ZOPEN: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5346 case NFA_ZOPEN1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5347 case NFA_ZOPEN2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5348 case NFA_ZOPEN3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5349 case NFA_ZOPEN4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5350 case NFA_ZOPEN5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5351 case NFA_ZOPEN6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5352 case NFA_ZOPEN7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5353 case NFA_ZOPEN8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5354 case NFA_ZOPEN9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5355 case NFA_ZCLOSE: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5356 case NFA_ZCLOSE1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5357 case NFA_ZCLOSE2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5358 case NFA_ZCLOSE3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5359 case NFA_ZCLOSE4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5360 case NFA_ZCLOSE5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5361 case NFA_ZCLOSE6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5362 case NFA_ZCLOSE7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5363 case NFA_ZCLOSE8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5364 case NFA_ZCLOSE9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5365 #endif |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5366 case NFA_NOPEN: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5367 case NFA_MCLOSE1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5368 case NFA_MCLOSE2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5369 case NFA_MCLOSE3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5370 case NFA_MCLOSE4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5371 case NFA_MCLOSE5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5372 case NFA_MCLOSE6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5373 case NFA_MCLOSE7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5374 case NFA_MCLOSE8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5375 case NFA_MCLOSE9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5376 case NFA_NCLOSE: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5377 return failure_chance(state->out, depth + 1); |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5378 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5379 case NFA_BACKREF1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5380 case NFA_BACKREF2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5381 case NFA_BACKREF3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5382 case NFA_BACKREF4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5383 case NFA_BACKREF5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5384 case NFA_BACKREF6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5385 case NFA_BACKREF7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5386 case NFA_BACKREF8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5387 case NFA_BACKREF9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5388 #ifdef FEAT_SYN_HL |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5389 case NFA_ZREF1: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5390 case NFA_ZREF2: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5391 case NFA_ZREF3: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5392 case NFA_ZREF4: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5393 case NFA_ZREF5: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5394 case NFA_ZREF6: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5395 case NFA_ZREF7: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5396 case NFA_ZREF8: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5397 case NFA_ZREF9: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5398 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5399 // backreferences don't match in many places |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5400 return 94; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5401 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5402 case NFA_LNUM_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5403 case NFA_LNUM_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5404 case NFA_COL_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5405 case NFA_COL_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5406 case NFA_VCOL_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5407 case NFA_VCOL_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5408 case NFA_MARK_GT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5409 case NFA_MARK_LT: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5410 case NFA_VISUAL: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5411 // before/after positions don't match very often |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5412 return 85; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5413 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5414 case NFA_LNUM: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5415 return 90; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5416 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5417 case NFA_CURSOR: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5418 case NFA_COL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5419 case NFA_VCOL: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5420 case NFA_MARK: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5421 // specific positions rarely match |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5422 return 98; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5423 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5424 case NFA_COMPOSING: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5425 return 95; |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5426 |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5427 default: |
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5428 if (c > 0) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5429 // character match fails often |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5430 return 95; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5431 } |
4742
6a706ca7a889
updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents:
4740
diff
changeset
|
5432 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5433 // something else, includes character classes |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5434 return 50; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5435 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5436 |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5437 /* |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5438 * 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
|
5439 */ |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5440 static int |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5441 skip_to_start(int c, colnr_T *colp) |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5442 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5443 char_u *s; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5444 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5445 // Used often, do some work to avoid call overhead. |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
5446 if (!rex.reg_ic && !has_mbyte) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5447 s = vim_strbyte(rex.line + *colp, c); |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5448 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5449 s = cstrchr(rex.line + *colp, c); |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5450 if (s == NULL) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5451 return FAIL; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5452 *colp = (int)(s - rex.line); |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5453 return OK; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5454 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5455 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
5456 /* |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5457 * Check for a match with match_text. |
4807
3dbd251777de
updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
5458 * 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
|
5459 * 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
|
5460 */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5461 static long |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5462 find_match_text(colnr_T startcol, int regstart, char_u *match_text) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5463 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5464 colnr_T col = startcol; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5465 int c1, c2; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5466 int len1, len2; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5467 int match; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5468 |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5469 for (;;) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5470 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5471 match = TRUE; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5472 len2 = MB_CHAR2LEN(regstart); // skip regstart |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5473 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
|
5474 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5475 c1 = PTR2CHAR(match_text + len1); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5476 c2 = PTR2CHAR(rex.line + col + len2); |
20772
097f5b5c907b
patch 8.2.0938: NFA regexp uses tolower ()to compare ignore-case
Bram Moolenaar <Bram@vim.org>
parents:
20677
diff
changeset
|
5477 if (c1 != c2 && (!rex.reg_ic || MB_CASEFOLD(c1) != MB_CASEFOLD(c2))) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5478 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5479 match = FALSE; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5480 break; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5481 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5482 len2 += MB_CHAR2LEN(c2); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5483 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5484 if (match |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5485 // check that no composing char follows |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5486 && !(enc_utf8 |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
5487 && utf_iscomposing(PTR2CHAR(rex.line + col + len2)))) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5488 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5489 cleanup_subexpr(); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5490 if (REG_MULTI) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5491 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5492 rex.reg_startpos[0].lnum = rex.lnum; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
5493 rex.reg_startpos[0].col = col; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5494 rex.reg_endpos[0].lnum = rex.lnum; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
5495 rex.reg_endpos[0].col = col + len2; |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5496 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5497 else |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5498 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5499 rex.reg_startp[0] = rex.line + col; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5500 rex.reg_endp[0] = rex.line + col + len2; |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5501 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5502 return 1L; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5503 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5504 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5505 // Try finding regstart after the current match. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5506 col += MB_CHAR2LEN(regstart); // skip regstart |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5507 if (skip_to_start(regstart, &col) == FAIL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5508 break; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5509 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5510 return 0L; |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5511 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5512 |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5513 #ifdef FEAT_RELTIME |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5514 static int |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5515 nfa_did_time_out() |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5516 { |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5517 if (nfa_time_limit != NULL && profile_passed_limit(nfa_time_limit)) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5518 { |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5519 if (nfa_timed_out != NULL) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5520 *nfa_timed_out = TRUE; |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5521 return TRUE; |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5522 } |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5523 return FALSE; |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5524 } |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5525 #endif |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5526 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
5527 /* |
4444 | 5528 * Main matching routine. |
5529 * | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5530 * Run NFA to determine whether it matches rex.input. |
4444 | 5531 * |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
5532 * 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
|
5533 * |
16491
38a323a6fd18
patch 8.1.1249: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5534 * Return TRUE if there is a match, FALSE if there is no match, |
38a323a6fd18
patch 8.1.1249: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5535 * NFA_TOO_EXPENSIVE if we end up with too many states. |
5372 | 5536 * When there is a match "submatch" contains the positions. |
16491
38a323a6fd18
patch 8.1.1249: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5537 * |
4444 | 5538 * Note: Caller must ensure that: start != NULL. |
5539 */ | |
5540 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5541 nfa_regmatch( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5542 nfa_regprog_T *prog, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5543 nfa_state_T *start, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5544 regsubs_T *submatch, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5545 regsubs_T *m) |
4444 | 5546 { |
16491
38a323a6fd18
patch 8.1.1249: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5547 int result = FALSE; |
6545 | 5548 size_t size = 0; |
4444 | 5549 int flag = 0; |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5550 int go_to_nextline = FALSE; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5551 nfa_thread_T *t; |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5552 nfa_list_T list[2]; |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5553 int listidx; |
4539
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5554 nfa_list_T *thislist; |
532c2e850256
updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents:
4537
diff
changeset
|
5555 nfa_list_T *nextlist; |
4444 | 5556 int *listids = NULL; |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
5557 int listids_len = 0; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5558 nfa_state_T *add_state; |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5559 int add_here; |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5560 int add_count; |
4819
8c4324e6f477
updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents:
4815
diff
changeset
|
5561 int add_off = 0; |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5562 int toplevel = start->c == NFA_MOPEN; |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5563 regsubs_T *r; |
4460 | 5564 #ifdef NFA_REGEXP_DEBUG_LOG |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5565 FILE *debug; |
4444 | 5566 #endif |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5567 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5568 // Some patterns may take a long time to match, especially when using |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5569 // recursive_regmatch(). Allow interrupting them with CTRL-C. |
5310 | 5570 fast_breakcheck(); |
5571 if (got_int) | |
5572 return FALSE; | |
6573 | 5573 #ifdef FEAT_RELTIME |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5574 if (nfa_did_time_out()) |
6573 | 5575 return FALSE; |
5576 #endif | |
5310 | 5577 |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5578 #ifdef NFA_REGEXP_DEBUG_LOG |
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5579 debug = fopen(NFA_REGEXP_DEBUG_LOG, "a"); |
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5580 if (debug == NULL) |
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5581 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
5582 semsg("(NFA) COULD NOT OPEN %s!", NFA_REGEXP_DEBUG_LOG); |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5583 return FALSE; |
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5584 } |
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8841
diff
changeset
|
5585 #endif |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
5586 nfa_match = FALSE; |
4444 | 5587 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5588 // Allocate memory for the lists of nodes. |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5589 size = (prog->nstate + 1) * sizeof(nfa_thread_T); |
6547 | 5590 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5591 list[0].t = alloc(size); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5592 list[0].len = prog->nstate + 1; |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
5593 list[1].t = alloc(size); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5594 list[1].len = prog->nstate + 1; |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5595 if (list[0].t == NULL || list[1].t == NULL) |
4444 | 5596 goto theend; |
5597 | |
5598 #ifdef ENABLE_LOG | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
5599 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a"); |
4444 | 5600 if (log_fd != NULL) |
5601 { | |
5602 fprintf(log_fd, "**********************************\n"); | |
5603 nfa_set_code(start->c); | |
5604 fprintf(log_fd, " RUNNING nfa_regmatch() starting with state %d, code %s\n", | |
5605 abs(start->id), code); | |
5606 fprintf(log_fd, "**********************************\n"); | |
5607 } | |
5608 else | |
5609 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
5610 emsg(_(e_log_open_failed)); |
4444 | 5611 log_fd = stderr; |
5612 } | |
5613 #endif | |
5614 | |
5615 thislist = &list[0]; | |
5616 thislist->n = 0; | |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
5617 thislist->has_pim = FALSE; |
4444 | 5618 nextlist = &list[1]; |
5619 nextlist->n = 0; | |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
5620 nextlist->has_pim = FALSE; |
4444 | 5621 #ifdef ENABLE_LOG |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5622 fprintf(log_fd, "(---) STARTSTATE first\n"); |
4444 | 5623 #endif |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5624 thislist->id = rex.nfa_listid + 1; |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5625 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5626 // Inline optimized code for addstate(thislist, start, m, 0) if we know |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5627 // it's the first MOPEN. |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5628 if (toplevel) |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5629 { |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5630 if (REG_MULTI) |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5631 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5632 m->norm.list.multi[0].start_lnum = rex.lnum; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5633 m->norm.list.multi[0].start_col = (colnr_T)(rex.input - rex.line); |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5634 } |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5635 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5636 m->norm.list.line[0].start = rex.input; |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5637 m->norm.in_use = 1; |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5638 r = addstate(thislist, start->out, m, NULL, 0); |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5639 } |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
5640 else |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5641 r = addstate(thislist, start, m, NULL, 0); |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5642 if (r == NULL) |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5643 { |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5644 nfa_match = NFA_TOO_EXPENSIVE; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5645 goto theend; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5646 } |
4444 | 5647 |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5648 #define ADD_STATE_IF_MATCH(state) \ |
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5649 if (result) { \ |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5650 add_state = state->out; \ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5651 add_off = clen; \ |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5652 } |
4444 | 5653 |
5654 /* | |
5655 * Run for each character. | |
5656 */ | |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5657 for (;;) |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5658 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5659 int curc; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5660 int clen; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5661 |
4444 | 5662 if (has_mbyte) |
5663 { | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5664 curc = (*mb_ptr2char)(rex.input); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5665 clen = (*mb_ptr2len)(rex.input); |
4444 | 5666 } |
5667 else | |
5668 { | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5669 curc = *rex.input; |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5670 clen = 1; |
4444 | 5671 } |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5672 if (curc == NUL) |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5673 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5674 clen = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5675 go_to_nextline = FALSE; |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5676 } |
4444 | 5677 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5678 // swap lists |
4444 | 5679 thislist = &list[flag]; |
5680 nextlist = &list[flag ^= 1]; | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5681 nextlist->n = 0; // clear nextlist |
5227
a08fa2919f2b
updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents:
5221
diff
changeset
|
5682 nextlist->has_pim = FALSE; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5683 ++rex.nfa_listid; |
14161
7cac4646c552
patch 8.1.0098: segfault when pattern with z() is very slow
Christian Brabandt <cb@256bit.org>
parents:
14159
diff
changeset
|
5684 if (prog->re_engine == AUTOMATIC_ENGINE |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5685 && (rex.nfa_listid >= NFA_MAX_STATES |
14173
4b59671bce9c
patch 8.1.0104: can't build without the +eval feature
Christian Brabandt <cb@256bit.org>
parents:
14163
diff
changeset
|
5686 # ifdef FEAT_EVAL |
4b59671bce9c
patch 8.1.0104: can't build without the +eval feature
Christian Brabandt <cb@256bit.org>
parents:
14163
diff
changeset
|
5687 || nfa_fail_for_testing |
4b59671bce9c
patch 8.1.0104: can't build without the +eval feature
Christian Brabandt <cb@256bit.org>
parents:
14163
diff
changeset
|
5688 # endif |
4b59671bce9c
patch 8.1.0104: can't build without the +eval feature
Christian Brabandt <cb@256bit.org>
parents:
14163
diff
changeset
|
5689 )) |
6328 | 5690 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5691 // too many states, retry with old engine |
6328 | 5692 nfa_match = NFA_TOO_EXPENSIVE; |
5693 goto theend; | |
5694 } | |
5695 | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5696 thislist->id = rex.nfa_listid; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5697 nextlist->id = rex.nfa_listid + 1; |
4444 | 5698 |
5699 #ifdef ENABLE_LOG | |
5700 fprintf(log_fd, "------------------------------------------\n"); | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5701 fprintf(log_fd, ">>> Reginput is \"%s\"\n", rex.input); |
14145
1cf832945469
patch 8.1.0090: "..." used inconsistently in a message
Christian Brabandt <cb@256bit.org>
parents:
14121
diff
changeset
|
5702 fprintf(log_fd, ">>> Advanced one character... Current char is %c (code %d) \n", curc, (int)curc); |
4444 | 5703 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
|
5704 { |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5705 int i; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5706 |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5707 for (i = 0; i < thislist->n; i++) |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
5708 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
|
5709 } |
4444 | 5710 fprintf(log_fd, "\n"); |
5711 #endif | |
5712 | |
4460 | 5713 #ifdef NFA_REGEXP_DEBUG_LOG |
4444 | 5714 fprintf(debug, "\n-------------------\n"); |
5715 #endif | |
4480 | 5716 /* |
5717 * If the state lists are empty we can stop. | |
5718 */ | |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5719 if (thislist->n == 0) |
4480 | 5720 break; |
4444 | 5721 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5722 // compute nextlist |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5723 for (listidx = 0; listidx < thislist->n; ++listidx) |
4444 | 5724 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5725 // If the list gets very long there probably is something wrong. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5726 // At least allow interrupting with CTRL-C. |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5727 fast_breakcheck(); |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5728 if (got_int) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5729 break; |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5730 #ifdef FEAT_RELTIME |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5731 if (nfa_time_limit != NULL && ++nfa_time_count == 20) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5732 { |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5733 nfa_time_count = 0; |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5734 if (nfa_did_time_out()) |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5735 break; |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5736 } |
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
5737 #endif |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5738 t = &thislist->t[listidx]; |
4444 | 5739 |
4460 | 5740 #ifdef NFA_REGEXP_DEBUG_LOG |
4444 | 5741 nfa_set_code(t->state->c); |
5742 fprintf(debug, "%s, ", code); | |
5743 #endif | |
5744 #ifdef ENABLE_LOG | |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5745 { |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5746 int col; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5747 |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
5748 if (t->subs.norm.in_use <= 0) |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5749 col = -1; |
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5750 else if (REG_MULTI) |
6547 | 5751 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
|
5752 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5753 col = (int)(t->subs.norm.list.line[0].start - rex.line); |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5754 nfa_set_code(t->state->c); |
14145
1cf832945469
patch 8.1.0090: "..." used inconsistently in a message
Christian Brabandt <cb@256bit.org>
parents:
14121
diff
changeset
|
5755 fprintf(log_fd, "(%d) char %d %s (start col %d)%s... \n", |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5756 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
|
5757 pim_info(&t->pim)); |
4657
93b7ed814bec
updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents:
4655
diff
changeset
|
5758 } |
4444 | 5759 #endif |
5760 | |
5761 /* | |
5762 * Handle the possible codes of the current state. | |
5763 * The most important is NFA_MATCH. | |
5764 */ | |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5765 add_state = NULL; |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5766 add_here = FALSE; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5767 add_count = 0; |
4444 | 5768 switch (t->state->c) |
5769 { | |
5770 case NFA_MATCH: | |
4567
96c1a7850097
updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents:
4565
diff
changeset
|
5771 { |
23262
dca9e6b931d3
patch 8.2.2177: pattern "^" does not match if first character is combining
Bram Moolenaar <Bram@vim.org>
parents:
23251
diff
changeset
|
5772 // If the match is not at the start of the line, ends before a |
dca9e6b931d3
patch 8.2.2177: pattern "^" does not match if first character is combining
Bram Moolenaar <Bram@vim.org>
parents:
23251
diff
changeset
|
5773 // composing characters and rex.reg_icombine is not set, that |
dca9e6b931d3
patch 8.2.2177: pattern "^" does not match if first character is combining
Bram Moolenaar <Bram@vim.org>
parents:
23251
diff
changeset
|
5774 // is not really a match. |
dca9e6b931d3
patch 8.2.2177: pattern "^" does not match if first character is combining
Bram Moolenaar <Bram@vim.org>
parents:
23251
diff
changeset
|
5775 if (enc_utf8 && !rex.reg_icombine |
dca9e6b931d3
patch 8.2.2177: pattern "^" does not match if first character is combining
Bram Moolenaar <Bram@vim.org>
parents:
23251
diff
changeset
|
5776 && rex.input != rex.line && utf_iscomposing(curc)) |
5901 | 5777 break; |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
5778 |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
5779 nfa_match = TRUE; |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5780 copy_sub(&submatch->norm, &t->subs.norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5781 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5782 if (rex.nfa_has_zsubexpr) |
4712
832bf8136d86
updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents:
4696
diff
changeset
|
5783 copy_sub(&submatch->synt, &t->subs.synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5784 #endif |
4444 | 5785 #ifdef ENABLE_LOG |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5786 log_subsexpr(&t->subs); |
4444 | 5787 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5788 // Found the left-most longest match, do not look at any other |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5789 // states at this position. When the list of states is going |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5790 // to be empty quit without advancing, so that "rex.input" is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5791 // correct. |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
5792 if (nextlist->n == 0) |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
5793 clen = 0; |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
5794 goto nextchar; |
4567
96c1a7850097
updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents:
4565
diff
changeset
|
5795 } |
4444 | 5796 |
5797 case NFA_END_INVISIBLE: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5798 case NFA_END_INVISIBLE_NEG: |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5799 case NFA_END_PATTERN: |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5800 /* |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5801 * 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
|
5802 * NFA_START_INVISIBLE_BEFORE node. |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5803 * They surround a zero-width group, used with "\@=", "\&", |
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5804 * "\@!", "\@<=" and "\@<!". |
4444 | 5805 * If we got here, it means that the current "invisible" group |
5806 * 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
|
5807 * 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
|
5808 * in the position in "nfa_endp". |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5809 * 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
|
5810 */ |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5811 #ifdef ENABLE_LOG |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5812 if (nfa_endp != NULL) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5813 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5814 if (REG_MULTI) |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5815 fprintf(log_fd, "Current lnum: %d, endp lnum: %d; current col: %d, endp col: %d\n", |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5816 (int)rex.lnum, |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5817 (int)nfa_endp->se_u.pos.lnum, |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5818 (int)(rex.input - rex.line), |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5819 nfa_endp->se_u.pos.col); |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5820 else |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5821 fprintf(log_fd, "Current col: %d, endp col: %d\n", |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5822 (int)(rex.input - rex.line), |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5823 (int)(nfa_endp->se_u.ptr - rex.input)); |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5824 } |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5825 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5826 // If "nfa_endp" is set it's only a match if it ends at |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5827 // "nfa_endp" |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5828 if (nfa_endp != NULL && (REG_MULTI |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5829 ? (rex.lnum != nfa_endp->se_u.pos.lnum |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5830 || (int)(rex.input - rex.line) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5831 != nfa_endp->se_u.pos.col) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5832 : rex.input != nfa_endp->se_u.ptr)) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5833 break; |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5834 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5835 // do not set submatches for \@! |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5836 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
|
5837 { |
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5838 copy_sub(&m->norm, &t->subs.norm); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5839 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5840 if (rex.nfa_has_zsubexpr) |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5841 copy_sub(&m->synt, &t->subs.synt); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
5842 #endif |
4444 | 5843 } |
4750
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, "Match found:\n"); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5846 log_subsexpr(m); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5847 #endif |
4716
a804309e7327
updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents:
4714
diff
changeset
|
5848 nfa_match = TRUE; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5849 // See comment above at "goto nextchar". |
5334 | 5850 if (nextlist->n == 0) |
5851 clen = 0; | |
5852 goto nextchar; | |
4444 | 5853 |
5854 case NFA_START_INVISIBLE: | |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5855 case NFA_START_INVISIBLE_FIRST: |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5856 case NFA_START_INVISIBLE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5857 case NFA_START_INVISIBLE_NEG_FIRST: |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
5858 case NFA_START_INVISIBLE_BEFORE: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5859 case NFA_START_INVISIBLE_BEFORE_FIRST: |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5860 case NFA_START_INVISIBLE_BEFORE_NEG: |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5861 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST: |
4444 | 5862 { |
4821
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5863 #ifdef ENABLE_LOG |
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5864 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
|
5865 failure_chance(t->state->out, 0), |
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5866 failure_chance(t->state->out1->out, 0)); |
2f1ee97f5f23
updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents:
4819
diff
changeset
|
5867 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5868 // Do it directly if there already is a PIM or when |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5869 // nfa_postprocess() detected it will work better. |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5870 if (t->pim.result != NFA_PIM_UNUSED |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5871 || t->state->c == NFA_START_INVISIBLE_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5872 || t->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5873 || t->state->c == NFA_START_INVISIBLE_BEFORE_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5874 || 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
|
5875 { |
5029
c9e2ccc53f2e
updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents:
5006
diff
changeset
|
5876 int in_use = m->norm.in_use; |
c9e2ccc53f2e
updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents:
5006
diff
changeset
|
5877 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5878 // Copy submatch info for the recursive call, opposite |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5879 // of what happens on success below. |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
5880 copy_sub_off(&m->norm, &t->subs.norm); |
5370 | 5881 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5882 if (rex.nfa_has_zsubexpr) |
5370 | 5883 copy_sub_off(&m->synt, &t->subs.synt); |
5884 #endif | |
4997
8a7d3a73adab
updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents:
4958
diff
changeset
|
5885 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5886 /* |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5887 * First try matching the invisible match, then what |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5888 * follows. |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5889 */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5890 result = recursive_regmatch(t->state, NULL, prog, |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
5891 submatch, m, &listids, &listids_len); |
6328 | 5892 if (result == NFA_TOO_EXPENSIVE) |
5893 { | |
5894 nfa_match = result; | |
5895 goto theend; | |
5896 } | |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5897 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5898 // for \@! and \@<! it is a match when the result is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5899 // FALSE |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
5900 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
|
5901 || t->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5902 || t->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5903 == NFA_START_INVISIBLE_BEFORE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5904 || t->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
5905 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5906 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5907 // Copy submatch info from the recursive call |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5908 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
|
5909 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5910 if (rex.nfa_has_zsubexpr) |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
5911 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
|
5912 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5913 // If the pattern has \ze and it matched in the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5914 // sub pattern, use it. |
5372 | 5915 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
|
5916 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5917 // t->state->out1 is the corresponding |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5918 // END_INVISIBLE node; Add its out to the current |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5919 // list (zero-width match). |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5920 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
5921 add_state = t->state->out1->out; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5922 } |
5029
c9e2ccc53f2e
updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents:
5006
diff
changeset
|
5923 m->norm.in_use = in_use; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5924 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5925 else |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5926 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5927 nfa_pim_T pim; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5928 |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5929 /* |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5930 * 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
|
5931 * 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
|
5932 * 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
|
5933 * about the invisible match. |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5934 */ |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5935 pim.state = t->state; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5936 pim.result = NFA_PIM_TODO; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5937 pim.subs.norm.in_use = 0; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5938 #ifdef FEAT_SYN_HL |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5939 pim.subs.synt.in_use = 0; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5940 #endif |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5941 if (REG_MULTI) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5942 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5943 pim.end.pos.col = (int)(rex.input - rex.line); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5944 pim.end.pos.lnum = rex.lnum; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5945 } |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
5946 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
5947 pim.end.ptr = rex.input; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5948 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5949 // t->state->out1 is the corresponding END_INVISIBLE |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5950 // node; Add its out to the current list (zero-width |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5951 // match). |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5952 if (addstate_here(thislist, t->state->out1->out, |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5953 &t->subs, &pim, &listidx) == NULL) |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5954 { |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5955 nfa_match = NFA_TOO_EXPENSIVE; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5956 goto theend; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
5957 } |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
5958 } |
4444 | 5959 } |
5960 break; | |
5961 | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
5962 case NFA_START_PATTERN: |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5963 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5964 nfa_state_T *skip = NULL; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5965 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5966 int skip_lid = 0; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5967 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5968 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5969 // There is no point in trying to match the pattern if the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
5970 // output state is not going to be added to the list. |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5971 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
|
5972 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5973 skip = t->state->out1->out; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5974 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5975 skip_lid = nextlist->id; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5976 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5977 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5978 else if (state_in_list(nextlist, |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5979 t->state->out1->out->out, &t->subs)) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5980 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5981 skip = t->state->out1->out->out; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5982 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5983 skip_lid = nextlist->id; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5984 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5985 } |
4897
91136a41f83f
updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents:
4893
diff
changeset
|
5986 else if (state_in_list(thislist, |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5987 t->state->out1->out->out, &t->subs)) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5988 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5989 skip = t->state->out1->out->out; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5990 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5991 skip_lid = thislist->id; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5992 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5993 } |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5994 if (skip != NULL) |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5995 { |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5996 #ifdef ENABLE_LOG |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5997 nfa_set_code(skip->c); |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
5998 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
|
5999 abs(skip->id), skip_lid, skip->c, code); |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
6000 #endif |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
6001 break; |
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
6002 } |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6003 // Copy submatch info to the recursive call, opposite of what |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6004 // happens afterwards. |
5370 | 6005 copy_sub_off(&m->norm, &t->subs.norm); |
6006 #ifdef FEAT_SYN_HL | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6007 if (rex.nfa_has_zsubexpr) |
5370 | 6008 copy_sub_off(&m->synt, &t->subs.synt); |
6009 #endif | |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
6010 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6011 // First try matching the pattern. |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6012 result = recursive_regmatch(t->state, NULL, prog, |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
6013 submatch, m, &listids, &listids_len); |
6328 | 6014 if (result == NFA_TOO_EXPENSIVE) |
6015 { | |
6016 nfa_match = result; | |
6017 goto theend; | |
6018 } | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6019 if (result) |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6020 { |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6021 int bytelen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6022 |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6023 #ifdef ENABLE_LOG |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6024 fprintf(log_fd, "NFA_START_PATTERN matches:\n"); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6025 log_subsexpr(m); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6026 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6027 // Copy submatch info from the recursive call |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6028 copy_sub_off(&t->subs.norm, &m->norm); |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6029 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6030 if (rex.nfa_has_zsubexpr) |
4768
82e6588762e4
updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents:
4762
diff
changeset
|
6031 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
|
6032 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6033 // Now we need to skip over the matched text and then |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6034 // continue with what follows. |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6035 if (REG_MULTI) |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6036 // TODO: multi-line match |
6547 | 6037 bytelen = m->norm.list.multi[0].end_col |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6038 - (int)(rex.input - rex.line); |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6039 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6040 bytelen = (int)(m->norm.list.line[0].end - rex.input); |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6041 |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6042 #ifdef ENABLE_LOG |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6043 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
|
6044 #endif |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6045 if (bytelen == 0) |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6046 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6047 // empty match, output of corresponding |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6048 // NFA_END_PATTERN/NFA_SKIP to be used at current |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6049 // position |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6050 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6051 add_state = t->state->out1->out->out; |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6052 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6053 else if (bytelen <= clen) |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6054 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6055 // match current character, output of corresponding |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6056 // NFA_END_PATTERN to be used at next position. |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6057 add_state = t->state->out1->out->out; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6058 add_off = clen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6059 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6060 else |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6061 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6062 // skip over the matched characters, set character |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6063 // count in NFA_SKIP |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6064 add_state = t->state->out1->out; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6065 add_off = bytelen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6066 add_count = bytelen - clen; |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6067 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6068 } |
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6069 break; |
4787
7fde662e1db2
updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents:
4785
diff
changeset
|
6070 } |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
6071 |
4444 | 6072 case NFA_BOL: |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6073 if (rex.input == rex.line) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6074 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6075 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6076 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6077 } |
4444 | 6078 break; |
6079 | |
6080 case NFA_EOL: | |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6081 if (curc == NUL) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6082 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6083 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6084 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6085 } |
4444 | 6086 break; |
6087 | |
6088 case NFA_BOW: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6089 result = TRUE; |
4444 | 6090 |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6091 if (curc == NUL) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6092 result = FALSE; |
4444 | 6093 else if (has_mbyte) |
6094 { | |
6095 int this_class; | |
6096 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6097 // Get class of current and previous char (if it exists). |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6098 this_class = mb_get_class_buf(rex.input, rex.reg_buf); |
4444 | 6099 if (this_class <= 1) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6100 result = FALSE; |
4444 | 6101 else if (reg_prev_class() == this_class) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6102 result = FALSE; |
4444 | 6103 } |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6104 else if (!vim_iswordc_buf(curc, rex.reg_buf) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6105 || (rex.input > rex.line |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6106 && vim_iswordc_buf(rex.input[-1], rex.reg_buf))) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6107 result = FALSE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6108 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6109 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6110 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6111 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6112 } |
4444 | 6113 break; |
6114 | |
6115 case NFA_EOW: | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6116 result = TRUE; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6117 if (rex.input == rex.line) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6118 result = FALSE; |
4444 | 6119 else if (has_mbyte) |
6120 { | |
6121 int this_class, prev_class; | |
6122 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6123 // Get class of current and previous char (if it exists). |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6124 this_class = mb_get_class_buf(rex.input, rex.reg_buf); |
4444 | 6125 prev_class = reg_prev_class(); |
6126 if (this_class == prev_class | |
6127 || prev_class == 0 || prev_class == 1) | |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6128 result = FALSE; |
4444 | 6129 } |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6130 else if (!vim_iswordc_buf(rex.input[-1], rex.reg_buf) |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6131 || (rex.input[0] != NUL |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6132 && vim_iswordc_buf(curc, rex.reg_buf))) |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6133 result = FALSE; |
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6134 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6135 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6136 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6137 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6138 } |
4444 | 6139 break; |
6140 | |
4671
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
6141 case NFA_BOF: |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6142 if (rex.lnum == 0 && rex.input == rex.line |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6143 && (!REG_MULTI || rex.reg_firstlnum == 1)) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6144 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6145 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6146 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6147 } |
4671
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
6148 break; |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
6149 |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
6150 case NFA_EOF: |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6151 if (rex.lnum == rex.reg_maxline && curc == NUL) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6152 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6153 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6154 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6155 } |
4671
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
6156 break; |
b3c59716e700
updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents:
4669
diff
changeset
|
6157 |
4444 | 6158 case NFA_COMPOSING: |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6159 { |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6160 int mc = curc; |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
6161 int len = 0; |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
6162 nfa_state_T *end; |
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
6163 nfa_state_T *sta; |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6164 int cchars[MAX_MCO]; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6165 int ccount = 0; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6166 int j; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6167 |
4444 | 6168 sta = t->state->out; |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6169 len = 0; |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
6170 if (utf_iscomposing(sta->c)) |
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
6171 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6172 // Only match composing character(s), ignore base |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6173 // character. Used for ".{composing}" and "{composing}" |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6174 // (no preceding character). |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6175 len += mb_char2len(mc); |
4535
45f97c349537
updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents:
4533
diff
changeset
|
6176 } |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6177 if (rex.reg_icombine && len == 0) |
4444 | 6178 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6179 // If \Z was present, then ignore composing characters. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6180 // When ignoring the base character this always matches. |
13208
e96663c35bab
patch 8.0.1478: unnecessary condition
Christian Brabandt <cb@256bit.org>
parents:
13192
diff
changeset
|
6181 if (sta->c != curc) |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6182 result = FAIL; |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6183 else |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6184 result = OK; |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6185 while (sta->c != NFA_END_COMPOSING) |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6186 sta = sta->out; |
4444 | 6187 } |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6188 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6189 // Check base character matches first, unless ignored. |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6190 else if (len > 0 || mc == sta->c) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6191 { |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6192 if (len == 0) |
4529
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6193 { |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6194 len += mb_char2len(mc); |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6195 sta = sta->out; |
432a6b8c7d93
updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents:
4527
diff
changeset
|
6196 } |
4444 | 6197 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6198 // We don't care about the order of composing characters. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6199 // Get them into cchars[] first. |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6200 while (len < clen) |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6201 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6202 mc = mb_ptr2char(rex.input + len); |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6203 cchars[ccount++] = mc; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6204 len += mb_char2len(mc); |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6205 if (ccount == MAX_MCO) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6206 break; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6207 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6208 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6209 // Check that each composing char in the pattern matches a |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6210 // composing char in the text. We do not check if all |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6211 // composing chars are matched. |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6212 result = OK; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6213 while (sta->c != NFA_END_COMPOSING) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6214 { |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6215 for (j = 0; j < ccount; ++j) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6216 if (cchars[j] == sta->c) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6217 break; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6218 if (j == ccount) |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6219 { |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6220 result = FAIL; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6221 break; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6222 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6223 sta = sta->out; |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6224 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6225 } |
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6226 else |
4525
36ddcf4cecbc
updated for version 7.3.1010
Bram Moolenaar <bram@vim.org>
parents:
4517
diff
changeset
|
6227 result = FAIL; |
4547
fc997f05cbc7
updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents:
4543
diff
changeset
|
6228 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6229 end = t->state->out1; // NFA_END_COMPOSING |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6230 ADD_STATE_IF_MATCH(end); |
4444 | 6231 break; |
4527
55bcaa1d2749
updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents:
4525
diff
changeset
|
6232 } |
4444 | 6233 |
6234 case NFA_NEWL: | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6235 if (curc == NUL && !rex.reg_line_lbr && REG_MULTI |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6236 && rex.lnum <= rex.reg_maxline) |
4444 | 6237 { |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6238 go_to_nextline = TRUE; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6239 // Pass -1 for the offset, which means taking the position |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6240 // at the start of the next line. |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6241 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6242 add_off = -1; |
4444 | 6243 } |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6244 else if (curc == '\n' && rex.reg_line_lbr) |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6245 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6246 // 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
|
6247 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6248 add_off = 1; |
4555
b2946c06d1b6
updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents:
4553
diff
changeset
|
6249 } |
4444 | 6250 break; |
6251 | |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6252 case NFA_START_COLL: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6253 case NFA_START_NEG_COLL: |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6254 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6255 // What follows is a list of characters, until NFA_END_COLL. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6256 // One of them must match or none of them must match. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6257 nfa_state_T *state; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6258 int result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6259 int c1, c2; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6260 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6261 // Never match EOL. If it's part of the collection it is added |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6262 // as a separate state with an OR. |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6263 if (curc == NUL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6264 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6265 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6266 state = t->state->out; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6267 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
|
6268 for (;;) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6269 { |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6270 if (state->c == NFA_END_COLL) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6271 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6272 result = !result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6273 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6274 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6275 if (state->c == NFA_RANGE_MIN) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6276 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6277 c1 = state->val; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6278 state = state->out; // advance to NFA_RANGE_MAX |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6279 c2 = state->val; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6280 #ifdef ENABLE_LOG |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6281 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
|
6282 curc, c1, c2); |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6283 #endif |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6284 if (curc >= c1 && curc <= c2) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6285 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6286 result = result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6287 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6288 } |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6289 if (rex.reg_ic) |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6290 { |
20772
097f5b5c907b
patch 8.2.0938: NFA regexp uses tolower ()to compare ignore-case
Bram Moolenaar <Bram@vim.org>
parents:
20677
diff
changeset
|
6291 int curc_low = MB_CASEFOLD(curc); |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6292 int done = FALSE; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6293 |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6294 for ( ; c1 <= c2; ++c1) |
20772
097f5b5c907b
patch 8.2.0938: NFA regexp uses tolower ()to compare ignore-case
Bram Moolenaar <Bram@vim.org>
parents:
20677
diff
changeset
|
6295 if (MB_CASEFOLD(c1) == curc_low) |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6296 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6297 result = result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6298 done = TRUE; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6299 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6300 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6301 if (done) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6302 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6303 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6304 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6305 else if (state->c < 0 ? check_char_class(state->c, curc) |
13192
9bd4151e5aeb
patch 8.0.1470: integer overflow when using regexp pattern
Christian Brabandt <cb@256bit.org>
parents:
13043
diff
changeset
|
6306 : (curc == state->c |
20772
097f5b5c907b
patch 8.2.0938: NFA regexp uses tolower ()to compare ignore-case
Bram Moolenaar <Bram@vim.org>
parents:
20677
diff
changeset
|
6307 || (rex.reg_ic && MB_CASEFOLD(curc) |
097f5b5c907b
patch 8.2.0938: NFA regexp uses tolower ()to compare ignore-case
Bram Moolenaar <Bram@vim.org>
parents:
20677
diff
changeset
|
6308 == MB_CASEFOLD(state->c)))) |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6309 { |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6310 result = result_if_matched; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6311 break; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6312 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6313 state = state->out; |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6314 } |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6315 if (result) |
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6316 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6317 // next state is in out of the NFA_END_COLL, out1 of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6318 // START points to the END state |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6319 add_state = t->state->out1->out; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6320 add_off = clen; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6321 } |
4444 | 6322 break; |
4781
c02c7df9bdc9
updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents:
4772
diff
changeset
|
6323 } |
4444 | 6324 |
6325 case NFA_ANY: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6326 // 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
|
6327 if (curc > 0) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6328 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6329 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6330 add_off = clen; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6331 } |
4444 | 6332 break; |
6333 | |
5901 | 6334 case NFA_ANY_COMPOSING: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6335 // On a composing character skip over it. Otherwise do |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6336 // nothing. Always matches. |
5901 | 6337 if (enc_utf8 && utf_iscomposing(curc)) |
6338 { | |
6339 add_off = clen; | |
6340 } | |
6341 else | |
6342 { | |
6343 add_here = TRUE; | |
6344 add_off = 0; | |
6345 } | |
6346 add_state = t->state->out; | |
6347 break; | |
6348 | |
4444 | 6349 /* |
6350 * Character classes like \a for alpha, \d for digit etc. | |
6351 */ | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6352 case NFA_IDENT: // \i |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6353 result = vim_isIDc(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6354 ADD_STATE_IF_MATCH(t->state); |
4444 | 6355 break; |
6356 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6357 case NFA_SIDENT: // \I |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6358 result = !VIM_ISDIGIT(curc) && vim_isIDc(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6359 ADD_STATE_IF_MATCH(t->state); |
4444 | 6360 break; |
6361 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6362 case NFA_KWORD: // \k |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6363 result = vim_iswordp_buf(rex.input, rex.reg_buf); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6364 ADD_STATE_IF_MATCH(t->state); |
4444 | 6365 break; |
6366 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6367 case NFA_SKWORD: // \K |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6368 result = !VIM_ISDIGIT(curc) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6369 && vim_iswordp_buf(rex.input, rex.reg_buf); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6370 ADD_STATE_IF_MATCH(t->state); |
4444 | 6371 break; |
6372 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6373 case NFA_FNAME: // \f |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6374 result = vim_isfilec(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6375 ADD_STATE_IF_MATCH(t->state); |
4444 | 6376 break; |
6377 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6378 case NFA_SFNAME: // \F |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6379 result = !VIM_ISDIGIT(curc) && vim_isfilec(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6380 ADD_STATE_IF_MATCH(t->state); |
4444 | 6381 break; |
6382 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6383 case NFA_PRINT: // \p |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6384 result = vim_isprintc(PTR2CHAR(rex.input)); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6385 ADD_STATE_IF_MATCH(t->state); |
4444 | 6386 break; |
6387 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6388 case NFA_SPRINT: // \P |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6389 result = !VIM_ISDIGIT(curc) && vim_isprintc(PTR2CHAR(rex.input)); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6390 ADD_STATE_IF_MATCH(t->state); |
4444 | 6391 break; |
6392 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6393 case NFA_WHITE: // \s |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6394 result = VIM_ISWHITE(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6395 ADD_STATE_IF_MATCH(t->state); |
4444 | 6396 break; |
6397 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6398 case NFA_NWHITE: // \S |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6399 result = curc != NUL && !VIM_ISWHITE(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6400 ADD_STATE_IF_MATCH(t->state); |
4444 | 6401 break; |
6402 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6403 case NFA_DIGIT: // \d |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6404 result = ri_digit(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6405 ADD_STATE_IF_MATCH(t->state); |
4444 | 6406 break; |
6407 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6408 case NFA_NDIGIT: // \D |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6409 result = curc != NUL && !ri_digit(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6410 ADD_STATE_IF_MATCH(t->state); |
4444 | 6411 break; |
6412 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6413 case NFA_HEX: // \x |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6414 result = ri_hex(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6415 ADD_STATE_IF_MATCH(t->state); |
4444 | 6416 break; |
6417 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6418 case NFA_NHEX: // \X |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6419 result = curc != NUL && !ri_hex(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6420 ADD_STATE_IF_MATCH(t->state); |
4444 | 6421 break; |
6422 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6423 case NFA_OCTAL: // \o |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6424 result = ri_octal(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6425 ADD_STATE_IF_MATCH(t->state); |
4444 | 6426 break; |
6427 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6428 case NFA_NOCTAL: // \O |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6429 result = curc != NUL && !ri_octal(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6430 ADD_STATE_IF_MATCH(t->state); |
4444 | 6431 break; |
6432 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6433 case NFA_WORD: // \w |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6434 result = ri_word(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6435 ADD_STATE_IF_MATCH(t->state); |
4444 | 6436 break; |
6437 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6438 case NFA_NWORD: // \W |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6439 result = curc != NUL && !ri_word(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6440 ADD_STATE_IF_MATCH(t->state); |
4444 | 6441 break; |
6442 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6443 case NFA_HEAD: // \h |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6444 result = ri_head(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6445 ADD_STATE_IF_MATCH(t->state); |
4444 | 6446 break; |
6447 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6448 case NFA_NHEAD: // \H |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6449 result = curc != NUL && !ri_head(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6450 ADD_STATE_IF_MATCH(t->state); |
4444 | 6451 break; |
6452 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6453 case NFA_ALPHA: // \a |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6454 result = ri_alpha(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6455 ADD_STATE_IF_MATCH(t->state); |
4444 | 6456 break; |
6457 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6458 case NFA_NALPHA: // \A |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6459 result = curc != NUL && !ri_alpha(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6460 ADD_STATE_IF_MATCH(t->state); |
4444 | 6461 break; |
6462 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6463 case NFA_LOWER: // \l |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6464 result = ri_lower(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6465 ADD_STATE_IF_MATCH(t->state); |
4444 | 6466 break; |
6467 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6468 case NFA_NLOWER: // \L |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6469 result = curc != NUL && !ri_lower(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6470 ADD_STATE_IF_MATCH(t->state); |
4444 | 6471 break; |
6472 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6473 case NFA_UPPER: // \u |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6474 result = ri_upper(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6475 ADD_STATE_IF_MATCH(t->state); |
4444 | 6476 break; |
6477 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6478 case NFA_NUPPER: // \U |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6479 result = curc != NUL && !ri_upper(curc); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6480 ADD_STATE_IF_MATCH(t->state); |
4444 | 6481 break; |
6482 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6483 case NFA_LOWER_IC: // [a-z] |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6484 result = ri_lower(curc) || (rex.reg_ic && ri_upper(curc)); |
5296 | 6485 ADD_STATE_IF_MATCH(t->state); |
6486 break; | |
6487 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6488 case NFA_NLOWER_IC: // [^a-z] |
5296 | 6489 result = curc != NUL |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6490 && !(ri_lower(curc) || (rex.reg_ic && ri_upper(curc))); |
5296 | 6491 ADD_STATE_IF_MATCH(t->state); |
6492 break; | |
6493 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6494 case NFA_UPPER_IC: // [A-Z] |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6495 result = ri_upper(curc) || (rex.reg_ic && ri_lower(curc)); |
5296 | 6496 ADD_STATE_IF_MATCH(t->state); |
6497 break; | |
6498 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6499 case NFA_NUPPER_IC: // ^[A-Z] |
5296 | 6500 result = curc != NUL |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6501 && !(ri_upper(curc) || (rex.reg_ic && ri_lower(curc))); |
5296 | 6502 ADD_STATE_IF_MATCH(t->state); |
6503 break; | |
6504 | |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6505 case NFA_BACKREF1: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6506 case NFA_BACKREF2: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6507 case NFA_BACKREF3: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6508 case NFA_BACKREF4: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6509 case NFA_BACKREF5: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6510 case NFA_BACKREF6: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6511 case NFA_BACKREF7: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6512 case NFA_BACKREF8: |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6513 case NFA_BACKREF9: |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6514 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6515 case NFA_ZREF1: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6516 case NFA_ZREF2: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6517 case NFA_ZREF3: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6518 case NFA_ZREF4: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6519 case NFA_ZREF5: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6520 case NFA_ZREF6: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6521 case NFA_ZREF7: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6522 case NFA_ZREF8: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6523 case NFA_ZREF9: |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6524 #endif |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6525 // \1 .. \9 \z1 .. \z9 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6526 { |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6527 int subidx; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6528 int bytelen; |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6529 |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6530 if (t->state->c <= NFA_BACKREF9) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6531 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6532 subidx = t->state->c - NFA_BACKREF1 + 1; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6533 result = match_backref(&t->subs.norm, subidx, &bytelen); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6534 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6535 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6536 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6537 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6538 subidx = t->state->c - NFA_ZREF1 + 1; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6539 result = match_zref(subidx, &bytelen); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6540 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6541 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
6542 |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6543 if (result) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6544 { |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6545 if (bytelen == 0) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6546 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6547 // empty match always works, output of NFA_SKIP to be |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6548 // used next |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6549 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6550 add_state = t->state->out->out; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6551 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6552 else if (bytelen <= clen) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6553 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6554 // match current character, jump ahead to out of |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6555 // NFA_SKIP |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6556 add_state = t->state->out->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6557 add_off = clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6558 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6559 else |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6560 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6561 // skip over the matched characters, set character |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6562 // count in NFA_SKIP |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6563 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6564 add_off = bytelen; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6565 add_count = bytelen - clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6566 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6567 } |
4482 | 6568 break; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6569 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6570 case NFA_SKIP: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6571 // character of previous matching \1 .. \9 or \@> |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6572 if (t->count - clen <= 0) |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6573 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6574 // end of match, go to what follows |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6575 add_state = t->state->out; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6576 add_off = clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6577 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6578 else |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6579 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6580 // add state again with decremented count |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6581 add_state = t->state; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6582 add_off = 0; |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6583 add_count = t->count - clen; |
4571
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6584 } |
b2a8e3a66f8c
updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents:
4569
diff
changeset
|
6585 break; |
4482 | 6586 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6587 case NFA_LNUM: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6588 case NFA_LNUM_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6589 case NFA_LNUM_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6590 result = (REG_MULTI && |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6591 nfa_re_num_cmp(t->state->val, t->state->c - NFA_LNUM, |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6592 (long_u)(rex.lnum + rex.reg_firstlnum))); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6593 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6594 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6595 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6596 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6597 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6598 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6599 |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6600 case NFA_COL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6601 case NFA_COL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6602 case NFA_COL_LT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6603 result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_COL, |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6604 (long_u)(rex.input - rex.line) + 1); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6605 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6606 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6607 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6608 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6609 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6610 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6611 |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6612 case NFA_VCOL: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6613 case NFA_VCOL_GT: |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6614 case NFA_VCOL_LT: |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6615 { |
6499 | 6616 int op = t->state->c - NFA_VCOL; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6617 colnr_T col = (colnr_T)(rex.input - rex.line); |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6618 win_T *wp = rex.reg_win == NULL ? curwin : rex.reg_win; |
6499 | 6619 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6620 // Bail out quickly when there can't be a match, avoid the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6621 // overhead of win_linetabsize() on long lines. |
6653 | 6622 if (op != 1 && col > t->state->val |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
6623 * (has_mbyte ? MB_MAXBYTES : 1)) |
6499 | 6624 break; |
6510 | 6625 result = FALSE; |
6626 if (op == 1 && col - 1 > t->state->val && col > 100) | |
6627 { | |
6628 int ts = wp->w_buffer->b_p_ts; | |
6629 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6630 // Guess that a character won't use more columns than |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6631 // 'tabstop', with a minimum of 4. |
6510 | 6632 if (ts < 4) |
6633 ts = 4; | |
6634 result = col > t->state->val * ts; | |
6635 } | |
6636 if (!result) | |
6637 result = nfa_re_num_cmp(t->state->val, op, | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6638 (long_u)win_linetabsize(wp, rex.line, col) + 1); |
6499 | 6639 if (result) |
6640 { | |
6641 add_here = TRUE; | |
6642 add_state = t->state->out; | |
6643 } | |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6644 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6645 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6646 |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6647 case NFA_MARK: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6648 case NFA_MARK_GT: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6649 case NFA_MARK_LT: |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6650 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6651 pos_T *pos = getmark_buf(rex.reg_buf, t->state->val, FALSE); |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6652 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6653 // Compare the mark position to the match position. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6654 result = (pos != NULL // mark doesn't exist |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6655 && pos->lnum > 0 // mark isn't set in reg_buf |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6656 && (pos->lnum == rex.lnum + rex.reg_firstlnum |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6657 ? (pos->col == (colnr_T)(rex.input - rex.line) |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6658 ? t->state->c == NFA_MARK |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6659 : (pos->col < (colnr_T)(rex.input - rex.line) |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6660 ? t->state->c == NFA_MARK_GT |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6661 : t->state->c == NFA_MARK_LT)) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6662 : (pos->lnum < rex.lnum + rex.reg_firstlnum |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6663 ? t->state->c == NFA_MARK_GT |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6664 : t->state->c == NFA_MARK_LT))); |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6665 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6666 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6667 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6668 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6669 } |
4732
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6670 break; |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6671 } |
0798b096bab3
updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents:
4730
diff
changeset
|
6672 |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6673 case NFA_CURSOR: |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6674 result = (rex.reg_win != NULL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6675 && (rex.lnum + rex.reg_firstlnum |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6676 == rex.reg_win->w_cursor.lnum) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6677 && ((colnr_T)(rex.input - rex.line) |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6678 == rex.reg_win->w_cursor.col)); |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6679 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6680 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6681 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6682 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6683 } |
4583
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6684 break; |
321cfbef9431
updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents:
4579
diff
changeset
|
6685 |
4756
96f3348f9f11
updated for version 7.3.1125
Bram Moolenaar <bram@vim.org>
parents:
4750
diff
changeset
|
6686 case NFA_VISUAL: |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6687 result = reg_match_visual(); |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6688 if (result) |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6689 { |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6690 add_here = TRUE; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6691 add_state = t->state->out; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6692 } |
4730
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6693 break; |
749e2b2755d5
updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents:
4728
diff
changeset
|
6694 |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6695 case NFA_MOPEN1: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6696 case NFA_MOPEN2: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6697 case NFA_MOPEN3: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6698 case NFA_MOPEN4: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6699 case NFA_MOPEN5: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6700 case NFA_MOPEN6: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6701 case NFA_MOPEN7: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6702 case NFA_MOPEN8: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6703 case NFA_MOPEN9: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6704 #ifdef FEAT_SYN_HL |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6705 case NFA_ZOPEN: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6706 case NFA_ZOPEN1: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6707 case NFA_ZOPEN2: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6708 case NFA_ZOPEN3: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6709 case NFA_ZOPEN4: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6710 case NFA_ZOPEN5: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6711 case NFA_ZOPEN6: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6712 case NFA_ZOPEN7: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6713 case NFA_ZOPEN8: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6714 case NFA_ZOPEN9: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6715 #endif |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6716 case NFA_NOPEN: |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6717 case NFA_ZSTART: |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6718 // These states are only added to be able to bail out when |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6719 // they are added again, nothing is to be done. |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6720 break; |
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6721 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6722 default: // regular character |
4559
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6723 { |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6724 int c = t->state->c; |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6725 |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6726 #ifdef DEBUG |
4785
3b5a023a4543
updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents:
4783
diff
changeset
|
6727 if (c < 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
6728 siemsg("INTERNAL: Negative state char: %ld", c); |
5251
2e63b6c763f7
updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents:
5227
diff
changeset
|
6729 #endif |
4559
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6730 result = (c == curc); |
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6731 |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6732 if (!result && rex.reg_ic) |
20772
097f5b5c907b
patch 8.2.0938: NFA regexp uses tolower ()to compare ignore-case
Bram Moolenaar <Bram@vim.org>
parents:
20677
diff
changeset
|
6733 result = MB_CASEFOLD(c) == MB_CASEFOLD(curc); |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6734 // If rex.reg_icombine is not set only skip over the character |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6735 // itself. When it is set skip over composing characters. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6736 if (result && enc_utf8 && !rex.reg_icombine) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6737 clen = utf_ptr2len(rex.input); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6738 ADD_STATE_IF_MATCH(t->state); |
4444 | 6739 break; |
4559
04086e297563
updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents:
4557
diff
changeset
|
6740 } |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6741 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6742 } // switch (t->state->c) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6743 |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6744 if (add_state != NULL) |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6745 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6746 nfa_pim_T *pim; |
5401 | 6747 nfa_pim_T pim_copy; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6748 |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6749 if (t->pim.result == NFA_PIM_UNUSED) |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6750 pim = NULL; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6751 else |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6752 pim = &t->pim; |
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6753 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6754 // Handle the postponed invisible match if the match might end |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6755 // without advancing and before the end of the line. |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6756 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
|
6757 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6758 if (pim->result == NFA_PIM_TODO) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6759 { |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6760 #ifdef ENABLE_LOG |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6761 fprintf(log_fd, "\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6762 fprintf(log_fd, "==================================\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6763 fprintf(log_fd, "Postponed recursive nfa_regmatch()\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6764 fprintf(log_fd, "\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6765 #endif |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6766 result = recursive_regmatch(pim->state, pim, |
14309
15530de011bc
patch 8.1.0170: invalid memory use with complicated pattern
Christian Brabandt <cb@256bit.org>
parents:
14173
diff
changeset
|
6767 prog, submatch, m, &listids, &listids_len); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6768 pim->result = result ? NFA_PIM_MATCH : NFA_PIM_NOMATCH; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6769 // for \@! and \@<! it is a match when the result is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6770 // FALSE |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6771 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
|
6772 || pim->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6773 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6774 == NFA_START_INVISIBLE_BEFORE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6775 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6776 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6777 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6778 // Copy submatch info from the recursive call |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6779 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
|
6780 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6781 if (rex.nfa_has_zsubexpr) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6782 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
|
6783 #endif |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6784 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6785 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6786 else |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6787 { |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6788 result = (pim->result == NFA_PIM_MATCH); |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6789 #ifdef ENABLE_LOG |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6790 fprintf(log_fd, "\n"); |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6791 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
|
6792 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
|
6793 fprintf(log_fd, "\n"); |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6794 #endif |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6795 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6796 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6797 // 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
|
6798 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
|
6799 || pim->state->c == NFA_START_INVISIBLE_NEG_FIRST |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6800 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6801 == NFA_START_INVISIBLE_BEFORE_NEG |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6802 || pim->state->c |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
6803 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)) |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6804 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6805 // Copy submatch info from the recursive call |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6806 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
|
6807 #ifdef FEAT_SYN_HL |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6808 if (rex.nfa_has_zsubexpr) |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6809 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
|
6810 #endif |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6811 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6812 else |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6813 // look-behind match failed, don't add the state |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6814 continue; |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6815 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6816 // Postponed invisible match was handled, don't add it to |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6817 // following states. |
4813
bc3f4804cf47
updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents:
4811
diff
changeset
|
6818 pim = NULL; |
4726
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6819 } |
3849c811cc0b
updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents:
4720
diff
changeset
|
6820 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6821 // If "pim" points into l->t it will become invalid when |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6822 // adding the state causes the list to be reallocated. Make a |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6823 // local copy to avoid that. |
5401 | 6824 if (pim == &t->pim) |
6825 { | |
6826 copy_pim(&pim_copy, pim); | |
6827 pim = &pim_copy; | |
6828 } | |
6829 | |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6830 if (add_here) |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6831 r = addstate_here(thislist, add_state, &t->subs, |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6832 pim, &listidx); |
4799
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6833 else |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6834 { |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6835 r = 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
|
6836 if (add_count > 0) |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6837 nextlist->t[nextlist->n - 1].count = add_count; |
e3f9e33fb28c
updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents:
4797
diff
changeset
|
6838 } |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6839 if (r == NULL) |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6840 { |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6841 nfa_match = NFA_TOO_EXPENSIVE; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6842 goto theend; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6843 } |
4444 | 6844 } |
6845 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6846 } // for (thislist = thislist; thislist->state; thislist++) |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6847 |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6848 // Look for the start of a match in the current position by adding the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6849 // start state to the list of states. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6850 // The first found match is the leftmost one, thus the order of states |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6851 // matters! |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6852 // Do not add the start state in recursive calls of nfa_regmatch(), |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6853 // because recursive calls should only start in the first position. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6854 // Unless "nfa_endp" is not NULL, then we match the end position. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6855 // 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
|
6856 if (nfa_match == FALSE |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6857 && ((toplevel |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6858 && rex.lnum == 0 |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6859 && clen != 0 |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6860 && (rex.reg_maxcol == 0 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6861 || (colnr_T)(rex.input - rex.line) < rex.reg_maxcol)) |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6862 || (nfa_endp != NULL |
4682
2f51ee8825db
updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents:
4679
diff
changeset
|
6863 && (REG_MULTI |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6864 ? (rex.lnum < nfa_endp->se_u.pos.lnum |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6865 || (rex.lnum == nfa_endp->se_u.pos.lnum |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6866 && (int)(rex.input - rex.line) |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6867 < nfa_endp->se_u.pos.col)) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6868 : rex.input < nfa_endp->se_u.ptr)))) |
4444 | 6869 { |
6870 #ifdef ENABLE_LOG | |
6871 fprintf(log_fd, "(---) STARTSTATE\n"); | |
6872 #endif | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6873 // Inline optimized code for addstate() if we know the state is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6874 // the first MOPEN. |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6875 if (toplevel) |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6876 { |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6877 int add = TRUE; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6878 int c; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6879 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6880 if (prog->regstart != NUL && clen != 0) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6881 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6882 if (nextlist->n == 0) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6883 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6884 colnr_T col = (colnr_T)(rex.input - rex.line) + clen; |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6885 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6886 // Nextlist is empty, we can skip ahead to the |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6887 // character that must appear at the start. |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6888 if (skip_to_start(prog->regstart, &col) == FAIL) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6889 break; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6890 #ifdef ENABLE_LOG |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6891 fprintf(log_fd, " Skipping ahead %d bytes to regstart\n", |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6892 col - ((colnr_T)(rex.input - rex.line) + clen)); |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6893 #endif |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6894 rex.input = rex.line + col - clen; |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6895 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6896 else |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6897 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6898 // Checking if the required start character matches is |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6899 // cheaper than adding a state that won't match. |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6900 c = PTR2CHAR(rex.input + clen); |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
6901 if (c != prog->regstart && (!rex.reg_ic |
20772
097f5b5c907b
patch 8.2.0938: NFA regexp uses tolower ()to compare ignore-case
Bram Moolenaar <Bram@vim.org>
parents:
20677
diff
changeset
|
6902 || MB_CASEFOLD(c) != MB_CASEFOLD(prog->regstart))) |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6903 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6904 #ifdef ENABLE_LOG |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6905 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
|
6906 #endif |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6907 add = FALSE; |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6908 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6909 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6910 } |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6911 |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6912 if (add) |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6913 { |
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6914 if (REG_MULTI) |
6547 | 6915 m->norm.list.multi[0].start_col = |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6916 (colnr_T)(rex.input - rex.line) + clen; |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6917 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6918 m->norm.list.line[0].start = rex.input + clen; |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6919 if (addstate(nextlist, start->out, m, NULL, clen) == NULL) |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6920 { |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6921 nfa_match = NFA_TOO_EXPENSIVE; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6922 goto theend; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6923 } |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
6924 } |
4797
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6925 } |
a30e3762957d
updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents:
4787
diff
changeset
|
6926 else |
15796
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6927 { |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6928 if (addstate(nextlist, start, m, NULL, clen) == NULL) |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6929 { |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6930 nfa_match = NFA_TOO_EXPENSIVE; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6931 goto theend; |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6932 } |
481452f6687c
patch 8.1.0905: complicated regexp causes a crash
Bram Moolenaar <Bram@vim.org>
parents:
15709
diff
changeset
|
6933 } |
4444 | 6934 } |
6935 | |
6936 #ifdef ENABLE_LOG | |
6937 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
|
6938 { |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6939 int i; |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6940 |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6941 for (i = 0; i < thislist->n; i++) |
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6942 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
|
6943 } |
4444 | 6944 fprintf(log_fd, "\n"); |
6945 #endif | |
6946 | |
6947 nextchar: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6948 // Advance to the next character, or advance to the next line, or |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6949 // finish. |
4549
849180347ac3
updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents:
4547
diff
changeset
|
6950 if (clen != 0) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6951 rex.input += clen; |
4694
efc4fb311d5d
updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents:
4692
diff
changeset
|
6952 else if (go_to_nextline || (nfa_endp != NULL && REG_MULTI |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6953 && rex.lnum < nfa_endp->se_u.pos.lnum)) |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6954 reg_nextline(); |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6955 else |
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6956 break; |
6499 | 6957 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6958 // Allow interrupting with CTRL-C. |
6573 | 6959 line_breakcheck(); |
6499 | 6960 if (got_int) |
6961 break; | |
6573 | 6962 #ifdef FEAT_RELTIME |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6963 // Check for timeout once in a twenty times to avoid overhead. |
6573 | 6964 if (nfa_time_limit != NULL && ++nfa_time_count == 20) |
6965 { | |
6966 nfa_time_count = 0; | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
6967 if (nfa_did_time_out()) |
6573 | 6968 break; |
6969 } | |
6970 #endif | |
4515
90e9917d4114
updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents:
4507
diff
changeset
|
6971 } |
4444 | 6972 |
6973 #ifdef ENABLE_LOG | |
6974 if (log_fd != stderr) | |
6975 fclose(log_fd); | |
6976 log_fd = NULL; | |
6977 #endif | |
6978 | |
6979 theend: | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
6980 // Free memory |
4444 | 6981 vim_free(list[0].t); |
6982 vim_free(list[1].t); | |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
6983 vim_free(listids); |
4783
47222d8b1e94
updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents:
4781
diff
changeset
|
6984 #undef ADD_STATE_IF_MATCH |
4460 | 6985 #ifdef NFA_REGEXP_DEBUG_LOG |
4444 | 6986 fclose(debug); |
6987 #endif | |
6988 | |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
6989 return nfa_match; |
4444 | 6990 } |
6991 | |
6992 /* | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
6993 * Try match of "prog" with at rex.line["col"]. |
6392 | 6994 * Returns <= 0 for failure, number of lines contained in the match otherwise. |
4444 | 6995 */ |
6996 static long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6997 nfa_regtry( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6998 nfa_regprog_T *prog, |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6999 colnr_T col, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7000 proftime_T *tm UNUSED, // timeout limit or NULL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7001 int *timed_out UNUSED) // flag set on timeout or NULL |
4444 | 7002 { |
7003 int i; | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7004 regsubs_T subs, m; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7005 nfa_state_T *start = prog->start; |
6328 | 7006 int result; |
4444 | 7007 #ifdef ENABLE_LOG |
7008 FILE *f; | |
7009 #endif | |
7010 | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7011 rex.input = rex.line + col; |
6573 | 7012 #ifdef FEAT_RELTIME |
7013 nfa_time_limit = tm; | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
7014 nfa_timed_out = timed_out; |
6573 | 7015 nfa_time_count = 0; |
7016 #endif | |
4444 | 7017 |
7018 #ifdef ENABLE_LOG | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
7019 f = fopen(NFA_REGEXP_RUN_LOG, "a"); |
4444 | 7020 if (f != NULL) |
7021 { | |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
7022 fprintf(f, "\n\n\t=======================================================\n"); |
4444 | 7023 #ifdef DEBUG |
7024 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr); | |
7025 #endif | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7026 fprintf(f, "\tInput text is \"%s\" \n", rex.input); |
4750
7793e737ec87
updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents:
4748
diff
changeset
|
7027 fprintf(f, "\t=======================================================\n\n"); |
4533
6a2005efa02b
updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents:
4531
diff
changeset
|
7028 nfa_print_state(f, start); |
4444 | 7029 fprintf(f, "\n\n"); |
7030 fclose(f); | |
7031 } | |
7032 else | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15265
diff
changeset
|
7033 emsg("Could not open temporary log file for writing"); |
4444 | 7034 #endif |
7035 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7036 clear_sub(&subs.norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7037 clear_sub(&m.norm); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7038 #ifdef FEAT_SYN_HL |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7039 clear_sub(&subs.synt); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7040 clear_sub(&m.synt); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7041 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7042 |
6328 | 7043 result = nfa_regmatch(prog, start, &subs, &m); |
7044 if (result == FALSE) | |
4444 | 7045 return 0; |
6328 | 7046 else if (result == NFA_TOO_EXPENSIVE) |
7047 return result; | |
4444 | 7048 |
7049 cleanup_subexpr(); | |
7050 if (REG_MULTI) | |
7051 { | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7052 for (i = 0; i < subs.norm.in_use; i++) |
4444 | 7053 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7054 rex.reg_startpos[i].lnum = subs.norm.list.multi[i].start_lnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7055 rex.reg_startpos[i].col = subs.norm.list.multi[i].start_col; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7056 |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7057 rex.reg_endpos[i].lnum = subs.norm.list.multi[i].end_lnum; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7058 rex.reg_endpos[i].col = subs.norm.list.multi[i].end_col; |
4444 | 7059 } |
7060 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7061 if (rex.reg_startpos[0].lnum < 0) |
4444 | 7062 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7063 rex.reg_startpos[0].lnum = 0; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7064 rex.reg_startpos[0].col = col; |
4444 | 7065 } |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7066 if (rex.reg_endpos[0].lnum < 0) |
4444 | 7067 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7068 // pattern has a \ze but it didn't match, use current end |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7069 rex.reg_endpos[0].lnum = rex.lnum; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7070 rex.reg_endpos[0].col = (int)(rex.input - rex.line); |
4444 | 7071 } |
7072 else | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7073 // Use line number of "\ze". |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7074 rex.lnum = rex.reg_endpos[0].lnum; |
4444 | 7075 } |
7076 else | |
7077 { | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7078 for (i = 0; i < subs.norm.in_use; i++) |
4444 | 7079 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7080 rex.reg_startp[i] = subs.norm.list.line[i].start; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7081 rex.reg_endp[i] = subs.norm.list.line[i].end; |
4444 | 7082 } |
7083 | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7084 if (rex.reg_startp[0] == NULL) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7085 rex.reg_startp[0] = rex.line + col; |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7086 if (rex.reg_endp[0] == NULL) |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7087 rex.reg_endp[0] = rex.input; |
4444 | 7088 } |
7089 | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7090 #ifdef FEAT_SYN_HL |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7091 // Package any found \z(...\) matches for export. Default is none. |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7092 unref_extmatch(re_extmatch_out); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7093 re_extmatch_out = NULL; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7094 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7095 if (prog->reghasz == REX_SET) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7096 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7097 cleanup_zsubexpr(); |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7098 re_extmatch_out = make_extmatch(); |
18945
c62d63d2b9f0
patch 8.2.0033: crash when make_extmatch() runs out of memory
Bram Moolenaar <Bram@vim.org>
parents:
18812
diff
changeset
|
7099 if (re_extmatch_out == NULL) |
c62d63d2b9f0
patch 8.2.0033: crash when make_extmatch() runs out of memory
Bram Moolenaar <Bram@vim.org>
parents:
18812
diff
changeset
|
7100 return 0; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7101 // Loop over \z1, \z2, etc. There is no \z0. |
7258
7245d8635ac7
commit https://github.com/vim/vim/commit/5ad075c0735d3d8b97708d17c22de8facb15f997
Christian Brabandt <cb@256bit.org>
parents:
7152
diff
changeset
|
7102 for (i = 1; i < subs.synt.in_use; i++) |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7103 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7104 if (REG_MULTI) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7105 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7106 struct multipos *mpos = &subs.synt.list.multi[i]; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7107 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7108 // Only accept single line matches that are valid. |
6547 | 7109 if (mpos->start_lnum >= 0 |
7110 && mpos->start_lnum == mpos->end_lnum | |
7111 && mpos->end_col >= mpos->start_col) | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7112 re_extmatch_out->matches[i] = |
6547 | 7113 vim_strnsave(reg_getline(mpos->start_lnum) |
7114 + mpos->start_col, | |
7115 mpos->end_col - mpos->start_col); | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7116 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7117 else |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7118 { |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7119 struct linepos *lpos = &subs.synt.list.line[i]; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7120 |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7121 if (lpos->start != NULL && lpos->end != NULL) |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7122 re_extmatch_out->matches[i] = |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20772
diff
changeset
|
7123 vim_strnsave(lpos->start, lpos->end - lpos->start); |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7124 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7125 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7126 } |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7127 #endif |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7128 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7129 return 1 + rex.lnum; |
4444 | 7130 } |
7131 | |
7132 /* | |
7133 * Match a regexp against a string ("line" points to the string) or multiple | |
7134 * lines ("line" is NULL, use reg_getline()). | |
7135 * | |
6392 | 7136 * Returns <= 0 for failure, number of lines contained in the match otherwise. |
4444 | 7137 */ |
7138 static long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7139 nfa_regexec_both( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7140 char_u *line, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7141 colnr_T startcol, // column to start looking for match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7142 proftime_T *tm, // timeout limit or NULL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7143 int *timed_out) // flag set on timeout or NULL |
4444 | 7144 { |
7145 nfa_regprog_T *prog; | |
7146 long retval = 0L; | |
7147 int i; | |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7148 colnr_T col = startcol; |
4444 | 7149 |
7150 if (REG_MULTI) | |
7151 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7152 prog = (nfa_regprog_T *)rex.reg_mmatch->regprog; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7153 line = reg_getline((linenr_T)0); // relative to the cursor |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7154 rex.reg_startpos = rex.reg_mmatch->startpos; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7155 rex.reg_endpos = rex.reg_mmatch->endpos; |
4444 | 7156 } |
7157 else | |
7158 { | |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7159 prog = (nfa_regprog_T *)rex.reg_match->regprog; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7160 rex.reg_startp = rex.reg_match->startp; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7161 rex.reg_endp = rex.reg_match->endp; |
4444 | 7162 } |
7163 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7164 // Be paranoid... |
4444 | 7165 if (prog == NULL || line == NULL) |
7166 { | |
22167
740b16b3c80b
patch 8.2.1633: some error messages are internal but do not use iemsg()
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
7167 iemsg(_(e_null)); |
4444 | 7168 goto theend; |
7169 } | |
7170 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7171 // If pattern contains "\c" or "\C": overrule value of rex.reg_ic |
4444 | 7172 if (prog->regflags & RF_ICASE) |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7173 rex.reg_ic = TRUE; |
4444 | 7174 else if (prog->regflags & RF_NOICASE) |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7175 rex.reg_ic = FALSE; |
4444 | 7176 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7177 // If pattern contains "\Z" overrule value of rex.reg_icombine |
4444 | 7178 if (prog->regflags & RF_ICOMBINE) |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7179 rex.reg_icombine = TRUE; |
4444 | 7180 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7181 rex.line = line; |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7182 rex.lnum = 0; // relative to line |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7183 |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7184 rex.nfa_has_zend = prog->has_zend; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7185 rex.nfa_has_backref = prog->has_backref; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7186 rex.nfa_nsubexpr = prog->nsubexp; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7187 rex.nfa_listid = 1; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7188 rex.nfa_alt_listid = 2; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7189 #ifdef DEBUG |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
7190 nfa_regengine.expr = prog->pattern; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7191 #endif |
4553
7b835b2969af
updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents:
4551
diff
changeset
|
7192 |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7193 if (prog->reganch && col > 0) |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7194 return 0L; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7195 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7196 rex.need_clear_subexpr = TRUE; |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7197 #ifdef FEAT_SYN_HL |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7198 // Clear the external match subpointers if necessary. |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7199 if (prog->reghasz == REX_SET) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7200 { |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7201 rex.nfa_has_zsubexpr = TRUE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7202 rex.need_clear_zsubexpr = TRUE; |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7203 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7204 else |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7205 { |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7206 rex.nfa_has_zsubexpr = FALSE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7207 rex.need_clear_zsubexpr = FALSE; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7208 } |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7209 #endif |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7210 |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7211 if (prog->regstart != NUL) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7212 { |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7213 // Skip ahead until a character we know the match must start with. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7214 // When there is none there is no match. |
4801
3cd3cc1e9119
updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents:
4799
diff
changeset
|
7215 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
|
7216 return 0L; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7217 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7218 // If match_text is set it contains the full text that must match. |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7219 // Nothing else to try. Doesn't handle combining chars well. |
15603
639b8318472c
patch 8.1.0809: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15490
diff
changeset
|
7220 if (prog->match_text != NULL && !rex.reg_icombine) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7221 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
|
7222 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7223 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7224 // If the start column is past the maximum column: no need to try. |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7225 if (rex.reg_maxcol > 0 && col >= rex.reg_maxcol) |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7226 goto theend; |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7227 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7228 // Set the "nstate" used by nfa_regcomp() to zero to trigger an error when |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7229 // it's accidentally used during execution. |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7230 nstate = 0; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7231 for (i = 0; i < prog->nstate; ++i) |
4444 | 7232 { |
7233 prog->state[i].id = i; | |
4718
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
7234 prog->state[i].lastlist[0] = 0; |
ec72bb4a0fc2
updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents:
4716
diff
changeset
|
7235 prog->state[i].lastlist[1] = 0; |
4444 | 7236 } |
7237 | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
7238 retval = nfa_regtry(prog, col, tm, timed_out); |
4444 | 7239 |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7240 #ifdef DEBUG |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
7241 nfa_regengine.expr = NULL; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7242 #endif |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
7243 |
4444 | 7244 theend: |
23270
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7245 if (retval > 0) |
23150
90b16a0022e5
patch 8.2.2121: internal error when using ze before zs in a pattern
Bram Moolenaar <Bram@vim.org>
parents:
22167
diff
changeset
|
7246 { |
23270
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7247 // Make sure the end is never before the start. Can happen when \zs and |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7248 // \ze are used. |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7249 if (REG_MULTI) |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7250 { |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7251 lpos_T *start = &rex.reg_mmatch->startpos[0]; |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7252 lpos_T *end = &rex.reg_mmatch->endpos[0]; |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7253 |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7254 if (end->lnum < start->lnum |
23150
90b16a0022e5
patch 8.2.2121: internal error when using ze before zs in a pattern
Bram Moolenaar <Bram@vim.org>
parents:
22167
diff
changeset
|
7255 || (end->lnum == start->lnum && end->col < start->col)) |
23270
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7256 rex.reg_mmatch->endpos[0] = rex.reg_mmatch->startpos[0]; |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7257 } |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7258 else |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7259 { |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7260 if (rex.reg_match->endp[0] < rex.reg_match->startp[0]) |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7261 rex.reg_match->endp[0] = rex.reg_match->startp[0]; |
22d0c25869d8
patch 8.2.2181: valgrind warnings for using uninitialized value
Bram Moolenaar <Bram@vim.org>
parents:
23262
diff
changeset
|
7262 } |
23150
90b16a0022e5
patch 8.2.2121: internal error when using ze before zs in a pattern
Bram Moolenaar <Bram@vim.org>
parents:
22167
diff
changeset
|
7263 } |
90b16a0022e5
patch 8.2.2121: internal error when using ze before zs in a pattern
Bram Moolenaar <Bram@vim.org>
parents:
22167
diff
changeset
|
7264 |
4444 | 7265 return retval; |
7266 } | |
7267 | |
7268 /* | |
7269 * Compile a regular expression into internal code for the NFA matcher. | |
7270 * Returns the program in allocated space. Returns NULL for an error. | |
7271 */ | |
7272 static regprog_T * | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7273 nfa_regcomp(char_u *expr, int re_flags) |
4444 | 7274 { |
4541
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7275 nfa_regprog_T *prog = NULL; |
4458 | 7276 size_t prog_size; |
4444 | 7277 int *postfix; |
7278 | |
7279 if (expr == NULL) | |
7280 return NULL; | |
7281 | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7282 #ifdef DEBUG |
4444 | 7283 nfa_regengine.expr = expr; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7284 #endif |
6533 | 7285 nfa_re_flags = re_flags; |
4444 | 7286 |
7287 init_class_tab(); | |
7288 | |
7289 if (nfa_regcomp_start(expr, re_flags) == FAIL) | |
7290 return NULL; | |
7291 | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7292 // Build postfix form of the regexp. Needed to build the NFA |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7293 // (and count its size). |
4444 | 7294 postfix = re2post(); |
7295 if (postfix == NULL) | |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7296 goto fail; // Cascaded (syntax?) error |
4444 | 7297 |
7298 /* | |
7299 * In order to build the NFA, we parse the input regexp twice: | |
7300 * 1. first pass to count size (so we can allocate space) | |
7301 * 2. second to emit code | |
7302 */ | |
7303 #ifdef ENABLE_LOG | |
7304 { | |
4531
1be43c095aff
updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents:
4529
diff
changeset
|
7305 FILE *f = fopen(NFA_REGEXP_RUN_LOG, "a"); |
4444 | 7306 |
7307 if (f != NULL) | |
7308 { | |
14145
1cf832945469
patch 8.1.0090: "..." used inconsistently in a message
Christian Brabandt <cb@256bit.org>
parents:
14121
diff
changeset
|
7309 fprintf(f, "\n*****************************\n\n\n\n\tCompiling regexp \"%s\"... hold on !\n", expr); |
4444 | 7310 fclose(f); |
7311 } | |
7312 } | |
7313 #endif | |
7314 | |
7315 /* | |
7316 * PASS 1 | |
7317 * Count number of NFA states in "nstate". Do not build the NFA. | |
7318 */ | |
7319 post2nfa(postfix, post_ptr, TRUE); | |
4541
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7320 |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7321 // allocate the regprog with space for the compiled regexp |
4837
05b8436873d4
updated for version 7.3.1165
Bram Moolenaar <bram@vim.org>
parents:
4821
diff
changeset
|
7322 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1); |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
7323 prog = alloc(prog_size); |
4541
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7324 if (prog == NULL) |
80170d61a85c
updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents:
4539
diff
changeset
|
7325 goto fail; |
4444 | 7326 state_ptr = prog->state; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7327 prog->re_in_use = FALSE; |
4444 | 7328 |
7329 /* | |
7330 * PASS 2 | |
7331 * Build the NFA | |
7332 */ | |
7333 prog->start = post2nfa(postfix, post_ptr, FALSE); | |
7334 if (prog->start == NULL) | |
7335 goto fail; | |
7336 | |
7337 prog->regflags = regflags; | |
7338 prog->engine = &nfa_regengine; | |
7339 prog->nstate = nstate; | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7340 prog->has_zend = rex.nfa_has_zend; |
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7341 prog->has_backref = rex.nfa_has_backref; |
4561
4d81fdda8f35
updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents:
4559
diff
changeset
|
7342 prog->nsubexp = regnpar; |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7343 |
4845
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
7344 nfa_postprocess(prog); |
a83fb2bd8c8e
updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents:
4837
diff
changeset
|
7345 |
4772
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7346 prog->reganch = nfa_get_reganch(prog->start, 0); |
03375ccf28a2
updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents:
4770
diff
changeset
|
7347 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
|
7348 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
|
7349 |
4444 | 7350 #ifdef ENABLE_LOG |
7351 nfa_postfix_dump(expr, OK); | |
7352 nfa_dump(prog); | |
7353 #endif | |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7354 #ifdef FEAT_SYN_HL |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7355 // Remember whether this pattern has any \z specials in it. |
4686
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7356 prog->reghasz = re_has_z; |
8db697ae406a
updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents:
4682
diff
changeset
|
7357 #endif |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7358 prog->pattern = vim_strsave(expr); |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7359 #ifdef DEBUG |
4690
9d97a0c045ef
updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents:
4688
diff
changeset
|
7360 nfa_regengine.expr = NULL; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7361 #endif |
4444 | 7362 |
7363 out: | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13208
diff
changeset
|
7364 VIM_CLEAR(post_start); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13208
diff
changeset
|
7365 post_ptr = post_end = NULL; |
4444 | 7366 state_ptr = NULL; |
7367 return (regprog_T *)prog; | |
7368 | |
7369 fail: | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13208
diff
changeset
|
7370 VIM_CLEAR(prog); |
4444 | 7371 #ifdef ENABLE_LOG |
7372 nfa_postfix_dump(expr, FAIL); | |
7373 #endif | |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7374 #ifdef DEBUG |
4444 | 7375 nfa_regengine.expr = NULL; |
14354
ffd834f893aa
patch 8.1.0192: executing regexp recursively fails with a crash
Christian Brabandt <cb@256bit.org>
parents:
14309
diff
changeset
|
7376 #endif |
4444 | 7377 goto out; |
7378 } | |
7379 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7380 /* |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7381 * 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
|
7382 */ |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7383 static void |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7384 nfa_regfree(regprog_T *prog) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7385 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7386 if (prog != NULL) |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7387 { |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7388 vim_free(((nfa_regprog_T *)prog)->match_text); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7389 vim_free(((nfa_regprog_T *)prog)->pattern); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7390 vim_free(prog); |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7391 } |
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4801
diff
changeset
|
7392 } |
4444 | 7393 |
7394 /* | |
7395 * Match a regexp against a string. | |
7396 * "rmp->regprog" is a compiled regexp as returned by nfa_regcomp(). | |
7397 * Uses curbuf for line count and 'iskeyword'. | |
5838 | 7398 * If "line_lbr" is TRUE consider a "\n" in "line" to be a line break. |
4444 | 7399 * |
6392 | 7400 * Returns <= 0 for failure, number of lines contained in the match otherwise. |
4444 | 7401 */ |
7402 static int | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7403 nfa_regexec_nl( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7404 regmatch_T *rmp, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7405 char_u *line, // string to match against |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7406 colnr_T col, // column to start looking for match |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7407 int line_lbr) |
4444 | 7408 { |
10245
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7409 rex.reg_match = rmp; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7410 rex.reg_mmatch = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7411 rex.reg_maxline = 0; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7412 rex.reg_line_lbr = line_lbr; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7413 rex.reg_buf = curbuf; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7414 rex.reg_win = NULL; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7415 rex.reg_ic = rmp->rm_ic; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7416 rex.reg_icombine = FALSE; |
d76ccdacb41e
commit https://github.com/vim/vim/commit/6100d02aab7c8294b581cb299250eea164b50e9d
Christian Brabandt <cb@256bit.org>
parents:
10170
diff
changeset
|
7417 rex.reg_maxcol = 0; |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
7418 return nfa_regexec_both(line, col, NULL, NULL); |
4444 | 7419 } |
7420 | |
7421 | |
7422 /* | |
7423 * Match a regexp against multiple lines. | |
7424 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). | |
7425 * Uses curbuf for line count and 'iskeyword'. | |
7426 * | |
6392 | 7427 * Return <= 0 if there is no match. Return number of lines contained in the |
4444 | 7428 * match otherwise. |
7429 * | |
7430 * Note: the body is the same as bt_regexec() except for nfa_regexec_both() | |
7431 * | |
7432 * ! Also NOTE : match may actually be in another line. e.g.: | |
7433 * when r.e. is \nc, cursor is at 'a' and the text buffer looks like | |
7434 * | |
7435 * +-------------------------+ | |
7436 * |a | | |
7437 * |b | | |
7438 * |c | | |
7439 * | | | |
7440 * +-------------------------+ | |
7441 * | |
7442 * then nfa_regexec_multi() returns 3. while the original | |
7443 * vim_regexec_multi() returns 0 and a second call at line 2 will return 2. | |
7444 * | |
7445 * FIXME if this behavior is not compatible. | |
7446 */ | |
7447 static long | |
7833
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7448 nfa_regexec_multi( |
c079097365f3
commit https://github.com/vim/vim/commit/055409764ca5f7978d4c399d2c440af0ce971c4f
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7449 regmmatch_T *rmp, |
18812
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7450 win_T *win, // window in which to search or NULL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7451 buf_T *buf, // buffer in which to search |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7452 linenr_T lnum, // nr of line to start looking for match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7453 colnr_T col, // column to start looking for match |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7454 proftime_T *tm, // timeout limit or NULL |
d34ec6fe207d
patch 8.1.2394: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
7455 int *timed_out) // flag set on timeout or NULL |
4444 | 7456 { |
19405
08f4dc2ba716
patch 8.2.0260: several lines of code are duplicated
Bram Moolenaar <Bram@vim.org>
parents:
18945
diff
changeset
|
7457 init_regexec_multi(rmp, win, buf, lnum); |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11480
diff
changeset
|
7458 return nfa_regexec_both(NULL, col, tm, timed_out); |
4444 | 7459 } |
7460 | |
7461 #ifdef DEBUG | |
7462 # undef ENABLE_LOG | |
7463 #endif |