annotate src/regexp_nfa.c @ 4728:43de4ebbe7ad v7.3.1111

updated for version 7.3.1111 Problem: nfa_recognize_char_class() implementation is inefficient. Solution: Use bits in an int instead of chars in a string. (Dominique Pelle)
author Bram Moolenaar <bram@vim.org>
date Tue, 04 Jun 2013 17:47:05 +0200
parents 3849c811cc0b
children 749e2b2755d5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 * NFA regular expression implementation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 * This file is included in "regexp.c".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 enum
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 NFA_SPLIT = -1024,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 NFA_MATCH,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 NFA_SKIP_CHAR, /* matches a 0-length char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 NFA_END_NEG_RANGE, /* Used when expanding [^ab] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 NFA_CONCAT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 NFA_OR,
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
41 NFA_STAR, /* greedy * */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
42 NFA_STAR_NONGREEDY, /* non-greedy * */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
43 NFA_QUEST, /* greedy \? */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
44 NFA_QUEST_NONGREEDY, /* non-greedy \? */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 NFA_NOT, /* used for [^ab] negated char ranges */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 NFA_BOL, /* ^ Begin line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 NFA_EOL, /* $ End line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 NFA_BOW, /* \< Begin word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 NFA_EOW, /* \> End word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 NFA_BOF, /* \%^ Begin file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 NFA_EOF, /* \%$ End file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 NFA_NEWL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 NFA_ZSTART, /* Used for \zs */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 NFA_ZEND, /* Used for \ze */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 NFA_NOPEN, /* Start of subexpression marked with \%( */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 NFA_NCLOSE, /* End of subexpr. marked with \%( ... \) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 NFA_START_INVISIBLE,
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
59 NFA_START_INVISIBLE_BEFORE,
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 NFA_END_INVISIBLE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 NFA_COMPOSING, /* Next nodes in NFA are part of the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 composing multibyte char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 NFA_END_COMPOSING, /* End of a composing char in the NFA */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 /* The following are used only in the postfix form, not in the NFA */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 NFA_PREV_ATOM_NO_WIDTH, /* Used for \@= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 NFA_PREV_ATOM_NO_WIDTH_NEG, /* Used for \@! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 NFA_PREV_ATOM_JUST_BEFORE, /* Used for \@<= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 NFA_PREV_ATOM_JUST_BEFORE_NEG, /* Used for \@<! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 NFA_PREV_ATOM_LIKE_PATTERN, /* Used for \@> */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
72 NFA_BACKREF1, /* \1 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
73 NFA_BACKREF2, /* \2 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
74 NFA_BACKREF3, /* \3 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
75 NFA_BACKREF4, /* \4 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
76 NFA_BACKREF5, /* \5 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
77 NFA_BACKREF6, /* \6 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
78 NFA_BACKREF7, /* \7 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
79 NFA_BACKREF8, /* \8 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
80 NFA_BACKREF9, /* \9 */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
81 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
82 NFA_ZREF1, /* \z1 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
83 NFA_ZREF2, /* \z2 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
84 NFA_ZREF3, /* \z3 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
85 NFA_ZREF4, /* \z4 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
86 NFA_ZREF5, /* \z5 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
87 NFA_ZREF6, /* \z6 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
88 NFA_ZREF7, /* \z7 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
89 NFA_ZREF8, /* \z8 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
90 NFA_ZREF9, /* \z9 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
91 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
92 NFA_SKIP, /* Skip characters */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
93
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 NFA_MOPEN,
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
95 NFA_MOPEN1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
96 NFA_MOPEN2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
97 NFA_MOPEN3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
98 NFA_MOPEN4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
99 NFA_MOPEN5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
100 NFA_MOPEN6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
101 NFA_MOPEN7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
102 NFA_MOPEN8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
103 NFA_MOPEN9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
104
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
105 NFA_MCLOSE,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
106 NFA_MCLOSE1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
107 NFA_MCLOSE2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
108 NFA_MCLOSE3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
109 NFA_MCLOSE4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
110 NFA_MCLOSE5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
111 NFA_MCLOSE6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
112 NFA_MCLOSE7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
113 NFA_MCLOSE8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
114 NFA_MCLOSE9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
115
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
116 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
117 NFA_ZOPEN,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
118 NFA_ZOPEN1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
119 NFA_ZOPEN2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
120 NFA_ZOPEN3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
121 NFA_ZOPEN4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
122 NFA_ZOPEN5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
123 NFA_ZOPEN6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
124 NFA_ZOPEN7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
125 NFA_ZOPEN8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
126 NFA_ZOPEN9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
127
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
128 NFA_ZCLOSE,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
129 NFA_ZCLOSE1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
130 NFA_ZCLOSE2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
131 NFA_ZCLOSE3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
132 NFA_ZCLOSE4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
133 NFA_ZCLOSE5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
134 NFA_ZCLOSE6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
135 NFA_ZCLOSE7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
136 NFA_ZCLOSE8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
137 NFA_ZCLOSE9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
138 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 /* NFA_FIRST_NL */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
141 NFA_ANY, /* Match any one character. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 NFA_ANYOF, /* Match any character in this string. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 NFA_ANYBUT, /* Match any character not in this string. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 NFA_IDENT, /* Match identifier char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 NFA_SIDENT, /* Match identifier char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 NFA_KWORD, /* Match keyword char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 NFA_SKWORD, /* Match word char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 NFA_FNAME, /* Match file name char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 NFA_SFNAME, /* Match file name char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 NFA_PRINT, /* Match printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 NFA_SPRINT, /* Match printable char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 NFA_WHITE, /* Match whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 NFA_NWHITE, /* Match non-whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 NFA_DIGIT, /* Match digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155 NFA_NDIGIT, /* Match non-digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 NFA_HEX, /* Match hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 NFA_NHEX, /* Match non-hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 NFA_OCTAL, /* Match octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 NFA_NOCTAL, /* Match non-octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 NFA_WORD, /* Match word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 NFA_NWORD, /* Match non-word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 NFA_HEAD, /* Match head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 NFA_NHEAD, /* Match non-head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 NFA_ALPHA, /* Match alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 NFA_NALPHA, /* Match non-alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 NFA_LOWER, /* Match lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 NFA_NLOWER, /* Match non-lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 NFA_UPPER, /* Match uppercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 NFA_NUPPER, /* Match non-uppercase char */
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
170
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
171 NFA_CURSOR, /* Match cursor pos */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
172 NFA_LNUM, /* Match line number */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
173 NFA_LNUM_GT, /* Match > line number */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
174 NFA_LNUM_LT, /* Match < line number */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
175 NFA_COL, /* Match cursor column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
176 NFA_COL_GT, /* Match > cursor column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
177 NFA_COL_LT, /* Match < cursor column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
178 NFA_VCOL, /* Match cursor virtual column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
179 NFA_VCOL_GT, /* Match > cursor virtual column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
180 NFA_VCOL_LT, /* Match < cursor virtual column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
181
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 NFA_FIRST_NL = NFA_ANY + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 NFA_LAST_NL = NFA_NUPPER + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 /* Character classes [:alnum:] etc */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186 NFA_CLASS_ALNUM,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187 NFA_CLASS_ALPHA,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 NFA_CLASS_BLANK,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 NFA_CLASS_CNTRL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 NFA_CLASS_DIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 NFA_CLASS_GRAPH,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 NFA_CLASS_LOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 NFA_CLASS_PRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 NFA_CLASS_PUNCT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 NFA_CLASS_SPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 NFA_CLASS_UPPER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 NFA_CLASS_XDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 NFA_CLASS_TAB,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 NFA_CLASS_RETURN,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 NFA_CLASS_BACKSPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201 NFA_CLASS_ESCAPE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 /* Keep in sync with classchars. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 static int nfa_classcodes[] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 NFA_ANY, NFA_IDENT, NFA_SIDENT, NFA_KWORD,NFA_SKWORD,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 NFA_FNAME, NFA_SFNAME, NFA_PRINT, NFA_SPRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 NFA_WHITE, NFA_NWHITE, NFA_DIGIT, NFA_NDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 NFA_HEX, NFA_NHEX, NFA_OCTAL, NFA_NOCTAL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 NFA_WORD, NFA_NWORD, NFA_HEAD, NFA_NHEAD,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 NFA_ALPHA, NFA_NALPHA, NFA_LOWER, NFA_NLOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 NFA_UPPER, NFA_NUPPER
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 static char_u e_misplaced[] = N_("E866: (NFA regexp) Misplaced %c");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 * NFA errors can be of 3 types:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 * *** NFA runtime errors, when something unknown goes wrong. The NFA fails
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 * silently and revert the to backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 * syntax_error = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 * *** Regexp syntax errors, when the input regexp is not syntactically correct.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 * The NFA engine displays an error message, and nothing else happens.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 * syntax_error = TRUE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 * *** Unsupported features, when the input regexp uses an operator that is not
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 * implemented in the NFA. The NFA engine fails silently, and reverts to the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 * old backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 * syntax_error = FALSE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 * "The NFA fails" means that "compiling the regexp with the NFA fails":
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 * nfa_regcomp() returns FAIL.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 static int syntax_error = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 /* NFA regexp \ze operator encountered. */
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
235 static int nfa_has_zend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
236
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
237 /* NFA regexp \1 .. \9 encountered. */
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
238 static int nfa_has_backref;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
239
4720
bd6bef0bd0fb updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents: 4718
diff changeset
240 #ifdef FEAT_SYN_HL
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
241 /* NFA regexp has \z( ), set zsubexpr. */
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
242 static int nfa_has_zsubexpr;
4720
bd6bef0bd0fb updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents: 4718
diff changeset
243 #endif
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
244
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
245 /* Number of sub expressions actually being used during execution. 1 if only
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
246 * the whole match (subexpr 0) is used. */
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
247 static int nfa_nsubexpr;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
248
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 static int *post_start; /* holds the postfix form of r.e. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250 static int *post_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 static int *post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
253 static int nstate; /* Number of states in the NFA. Also used when
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
254 * executing. */
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
255 static int istate; /* Index in the state vector, used in alloc_state() */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
256
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
257 /* If not NULL match must end at this position */
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
258 static save_se_T *nfa_endp = NULL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
260 /* listid is global, so that it increases on recursive calls to
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
261 * nfa_regmatch(), which means we don't have to clear the lastlist field of
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
262 * all the states. */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
263 static int nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
264 static int nfa_alt_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
265
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
266 /* 0 for first call to nfa_regmatch(), 1 for recursive call. */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
267 static int nfa_ll_index = 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
268
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269 static int nfa_regcomp_start __ARGS((char_u*expr, int re_flags));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
270 static int nfa_recognize_char_class __ARGS((char_u *start, char_u *end, int extra_newl));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 static int nfa_emit_equi_class __ARGS((int c, int neg));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 static int nfa_regatom __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 static int nfa_regpiece __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 static int nfa_regconcat __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 static int nfa_regbranch __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276 static int nfa_reg __ARGS((int paren));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 static void nfa_set_code __ARGS((int c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 static void nfa_postfix_dump __ARGS((char_u *expr, int retval));
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
280 static void nfa_print_state __ARGS((FILE *debugf, nfa_state_T *state));
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
281 static void nfa_print_state2 __ARGS((FILE *debugf, nfa_state_T *state, garray_T *indent));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 static void nfa_dump __ARGS((nfa_regprog_T *prog));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 static int *re2post __ARGS((void));
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
285 static nfa_state_T *alloc_state __ARGS((int c, nfa_state_T *out, nfa_state_T *out1));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 static int check_char_class __ARGS((int class, int c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288 static void st_error __ARGS((int *postfix, int *end, int *p));
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
289 static void nfa_save_listids __ARGS((nfa_regprog_T *prog, int *list));
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
290 static void nfa_restore_listids __ARGS((nfa_regprog_T *prog, int *list));
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
291 static int nfa_re_num_cmp __ARGS((long_u val, int op, long_u pos));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
292 static long nfa_regtry __ARGS((nfa_regprog_T *prog, colnr_T col));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293 static long nfa_regexec_both __ARGS((char_u *line, colnr_T col));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 static int nfa_regexec __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296 static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
298 /* helper functions used when doing re2post() ... regatom() parsing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299 #define EMIT(c) do { \
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
300 if (post_ptr >= post_end && realloc_post_list() == FAIL) \
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
301 return FAIL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
302 *post_ptr++ = c; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 } while (0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 * Initialize internal variables before NFA compilation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
307 * Return OK on success, FAIL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
308 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
309 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
310 nfa_regcomp_start(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
311 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
312 int re_flags; /* see vim_regcomp() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
313 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
314 size_t postfix_size;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
315 int nstate_max;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317 nstate = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 istate = 0;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
319 /* A reasonable estimation for maximum size */
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
320 nstate_max = (int)(STRLEN(expr) + 1) * 25;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
321
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
322 /* Some items blow up in size, such as [A-z]. Add more space for that.
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
323 * When it is still not enough realloc_post_list() will be used. */
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
324 nstate_max += 1000;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
325
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
326 /* Size for postfix representation of expr. */
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
327 postfix_size = sizeof(int) * nstate_max;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
328
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 post_start = (int *)lalloc(postfix_size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 if (post_start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
331 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
332 vim_memset(post_start, 0, postfix_size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
333 post_ptr = post_start;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
334 post_end = post_start + nstate_max;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 nfa_has_zend = FALSE;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
336 nfa_has_backref = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
338 /* shared with BT engine */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 regcomp_start(expr, re_flags);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
340
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
341 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
342 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 /*
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
345 * Allocate more space for post_start. Called when
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
346 * running above the estimated number of states.
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
347 */
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
348 static int
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
349 realloc_post_list()
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
350 {
4667
9e7ef781d494 updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents: 4661
diff changeset
351 int nstate_max = (int)(post_end - post_start);
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
352 int new_max = nstate_max + 1000;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
353 int *new_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
354 int *old_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
355
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
356 new_start = (int *)lalloc(new_max * sizeof(int), TRUE);
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
357 if (new_start == NULL)
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
358 return FAIL;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
359 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
360 vim_memset(new_start + nstate_max, 0, 1000 * sizeof(int));
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
361 old_start = post_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
362 post_start = new_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
363 post_ptr = new_start + (post_ptr - old_start);
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
364 post_end = post_start + new_max;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
365 vim_free(old_start);
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
366 return OK;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
367 }
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
368
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
369 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 * Search between "start" and "end" and try to recognize a
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 * character class in expanded form. For example [0-9].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372 * On success, return the id the character class to be emitted.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
373 * On failure, return 0 (=FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
374 * Start points to the first char of the range, while end should point
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
375 * to the closing brace.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
377 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
378 nfa_recognize_char_class(start, end, extra_newl)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379 char_u *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 char_u *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 int extra_newl;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
383 # define CLASS_not 0x80
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
384 # define CLASS_af 0x40
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
385 # define CLASS_AF 0x20
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
386 # define CLASS_az 0x10
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
387 # define CLASS_AZ 0x08
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
388 # define CLASS_o7 0x04
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
389 # define CLASS_o9 0x02
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
390 # define CLASS_underscore 0x01
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
391
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
392 int newl = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 char_u *p;
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
394 int config = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396 if (extra_newl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399 if (*end != ']')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401 p = start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
402 if (*p == '^')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
404 config |= CLASS_not;
4720
bd6bef0bd0fb updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents: 4718
diff changeset
405 p++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
406 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
407
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
408 while (p < end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
409 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
410 if (p + 2 < end && *(p + 1) == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414 case '0':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415 if (*(p + 2) == '9')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
417 config |= CLASS_o9;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
418 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
420 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421 if (*(p + 2) == '7')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
423 config |= CLASS_o7;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
424 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 case 'a':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427 if (*(p + 2) == 'z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
428 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
429 config |= CLASS_az;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
431 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
432 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433 if (*(p + 2) == 'f')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
434 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
435 config |= CLASS_af;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
436 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438 case 'A':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
439 if (*(p + 2) == 'Z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
440 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
441 config |= CLASS_AZ;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
442 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
443 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
444 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
445 if (*(p + 2) == 'F')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
446 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
447 config |= CLASS_AF;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
448 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
449 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
450 /* FALLTHROUGH */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
451 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
452 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
453 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
454 p += 3;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
455 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456 else if (p + 1 < end && *p == '\\' && *(p + 1) == 'n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
459 p += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
461 else if (*p == '_')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
462 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
463 config |= CLASS_underscore;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
464 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
465 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
466 else if (*p == '\n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
467 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
468 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
469 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
470 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
471 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
472 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
473 } /* while (p < end) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
474
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
475 if (p != end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
476 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
477
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
478 if (newl == TRUE)
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
479 extra_newl = ADD_NL;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
480
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
481 switch (config)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
482 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
483 case CLASS_o9:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
484 return extra_newl + NFA_DIGIT;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
485 case CLASS_not | CLASS_o9:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
486 return extra_newl + NFA_NDIGIT;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
487 case CLASS_af | CLASS_AF | CLASS_o9:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
488 return extra_newl + NFA_HEX;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
489 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
490 return extra_newl + NFA_NHEX;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
491 case CLASS_o7:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
492 return extra_newl + NFA_OCTAL;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
493 case CLASS_not | CLASS_o7:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
494 return extra_newl + NFA_NOCTAL;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
495 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
496 return extra_newl + NFA_WORD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
497 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
498 return extra_newl + NFA_NWORD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
499 case CLASS_az | CLASS_AZ | CLASS_underscore:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
500 return extra_newl + NFA_HEAD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
501 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
502 return extra_newl + NFA_NHEAD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
503 case CLASS_az | CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
504 return extra_newl + NFA_ALPHA;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
505 case CLASS_not | CLASS_az | CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
506 return extra_newl + NFA_NALPHA;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
507 case CLASS_az:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
508 return extra_newl + NFA_LOWER;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
509 case CLASS_not | CLASS_az:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
510 return extra_newl + NFA_NLOWER;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
511 case CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
512 return extra_newl + NFA_UPPER;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
513 case CLASS_not | CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
514 return extra_newl + NFA_NUPPER;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
515 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
516 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
517 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
518
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
519 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
520 * Produce the bytes for equivalence class "c".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
521 * Currently only handles latin1, latin9 and utf-8.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
522 * Emits bytes in postfix notation: 'a,b,NFA_OR,c,NFA_OR' is
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
523 * equivalent to 'a OR b OR c'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
524 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
525 * NOTE! When changing this function, also update reg_equi_class()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
526 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
527 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528 nfa_emit_equi_class(c, neg)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530 int neg;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
532 int first = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
533 int glue = neg == TRUE ? NFA_CONCAT : NFA_OR;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
534 #define EMIT2(c) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
535 EMIT(c); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
536 if (neg == TRUE) { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
537 EMIT(NFA_NOT); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
538 } \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
539 if (first == FALSE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
540 EMIT(glue); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
541 else \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
542 first = FALSE; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
543
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
544 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
545 if (enc_utf8 || STRCMP(p_enc, "latin1") == 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
546 || STRCMP(p_enc, "iso-8859-15") == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
547 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
548 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
549 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
550 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
551 case 'A': case '\300': case '\301': case '\302':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
552 case '\303': case '\304': case '\305':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
553 EMIT2('A'); EMIT2('\300'); EMIT2('\301');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
554 EMIT2('\302'); EMIT2('\303'); EMIT2('\304');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
555 EMIT2('\305');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
556 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
557
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
558 case 'C': case '\307':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
559 EMIT2('C'); EMIT2('\307');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
560 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
561
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
562 case 'E': case '\310': case '\311': case '\312': case '\313':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
563 EMIT2('E'); EMIT2('\310'); EMIT2('\311');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
564 EMIT2('\312'); EMIT2('\313');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
565 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
566
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
567 case 'I': case '\314': case '\315': case '\316': case '\317':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
568 EMIT2('I'); EMIT2('\314'); EMIT2('\315');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
569 EMIT2('\316'); EMIT2('\317');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
570 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
571
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
572 case 'N': case '\321':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
573 EMIT2('N'); EMIT2('\321');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
574 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
575
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
576 case 'O': case '\322': case '\323': case '\324': case '\325':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
577 case '\326':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
578 EMIT2('O'); EMIT2('\322'); EMIT2('\323');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
579 EMIT2('\324'); EMIT2('\325'); EMIT2('\326');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
580 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
581
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
582 case 'U': case '\331': case '\332': case '\333': case '\334':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
583 EMIT2('U'); EMIT2('\331'); EMIT2('\332');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
584 EMIT2('\333'); EMIT2('\334');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
585 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
586
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
587 case 'Y': case '\335':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
588 EMIT2('Y'); EMIT2('\335');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
589 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
590
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
591 case 'a': case '\340': case '\341': case '\342':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
592 case '\343': case '\344': case '\345':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
593 EMIT2('a'); EMIT2('\340'); EMIT2('\341');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
594 EMIT2('\342'); EMIT2('\343'); EMIT2('\344');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
595 EMIT2('\345');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
596 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
597
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
598 case 'c': case '\347':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
599 EMIT2('c'); EMIT2('\347');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
600 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
601
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
602 case 'e': case '\350': case '\351': case '\352': case '\353':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
603 EMIT2('e'); EMIT2('\350'); EMIT2('\351');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
604 EMIT2('\352'); EMIT2('\353');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
605 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 case 'i': case '\354': case '\355': case '\356': case '\357':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 EMIT2('i'); EMIT2('\354'); EMIT2('\355');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
609 EMIT2('\356'); EMIT2('\357');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
610 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
611
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
612 case 'n': case '\361':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
613 EMIT2('n'); EMIT2('\361');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
614 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
616 case 'o': case '\362': case '\363': case '\364': case '\365':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
617 case '\366':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
618 EMIT2('o'); EMIT2('\362'); EMIT2('\363');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
619 EMIT2('\364'); EMIT2('\365'); EMIT2('\366');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
621
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
622 case 'u': case '\371': case '\372': case '\373': case '\374':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
623 EMIT2('u'); EMIT2('\371'); EMIT2('\372');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
624 EMIT2('\373'); EMIT2('\374');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
625 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
626
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 case 'y': case '\375': case '\377':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
628 EMIT2('y'); EMIT2('\375'); EMIT2('\377');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
630
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
631 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
632 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
633 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
634 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
635
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
636 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
637 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
638 #undef EMIT2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
639 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
640
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
641 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
642 * Code to parse regular expression.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
643 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
644 * We try to reuse parsing functions in regexp.c to
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
645 * minimize surprise and keep the syntax consistent.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
646 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
647
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
648 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
649 * Parse the lowest level.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651 * An atom can be one of a long list of items. Many atoms match one character
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
652 * in the text. It is often an ordinary character or a character class.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
653 * Braces can be used to make a pattern into an atom. The "\z(\)" construct
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
654 * is only for syntax highlighting.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
655 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
656 * atom ::= ordinary-atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
657 * or \( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
658 * or \%( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
659 * or \z( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
660 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
661 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
662 nfa_regatom()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
663 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
664 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
665 int charclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 int equiclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 int collclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
668 int got_coll_char;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
669 char_u *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
670 char_u *endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
671 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
672 char_u *old_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
673 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 int extra = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675 int first;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 int emit_range;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677 int negated;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
679 int startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
680 int endc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 int oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
682 int cpo_lit; /* 'cpoptions' contains 'l' flag */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
683 int cpo_bsl; /* 'cpoptions' contains '\' flag */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
684 int glue; /* ID that will "glue" nodes together */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
685
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
686 cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
687 cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
688
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
689 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
690 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 {
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
692 case NUL:
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
693 syntax_error = TRUE;
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
694 EMSG_RET_FAIL(_("E865: (NFA) Regexp end encountered prematurely"));
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
695
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
696 case Magic('^'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
697 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
698 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
699
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
700 case Magic('$'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
701 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
702 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
703 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
704 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
705 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
706
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
707 case Magic('<'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
708 EMIT(NFA_BOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
709 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
710
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
711 case Magic('>'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
712 EMIT(NFA_EOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
713 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
714
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
715 case Magic('_'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
716 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
717 if (c == '^') /* "\_^" is start-of-line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
718 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
719 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
720 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
721 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
722 if (c == '$') /* "\_$" is end-of-line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
723 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
724 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
725 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
726 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
727 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
728 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
730
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
731 extra = ADD_NL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
733 /* "\_[" is collection plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
734 if (c == '[')
4517
9a2183bd8295 updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents: 4515
diff changeset
735 goto collection;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
736
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
737 /* "\_x" is character class plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
738 /*FALLTHROUGH*/
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
739
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
741 * Character classes.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
742 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
743 case Magic('.'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
744 case Magic('i'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
745 case Magic('I'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
746 case Magic('k'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
747 case Magic('K'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
748 case Magic('f'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
749 case Magic('F'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750 case Magic('p'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
751 case Magic('P'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
752 case Magic('s'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
753 case Magic('S'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 case Magic('d'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755 case Magic('D'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
756 case Magic('x'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
757 case Magic('X'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
758 case Magic('o'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
759 case Magic('O'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
760 case Magic('w'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
761 case Magic('W'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
762 case Magic('h'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
763 case Magic('H'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
764 case Magic('a'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
765 case Magic('A'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
766 case Magic('l'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
767 case Magic('L'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
768 case Magic('u'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
769 case Magic('U'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
770 p = vim_strchr(classchars, no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
771 if (p == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
772 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
773 EMSGN("INTERNAL: Unknown character class char: %ld", c);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
774 return FAIL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
775 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
776 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
777 /* When '.' is followed by a composing char ignore the dot, so that
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
778 * the composing char is matched here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr()))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780 {
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
781 old_regparse = regparse;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
782 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783 goto nfa_do_multibyte;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
784 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
785 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
786 EMIT(nfa_classcodes[p - classchars]);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
787 if (extra == ADD_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
788 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
789 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
790 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
791 regflags |= RF_HASNL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
792 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
793 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795 case Magic('n'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
796 if (reg_string)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
797 /* In a string "\n" matches a newline character. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
798 EMIT(NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
799 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
800 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
801 /* In buffer text "\n" matches the end of a line. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
802 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
803 regflags |= RF_HASNL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
804 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
805 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
806
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
807 case Magic('('):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
808 if (nfa_reg(REG_PAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
809 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
810 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
811
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
812 case Magic('|'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
813 case Magic('&'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
814 case Magic(')'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
815 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
816 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
817 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
818
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
819 case Magic('='):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
820 case Magic('?'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
821 case Magic('+'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
822 case Magic('@'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
823 case Magic('*'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
824 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
825 /* these should follow an atom, not form an atom */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
826 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
827 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
828 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
829
4714
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
830 case Magic('~'):
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
831 {
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
832 char_u *lp;
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
833
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
834 /* Previous substitute pattern.
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
835 * Generated as "\%(pattern\)". */
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
836 if (reg_prev_sub == NULL)
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
837 {
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
838 EMSG(_(e_nopresub));
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
839 return FAIL;
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
840 }
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
841 for (lp = reg_prev_sub; *lp != NUL; mb_cptr_adv(lp))
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
842 {
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
843 EMIT(PTR2CHAR(lp));
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
844 if (lp != reg_prev_sub)
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
845 EMIT(NFA_CONCAT);
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
846 }
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
847 EMIT(NFA_NOPEN);
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
848 break;
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
849 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
850
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
851 case Magic('1'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
852 case Magic('2'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
853 case Magic('3'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
854 case Magic('4'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
855 case Magic('5'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
856 case Magic('6'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
857 case Magic('7'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
858 case Magic('8'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
859 case Magic('9'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
860 EMIT(NFA_BACKREF1 + (no_Magic(c) - '1'));
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
861 nfa_has_backref = TRUE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
862 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
863
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
864 case Magic('z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
865 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
866 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
867 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
868 case 's':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
869 EMIT(NFA_ZSTART);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
870 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
871 case 'e':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
872 EMIT(NFA_ZEND);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
873 nfa_has_zend = TRUE;
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
874 break;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
875 #ifdef FEAT_SYN_HL
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
876 case '1':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
877 case '2':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
878 case '3':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
879 case '4':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
880 case '5':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
881 case '6':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
882 case '7':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
883 case '8':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
884 case '9':
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
885 /* \z1...\z9 */
4688
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
886 if (reg_do_extmatch != REX_USE)
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
887 EMSG_RET_FAIL(_(e_z1_not_allowed));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
888 EMIT(NFA_ZREF1 + (no_Magic(c) - '1'));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
889 /* No need to set nfa_has_backref, the sub-matches don't
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
890 * change when \z1 .. \z9 matches or not. */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
891 re_has_z = REX_USE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
892 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
893 case '(':
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
894 /* \z( */
4688
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
895 if (reg_do_extmatch != REX_SET)
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
896 EMSG_RET_FAIL(_(e_z_not_allowed));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
897 if (nfa_reg(REG_ZPAREN) == FAIL)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
898 return FAIL; /* cascaded error */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
899 re_has_z = REX_SET;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
900 break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
901 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
902 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
903 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
904 EMSGN(_("E867: (NFA) Unknown operator '\\z%c'"),
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
905 no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
906 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
907 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
908 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
909
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
910 case Magic('%'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
911 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
912 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
913 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
914 /* () without a back reference */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
915 case '(':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
916 if (nfa_reg(REG_NPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
917 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
918 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
919 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
920
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
921 case 'd': /* %d123 decimal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
922 case 'o': /* %o123 octal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
923 case 'x': /* %xab hex 2 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
924 case 'u': /* %uabcd hex 4 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
925 case 'U': /* %U1234abcd hex 8 */
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
926 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
927 int nr;
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
928
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
929 switch (c)
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
930 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
931 case 'd': nr = getdecchrs(); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
932 case 'o': nr = getoctchrs(); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
933 case 'x': nr = gethexchrs(2); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
934 case 'u': nr = gethexchrs(4); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
935 case 'U': nr = gethexchrs(8); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
936 default: nr = -1; break;
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
937 }
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
938
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
939 if (nr < 0)
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
940 EMSG2_RET_FAIL(
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
941 _("E678: Invalid character after %s%%[dxouU]"),
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
942 reg_magic == MAGIC_ALL);
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
943 /* TODO: what if a composing character follows? */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
944 EMIT(nr);
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
945 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
946 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
947
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
948 /* Catch \%^ and \%$ regardless of where they appear in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
949 * pattern -- regardless of whether or not it makes sense. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
950 case '^':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
951 EMIT(NFA_BOF);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
952 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
953
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
954 case '$':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
955 EMIT(NFA_EOF);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
956 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
957
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
958 case '#':
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
959 EMIT(NFA_CURSOR);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
960 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
961
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
962 case 'V':
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
963 /* TODO: not supported yet */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
964 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
965 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
966
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
967 case '[':
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
968 /* TODO: \%[abc] not supported yet */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
969 return FAIL;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
970
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
971 default:
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
972 {
4655
779ca415f8e1 updated for version 7.3.1075
Bram Moolenaar <bram@vim.org>
parents: 4651
diff changeset
973 int n = 0;
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
974 int cmp = c;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
975
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
976 if (c == '<' || c == '>')
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
977 c = getchr();
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
978 while (VIM_ISDIGIT(c))
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
979 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
980 n = n * 10 + (c - '0');
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
981 c = getchr();
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
982 }
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
983 if (c == 'l' || c == 'c' || c == 'v')
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
984 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
985 EMIT(n);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
986 if (c == 'l')
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
987 EMIT(cmp == '<' ? NFA_LNUM_LT :
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
988 cmp == '>' ? NFA_LNUM_GT : NFA_LNUM);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
989 else if (c == 'c')
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
990 EMIT(cmp == '<' ? NFA_COL_LT :
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
991 cmp == '>' ? NFA_COL_GT : NFA_COL);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
992 else
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
993 EMIT(cmp == '<' ? NFA_VCOL_LT :
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
994 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
995 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
996 }
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
997 else if (c == '\'')
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
998 /* TODO: \%'m not supported yet */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
999 return FAIL;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1000 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1001 syntax_error = TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1002 EMSGN(_("E867: (NFA) Unknown operator '\\%%%c'"),
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1003 no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1004 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1005 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1006 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1007
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1008 case Magic('['):
4517
9a2183bd8295 updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents: 4515
diff changeset
1009 collection:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1010 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1011 * Glue is emitted between several atoms from the [].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1012 * It is either NFA_OR, or NFA_CONCAT.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1013 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1014 * [abc] expands to 'a b NFA_OR c NFA_OR' (in postfix notation)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1015 * [^abc] expands to 'a NFA_NOT b NFA_NOT NFA_CONCAT c NFA_NOT
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1016 * NFA_CONCAT NFA_END_NEG_RANGE NFA_CONCAT' (in postfix
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1017 * notation)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1018 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1019 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1020
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1021
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1022 /* Emit negation atoms, if needed.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1023 * The CONCAT below merges the NOT with the previous node. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1024 #define TRY_NEG() \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1025 if (negated == TRUE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1026 { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1027 EMIT(NFA_NOT); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1028 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1029
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1030 /* Emit glue between important nodes : CONCAT or OR. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1031 #define EMIT_GLUE() \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1032 if (first == FALSE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1033 EMIT(glue); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1034 else \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1035 first = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1036
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1037 p = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1038 endp = skip_anyof(p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1039 if (*endp == ']')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1040 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1041 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1042 * Try to reverse engineer character classes. For example,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1043 * recognize that [0-9] stands for \d and [A-Za-z_] with \h,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1044 * and perform the necessary substitutions in the NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1045 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1046 result = nfa_recognize_char_class(regparse, endp,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1047 extra == ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1048 if (result != FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1049 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1050 if (result >= NFA_DIGIT && result <= NFA_NUPPER)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1051 EMIT(result);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1052 else /* must be char class + newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1053 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1054 EMIT(result - ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1055 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1056 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1057 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1058 regparse = endp;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1059 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1060 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1061 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1062 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1063 * Failed to recognize a character class. Use the simple
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1064 * version that turns [abc] into 'a' OR 'b' OR 'c'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1065 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1066 startc = endc = oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1067 first = TRUE; /* Emitting first atom in this sequence? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1068 negated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1069 glue = NFA_OR;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1070 if (*regparse == '^') /* negated range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1071 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1072 negated = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1073 glue = NFA_CONCAT;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1074 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1075 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1076 if (*regparse == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1077 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1078 startc = '-';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1079 EMIT(startc);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1080 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1081 EMIT_GLUE();
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1082 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1083 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1084 /* Emit the OR branches for each character in the [] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1085 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1086 while (regparse < endp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1087 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1088 oldstartc = startc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1089 startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1090 got_coll_char = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1091 if (*regparse == '[')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1092 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1093 /* Check for [: :], [= =], [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1094 equiclass = collclass = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1095 charclass = get_char_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1096 if (charclass == CLASS_NONE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1097 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1098 equiclass = get_equi_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1099 if (equiclass == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1100 collclass = get_coll_element(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1101 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1102
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1103 /* Character class like [:alpha:] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1104 if (charclass != CLASS_NONE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1105 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1106 switch (charclass)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1107 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1108 case CLASS_ALNUM:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1109 EMIT(NFA_CLASS_ALNUM);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1110 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1111 case CLASS_ALPHA:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1112 EMIT(NFA_CLASS_ALPHA);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1113 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1114 case CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1115 EMIT(NFA_CLASS_BLANK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1116 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1117 case CLASS_CNTRL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1118 EMIT(NFA_CLASS_CNTRL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1119 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1120 case CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1121 EMIT(NFA_CLASS_DIGIT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1122 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1123 case CLASS_GRAPH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1124 EMIT(NFA_CLASS_GRAPH);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1125 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1126 case CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1127 EMIT(NFA_CLASS_LOWER);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1128 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1129 case CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1130 EMIT(NFA_CLASS_PRINT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1131 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1132 case CLASS_PUNCT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1133 EMIT(NFA_CLASS_PUNCT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1134 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1135 case CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1136 EMIT(NFA_CLASS_SPACE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1137 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1138 case CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1139 EMIT(NFA_CLASS_UPPER);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1140 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1141 case CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1142 EMIT(NFA_CLASS_XDIGIT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1143 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1144 case CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1145 EMIT(NFA_CLASS_TAB);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1146 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1147 case CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1148 EMIT(NFA_CLASS_RETURN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1149 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1150 case CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1151 EMIT(NFA_CLASS_BACKSPACE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1152 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1153 case CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1154 EMIT(NFA_CLASS_ESCAPE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1155 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1156 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1157 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1158 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1159 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1160 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1161 /* Try equivalence class [=a=] and the like */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1162 if (equiclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1163 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1164 result = nfa_emit_equi_class(equiclass, negated);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1165 if (result == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1166 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1167 /* should never happen */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1168 EMSG_RET_FAIL(_("E868: Error building NFA with equivalence class!"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1169 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1170 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1171 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1172 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1173 /* Try collating class like [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1174 if (collclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1175 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1176 startc = collclass; /* allow [.a.]-x as a range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1177 /* Will emit the proper atom at the end of the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1178 * while loop. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1179 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1180 }
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1181 /* Try a range like 'a-x' or '\t-z'. Also allows '-' as a
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1182 * start character. */
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1183 if (*regparse == '-' && oldstartc != -1)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1184 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1185 emit_range = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1186 startc = oldstartc;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1187 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1188 continue; /* reading the end of the range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1189 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1190
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1191 /* Now handle simple and escaped characters.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1192 * Only "\]", "\^", "\]" and "\\" are special in Vi. Vim
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1193 * accepts "\t", "\e", etc., but only when the 'l' flag in
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1194 * 'cpoptions' is not included.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1195 * Posix doesn't recognize backslash at all.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1196 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1197 if (*regparse == '\\'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1198 && !cpo_bsl
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1199 && regparse + 1 <= endp
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1200 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1201 || (!cpo_lit
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1202 && vim_strchr(REGEXP_ABBR, regparse[1])
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1203 != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1204 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1205 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1206 {
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1207 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1208
4507
9dbbddb2ed10 updated for version 7.3.1001
Bram Moolenaar <bram@vim.org>
parents: 4503
diff changeset
1209 if (*regparse == 'n')
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1210 startc = reg_string ? NL : NFA_NEWL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1211 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1212 if (*regparse == 'd'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1213 || *regparse == 'o'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1214 || *regparse == 'x'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1215 || *regparse == 'u'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1216 || *regparse == 'U'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1217 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1218 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1219 /* TODO(RE) This needs more testing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1220 startc = coll_get_char();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1221 got_coll_char = TRUE;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1222 mb_ptr_back(old_regparse, regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1223 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1224 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1225 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1226 /* \r,\t,\e,\b */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1227 startc = backslash_trans(*regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1228 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1229 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1230
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1231 /* Normal printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1232 if (startc == -1)
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1233 startc = PTR2CHAR(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1234
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1235 /* Previous char was '-', so this char is end of range. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1236 if (emit_range)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1237 {
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1238 endc = startc;
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1239 startc = oldstartc;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1240 if (startc > endc)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1241 EMSG_RET_FAIL(_(e_invrange));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1242 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1243 if (has_mbyte && ((*mb_char2len)(startc) > 1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1244 || (*mb_char2len)(endc) > 1))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1245 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1246 if (endc > startc + 256)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1247 EMSG_RET_FAIL(_(e_invrange));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1248 /* Emit the range. "startc" was already emitted, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1249 * skip it. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1250 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1251 {
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1252 EMIT(c);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1253 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1254 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1255 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1256 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1257 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1258 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1259 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1260 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1261 int alpha_only = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1262
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1263 /* for alphabetical range skip the gaps
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1264 * 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1265 if (isalpha(startc) && isalpha(endc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1266 alpha_only = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1267 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1268 /* Emit the range. "startc" was already emitted, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1269 * skip it. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1270 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1271 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1272 if (!alpha_only || isalpha(startc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1273 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1274 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1275 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1276 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1277 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1278 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1279 }
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1280 emit_range = FALSE;
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1281 startc = -1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1282 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1283 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1284 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1285 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1286 * This char (startc) is not part of a range. Just
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1287 * emit it.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1288 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1289 * Normally, simply emit startc. But if we get char
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1290 * code=0 from a collating char, then replace it with
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1291 * 0x0a.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1292 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1293 * This is needed to completely mimic the behaviour of
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1294 * the backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1295 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1296 if (got_coll_char == TRUE && startc == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1297 EMIT(0x0a);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1298 else
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1299 EMIT(startc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1300 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1301 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1302 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1303
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1304 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1305 } /* while (p < endp) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1306
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1307 mb_ptr_back(old_regparse, regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1308 if (*regparse == '-') /* if last, '-' is just a char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1309 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1310 EMIT('-');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1311 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1312 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1313 }
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1314 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1315
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1316 /* skip the trailing ] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1317 regparse = endp;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1318 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1319 if (negated == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1320 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1321 /* Mark end of negated char range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1322 EMIT(NFA_END_NEG_RANGE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1323 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1324 }
4615
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1325
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1326 /* \_[] also matches \n but it's not negated */
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1327 if (extra == ADD_NL)
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1328 {
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1329 EMIT(reg_string ? NL : NFA_NEWL);
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1330 EMIT(NFA_OR);
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1331 }
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1332
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1333 return OK;
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1334 } /* if exists closing ] */
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1335
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1336 if (reg_strict)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1337 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1338 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1339 EMSG_RET_FAIL(_(e_missingbracket));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1340 }
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1341 /* FALLTHROUGH */
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1342
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1343 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1344 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1345 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1346 int plen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1347
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1348 nfa_do_multibyte:
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1349 /* plen is length of current char with composing chars */
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1350 if (enc_utf8 && ((*mb_char2len)(c)
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1351 != (plen = (*mb_ptr2len)(old_regparse))
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1352 || utf_iscomposing(c)))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1353 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1354 int i = 0;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1355
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
1356 /* A base character plus composing characters, or just one
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
1357 * or more composing characters.
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1358 * This requires creating a separate atom as if enclosing
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1359 * the characters in (), where NFA_COMPOSING is the ( and
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1360 * NFA_END_COMPOSING is the ). Note that right now we are
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1361 * building the postfix form, not the NFA itself;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1362 * a composing char could be: a, b, c, NFA_COMPOSING
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1363 * where 'b' and 'c' are chars with codes > 256. */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1364 for (;;)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1365 {
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1366 EMIT(c);
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1367 if (i > 0)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1368 EMIT(NFA_CONCAT);
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1369 if ((i += utf_char2len(c)) >= plen)
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1370 break;
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1371 c = utf_ptr2char(old_regparse + i);
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1372 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1373 EMIT(NFA_COMPOSING);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1374 regparse = old_regparse + plen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1375 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1376 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1377 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1378 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1379 c = no_Magic(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1380 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1381 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1382 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1383 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1384 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1385
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1386 #undef TRY_NEG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1387 #undef EMIT_GLUE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1388
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1389 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1390 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1391
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1392 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1393 * Parse something followed by possible [*+=].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1394 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1395 * A piece is an atom, possibly followed by a multi, an indication of how many
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1396 * times the atom can be matched. Example: "a*" matches any sequence of "a"
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1397 * characters: "", "a", "aa", etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1398 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1399 * piece ::= atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1400 * or atom multi
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1401 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1402 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1403 nfa_regpiece()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1404 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1405 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1406 int op;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1407 int ret;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1408 long minval, maxval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1409 int greedy = TRUE; /* Braces are prefixed with '-' ? */
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1410 parse_state_T old_state;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1411 parse_state_T new_state;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1412 int c2;
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1413 int old_post_pos;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1414 int my_post_start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1415 int quest;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1416
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1417 /* Save the current parse state, so that we can use it if <atom>{m,n} is
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1418 * next. */
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1419 save_parse_state(&old_state);
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1420
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1421 /* 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
1422 my_post_start = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1423
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1424 ret = nfa_regatom();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1425 if (ret == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1426 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1427
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1428 op = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1429 if (re_multi_type(op) == NOT_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1430 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1431
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1432 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1433 switch (op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1434 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1435 case Magic('*'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1436 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1437 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1438
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1439 case Magic('+'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1440 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1441 * Trick: Normally, (a*)\+ would match the whole input "aaa". The
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1442 * first and only submatch would be "aaa". But the backtracking
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1443 * engine interprets the plus as "try matching one more time", and
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1444 * a* matches a second time at the end of the input, the empty
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1445 * string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1446 * The submatch will the empty string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1447 *
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1448 * 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
1449 * <atom>+ with <atom><atom>*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1450 */
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1451 restore_parse_state(&old_state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1452 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1453 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1454 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1455 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1456 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1457 skipchr(); /* skip the \+ */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1458 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1459
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1460 case Magic('@'):
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1461 c2 = getdecchrs();
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1462 op = no_Magic(getchr());
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1463 i = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1464 switch(op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1465 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1466 case '=':
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1467 /* \@= */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1468 i = NFA_PREV_ATOM_NO_WIDTH;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1469 break;
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
1470 case '!':
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1471 /* \@! */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1472 i = NFA_PREV_ATOM_NO_WIDTH_NEG;
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
1473 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1474 case '<':
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1475 op = no_Magic(getchr());
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1476 if (op == '=')
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1477 /* \@<= */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1478 i = NFA_PREV_ATOM_JUST_BEFORE;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1479 else if (op == '!')
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1480 /* \@<! */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1481 i = NFA_PREV_ATOM_JUST_BEFORE_NEG;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1482 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1483 case '>':
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1484 /* \@> Not supported yet */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1485 /* i = NFA_PREV_ATOM_LIKE_PATTERN; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1486 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1487 }
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1488 if (i == 0)
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1489 {
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1490 syntax_error = TRUE;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1491 EMSGN(_("E869: (NFA) Unknown operator '\\@%c'"), op);
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1492 return FAIL;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1493 }
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1494 EMIT(i);
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1495 if (i == NFA_PREV_ATOM_JUST_BEFORE
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1496 || i == NFA_PREV_ATOM_JUST_BEFORE_NEG)
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1497 EMIT(c2);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1498 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1499
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1500 case Magic('?'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1501 case Magic('='):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1502 EMIT(NFA_QUEST);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1503 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1504
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1505 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1506 /* a{2,5} will expand to 'aaa?a?a?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1507 * a{-1,3} will expand to 'aa??a??', where ?? is the nongreedy
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1508 * version of '?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1509 * \v(ab){2,3} will expand to '(ab)(ab)(ab)?', where all the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1510 * parenthesis have the same id
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1511 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1512
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1513 greedy = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1514 c2 = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1515 if (c2 == '-' || c2 == Magic('-'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1516 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1517 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1518 greedy = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1519 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1520 if (!read_limits(&minval, &maxval))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1521 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1522 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1523 EMSG_RET_FAIL(_("E870: (NFA regexp) Error reading repetition limits"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1524 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1525 /* <atom>{0,inf}, <atom>{0,} and <atom>{} are equivalent to
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1526 * <atom>* */
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1527 if (minval == 0 && maxval == MAX_LIMIT)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1528 {
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1529 if (greedy)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1530 /* \{}, \{0,} */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1531 EMIT(NFA_STAR);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1532 else
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1533 /* \{-}, \{-0,} */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1534 EMIT(NFA_STAR_NONGREEDY);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1535 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1536 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1537
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1538 /* Special case: x{0} or x{-0} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1539 if (maxval == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1540 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1541 /* 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
1542 post_ptr = post_start + my_post_start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1543 /* NFA_SKIP_CHAR has 0-length and works everywhere */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1544 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1545 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1546 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1547
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1548 /* Ignore previous call to nfa_regatom() */
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1549 post_ptr = post_start + my_post_start;
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1550 /* Save parse state after the repeated atom and the \{} */
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1551 save_parse_state(&new_state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1552
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1553 quest = (greedy == TRUE? NFA_QUEST : NFA_QUEST_NONGREEDY);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1554 for (i = 0; i < maxval; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1555 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1556 /* Goto beginning of the repeated atom */
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1557 restore_parse_state(&old_state);
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1558 old_post_pos = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1559 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1560 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1561 /* after "minval" times, atoms are optional */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1562 if (i + 1 > minval)
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1563 {
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1564 if (maxval == MAX_LIMIT)
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1565 {
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1566 if (greedy)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1567 EMIT(NFA_STAR);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1568 else
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1569 EMIT(NFA_STAR_NONGREEDY);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1570 }
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1571 else
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1572 EMIT(quest);
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1573 }
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1574 if (old_post_pos != my_post_start)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1575 EMIT(NFA_CONCAT);
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1576 if (i + 1 > minval && maxval == MAX_LIMIT)
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1577 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1578 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1579
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1580 /* 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
1581 restore_parse_state(&new_state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1582 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1583
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1584 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1585
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1586
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1587 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1588 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1589 } /* end switch */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1590
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1591 if (re_multi_type(peekchr()) != NOT_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1592 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1593 /* Can't have a multi follow a multi. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1594 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1595 EMSG_RET_FAIL(_("E871: (NFA regexp) Can't have a multi follow a multi !"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1596 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1597
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1598 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1599 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1600
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1601 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1602 * Parse one or more pieces, concatenated. It matches a match for the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1603 * first piece, followed by a match for the second piece, etc. Example:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1604 * "f[0-9]b", first matches "f", then a digit and then "b".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1605 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1606 * concat ::= piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1607 * or piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1608 * or piece piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1609 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1610 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1611 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1612 nfa_regconcat()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1613 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1614 int cont = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1615 int first = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1616
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1617 while (cont)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1618 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1619 switch (peekchr())
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1620 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1621 case NUL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1622 case Magic('|'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1623 case Magic('&'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1624 case Magic(')'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1625 cont = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1626 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1627
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1628 case Magic('Z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1629 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1630 regflags |= RF_ICOMBINE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1631 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1632 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1633 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1634 case Magic('c'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1635 regflags |= RF_ICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1636 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1637 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1638 case Magic('C'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1639 regflags |= RF_NOICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1640 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1641 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1642 case Magic('v'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1643 reg_magic = MAGIC_ALL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1644 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1645 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1646 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1647 case Magic('m'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1648 reg_magic = MAGIC_ON;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1649 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1650 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1651 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1652 case Magic('M'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1653 reg_magic = MAGIC_OFF;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1654 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1655 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1656 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1657 case Magic('V'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1658 reg_magic = MAGIC_NONE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1659 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1660 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1661 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1662
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1663 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1664 if (nfa_regpiece() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1665 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1666 if (first == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1667 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1668 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1669 first = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1670 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1671 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1672 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1673
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1674 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1675 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1676
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1677 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1678 * Parse a branch, one or more concats, separated by "\&". It matches the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1679 * last concat, but only if all the preceding concats also match at the same
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1680 * position. Examples:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1681 * "foobeep\&..." matches "foo" in "foobeep".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1682 * ".*Peter\&.*Bob" matches in a line containing both "Peter" and "Bob"
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1683 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1684 * branch ::= concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1685 * or concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1686 * or concat \& concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1687 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1688 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1689 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1690 nfa_regbranch()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1691 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1692 int ch;
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1693 int old_post_pos;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1694
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1695 old_post_pos = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1696
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1697 /* First branch, possibly the only one */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1698 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1699 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1700
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1701 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1702 /* Try next concats */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1703 while (ch == Magic('&'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1704 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1705 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1706 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1707 EMIT(NFA_PREV_ATOM_NO_WIDTH);
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1708 old_post_pos = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1709 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1710 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1711 /* if concat is empty, skip a input char. But do emit a node */
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1712 if (old_post_pos == (int)(post_ptr - post_start))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1713 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1714 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1715 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1716 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1717
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1718 /* Even 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
1719 if (old_post_pos == (int)(post_ptr - post_start))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1720 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1721
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1722 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1723 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1724
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1725 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1726 * Parse a pattern, one or more branches, separated by "\|". It matches
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1727 * anything that matches one of the branches. Example: "foo\|beep" matches
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1728 * "foo" and matches "beep". If more than one branch matches, the first one
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1729 * is used.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1730 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1731 * pattern ::= branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1732 * or branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1733 * or branch \| branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1734 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1735 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1736 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1737 nfa_reg(paren)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1738 int paren; /* REG_NOPAREN, REG_PAREN, REG_NPAREN or REG_ZPAREN */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1739 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1740 int parno = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1741
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1742 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1743 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1744 if (regnpar >= NSUBEXP) /* Too many `(' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1745 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1746 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1747 EMSG_RET_FAIL(_("E872: (NFA regexp) Too many '('"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1748 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1749 parno = regnpar++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1750 }
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1751 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1752 else if (paren == REG_ZPAREN)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1753 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1754 /* Make a ZOPEN node. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1755 if (regnzpar >= NSUBEXP)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1756 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1757 syntax_error = TRUE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1758 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
1759 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1760 parno = regnzpar++;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1761 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1762 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1763
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1764 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1765 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1766
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1767 while (peekchr() == Magic('|'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1768 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1769 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1770 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1771 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1772 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1773 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1774
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1775 /* Check for proper termination. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1776 if (paren != REG_NOPAREN && getchr() != Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1777 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1778 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1779 if (paren == REG_NPAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1780 EMSG2_RET_FAIL(_(e_unmatchedpp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1781 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1782 EMSG2_RET_FAIL(_(e_unmatchedp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1783 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1784 else if (paren == REG_NOPAREN && peekchr() != NUL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1785 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1786 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1787 if (peekchr() == Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1788 EMSG2_RET_FAIL(_(e_unmatchedpar), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1789 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1790 EMSG_RET_FAIL(_("E873: (NFA regexp) proper termination error"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1791 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1792 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1793 * Here we set the flag allowing back references to this set of
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1794 * parentheses.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1795 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1796 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1797 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1798 had_endbrace[parno] = TRUE; /* have seen the close paren */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1799 EMIT(NFA_MOPEN + parno);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1800 }
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1801 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1802 else if (paren == REG_ZPAREN)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1803 EMIT(NFA_ZOPEN + parno);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1804 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1805
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1806 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1807 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1808
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1809 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1810 static char_u code[50];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1811
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1812 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1813 nfa_set_code(c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1814 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1815 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1816 int addnl = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1817
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1818 if (c >= NFA_FIRST_NL && c <= NFA_LAST_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1819 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1820 addnl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1821 c -= ADD_NL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1822 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1823
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1824 STRCPY(code, "");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1825 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1826 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1827 case NFA_MATCH: STRCPY(code, "NFA_MATCH "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1828 case NFA_SPLIT: STRCPY(code, "NFA_SPLIT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1829 case NFA_CONCAT: STRCPY(code, "NFA_CONCAT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1830 case NFA_NEWL: STRCPY(code, "NFA_NEWL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1831 case NFA_ZSTART: STRCPY(code, "NFA_ZSTART"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1832 case NFA_ZEND: STRCPY(code, "NFA_ZEND"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1833
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1834 case NFA_BACKREF1: STRCPY(code, "NFA_BACKREF1"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1835 case NFA_BACKREF2: STRCPY(code, "NFA_BACKREF2"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1836 case NFA_BACKREF3: STRCPY(code, "NFA_BACKREF3"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1837 case NFA_BACKREF4: STRCPY(code, "NFA_BACKREF4"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1838 case NFA_BACKREF5: STRCPY(code, "NFA_BACKREF5"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1839 case NFA_BACKREF6: STRCPY(code, "NFA_BACKREF6"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1840 case NFA_BACKREF7: STRCPY(code, "NFA_BACKREF7"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1841 case NFA_BACKREF8: STRCPY(code, "NFA_BACKREF8"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1842 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
1843 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1844 case NFA_ZREF1: STRCPY(code, "NFA_ZREF1"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1845 case NFA_ZREF2: STRCPY(code, "NFA_ZREF2"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1846 case NFA_ZREF3: STRCPY(code, "NFA_ZREF3"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1847 case NFA_ZREF4: STRCPY(code, "NFA_ZREF4"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1848 case NFA_ZREF5: STRCPY(code, "NFA_ZREF5"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1849 case NFA_ZREF6: STRCPY(code, "NFA_ZREF6"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1850 case NFA_ZREF7: STRCPY(code, "NFA_ZREF7"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1851 case NFA_ZREF8: STRCPY(code, "NFA_ZREF8"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1852 case NFA_ZREF9: STRCPY(code, "NFA_ZREF9"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1853 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1854 case NFA_SKIP: STRCPY(code, "NFA_SKIP"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1855
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1856 case NFA_PREV_ATOM_NO_WIDTH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1857 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
1858 case NFA_PREV_ATOM_NO_WIDTH_NEG:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1859 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
1860 case NFA_PREV_ATOM_JUST_BEFORE:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1861 STRCPY(code, "NFA_PREV_ATOM_JUST_BEFORE"); break;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1862 case NFA_PREV_ATOM_JUST_BEFORE_NEG:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1863 STRCPY(code, "NFA_PREV_ATOM_JUST_BEFORE_NEG"); break;
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
1864 case NFA_NOPEN: STRCPY(code, "NFA_NOPEN"); break;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
1865 case NFA_NCLOSE: STRCPY(code, "NFA_NCLOSE"); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1866 case NFA_START_INVISIBLE: STRCPY(code, "NFA_START_INVISIBLE"); break;
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1867 case NFA_START_INVISIBLE_BEFORE:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1868 STRCPY(code, "NFA_START_INVISIBLE_BEFORE"); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1869 case NFA_END_INVISIBLE: STRCPY(code, "NFA_END_INVISIBLE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1870
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1871 case NFA_COMPOSING: STRCPY(code, "NFA_COMPOSING"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1872 case NFA_END_COMPOSING: STRCPY(code, "NFA_END_COMPOSING"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1873
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1874 case NFA_MOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1875 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1876 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1877 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1878 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1879 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1880 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1881 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1882 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1883 case NFA_MOPEN9:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1884 STRCPY(code, "NFA_MOPEN(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1885 code[10] = c - NFA_MOPEN + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1886 break;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1887 case NFA_MCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1888 case NFA_MCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1889 case NFA_MCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1890 case NFA_MCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1891 case NFA_MCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1892 case NFA_MCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1893 case NFA_MCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1894 case NFA_MCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1895 case NFA_MCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1896 case NFA_MCLOSE9:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1897 STRCPY(code, "NFA_MCLOSE(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1898 code[11] = c - NFA_MCLOSE + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1899 break;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1900 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1901 case NFA_ZOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1902 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1903 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1904 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1905 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1906 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1907 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1908 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1909 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1910 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1911 STRCPY(code, "NFA_ZOPEN(x)");
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1912 code[10] = c - NFA_ZOPEN + '0';
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1913 break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1914 case NFA_ZCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1915 case NFA_ZCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1916 case NFA_ZCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1917 case NFA_ZCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1918 case NFA_ZCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1919 case NFA_ZCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1920 case NFA_ZCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1921 case NFA_ZCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1922 case NFA_ZCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1923 case NFA_ZCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1924 STRCPY(code, "NFA_ZCLOSE(x)");
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1925 code[11] = c - NFA_ZCLOSE + '0';
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1926 break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1927 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1928 case NFA_EOL: STRCPY(code, "NFA_EOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1929 case NFA_BOL: STRCPY(code, "NFA_BOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1930 case NFA_EOW: STRCPY(code, "NFA_EOW "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1931 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
1932 case NFA_EOF: STRCPY(code, "NFA_EOF "); break;
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
1933 case NFA_BOF: STRCPY(code, "NFA_BOF "); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1934 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
1935 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
1936 case NFA_QUEST: STRCPY(code, "NFA_QUEST"); break;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1937 case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1938 case NFA_NOT: STRCPY(code, "NFA_NOT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1939 case NFA_SKIP_CHAR: STRCPY(code, "NFA_SKIP_CHAR"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1940 case NFA_OR: STRCPY(code, "NFA_OR"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1941 case NFA_END_NEG_RANGE: STRCPY(code, "NFA_END_NEG_RANGE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1942 case NFA_CLASS_ALNUM: STRCPY(code, "NFA_CLASS_ALNUM"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1943 case NFA_CLASS_ALPHA: STRCPY(code, "NFA_CLASS_ALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1944 case NFA_CLASS_BLANK: STRCPY(code, "NFA_CLASS_BLANK"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1945 case NFA_CLASS_CNTRL: STRCPY(code, "NFA_CLASS_CNTRL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1946 case NFA_CLASS_DIGIT: STRCPY(code, "NFA_CLASS_DIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1947 case NFA_CLASS_GRAPH: STRCPY(code, "NFA_CLASS_GRAPH"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1948 case NFA_CLASS_LOWER: STRCPY(code, "NFA_CLASS_LOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1949 case NFA_CLASS_PRINT: STRCPY(code, "NFA_CLASS_PRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1950 case NFA_CLASS_PUNCT: STRCPY(code, "NFA_CLASS_PUNCT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1951 case NFA_CLASS_SPACE: STRCPY(code, "NFA_CLASS_SPACE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1952 case NFA_CLASS_UPPER: STRCPY(code, "NFA_CLASS_UPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1953 case NFA_CLASS_XDIGIT: STRCPY(code, "NFA_CLASS_XDIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1954 case NFA_CLASS_TAB: STRCPY(code, "NFA_CLASS_TAB"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1955 case NFA_CLASS_RETURN: STRCPY(code, "NFA_CLASS_RETURN"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1956 case NFA_CLASS_BACKSPACE: STRCPY(code, "NFA_CLASS_BACKSPACE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1957 case NFA_CLASS_ESCAPE: STRCPY(code, "NFA_CLASS_ESCAPE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1958
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1959 case NFA_ANY: STRCPY(code, "NFA_ANY"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1960 case NFA_IDENT: STRCPY(code, "NFA_IDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1961 case NFA_SIDENT:STRCPY(code, "NFA_SIDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1962 case NFA_KWORD: STRCPY(code, "NFA_KWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1963 case NFA_SKWORD:STRCPY(code, "NFA_SKWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1964 case NFA_FNAME: STRCPY(code, "NFA_FNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1965 case NFA_SFNAME:STRCPY(code, "NFA_SFNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1966 case NFA_PRINT: STRCPY(code, "NFA_PRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1967 case NFA_SPRINT:STRCPY(code, "NFA_SPRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1968 case NFA_WHITE: STRCPY(code, "NFA_WHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1969 case NFA_NWHITE:STRCPY(code, "NFA_NWHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1970 case NFA_DIGIT: STRCPY(code, "NFA_DIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1971 case NFA_NDIGIT:STRCPY(code, "NFA_NDIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1972 case NFA_HEX: STRCPY(code, "NFA_HEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1973 case NFA_NHEX: STRCPY(code, "NFA_NHEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1974 case NFA_OCTAL: STRCPY(code, "NFA_OCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1975 case NFA_NOCTAL:STRCPY(code, "NFA_NOCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1976 case NFA_WORD: STRCPY(code, "NFA_WORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1977 case NFA_NWORD: STRCPY(code, "NFA_NWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1978 case NFA_HEAD: STRCPY(code, "NFA_HEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1979 case NFA_NHEAD: STRCPY(code, "NFA_NHEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1980 case NFA_ALPHA: STRCPY(code, "NFA_ALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1981 case NFA_NALPHA:STRCPY(code, "NFA_NALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1982 case NFA_LOWER: STRCPY(code, "NFA_LOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1983 case NFA_NLOWER:STRCPY(code, "NFA_NLOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1984 case NFA_UPPER: STRCPY(code, "NFA_UPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1985 case NFA_NUPPER:STRCPY(code, "NFA_NUPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1986
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1987 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1988 STRCPY(code, "CHAR(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1989 code[5] = c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1990 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1991
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1992 if (addnl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1993 STRCAT(code, " + NEWLINE ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1994
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1995 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1996
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1997 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1998 static FILE *log_fd;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1999
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2000 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2001 * Print the postfix notation of the current regexp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2002 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2003 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2004 nfa_postfix_dump(expr, retval)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2005 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2006 int retval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2007 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2008 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2009 FILE *f;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2010
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2011 f = fopen(NFA_REGEXP_DUMP_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2012 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2013 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2014 fprintf(f, "\n-------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2015 if (retval == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2016 fprintf(f, ">>> NFA engine failed ... \n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2017 else if (retval == OK)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2018 fprintf(f, ">>> NFA engine succeeded !\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2019 fprintf(f, "Regexp: \"%s\"\nPostfix notation (char): \"", expr);
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2020 for (p = post_start; *p && p < post_end; p++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2021 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2022 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2023 fprintf(f, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2024 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2025 fprintf(f, "\"\nPostfix notation (int): ");
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2026 for (p = post_start; *p && p < post_end; p++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2027 fprintf(f, "%d ", *p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2028 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2029 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2030 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2031 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2032
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2033 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2034 * Print the NFA starting with a root node "state".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2035 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2036 static void
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2037 nfa_print_state(debugf, state)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2038 FILE *debugf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2039 nfa_state_T *state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2040 {
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2041 garray_T indent;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2042
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2043 ga_init2(&indent, 1, 64);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2044 ga_append(&indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2045 nfa_print_state2(debugf, state, &indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2046 ga_clear(&indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2047 }
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2048
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2049 static void
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2050 nfa_print_state2(debugf, state, indent)
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2051 FILE *debugf;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2052 nfa_state_T *state;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2053 garray_T *indent;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2054 {
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2055 char_u *p;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2056
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2057 if (state == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2058 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2059
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2060 fprintf(debugf, "(%2d)", abs(state->id));
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2061
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2062 /* Output indent */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2063 p = (char_u *)indent->ga_data;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2064 if (indent->ga_len >= 3)
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2065 {
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2066 int last = indent->ga_len - 3;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2067 char_u save[2];
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2068
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2069 STRNCPY(save, &p[last], 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2070 STRNCPY(&p[last], "+-", 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2071 fprintf(debugf, " %s", p);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2072 STRNCPY(&p[last], save, 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2073 }
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2074 else
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2075 fprintf(debugf, " %s", p);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2076
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2077 nfa_set_code(state->c);
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2078 fprintf(debugf, "%s%s (%d) (id=%d)\n",
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2079 state->negated ? "NOT " : "", code, state->c, abs(state->id));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2080 if (state->id < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2081 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2082
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2083 state->id = abs(state->id) * -1;
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2084
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2085 /* grow indent for state->out */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2086 indent->ga_len -= 1;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2087 if (state->out1)
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
2088 ga_concat(indent, (char_u *)"| ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2089 else
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
2090 ga_concat(indent, (char_u *)" ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2091 ga_append(indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2092
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2093 nfa_print_state2(debugf, state->out, indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2094
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2095 /* replace last part of indent for state->out1 */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2096 indent->ga_len -= 3;
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
2097 ga_concat(indent, (char_u *)" ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2098 ga_append(indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2099
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2100 nfa_print_state2(debugf, state->out1, indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2101
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2102 /* shrink indent */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2103 indent->ga_len -= 3;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2104 ga_append(indent, '\0');
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2105 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2106
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2107 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2108 * Print the NFA state machine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2109 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2110 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2111 nfa_dump(prog)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2112 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2113 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2114 FILE *debugf = fopen(NFA_REGEXP_DUMP_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2115
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2116 if (debugf != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2117 {
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2118 nfa_print_state(debugf, prog->start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2119 fclose(debugf);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2120 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2121 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2122 #endif /* ENABLE_LOG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2123 #endif /* DEBUG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2124
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2125 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2126 * Parse r.e. @expr and convert it into postfix form.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2127 * Return the postfix string on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2128 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2129 static int *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2130 re2post()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2131 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2132 if (nfa_reg(REG_NOPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2133 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2134 EMIT(NFA_MOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2135 return post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2136 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2137
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2138 /* NB. Some of the code below is inspired by Russ's. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2139
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2140 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2141 * Represents an NFA state plus zero or one or two arrows exiting.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2142 * if c == MATCH, no arrows out; matching state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2143 * If c == SPLIT, unlabeled arrows to out and out1 (if != NULL).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2144 * If c < 256, labeled arrow with character c to out.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2145 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2146
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2147 static nfa_state_T *state_ptr; /* points to nfa_prog->state */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2148
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2149 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2150 * Allocate and initialize nfa_state_T.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2151 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2152 static nfa_state_T *
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2153 alloc_state(c, out, out1)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2154 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2155 nfa_state_T *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2156 nfa_state_T *out1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2157 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2158 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2159
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2160 if (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2161 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2162
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2163 s = &state_ptr[istate++];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2164
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2165 s->c = c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2166 s->out = out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2167 s->out1 = out1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2168
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2169 s->id = istate;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
2170 s->lastlist[0] = 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
2171 s->lastlist[1] = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2172 s->negated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2173
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2174 return s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2175 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2176
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2177 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2178 * A partially built NFA without the matching state filled in.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2179 * Frag_T.start points at the start state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2180 * Frag_T.out is a list of places that need to be set to the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2181 * next state for this fragment.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2182 */
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2183
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2184 /* Since the out pointers in the list are always
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2185 * uninitialized, we use the pointers themselves
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2186 * as storage for the Ptrlists. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2187 typedef union Ptrlist Ptrlist;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2188 union Ptrlist
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2189 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2190 Ptrlist *next;
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2191 nfa_state_T *s;
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2192 };
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2193
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2194 struct Frag
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2195 {
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2196 nfa_state_T *start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2197 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2198 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2199 typedef struct Frag Frag_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2200
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2201 static Frag_T frag __ARGS((nfa_state_T *start, Ptrlist *out));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2202 static Ptrlist *list1 __ARGS((nfa_state_T **outp));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2203 static void patch __ARGS((Ptrlist *l, nfa_state_T *s));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2204 static Ptrlist *append __ARGS((Ptrlist *l1, Ptrlist *l2));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2205 static void st_push __ARGS((Frag_T s, Frag_T **p, Frag_T *stack_end));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2206 static Frag_T st_pop __ARGS((Frag_T **p, Frag_T *stack));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2207
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2208 /*
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2209 * Initialize a Frag_T struct and return it.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2210 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2211 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2212 frag(start, out)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2213 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2214 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2215 {
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2216 Frag_T n;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2217
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2218 n.start = start;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2219 n.out = out;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2220 return n;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2221 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2222
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2223 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2224 * Create singleton list containing just outp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2225 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2226 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2227 list1(outp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2228 nfa_state_T **outp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2229 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2230 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2231
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2232 l = (Ptrlist *)outp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2233 l->next = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2234 return l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2235 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2236
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2237 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2238 * Patch the list of states at out to point to start.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2239 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2240 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2241 patch(l, s)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2242 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2243 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2244 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2245 Ptrlist *next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2246
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2247 for (; l; l = next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2248 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2249 next = l->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2250 l->s = s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2251 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2252 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2253
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2254
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2255 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2256 * Join the two lists l1 and l2, returning the combination.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2257 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2258 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2259 append(l1, l2)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2260 Ptrlist *l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2261 Ptrlist *l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2262 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2263 Ptrlist *oldl1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2264
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2265 oldl1 = l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2266 while (l1->next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2267 l1 = l1->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2268 l1->next = l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2269 return oldl1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2270 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2271
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2272 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2273 * Stack used for transforming postfix form into NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2274 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2275 static Frag_T empty;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2276
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2277 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2278 st_error(postfix, end, p)
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2279 int *postfix UNUSED;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2280 int *end UNUSED;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2281 int *p UNUSED;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2282 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2283 #ifdef NFA_REGEXP_ERROR_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2284 FILE *df;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2285 int *p2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2286
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2287 df = fopen(NFA_REGEXP_ERROR_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2288 if (df)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2289 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2290 fprintf(df, "Error popping the stack!\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2291 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2292 fprintf(df, "Current regexp is \"%s\"\n", nfa_regengine.expr);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2293 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2294 fprintf(df, "Postfix form is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2295 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2296 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2297 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2298 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2299 fprintf(df, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2300 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2301 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2302 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2303 for (p2 = postfix; p2 <= p; p2 ++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2304 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2305 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2306 fprintf(df, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2307 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2308 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2309 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2310 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2311 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2312 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2313 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2314 for (p2 = postfix; p2 <= p; p2 ++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2315 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2316 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2317 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2318 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2319 fprintf(df, "\n--------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2320 fclose(df);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2321 }
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2322 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2323 EMSG(_("E874: (NFA) Could not pop the stack !"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2324 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2325
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2326 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2327 * Push an item onto the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2328 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2329 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2330 st_push(s, p, stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2331 Frag_T s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2332 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2333 Frag_T *stack_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2334 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2335 Frag_T *stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2336
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2337 if (stackp >= stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2338 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2339 *stackp = s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2340 *p = *p + 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2341 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2342
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2343 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2344 * Pop an item from the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2345 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2346 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2347 st_pop(p, stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2348 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2349 Frag_T *stack;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2350 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2351 Frag_T *stackp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2352
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2353 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2354 stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2355 if (stackp < stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2356 return empty;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2357 return **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2358 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2359
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2360 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2361 * Convert a postfix form into its equivalent NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2362 * Return the NFA start state on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2363 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2364 static nfa_state_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2365 post2nfa(postfix, end, nfa_calc_size)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2366 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2367 int *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2368 int nfa_calc_size;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2369 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2370 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2371 int mopen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2372 int mclose;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2373 Frag_T *stack = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2374 Frag_T *stackp = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2375 Frag_T *stack_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2376 Frag_T e1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2377 Frag_T e2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2378 Frag_T e;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2379 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2380 nfa_state_T *s1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2381 nfa_state_T *matchstate;
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2382 nfa_state_T *ret = NULL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2383
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2384 if (postfix == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2385 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2386
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2387 #define PUSH(s) st_push((s), &stackp, stack_end)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2388 #define POP() st_pop(&stackp, stack); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2389 if (stackp < stack) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2390 { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2391 st_error(postfix, end, p); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2392 return NULL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2393 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2394
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2395 if (nfa_calc_size == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2396 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2397 /* Allocate space for the stack. Max states on the stack : nstate */
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2398 stack = (Frag_T *)lalloc((nstate + 1) * sizeof(Frag_T), TRUE);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2399 stackp = stack;
4462
a63361b90979 updated for version 7.3.979
Bram Moolenaar <bram@vim.org>
parents: 4460
diff changeset
2400 stack_end = stack + (nstate + 1);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2401 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2402
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2403 for (p = postfix; p < end; ++p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2404 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2405 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2406 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2407 case NFA_CONCAT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2408 /* Catenation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2409 * Pay attention: this operator does not exist
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2410 * in the r.e. itself (it is implicit, really).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2411 * It is added when r.e. is translated to postfix
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2412 * form in re2post().
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2413 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2414 * No new state added here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2415 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2416 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2417 /* nstate += 0; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2418 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2419 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2420 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2421 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2422 patch(e1.out, e2.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2423 PUSH(frag(e1.start, e2.out));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2424 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2425
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2426 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2427 /* Negation of a character */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2428 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2429 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2430 /* nstate += 0; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2431 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2432 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2433 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2434 e1.start->negated = TRUE;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2435 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2436 if (e1.start->c == NFA_COMPOSING)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2437 e1.start->out1->negated = TRUE;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2438 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2439 PUSH(e1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2440 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2441
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2442 case NFA_OR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2443 /* Alternation */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2444 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2445 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2446 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2447 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2448 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2449 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2450 e1 = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2451 s = alloc_state(NFA_SPLIT, e1.start, e2.start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2452 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2453 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2454 PUSH(frag(s, append(e1.out, e2.out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2455 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2456
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2457 case NFA_STAR:
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2458 /* Zero or more, prefer more */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2459 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2460 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2461 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2462 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2463 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2464 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2465 s = alloc_state(NFA_SPLIT, e.start, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2466 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2467 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2468 patch(e.out, s);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2469 PUSH(frag(s, list1(&s->out1)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2470 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2471
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2472 case NFA_STAR_NONGREEDY:
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2473 /* Zero or more, prefer zero */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2474 if (nfa_calc_size == TRUE)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2475 {
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2476 nstate++;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2477 break;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2478 }
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2479 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2480 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
2481 if (s == NULL)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2482 goto theend;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2483 patch(e.out, s);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2484 PUSH(frag(s, list1(&s->out)));
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2485 break;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2486
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2487 case NFA_QUEST:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2488 /* one or zero atoms=> greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2489 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2490 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2491 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2492 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2493 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2494 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2495 s = alloc_state(NFA_SPLIT, e.start, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2496 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2497 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2498 PUSH(frag(s, append(e.out, list1(&s->out1))));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2499 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2500
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2501 case NFA_QUEST_NONGREEDY:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2502 /* zero or one atoms => non-greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2503 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2504 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2505 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2506 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2507 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2508 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2509 s = alloc_state(NFA_SPLIT, NULL, e.start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2510 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2511 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2512 PUSH(frag(s, append(e.out, list1(&s->out))));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2513 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2514
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2515 case NFA_SKIP_CHAR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2516 /* Symbol of 0-length, Used in a repetition
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2517 * with max/min count of 0 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2518 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2519 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2520 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2521 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2522 }
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2523 s = alloc_state(NFA_SKIP_CHAR, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2524 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2525 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2526 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2527 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2528
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2529 case NFA_PREV_ATOM_NO_WIDTH:
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
2530 case NFA_PREV_ATOM_NO_WIDTH_NEG:
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2531 case NFA_PREV_ATOM_JUST_BEFORE:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2532 case NFA_PREV_ATOM_JUST_BEFORE_NEG:
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
2533 /* The \@= operator: match the preceding atom with zero width.
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
2534 * The \@! operator: no match for the preceding atom.
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2535 * The \@<= operator: match for the preceding atom.
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2536 * The \@<! operator: no match for the preceding atom.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2537 * Surrounds the preceding atom with START_INVISIBLE and
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
2538 * END_INVISIBLE, similarly to MOPEN. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2539
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2540 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2541 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2542 nstate += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2543 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2544 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2545 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2546 s1 = alloc_state(NFA_END_INVISIBLE, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2547 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2548 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2549 patch(e.out, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2550
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2551 s = alloc_state(NFA_START_INVISIBLE, e.start, s1);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2552 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2553 goto theend;
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2554 if (*p == NFA_PREV_ATOM_NO_WIDTH_NEG
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2555 || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG)
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
2556 {
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
2557 s->negated = TRUE;
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
2558 s1->negated = TRUE;
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
2559 }
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2560 if (*p == NFA_PREV_ATOM_JUST_BEFORE
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2561 || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG)
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2562 {
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2563 s->val = *++p; /* get the count */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2564 ++s->c; /* NFA_START_INVISIBLE -> NFA_START_INVISIBLE_BEFORE */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2565 }
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
2566
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2567 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2568 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2569
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2570 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2571 case NFA_COMPOSING: /* char with composing char */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2572 #if 0
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2573 /* TODO */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2574 if (regflags & RF_ICOMBINE)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2575 {
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
2576 /* use the base character only */
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2577 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2578 #endif
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2579 /* FALLTHROUGH */
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2580 #endif
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2581
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2582 case NFA_MOPEN: /* \( \) Submatch */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2583 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2584 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2585 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2586 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2587 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2588 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2589 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2590 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2591 case NFA_MOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2592 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2593 case NFA_ZOPEN: /* \z( \) Submatch */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2594 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2595 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2596 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2597 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2598 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2599 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2600 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2601 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2602 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2603 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2604 case NFA_NOPEN: /* \%( \) "Invisible Submatch" */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2605 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2606 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2607 nstate += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2608 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2609 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2610
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2611 mopen = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2612 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2613 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2614 case NFA_NOPEN: mclose = NFA_NCLOSE; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2615 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2616 case NFA_ZOPEN: mclose = NFA_ZCLOSE; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2617 case NFA_ZOPEN1: mclose = NFA_ZCLOSE1; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2618 case NFA_ZOPEN2: mclose = NFA_ZCLOSE2; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2619 case NFA_ZOPEN3: mclose = NFA_ZCLOSE3; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2620 case NFA_ZOPEN4: mclose = NFA_ZCLOSE4; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2621 case NFA_ZOPEN5: mclose = NFA_ZCLOSE5; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2622 case NFA_ZOPEN6: mclose = NFA_ZCLOSE6; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2623 case NFA_ZOPEN7: mclose = NFA_ZCLOSE7; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2624 case NFA_ZOPEN8: mclose = NFA_ZCLOSE8; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2625 case NFA_ZOPEN9: mclose = NFA_ZCLOSE9; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2626 #endif
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2627 #ifdef FEAT_MBYTE
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2628 case NFA_COMPOSING: mclose = NFA_END_COMPOSING; break;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2629 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2630 default:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2631 /* NFA_MOPEN, NFA_MOPEN1 .. NFA_MOPEN9 */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2632 mclose = *p + NSUBEXP;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2633 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2634 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2635
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2636 /* Allow "NFA_MOPEN" as a valid postfix representation for
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2637 * the empty regexp "". In this case, the NFA will be
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2638 * NFA_MOPEN -> NFA_MCLOSE. Note that this also allows
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2639 * empty groups of parenthesis, and empty mbyte chars */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2640 if (stackp == stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2641 {
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2642 s = alloc_state(mopen, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2643 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2644 goto theend;
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2645 s1 = alloc_state(mclose, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2646 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2647 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2648 patch(list1(&s->out), s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2649 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2650 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2651 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2652
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2653 /* At least one node was emitted before NFA_MOPEN, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2654 * at least one node will be between NFA_MOPEN and NFA_MCLOSE */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2655 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2656 s = alloc_state(mopen, e.start, NULL); /* `(' */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2657 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2658 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2659
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2660 s1 = alloc_state(mclose, NULL, NULL); /* `)' */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2661 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2662 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2663 patch(e.out, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2664
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2665 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2666 if (mopen == NFA_COMPOSING)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2667 /* COMPOSING->out1 = END_COMPOSING */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2668 patch(list1(&s->out1), s1);
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2669 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2670
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2671 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2672 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2673
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2674 case NFA_BACKREF1:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2675 case NFA_BACKREF2:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2676 case NFA_BACKREF3:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2677 case NFA_BACKREF4:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2678 case NFA_BACKREF5:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2679 case NFA_BACKREF6:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2680 case NFA_BACKREF7:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2681 case NFA_BACKREF8:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2682 case NFA_BACKREF9:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2683 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2684 case NFA_ZREF1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2685 case NFA_ZREF2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2686 case NFA_ZREF3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2687 case NFA_ZREF4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2688 case NFA_ZREF5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2689 case NFA_ZREF6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2690 case NFA_ZREF7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2691 case NFA_ZREF8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2692 case NFA_ZREF9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2693 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2694 if (nfa_calc_size == TRUE)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2695 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2696 nstate += 2;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2697 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2698 }
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2699 s = alloc_state(*p, NULL, NULL);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2700 if (s == NULL)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2701 goto theend;
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2702 s1 = alloc_state(NFA_SKIP, NULL, NULL);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2703 if (s1 == NULL)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2704 goto theend;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2705 patch(list1(&s->out), s1);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2706 PUSH(frag(s, list1(&s1->out)));
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2707 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2708
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2709 case NFA_LNUM:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2710 case NFA_LNUM_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2711 case NFA_LNUM_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2712 case NFA_VCOL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2713 case NFA_VCOL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2714 case NFA_VCOL_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2715 case NFA_COL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2716 case NFA_COL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2717 case NFA_COL_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2718 if (nfa_calc_size == TRUE)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2719 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2720 nstate += 1;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2721 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2722 }
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2723 e1 = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2724 s = alloc_state(*p, NULL, NULL);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2725 if (s == NULL)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2726 goto theend;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2727 s->val = e1.start->c;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2728 PUSH(frag(s, list1(&s->out)));
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2729 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2730
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2731 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2732 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2733 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2734 /* Operands */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2735 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2736 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2737 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2738 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2739 }
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2740 s = alloc_state(*p, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2741 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2742 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2743 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2744 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2745
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2746 } /* switch(*p) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2747
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2748 } /* for(p = postfix; *p; ++p) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2749
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2750 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2751 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2752 nstate++;
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2753 goto theend; /* Return value when counting size is ignored anyway */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2754 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2755
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2756 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2757 if (stackp != stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2758 EMSG_RET_NULL(_("E875: (NFA regexp) (While converting from postfix to NFA), too many states left on stack"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2759
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2760 if (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2761 EMSG_RET_NULL(_("E876: (NFA regexp) Not enough space to store the whole NFA "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2762
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2763 matchstate = &state_ptr[istate++]; /* the match state */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2764 matchstate->c = NFA_MATCH;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2765 matchstate->out = matchstate->out1 = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2766
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2767 patch(e.out, matchstate);
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2768 ret = e.start;
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2769
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2770 theend:
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2771 vim_free(stack);
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2772 return ret;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2773
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2774 #undef POP1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2775 #undef PUSH1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2776 #undef POP2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2777 #undef PUSH2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2778 #undef POP
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2779 #undef PUSH
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2780 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2781
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2782 /****************************************************************
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2783 * NFA execution code.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2784 ****************************************************************/
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2785
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2786 typedef struct
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2787 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2788 int in_use; /* number of subexpr with useful info */
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2789
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2790 /* 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
2791 union
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2792 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2793 struct multipos
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2794 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2795 lpos_T start;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2796 lpos_T end;
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2797 } multi[NSUBEXP];
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2798 struct linepos
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2799 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2800 char_u *start;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2801 char_u *end;
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2802 } line[NSUBEXP];
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2803 } list;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2804 } regsub_T;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2805
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2806 typedef struct
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2807 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2808 regsub_T norm; /* \( .. \) matches */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2809 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2810 regsub_T synt; /* \z( .. \) matches */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2811 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2812 } regsubs_T;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2813
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2814 /* nfa_pim_T stores a Postponed Invisible Match. */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2815 typedef struct nfa_pim_S nfa_pim_T;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2816 struct nfa_pim_S
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2817 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2818 nfa_state_T *state;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2819 int result; /* NFA_PIM_TODO, NFA_PIM_[NO]MATCH */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2820 nfa_pim_T *pim; /* another PIM at the same position */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2821 regsubs_T subs; /* submatch info, only party used */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2822 };
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2823
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2824 /* Values for done in nfa_pim_T. */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2825 #define NFA_PIM_TODO 0
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2826 #define NFA_PIM_MATCH 1
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2827 #define NFA_PIM_NOMATCH -1
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2828
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2829
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2830 /* 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
2831 typedef struct
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2832 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2833 nfa_state_T *state;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2834 int count;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2835 nfa_pim_T *pim; /* if not NULL: postponed invisible match */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2836 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
2837 } nfa_thread_T;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2838
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2839 /* nfa_list_T contains the alternative NFA execution states. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2840 typedef struct
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2841 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2842 nfa_thread_T *t; /* allocated array of states */
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2843 int n; /* nr of states currently in "t" */
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2844 int len; /* max nr of states in "t" */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2845 int id; /* ID of the list */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2846 } nfa_list_T;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2847
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2848 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2849 static void log_subsexpr __ARGS((regsubs_T *subs));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2850 static void log_subexpr __ARGS((regsub_T *sub));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2851
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2852 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2853 log_subsexpr(subs)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2854 regsubs_T *subs;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2855 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2856 log_subexpr(&subs->norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2857 # ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2858 log_subexpr(&subs->synt);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2859 # endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2860 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2861
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2862 static void
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2863 log_subexpr(sub)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2864 regsub_T *sub;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2865 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2866 int j;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2867
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2868 for (j = 0; j < sub->in_use; j++)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2869 if (REG_MULTI)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2870 fprintf(log_fd, "\n *** group %d, start: c=%d, l=%d, end: c=%d, l=%d",
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2871 j,
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2872 sub->list.multi[j].start.col,
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2873 (int)sub->list.multi[j].start.lnum,
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2874 sub->list.multi[j].end.col,
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2875 (int)sub->list.multi[j].end.lnum);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2876 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2877 fprintf(log_fd, "\n *** group %d, start: \"%s\", end: \"%s\"",
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2878 j,
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2879 (char *)sub->list.line[j].start,
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
2880 (char *)sub->list.line[j].end);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2881 fprintf(log_fd, "\n");
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2882 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2883 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2884
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2885 /* Used during execution: whether a match has been found. */
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2886 static int nfa_match;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2887
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2888 static void clear_sub __ARGS((regsub_T *sub));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2889 static void copy_sub __ARGS((regsub_T *to, regsub_T *from));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2890 static void copy_sub_off __ARGS((regsub_T *to, regsub_T *from));
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2891 static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2892 static void addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, int off));
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
2893 static void addstate_here __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim, int *ip));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2894
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2895 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2896 clear_sub(sub)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2897 regsub_T *sub;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2898 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2899 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2900 /* Use 0xff to set lnum to -1 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2901 vim_memset(sub->list.multi, 0xff,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2902 sizeof(struct multipos) * nfa_nsubexpr);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2903 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2904 vim_memset(sub->list.line, 0, sizeof(struct linepos) * nfa_nsubexpr);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2905 sub->in_use = 0;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2906 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2907
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2908 /*
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2909 * Copy the submatches from "from" to "to".
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2910 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2911 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2912 copy_sub(to, from)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2913 regsub_T *to;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2914 regsub_T *from;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2915 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2916 to->in_use = from->in_use;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2917 if (from->in_use > 0)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2918 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2919 /* Copy the match start and end positions. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2920 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2921 mch_memmove(&to->list.multi[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2922 &from->list.multi[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2923 sizeof(struct multipos) * from->in_use);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2924 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2925 mch_memmove(&to->list.line[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2926 &from->list.line[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2927 sizeof(struct linepos) * from->in_use);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2928 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2929 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2930
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2931 /*
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2932 * Like copy_sub() but exclude the main match.
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2933 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2934 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2935 copy_sub_off(to, from)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2936 regsub_T *to;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2937 regsub_T *from;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2938 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2939 if (to->in_use < from->in_use)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2940 to->in_use = from->in_use;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2941 if (from->in_use > 1)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2942 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2943 /* Copy the match start and end positions. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2944 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2945 mch_memmove(&to->list.multi[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2946 &from->list.multi[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2947 sizeof(struct multipos) * (from->in_use - 1));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2948 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2949 mch_memmove(&to->list.line[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2950 &from->list.line[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2951 sizeof(struct linepos) * (from->in_use - 1));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2952 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2953 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2954
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2955 /*
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2956 * Return TRUE if "sub1" and "sub2" have the same positions.
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2957 */
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2958 static int
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2959 sub_equal(sub1, sub2)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2960 regsub_T *sub1;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2961 regsub_T *sub2;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2962 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2963 int i;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2964 int todo;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2965 linenr_T s1, e1;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2966 linenr_T s2, e2;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2967 char_u *sp1, *ep1;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2968 char_u *sp2, *ep2;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2969
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2970 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
2971 if (REG_MULTI)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2972 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2973 for (i = 0; i < todo; ++i)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2974 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2975 if (i < sub1->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2976 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2977 s1 = sub1->list.multi[i].start.lnum;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2978 e1 = sub1->list.multi[i].end.lnum;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2979 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2980 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2981 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2982 s1 = 0;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2983 e1 = 0;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2984 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2985 if (i < sub2->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2986 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2987 s2 = sub2->list.multi[i].start.lnum;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2988 e2 = sub2->list.multi[i].end.lnum;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2989 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2990 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2991 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2992 s2 = 0;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2993 e2 = 0;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2994 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2995 if (s1 != s2 || e1 != e2)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2996 return FALSE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2997 if (s1 != 0 && sub1->list.multi[i].start.col
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2998 != sub2->list.multi[i].start.col)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
2999 return FALSE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3000 if (e1 != 0 && sub1->list.multi[i].end.col
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3001 != sub2->list.multi[i].end.col)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3002 return FALSE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3003 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3004 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3005 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3006 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3007 for (i = 0; i < todo; ++i)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3008 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3009 if (i < sub1->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3010 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3011 sp1 = sub1->list.line[i].start;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3012 ep1 = sub1->list.line[i].end;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3013 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3014 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3015 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3016 sp1 = NULL;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3017 ep1 = NULL;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3018 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3019 if (i < sub2->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3020 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3021 sp2 = sub2->list.line[i].start;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3022 ep2 = sub2->list.line[i].end;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3023 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3024 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3025 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3026 sp2 = NULL;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3027 ep2 = NULL;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3028 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3029 if (sp1 != sp2 || ep1 != ep2)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3030 return FALSE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3031 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3032 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3033
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3034 return TRUE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3035 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3036
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3037 #ifdef ENABLE_LOG
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3038 static void
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3039 report_state(char *action, regsub_T *sub, nfa_state_T *state, int lid)
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3040 {
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3041 int col;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3042
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3043 if (sub->in_use <= 0)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3044 col = -1;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3045 else if (REG_MULTI)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3046 col = sub->list.multi[0].start.col;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3047 else
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3048 col = (int)(sub->list.line[0].start - regline);
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3049 nfa_set_code(state->c);
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3050 fprintf(log_fd, "> %s state %d to list %d. char %d: %s (start col %d)\n",
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3051 action, abs(state->id), lid, state->c, code, col);
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3052 }
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3053 #endif
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3054
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3055 static void
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3056 addstate(l, state, subs, off)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3057 nfa_list_T *l; /* runtime state list */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3058 nfa_state_T *state; /* state to update */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3059 regsubs_T *subs; /* pointers to subexpressions */
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3060 int off; /* byte offset, when -1 go to next line */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3061 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3062 int subidx;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3063 nfa_thread_T *thread;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3064 lpos_T save_lpos;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3065 int save_in_use;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3066 char_u *save_ptr;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3067 int i;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3068 regsub_T *sub;
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3069 #ifdef ENABLE_LOG
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3070 int did_print = FALSE;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3071 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3072
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3073 if (l == NULL || state == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3074 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3075
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3076 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3077 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3078 case NFA_SPLIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3079 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3080 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3081 case NFA_NCLOSE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3082 case NFA_MCLOSE:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3083 case NFA_MCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3084 case NFA_MCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3085 case NFA_MCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3086 case NFA_MCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3087 case NFA_MCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3088 case NFA_MCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3089 case NFA_MCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3090 case NFA_MCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3091 case NFA_MCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3092 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3093 case NFA_ZCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3094 case NFA_ZCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3095 case NFA_ZCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3096 case NFA_ZCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3097 case NFA_ZCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3098 case NFA_ZCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3099 case NFA_ZCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3100 case NFA_ZCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3101 case NFA_ZCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3102 case NFA_ZCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3103 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3104 /* These nodes are not added themselves but their "out" and/or
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3105 * "out1" may be added below. */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3106 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3107
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3108 case NFA_MOPEN:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3109 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3110 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3111 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3112 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3113 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3114 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3115 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3116 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3117 case NFA_MOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3118 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3119 case NFA_ZOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3120 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3121 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3122 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3123 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3124 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3125 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3126 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3127 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3128 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3129 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3130 /* These nodes do not need to be added, but we need to bail out
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3131 * when it was tried to be added to this list before. */
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3132 if (state->lastlist[nfa_ll_index] == l->id)
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3133 goto skip_add;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3134 state->lastlist[nfa_ll_index] = l->id;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3135 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3136
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3137 case NFA_BOL:
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3138 case NFA_BOF:
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3139 /* "^" won't match past end-of-line, don't bother trying.
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3140 * Except when we are going to the next line for a look-behind
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3141 * match. */
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3142 if (reginput > regline
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3143 && (nfa_endp == NULL
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3144 || !REG_MULTI
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3145 || reglnum == nfa_endp->se_u.pos.lnum))
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3146 goto skip_add;
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3147 /* FALLTHROUGH */
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3148
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3149 default:
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3150 if (state->lastlist[nfa_ll_index] == l->id)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3151 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3152 /* This state is already in the list, don't add it again,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3153 * unless it is an MOPEN that is used for a backreference. */
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3154 if (!nfa_has_backref)
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3155 {
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3156 skip_add:
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3157 #ifdef ENABLE_LOG
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3158 nfa_set_code(state->c);
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3159 fprintf(log_fd, "> Not adding state %d to list %d. char %d: %s\n",
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3160 abs(state->id), l->id, state->c, code);
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3161 #endif
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3162 return;
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3163 }
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3164
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3165 /* See if the same state is already in the list with the same
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3166 * positions. */
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3167 for (i = 0; i < l->n; ++i)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3168 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3169 thread = &l->t[i];
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3170 if (thread->state->id == state->id
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3171 && sub_equal(&thread->subs.norm, &subs->norm)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3172 #ifdef FEAT_SYN_HL
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3173 && (!nfa_has_zsubexpr ||
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3174 sub_equal(&thread->subs.synt, &subs->synt))
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3175 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3176 )
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3177 goto skip_add;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3178 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3179 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3180
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3181 /* when there are backreferences or look-behind matches the number
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3182 * of states may be (a lot) bigger */
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3183 if (nfa_has_backref && l->n == l->len)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3184 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3185 int newlen = l->len * 3 / 2 + 50;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3186
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3187 l->t = vim_realloc(l->t, newlen * sizeof(nfa_thread_T));
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3188 l->len = newlen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3189 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3190
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3191 /* add the state to the list */
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3192 state->lastlist[nfa_ll_index] = l->id;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3193 thread = &l->t[l->n++];
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3194 thread->state = state;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3195 thread->pim = NULL;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3196 copy_sub(&thread->subs.norm, &subs->norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3197 #ifdef FEAT_SYN_HL
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3198 if (nfa_has_zsubexpr)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3199 copy_sub(&thread->subs.synt, &subs->synt);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3200 #endif
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3201 #ifdef ENABLE_LOG
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3202 report_state("Adding", &thread->subs.norm, state, l->id);
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3203 did_print = TRUE;
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3204 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3205 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3206
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3207 #ifdef ENABLE_LOG
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3208 if (!did_print)
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3209 report_state("Processing", &subs->norm, state, l->id);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3210 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3211 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3212 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3213 case NFA_MATCH:
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3214 nfa_match = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3215 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3216
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3217 case NFA_SPLIT:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3218 /* order matters here */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3219 addstate(l, state->out, subs, off);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3220 addstate(l, state->out1, subs, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3221 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3222
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3223 case NFA_SKIP_CHAR:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3224 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3225 case NFA_NCLOSE:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3226 addstate(l, state->out, subs, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3227 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3228
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3229 case NFA_MOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3230 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3231 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3232 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3233 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3234 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3235 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3236 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3237 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3238 case NFA_MOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3239 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3240 case NFA_ZOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3241 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3242 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3243 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3244 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3245 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3246 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3247 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3248 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3249 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3250 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3251 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3252 if (state->c == NFA_ZSTART)
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3253 {
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3254 subidx = 0;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3255 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3256 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3257 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3258 else if (state->c >= NFA_ZOPEN)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3259 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3260 subidx = state->c - NFA_ZOPEN;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3261 sub = &subs->synt;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3262 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3263 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3264 else
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3265 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3266 subidx = state->c - NFA_MOPEN;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3267 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3268 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3269
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3270 /* Set the position (with "off") in the subexpression. Save and
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3271 * restore it when it was in use. Otherwise fill any gap. */
4649
9f502d8d5165 updated for version 7.3.1072
Bram Moolenaar <bram@vim.org>
parents: 4647
diff changeset
3272 save_ptr = NULL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3273 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3274 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3275 if (subidx < sub->in_use)
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3276 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3277 save_lpos = sub->list.multi[subidx].start;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3278 save_in_use = -1;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3279 }
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3280 else
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3281 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3282 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3283 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
3284 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3285 sub->list.multi[i].start.lnum = -1;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3286 sub->list.multi[i].end.lnum = -1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3287 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3288 sub->in_use = subidx + 1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3289 }
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3290 if (off == -1)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3291 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3292 sub->list.multi[subidx].start.lnum = reglnum + 1;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3293 sub->list.multi[subidx].start.col = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3294 }
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3295 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3296 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3297 sub->list.multi[subidx].start.lnum = reglnum;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3298 sub->list.multi[subidx].start.col =
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3299 (colnr_T)(reginput - regline + off);
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3300 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3301 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3302 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3303 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3304 if (subidx < sub->in_use)
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3305 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3306 save_ptr = sub->list.line[subidx].start;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3307 save_in_use = -1;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3308 }
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3309 else
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3310 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3311 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3312 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
3313 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3314 sub->list.line[i].start = NULL;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3315 sub->list.line[i].end = NULL;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3316 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3317 sub->in_use = subidx + 1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3318 }
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3319 sub->list.line[subidx].start = reginput + off;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3320 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3321
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3322 addstate(l, state->out, subs, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3323
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3324 if (save_in_use == -1)
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3325 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3326 if (REG_MULTI)
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3327 sub->list.multi[subidx].start = save_lpos;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3328 else
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3329 sub->list.line[subidx].start = save_ptr;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3330 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3331 else
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3332 sub->in_use = save_in_use;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3333 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3334
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3335 case NFA_MCLOSE:
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
3336 if (nfa_has_zend)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3337 {
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
3338 /* Do not overwrite the position set by \ze. If no \ze
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
3339 * encountered end will be set in nfa_regtry(). */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3340 addstate(l, state->out, subs, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3341 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3342 }
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3343 case NFA_MCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3344 case NFA_MCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3345 case NFA_MCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3346 case NFA_MCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3347 case NFA_MCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3348 case NFA_MCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3349 case NFA_MCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3350 case NFA_MCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3351 case NFA_MCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3352 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3353 case NFA_ZCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3354 case NFA_ZCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3355 case NFA_ZCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3356 case NFA_ZCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3357 case NFA_ZCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3358 case NFA_ZCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3359 case NFA_ZCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3360 case NFA_ZCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3361 case NFA_ZCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3362 case NFA_ZCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3363 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3364 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3365 if (state->c == NFA_ZEND)
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3366 {
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3367 subidx = 0;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3368 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3369 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3370 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3371 else if (state->c >= NFA_ZCLOSE)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3372 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3373 subidx = state->c - NFA_ZCLOSE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3374 sub = &subs->synt;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3375 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3376 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3377 else
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3378 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3379 subidx = state->c - NFA_MCLOSE;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3380 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3381 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3382
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3383 /* We don't fill in gaps here, there must have been an MOPEN that
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3384 * has done that. */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3385 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3386 if (sub->in_use <= subidx)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3387 sub->in_use = subidx + 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3388 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3389 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3390 save_lpos = sub->list.multi[subidx].end;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3391 if (off == -1)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3392 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3393 sub->list.multi[subidx].end.lnum = reglnum + 1;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3394 sub->list.multi[subidx].end.col = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3395 }
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3396 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3397 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3398 sub->list.multi[subidx].end.lnum = reglnum;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3399 sub->list.multi[subidx].end.col =
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3400 (colnr_T)(reginput - regline + off);
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3401 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3402 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3403 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3404 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3405 save_ptr = sub->list.line[subidx].end;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3406 sub->list.line[subidx].end = reginput + off;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3407 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3408
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3409 addstate(l, state->out, subs, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3410
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3411 if (REG_MULTI)
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3412 sub->list.multi[subidx].end = save_lpos;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3413 else
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3414 sub->list.line[subidx].end = save_ptr;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3415 sub->in_use = save_in_use;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3416 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3417 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3418 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3419
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3420 /*
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3421 * 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
3422 * 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
3423 * 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
3424 * matters for alternatives.
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3425 */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3426 static void
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3427 addstate_here(l, state, subs, pim, ip)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3428 nfa_list_T *l; /* runtime state list */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3429 nfa_state_T *state; /* state to update */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3430 regsubs_T *subs; /* pointers to subexpressions */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3431 nfa_pim_T *pim; /* postponed look-behind match */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3432 int *ip;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3433 {
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3434 int tlen = l->n;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3435 int count;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3436 int listidx = *ip;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3437 int i;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3438
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3439 /* first add the state(s) at the end, so that we know how many there are */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3440 addstate(l, state, subs, 0);
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3441
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3442 /* fill in the "pim" field in the new states */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3443 if (pim != NULL)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3444 for (i = tlen; i < l->n; ++i)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3445 l->t[i].pim = pim;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3446
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3447 /* 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
3448 if (listidx + 1 == tlen)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3449 return;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3450
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3451 /* re-order to put the new state at the current position */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3452 count = l->n - tlen;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3453 if (count == 1)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3454 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3455 /* overwrite the current state */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3456 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
3457 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3458 else if (count > 1)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3459 {
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3460 /* make space for new states, then move them from the
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3461 * end to the current position */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3462 mch_memmove(&(l->t[listidx + count]),
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3463 &(l->t[listidx + 1]),
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3464 sizeof(nfa_thread_T) * (l->n - listidx - 1));
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3465 mch_memmove(&(l->t[listidx]),
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3466 &(l->t[l->n - 1]),
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3467 sizeof(nfa_thread_T) * count);
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3468 }
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3469 --l->n;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3470 *ip = listidx - 1;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3471 }
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3472
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3473 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3474 * Check character class "class" against current character c.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3475 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3476 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3477 check_char_class(class, c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3478 int class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3479 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3480 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3481 switch (class)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3482 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3483 case NFA_CLASS_ALNUM:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
3484 if (c >= 1 && c <= 255 && isalnum(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3485 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3486 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3487 case NFA_CLASS_ALPHA:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
3488 if (c >= 1 && c <= 255 && isalpha(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3489 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3490 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3491 case NFA_CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3492 if (c == ' ' || c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3493 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3494 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3495 case NFA_CLASS_CNTRL:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
3496 if (c >= 1 && c <= 255 && iscntrl(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3497 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3498 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3499 case NFA_CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3500 if (VIM_ISDIGIT(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3501 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3502 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3503 case NFA_CLASS_GRAPH:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
3504 if (c >= 1 && c <= 255 && isgraph(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3505 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3506 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3507 case NFA_CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3508 if (MB_ISLOWER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3509 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3510 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3511 case NFA_CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3512 if (vim_isprintc(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3513 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3514 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3515 case NFA_CLASS_PUNCT:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
3516 if (c >= 1 && c <= 255 && ispunct(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3517 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3518 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3519 case NFA_CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3520 if ((c >=9 && c <= 13) || (c == ' '))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3521 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3522 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3523 case NFA_CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3524 if (MB_ISUPPER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3525 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3526 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3527 case NFA_CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3528 if (vim_isxdigit(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3529 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3530 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3531 case NFA_CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3532 if (c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3533 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3534 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3535 case NFA_CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3536 if (c == '\r')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3537 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3538 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3539 case NFA_CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3540 if (c == '\b')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3541 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3542 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3543 case NFA_CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3544 if (c == '\033')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3545 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3546 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3547
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3548 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3549 /* should not be here :P */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3550 EMSG_RET_FAIL(_("E877: (NFA regexp) Invalid character class "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3551 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3552 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3553 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3554
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3555 static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3556
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3557 /*
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3558 * Check for a match with subexpression "subidx".
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3559 * Return TRUE if it matches.
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3560 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3561 static int
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3562 match_backref(sub, subidx, bytelen)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3563 regsub_T *sub; /* pointers to subexpressions */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3564 int subidx;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3565 int *bytelen; /* out: length of match in bytes */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3566 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3567 int len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3568
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3569 if (sub->in_use <= subidx)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3570 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3571 retempty:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3572 /* backref was not set, match an empty string */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3573 *bytelen = 0;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3574 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3575 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3576
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3577 if (REG_MULTI)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3578 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3579 if (sub->list.multi[subidx].start.lnum < 0
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3580 || sub->list.multi[subidx].end.lnum < 0)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3581 goto retempty;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3582 /* TODO: line breaks */
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3583 len = sub->list.multi[subidx].end.col
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3584 - sub->list.multi[subidx].start.col;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3585 if (cstrncmp(regline + sub->list.multi[subidx].start.col,
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3586 reginput, &len) == 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3587 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3588 *bytelen = len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3589 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3590 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3591 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3592 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3593 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3594 if (sub->list.line[subidx].start == NULL
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3595 || sub->list.line[subidx].end == NULL)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3596 goto retempty;
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3597 len = (int)(sub->list.line[subidx].end - sub->list.line[subidx].start);
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3598 if (cstrncmp(sub->list.line[subidx].start, reginput, &len) == 0)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3599 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3600 *bytelen = len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3601 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3602 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3603 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3604 return FALSE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3605 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3606
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3607 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3608
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3609 static int match_zref __ARGS((int subidx, int *bytelen));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3610
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3611 /*
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3612 * Check for a match with \z subexpression "subidx".
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3613 * Return TRUE if it matches.
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3614 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3615 static int
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3616 match_zref(subidx, bytelen)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3617 int subidx;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3618 int *bytelen; /* out: length of match in bytes */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3619 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3620 int len;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3621
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3622 cleanup_zsubexpr();
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3623 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
3624 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3625 /* backref was not set, match an empty string */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3626 *bytelen = 0;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3627 return TRUE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3628 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3629
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3630 len = (int)STRLEN(re_extmatch_in->matches[subidx]);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3631 if (cstrncmp(re_extmatch_in->matches[subidx], reginput, &len) == 0)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3632 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3633 *bytelen = len;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3634 return TRUE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3635 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3636 return FALSE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3637 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3638 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3639
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3640 /*
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3641 * 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
3642 * Also reset the IDs to zero.
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3643 * Only used for the recursive value lastlist[1].
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3644 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3645 static void
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3646 nfa_save_listids(prog, list)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3647 nfa_regprog_T *prog;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3648 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3649 {
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3650 int i;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3651 nfa_state_T *p;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3652
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3653 /* Order in the list is reverse, it's a bit faster that way. */
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3654 p = &prog->state[0];
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3655 for (i = prog->nstate; --i >= 0; )
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3656 {
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3657 list[i] = p->lastlist[1];
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3658 p->lastlist[1] = 0;
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3659 ++p;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3660 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3661 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3662
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3663 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3664 * Restore list IDs from "list" to all NFA states.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3665 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3666 static void
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3667 nfa_restore_listids(prog, list)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3668 nfa_regprog_T *prog;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3669 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3670 {
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3671 int i;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3672 nfa_state_T *p;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3673
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3674 p = &prog->state[0];
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3675 for (i = prog->nstate; --i >= 0; )
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3676 {
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3677 p->lastlist[1] = list[i];
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3678 ++p;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3679 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3680 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3681
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3682 static int
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3683 nfa_re_num_cmp(val, op, pos)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3684 long_u val;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3685 int op;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3686 long_u pos;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3687 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3688 if (op == 1) return pos > val;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3689 if (op == 2) return pos < val;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3690 return val == pos;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3691 }
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3692
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3693 static int recursive_regmatch __ARGS((nfa_state_T *state, nfa_regprog_T *prog, regsubs_T *submatch, regsubs_T *m, int **listids));
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3694 static int nfa_regmatch __ARGS((nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *submatch, regsubs_T *m));
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3695
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3696 /*
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3697 * Recursively call nfa_regmatch()
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3698 */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3699 static int
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3700 recursive_regmatch(state, prog, submatch, m, listids)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3701 nfa_state_T *state;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3702 nfa_regprog_T *prog;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3703 regsubs_T *submatch;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3704 regsubs_T *m;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3705 int **listids;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3706 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3707 char_u *save_reginput = reginput;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3708 char_u *save_regline = regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3709 int save_reglnum = reglnum;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3710 int save_nfa_match = nfa_match;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3711 int save_nfa_listid = nfa_listid;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3712 save_se_T *save_nfa_endp = nfa_endp;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3713 save_se_T endpos;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3714 save_se_T *endposp = NULL;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3715 int result;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3716 int need_restore = FALSE;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3717
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3718 if (state->c == NFA_START_INVISIBLE_BEFORE)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3719 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3720 /* The recursive match must end at the current position. */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3721 endposp = &endpos;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3722 if (REG_MULTI)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3723 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3724 endpos.se_u.pos.col = (int)(reginput - regline);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3725 endpos.se_u.pos.lnum = reglnum;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3726 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3727 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3728 endpos.se_u.ptr = reginput;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3729
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3730 /* Go back the specified number of bytes, or as far as the
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3731 * start of the previous line, to try matching "\@<=" or
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3732 * not matching "\@<!".
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3733 * TODO: This is very inefficient! Would be better to
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3734 * first check for a match with what follows. */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3735 if (state->val <= 0)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3736 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3737 if (REG_MULTI)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3738 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3739 regline = reg_getline(--reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3740 if (regline == NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3741 /* can't go before the first line */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3742 regline = reg_getline(++reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3743 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3744 reginput = regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3745 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3746 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3747 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3748 if (REG_MULTI && (int)(reginput - regline) < state->val)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3749 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3750 /* Not enough bytes in this line, go to end of
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3751 * previous line. */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3752 regline = reg_getline(--reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3753 if (regline == NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3754 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3755 /* can't go before the first line */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3756 regline = reg_getline(++reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3757 reginput = regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3758 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3759 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3760 reginput = regline + STRLEN(regline);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3761 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3762 if ((int)(reginput - regline) >= state->val)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3763 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3764 reginput -= state->val;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3765 #ifdef FEAT_MBYTE
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3766 if (has_mbyte)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3767 reginput -= mb_head_off(regline, reginput);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3768 #endif
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3769 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3770 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3771 reginput = regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3772 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3773 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3774
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3775 #ifdef ENABLE_LOG
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3776 if (log_fd != stderr)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3777 fclose(log_fd);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3778 log_fd = NULL;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3779 #endif
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3780 /* Have to clear the lastlist field of the NFA nodes, so that
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3781 * nfa_regmatch() and addstate() can run properly after recursion. */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3782 if (nfa_ll_index == 1)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3783 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3784 /* Already calling nfa_regmatch() recursively. Save the lastlist[1]
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3785 * values and clear them. */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3786 if (*listids == NULL)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3787 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3788 *listids = (int *)lalloc(sizeof(int) * nstate, TRUE);
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3789 if (*listids == NULL)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3790 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3791 EMSG(_("E878: (NFA) Could not allocate memory for branch traversal!"));
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3792 return 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3793 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3794 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3795 nfa_save_listids(prog, *listids);
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3796 need_restore = TRUE;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3797 /* any value of nfa_listid will do */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3798 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3799 else
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3800 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3801 /* First recursive nfa_regmatch() call, switch to the second lastlist
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3802 * entry. Make sure nfa_listid is different from a previous recursive
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3803 * call, because some states may still have this ID. */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3804 ++nfa_ll_index;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3805 if (nfa_listid <= nfa_alt_listid)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3806 nfa_listid = nfa_alt_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3807 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3808
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3809 /* Call nfa_regmatch() to check if the current concat matches at this
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3810 * 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
3811 nfa_endp = endposp;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3812 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
3813
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3814 if (need_restore)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3815 nfa_restore_listids(prog, *listids);
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3816 else
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3817 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3818 --nfa_ll_index;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3819 nfa_alt_listid = nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3820 }
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3821
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3822 /* restore position in input text */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3823 reginput = save_reginput;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3824 regline = save_regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3825 reglnum = save_reglnum;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3826 nfa_match = save_nfa_match;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3827 nfa_endp = save_nfa_endp;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3828 nfa_listid = save_nfa_listid;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3829
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3830 #ifdef ENABLE_LOG
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3831 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3832 if (log_fd != NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3833 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3834 fprintf(log_fd, "****************************\n");
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3835 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
3836 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
3837 fprintf(log_fd, "****************************\n");
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3838 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3839 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3840 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3841 EMSG(_("Could not open temporary log file for writing, displaying on stderr ... "));
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3842 log_fd = stderr;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3843 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3844 #endif
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3845
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3846 return result;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3847 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3848
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3849 static int failure_chance __ARGS((nfa_state_T *state, int depth));
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3850
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3851 /*
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3852 * Estimate the chance of a match with "state" failing.
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3853 * NFA_ANY: 1
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3854 * specific character: 99
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3855 */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3856 static int
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3857 failure_chance(state, depth)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3858 nfa_state_T *state;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3859 int depth;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3860 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3861 int c = state->c;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3862 int l, r;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3863
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3864 /* detect looping */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3865 if (depth > 4)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3866 return 1;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3867
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3868 if (c == NFA_SPLIT)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3869 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3870 if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3871 return 1;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3872 l = failure_chance(state->out, depth + 1);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3873 r = failure_chance(state->out1, depth + 1);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3874 return l < r ? l : r;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3875 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3876 if (c == NFA_ANY)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3877 return 1;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3878 if (c > 0)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3879 return 99;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3880 if ((c >= NFA_MOPEN && c <= NFA_MOPEN9)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3881 || (c >= NFA_ZOPEN && c <= NFA_ZOPEN9)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3882 || c == NFA_NOPEN)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3883 return failure_chance(state->out, depth + 1);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3884 /* something else */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3885 return 50;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3886 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3887
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
3888 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3889 * Main matching routine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3890 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3891 * Run NFA to determine whether it matches reginput.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3892 *
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3893 * 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
3894 *
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3895 * Return TRUE if there is a match, FALSE otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3896 * Note: Caller must ensure that: start != NULL.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3897 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3898 static int
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3899 nfa_regmatch(prog, start, submatch, m)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3900 nfa_regprog_T *prog;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3901 nfa_state_T *start;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3902 regsubs_T *submatch;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3903 regsubs_T *m;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3904 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3905 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3906 int size = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3907 int flag = 0;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3908 int go_to_nextline = FALSE;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3909 nfa_thread_T *t;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3910 nfa_list_T list[3];
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3911 nfa_list_T *listtbl[2][2];
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3912 nfa_list_T *ll;
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3913 int listidx;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3914 nfa_list_T *thislist;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3915 nfa_list_T *nextlist;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3916 nfa_list_T *neglist;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3917 int *listids = NULL;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3918 nfa_state_T *add_state;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3919 int add_count;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3920 int add_off;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3921 garray_T pimlist;
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
3922 #ifdef NFA_REGEXP_DEBUG_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3923 FILE *debug = fopen(NFA_REGEXP_DEBUG_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3924
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3925 if (debug == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3926 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3927 EMSG2(_("(NFA) COULD NOT OPEN %s !"), NFA_REGEXP_DEBUG_LOG);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3928 return FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3929 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3930 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3931 nfa_match = FALSE;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3932 ga_init2(&pimlist, sizeof(nfa_pim_T), 5);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3933
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3934 /* Allocate memory for the lists of nodes. */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3935 size = (nstate + 1) * sizeof(nfa_thread_T);
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3936 list[0].t = (nfa_thread_T *)lalloc_clear(size, TRUE);
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3937 list[0].len = nstate + 1;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3938 list[1].t = (nfa_thread_T *)lalloc_clear(size, TRUE);
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3939 list[1].len = nstate + 1;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3940 list[2].t = (nfa_thread_T *)lalloc_clear(size, TRUE);
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3941 list[2].len = nstate + 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3942 if (list[0].t == NULL || list[1].t == NULL || list[2].t == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3943 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3944
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3945 #ifdef ENABLE_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3946 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3947 if (log_fd != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3948 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3949 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3950 nfa_set_code(start->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3951 fprintf(log_fd, " RUNNING nfa_regmatch() starting with state %d, code %s\n",
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3952 abs(start->id), code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3953 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3954 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3955 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3956 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3957 EMSG(_("Could not open temporary log file for writing, displaying on stderr ... "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3958 log_fd = stderr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3959 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3960 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3961
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3962 thislist = &list[0];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3963 thislist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3964 nextlist = &list[1];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3965 nextlist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3966 neglist = &list[2];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3967 neglist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3968 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3969 fprintf(log_fd, "(---) STARTSTATE\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3970 #endif
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3971 thislist->id = nfa_listid + 1;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3972 addstate(thislist, start, m, 0);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3973
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3974 /* There are two cases when the NFA advances: 1. input char matches the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3975 * NFA node and 2. input char does not match the NFA node, but the next
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3976 * node is NFA_NOT. The following macro calls addstate() according to
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3977 * these rules. It is used A LOT, so use the "listtbl" table for speed */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3978 listtbl[0][0] = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3979 listtbl[0][1] = neglist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3980 listtbl[1][0] = nextlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3981 listtbl[1][1] = NULL;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3982 #define ADD_POS_NEG_STATE(state) \
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3983 ll = listtbl[result ? 1 : 0][state->negated]; \
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3984 if (ll != NULL) { \
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3985 add_state = state->out; \
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3986 add_off = clen; \
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3987 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3988
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3989 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3990 * Run for each character.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3991 */
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3992 for (;;)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3993 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3994 int curc;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3995 int clen;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3996
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3997 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3998 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3999 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4000 curc = (*mb_ptr2char)(reginput);
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4001 clen = (*mb_ptr2len)(reginput);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4002 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4003 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4004 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4005 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4006 curc = *reginput;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4007 clen = 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4008 }
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4009 if (curc == NUL)
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4010 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4011 clen = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4012 go_to_nextline = FALSE;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4013 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4014
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4015 /* swap lists */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4016 thislist = &list[flag];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4017 nextlist = &list[flag ^= 1];
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4018 nextlist->n = 0; /* clear nextlist */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4019 listtbl[1][0] = nextlist;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4020 ++nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4021 thislist->id = nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4022 nextlist->id = nfa_listid + 1;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4023 neglist->id = nfa_listid + 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4024
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4025 pimlist.ga_len = 0;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4026
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4027 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4028 fprintf(log_fd, "------------------------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4029 fprintf(log_fd, ">>> Reginput is \"%s\"\n", reginput);
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4030 fprintf(log_fd, ">>> Advanced one character ... Current char is %c (code %d) \n", curc, (int)curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4031 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
4032 {
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4033 int i;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4034
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4035 for (i = 0; i < thislist->n; i++)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4036 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
4037 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4038 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4039 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4040
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
4041 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4042 fprintf(debug, "\n-------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4043 #endif
4480
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
4044 /*
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
4045 * If the state lists are empty we can stop.
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
4046 */
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
4047 if (thislist->n == 0 && neglist->n == 0)
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
4048 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4049
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4050 /* compute nextlist */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4051 for (listidx = 0; listidx < thislist->n || neglist->n > 0; ++listidx)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4052 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4053 if (neglist->n > 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4054 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4055 t = &neglist->t[0];
4468
dde1cf311be6 updated for version 7.3.982
Bram Moolenaar <bram@vim.org>
parents: 4464
diff changeset
4056 neglist->n--;
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4057 listidx--;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4058 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4059 else
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4060 t = &thislist->t[listidx];
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4061
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
4062 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4063 nfa_set_code(t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4064 fprintf(debug, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4065 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4066 #ifdef ENABLE_LOG
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4067 {
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4068 int col;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4069
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
4070 if (t->subs.norm.in_use <= 0)
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4071 col = -1;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4072 else if (REG_MULTI)
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
4073 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
4074 else
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
4075 col = (int)(t->subs.norm.list.line[0].start - regline);
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4076 nfa_set_code(t->state->c);
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4077 fprintf(log_fd, "(%d) char %d %s (start col %d) ... \n",
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4078 abs(t->state->id), (int)t->state->c, code, col);
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4079 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4080 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4081
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4082 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4083 * Handle the possible codes of the current state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4084 * The most important is NFA_MATCH.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4085 */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4086 add_state = NULL;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4087 add_count = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4088 switch (t->state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4089 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4090 case NFA_MATCH:
4567
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
4091 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4092 nfa_match = TRUE;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4093 copy_sub(&submatch->norm, &t->subs.norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4094 #ifdef FEAT_SYN_HL
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4095 if (nfa_has_zsubexpr)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4096 copy_sub(&submatch->synt, &t->subs.synt);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4097 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4098 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4099 log_subsexpr(&t->subs);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4100 #endif
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4101 /* Found the left-most longest match, do not look at any other
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4102 * states at this position. When the list of states is going
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4103 * to be empty quit without advancing, so that "reginput" is
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4104 * correct. */
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4105 if (nextlist->n == 0 && neglist->n == 0)
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4106 clen = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4107 goto nextchar;
4567
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
4108 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4109
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4110 case NFA_END_INVISIBLE:
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4111 /*
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4112 * 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
4113 * NFA_START_INVISIBLE_BEFORE node.
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4114 * They surround a zero-width group, used with "\@=", "\&",
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4115 * "\@!", "\@<=" and "\@<!".
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4116 * If we got here, it means that the current "invisible" group
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4117 * 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
4118 * 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
4119 * in the position in "nfa_endp".
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4120 * 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
4121 */
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4122 #ifdef ENABLE_LOG
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4123 if (nfa_endp != NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4124 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4125 if (REG_MULTI)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4126 fprintf(log_fd, "Current lnum: %d, endp lnum: %d; current col: %d, endp col: %d\n",
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4127 (int)reglnum,
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4128 (int)nfa_endp->se_u.pos.lnum,
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4129 (int)(reginput - regline),
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4130 nfa_endp->se_u.pos.col);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4131 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4132 fprintf(log_fd, "Current col: %d, endp col: %d\n",
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4133 (int)(reginput - regline),
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4134 (int)(nfa_endp->se_u.ptr - reginput));
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4135 }
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4136 #endif
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4137 /* It's only a match if it ends at "nfa_endp" */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4138 if (nfa_endp != NULL && (REG_MULTI
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4139 ? (reglnum != nfa_endp->se_u.pos.lnum
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4140 || (int)(reginput - regline)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4141 != nfa_endp->se_u.pos.col)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4142 : reginput != nfa_endp->se_u.ptr))
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4143 break;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4144
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4145 /* do not set submatches for \@! */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4146 if (!t->state->negated)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4147 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4148 copy_sub(&m->norm, &t->subs.norm);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4149 #ifdef FEAT_SYN_HL
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4150 if (nfa_has_zsubexpr)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4151 copy_sub(&m->synt, &t->subs.synt);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4152 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4153 }
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4154 nfa_match = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4155 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4156
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4157 case NFA_START_INVISIBLE:
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4158 case NFA_START_INVISIBLE_BEFORE:
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4159 /* If invisible match has a higher chance to fail, do it
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4160 * right away. Otherwise postpone it until what follows is
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4161 * matching and causes addstate(nextlist, ..) to be called.
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4162 * This is indicated by the "pim" field. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4163 {
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4164 nfa_pim_T *pim;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4165 int cout = t->state->out1->out->c;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4166
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4167 /* Do it directly when what follows is possibly end of
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4168 * match (closing paren).
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4169 * Postpone when it is \@<= or \@<!, these are expensive.
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4170 * TODO: remove the check for t->pim and check multiple
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4171 * where it's used?
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4172 * Otherwise first do the one that has the highest chance
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4173 * of failing. */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4174 if ((cout >= NFA_MCLOSE && cout <= NFA_MCLOSE9)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4175 || (cout >= NFA_ZCLOSE && cout <= NFA_ZCLOSE9)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4176 || cout == NFA_NCLOSE
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4177 || t->pim != NULL
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4178 || (t->state->c != NFA_START_INVISIBLE_BEFORE
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4179 && failure_chance(t->state->out1->out, 0)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4180 < failure_chance(t->state->out, 0)))
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4181 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4182 /*
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4183 * First try matching the invisible match, then what
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4184 * follows.
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4185 */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4186 result = recursive_regmatch(t->state, prog,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4187 submatch, m, &listids);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4188
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4189 /* for \@! it is a match when result is FALSE */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4190 if (result != t->state->negated)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4191 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4192 /* Copy submatch info from the recursive call */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4193 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
4194 #ifdef FEAT_SYN_HL
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4195 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
4196 #endif
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4197
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4198 /* t->state->out1 is the corresponding
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4199 * END_INVISIBLE node; Add its out to the current
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4200 * list (zero-width match). */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4201 addstate_here(thislist, t->state->out1->out,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4202 &t->subs, t->pim, &listidx);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4203 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4204 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4205 else
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4206 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4207 /*
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4208 * First try matching what follows at the current
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4209 * position. Only if a match is found, addstate() is
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4210 * called, then verify the invisible match matches.
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4211 * Add a nfa_pim_T to the following states, it
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4212 * contains info about the invisible match.
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4213 */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4214 if (ga_grow(&pimlist, 1) == FAIL)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4215 goto theend;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4216 pim = (nfa_pim_T *)pimlist.ga_data + pimlist.ga_len;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4217 ++pimlist.ga_len;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4218 pim->state = t->state;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4219 pim->pim = NULL;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4220 pim->result = NFA_PIM_TODO;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4221
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4222 /* t->state->out1 is the corresponding END_INVISIBLE
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4223 * node; Add its out to the current list (zero-width
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4224 * match). */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4225 addstate_here(thislist, t->state->out1->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4226 pim, &listidx);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4227 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4228 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4229 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4230
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4231 case NFA_BOL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4232 if (reginput == regline)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4233 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4234 t->pim, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4235 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4236
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4237 case NFA_EOL:
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4238 if (curc == NUL)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4239 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4240 t->pim, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4241 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4242
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4243 case NFA_BOW:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4244 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4245 int bow = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4246
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4247 if (curc == NUL)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4248 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4249 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4250 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4251 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4252 int this_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4253
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4254 /* Get class of current and previous char (if it exists). */
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
4255 this_class = mb_get_class_buf(reginput, reg_buf);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4256 if (this_class <= 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4257 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4258 else if (reg_prev_class() == this_class)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4259 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4260 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4261 #endif
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4262 else if (!vim_iswordc_buf(curc, reg_buf)
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
4263 || (reginput > regline
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
4264 && vim_iswordc_buf(reginput[-1], reg_buf)))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4265 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4266 if (bow)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4267 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4268 t->pim, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4269 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4270 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4271
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4272 case NFA_EOW:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4273 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4274 int eow = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4275
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4276 if (reginput == regline)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4277 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4278 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4279 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4280 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4281 int this_class, prev_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4282
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4283 /* Get class of current and previous char (if it exists). */
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
4284 this_class = mb_get_class_buf(reginput, reg_buf);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4285 prev_class = reg_prev_class();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4286 if (this_class == prev_class
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4287 || prev_class == 0 || prev_class == 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4288 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4289 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4290 #endif
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
4291 else if (!vim_iswordc_buf(reginput[-1], reg_buf)
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4292 || (reginput[0] != NUL
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4293 && vim_iswordc_buf(curc, reg_buf)))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4294 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4295 if (eow)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4296 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4297 t->pim, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4298 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4299 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4300
4671
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4301 case NFA_BOF:
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4302 if (reglnum == 0 && reginput == regline
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4303 && (!REG_MULTI || reg_firstlnum == 1))
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4304 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4305 t->pim, &listidx);
4671
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4306 break;
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4307
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4308 case NFA_EOF:
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4309 if (reglnum == reg_maxline && curc == NUL)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4310 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4311 t->pim, &listidx);
4671
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4312 break;
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
4313
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4314 #ifdef FEAT_MBYTE
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4315 case NFA_COMPOSING:
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4316 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4317 int mc = curc;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
4318 int len = 0;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
4319 nfa_state_T *end;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
4320 nfa_state_T *sta;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4321 int cchars[MAX_MCO];
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4322 int ccount = 0;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4323 int j;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4324
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4325 sta = t->state->out;
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4326 len = 0;
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4327 if (utf_iscomposing(sta->c))
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4328 {
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4329 /* Only match composing character(s), ignore base
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4330 * character. Used for ".{composing}" and "{composing}"
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4331 * (no preceding character). */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4332 len += mb_char2len(mc);
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4333 }
4551
f0c37f5cf4ea updated for version 7.3.1023
Bram Moolenaar <bram@vim.org>
parents: 4549
diff changeset
4334 if (ireg_icombine && len == 0)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4335 {
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4336 /* If \Z was present, then ignore composing characters.
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
4337 * When ignoring the base character this always matches. */
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4338 /* TODO: How about negated? */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4339 if (len == 0 && sta->c != curc)
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4340 result = FAIL;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4341 else
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4342 result = OK;
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4343 while (sta->c != NFA_END_COMPOSING)
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4344 sta = sta->out;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4345 }
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4346
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4347 /* Check base character matches first, unless ignored. */
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4348 else if (len > 0 || mc == sta->c)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4349 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4350 if (len == 0)
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4351 {
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4352 len += mb_char2len(mc);
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4353 sta = sta->out;
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
4354 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4355
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4356 /* We don't care about the order of composing characters.
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4357 * Get them into cchars[] first. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4358 while (len < clen)
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4359 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4360 mc = mb_ptr2char(reginput + len);
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4361 cchars[ccount++] = mc;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4362 len += mb_char2len(mc);
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4363 if (ccount == MAX_MCO)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4364 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4365 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4366
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4367 /* Check that each composing char in the pattern matches a
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4368 * composing char in the text. We do not check if all
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4369 * composing chars are matched. */
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4370 result = OK;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4371 while (sta->c != NFA_END_COMPOSING)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4372 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4373 for (j = 0; j < ccount; ++j)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4374 if (cchars[j] == sta->c)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4375 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4376 if (j == ccount)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4377 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4378 result = FAIL;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4379 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4380 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4381 sta = sta->out;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4382 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4383 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4384 else
4525
36ddcf4cecbc updated for version 7.3.1010
Bram Moolenaar <bram@vim.org>
parents: 4517
diff changeset
4385 result = FAIL;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
4386
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4387 end = t->state->out1; /* NFA_END_COMPOSING */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4388 ADD_POS_NEG_STATE(end);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4389 break;
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4390 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4391 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4392
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4393 case NFA_NEWL:
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4394 if (curc == NUL && !reg_line_lbr && REG_MULTI
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4395 && reglnum <= reg_maxline)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4396 {
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4397 go_to_nextline = TRUE;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4398 /* Pass -1 for the offset, which means taking the position
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4399 * at the start of the next line. */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4400 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4401 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4402 add_off = -1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4403 }
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4404 else if (curc == '\n' && reg_line_lbr)
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4405 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4406 /* 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
4407 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4408 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4409 add_off = 1;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4410 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4411 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4412
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4413 case NFA_CLASS_ALNUM:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4414 case NFA_CLASS_ALPHA:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4415 case NFA_CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4416 case NFA_CLASS_CNTRL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4417 case NFA_CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4418 case NFA_CLASS_GRAPH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4419 case NFA_CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4420 case NFA_CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4421 case NFA_CLASS_PUNCT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4422 case NFA_CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4423 case NFA_CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4424 case NFA_CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4425 case NFA_CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4426 case NFA_CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4427 case NFA_CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4428 case NFA_CLASS_ESCAPE:
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4429 result = check_char_class(t->state->c, curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4430 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4431 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4432
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4433 case NFA_END_NEG_RANGE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4434 /* This follows a series of negated nodes, like:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4435 * CHAR(x), NFA_NOT, CHAR(y), NFA_NOT etc. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4436 if (curc > 0)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4437 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4438 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4439 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4440 add_off = clen;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4441 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4442 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4443
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4444 case NFA_ANY:
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4445 /* 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
4446 if (curc > 0)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4447 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4448 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4449 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4450 add_off = clen;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4451 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4452 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4453
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4454 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4455 * Character classes like \a for alpha, \d for digit etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4456 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4457 case NFA_IDENT: /* \i */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4458 result = vim_isIDc(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4459 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4460 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4461
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4462 case NFA_SIDENT: /* \I */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4463 result = !VIM_ISDIGIT(curc) && vim_isIDc(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4464 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4465 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4466
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4467 case NFA_KWORD: /* \k */
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
4468 result = vim_iswordp_buf(reginput, reg_buf);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4469 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4470 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4471
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4472 case NFA_SKWORD: /* \K */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4473 result = !VIM_ISDIGIT(curc)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4474 && vim_iswordp_buf(reginput, reg_buf);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4475 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4476 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4477
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4478 case NFA_FNAME: /* \f */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4479 result = vim_isfilec(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4480 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4481 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4482
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4483 case NFA_SFNAME: /* \F */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4484 result = !VIM_ISDIGIT(curc) && vim_isfilec(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4485 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4486 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4487
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4488 case NFA_PRINT: /* \p */
4470
ab5154170c3d updated for version 7.3.983
Bram Moolenaar <bram@vim.org>
parents: 4468
diff changeset
4489 result = ptr2cells(reginput) == 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4490 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4491 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4492
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4493 case NFA_SPRINT: /* \P */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4494 result = !VIM_ISDIGIT(curc) && ptr2cells(reginput) == 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4495 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4496 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4497
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4498 case NFA_WHITE: /* \s */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4499 result = vim_iswhite(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4500 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4501 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4502
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4503 case NFA_NWHITE: /* \S */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4504 result = curc != NUL && !vim_iswhite(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4505 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4506 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4507
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4508 case NFA_DIGIT: /* \d */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4509 result = ri_digit(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4510 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4511 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4512
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4513 case NFA_NDIGIT: /* \D */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4514 result = curc != NUL && !ri_digit(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4515 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4516 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4517
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4518 case NFA_HEX: /* \x */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4519 result = ri_hex(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4520 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4521 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4522
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4523 case NFA_NHEX: /* \X */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4524 result = curc != NUL && !ri_hex(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4525 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4526 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4527
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4528 case NFA_OCTAL: /* \o */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4529 result = ri_octal(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4530 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4531 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4532
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4533 case NFA_NOCTAL: /* \O */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4534 result = curc != NUL && !ri_octal(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4535 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4536 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4537
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4538 case NFA_WORD: /* \w */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4539 result = ri_word(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4540 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4541 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4542
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4543 case NFA_NWORD: /* \W */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4544 result = curc != NUL && !ri_word(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4545 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4546 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4547
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4548 case NFA_HEAD: /* \h */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4549 result = ri_head(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4550 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4551 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4552
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4553 case NFA_NHEAD: /* \H */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4554 result = curc != NUL && !ri_head(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4555 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4556 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4557
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4558 case NFA_ALPHA: /* \a */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4559 result = ri_alpha(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4560 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4561 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4562
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4563 case NFA_NALPHA: /* \A */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4564 result = curc != NUL && !ri_alpha(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4565 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4566 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4567
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4568 case NFA_LOWER: /* \l */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4569 result = ri_lower(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4570 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4571 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4572
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4573 case NFA_NLOWER: /* \L */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4574 result = curc != NUL && !ri_lower(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4575 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4576 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4577
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4578 case NFA_UPPER: /* \u */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4579 result = ri_upper(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4580 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4581 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4582
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4583 case NFA_NUPPER: /* \U */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4584 result = curc != NUL && !ri_upper(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4585 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4586 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4587
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4588 case NFA_BACKREF1:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4589 case NFA_BACKREF2:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4590 case NFA_BACKREF3:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4591 case NFA_BACKREF4:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4592 case NFA_BACKREF5:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4593 case NFA_BACKREF6:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4594 case NFA_BACKREF7:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4595 case NFA_BACKREF8:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4596 case NFA_BACKREF9:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4597 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4598 case NFA_ZREF1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4599 case NFA_ZREF2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4600 case NFA_ZREF3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4601 case NFA_ZREF4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4602 case NFA_ZREF5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4603 case NFA_ZREF6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4604 case NFA_ZREF7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4605 case NFA_ZREF8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4606 case NFA_ZREF9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4607 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4608 /* \1 .. \9 \z1 .. \z9 */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4609 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4610 int subidx;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4611 int bytelen;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4612
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4613 if (t->state->c <= NFA_BACKREF9)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4614 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4615 subidx = t->state->c - NFA_BACKREF1 + 1;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4616 result = match_backref(&t->subs.norm, subidx, &bytelen);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4617 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4618 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4619 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4620 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4621 subidx = t->state->c - NFA_ZREF1 + 1;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4622 result = match_zref(subidx, &bytelen);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4623 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4624 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4625
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4626 if (result)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4627 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4628 if (bytelen == 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4629 {
4692
08fbb1ce1bc5 updated for version 7.3.1093
Bram Moolenaar <bram@vim.org>
parents: 4690
diff changeset
4630 /* empty match always works, output of NFA_SKIP to be
08fbb1ce1bc5 updated for version 7.3.1093
Bram Moolenaar <bram@vim.org>
parents: 4690
diff changeset
4631 * used next */
08fbb1ce1bc5 updated for version 7.3.1093
Bram Moolenaar <bram@vim.org>
parents: 4690
diff changeset
4632 addstate_here(thislist, t->state->out->out, &t->subs,
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4633 t->pim, &listidx);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4634 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4635 else if (bytelen <= clen)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4636 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4637 /* match current character, jump ahead to out of
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4638 * NFA_SKIP */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4639 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4640 add_state = t->state->out->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4641 add_off = clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4642 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4643 log_subsexpr(&nextlist->t[nextlist->n - 1].subs);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4644 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4645 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4646 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4647 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
4648 /* skip over the matched characters, set character
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4649 * count in NFA_SKIP */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4650 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4651 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4652 add_off = bytelen;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4653 add_count = bytelen - clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4654 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4655 log_subsexpr(&nextlist->t[nextlist->n - 1].subs);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4656 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4657 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4658
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4659 }
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4660 break;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4661 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4662 case NFA_SKIP:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4663 /* charater of previous matching \1 .. \9 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4664 if (t->count - clen <= 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4665 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4666 /* end of match, go to what follows */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4667 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4668 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4669 add_off = clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4670 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4671 log_subsexpr(&nextlist->t[nextlist->n - 1].subs);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4672 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4673 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4674 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4675 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4676 /* add state again with decremented count */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4677 ll = nextlist;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4678 add_state = t->state;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4679 add_off = 0;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4680 add_count = t->count - clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4681 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4682 log_subsexpr(&nextlist->t[nextlist->n - 1].subs);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4683 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4684 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4685 break;
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4686
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4687 case NFA_SKIP_CHAR:
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4688 case NFA_ZSTART:
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
4689 case NFA_ZEND:
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4690 /* TODO: should not happen? */
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4691 break;
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4692
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4693 case NFA_LNUM:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4694 case NFA_LNUM_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4695 case NFA_LNUM_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4696 result = (REG_MULTI &&
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4697 nfa_re_num_cmp(t->state->val, t->state->c - NFA_LNUM,
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4698 (long_u)(reglnum + reg_firstlnum)));
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4699 if (result)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4700 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4701 t->pim, &listidx);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4702 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4703
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4704 case NFA_COL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4705 case NFA_COL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4706 case NFA_COL_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4707 result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_COL,
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4708 (long_u)(reginput - regline) + 1);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4709 if (result)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4710 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4711 t->pim, &listidx);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4712 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4713
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4714 case NFA_VCOL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4715 case NFA_VCOL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4716 case NFA_VCOL_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4717 result = nfa_re_num_cmp(t->state->val, t->state->c - NFA_VCOL,
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4718 (long_u)win_linetabsize(
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4719 reg_win == NULL ? curwin : reg_win,
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4720 regline, (colnr_T)(reginput - regline)) + 1);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4721 if (result)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4722 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4723 t->pim, &listidx);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4724 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4725
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4726 case NFA_CURSOR:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4727 result = (reg_win != NULL
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4728 && (reglnum + reg_firstlnum == reg_win->w_cursor.lnum)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4729 && ((colnr_T)(reginput - regline)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4730 == reg_win->w_cursor.col));
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4731 if (result)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4732 addstate_here(thislist, t->state->out, &t->subs,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4733 t->pim, &listidx);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4734 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4735
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4736 default: /* regular character */
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4737 {
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4738 int c = t->state->c;
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4739
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
4740 /* TODO: put this in #ifdef later */
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4741 if (c < -256)
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4742 EMSGN("INTERNAL: Negative state char: %ld", c);
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4743 if (is_Magic(c))
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4744 c = un_Magic(c);
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4745 result = (c == curc);
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4746
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4747 if (!result && ireg_ic)
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4748 result = MB_TOLOWER(c) == MB_TOLOWER(curc);
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4749 #ifdef FEAT_MBYTE
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4750 /* If there is a composing character which is not being
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4751 * ignored there can be no match. Match with composing
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4752 * character uses NFA_COMPOSING above. */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4753 if (result && enc_utf8 && !ireg_icombine
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4754 && clen != utf_char2len(curc))
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4755 result = FALSE;
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
4756 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4757 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4758 break;
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
4759 }
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4760
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4761 } /* switch (t->state->c) */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4762
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4763 if (add_state != NULL)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4764 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4765 if (t->pim != NULL)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4766 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4767 /* postponed invisible match */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4768 /* TODO: also do t->pim->pim recursively? */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4769 if (t->pim->result == NFA_PIM_TODO)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4770 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4771 #ifdef ENABLE_LOG
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4772 fprintf(log_fd, "\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4773 fprintf(log_fd, "==================================\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4774 fprintf(log_fd, "Postponed recursive nfa_regmatch()\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4775 fprintf(log_fd, "\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4776 #endif
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4777 result = recursive_regmatch(t->pim->state,
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4778 prog, submatch, m, &listids);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4779 t->pim->result = result ? NFA_PIM_MATCH
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4780 : NFA_PIM_NOMATCH;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4781 /* for \@! it is a match when result is FALSE */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4782 if (result != t->pim->state->negated)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4783 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4784 /* Copy submatch info from the recursive call */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4785 copy_sub_off(&t->pim->subs.norm, &m->norm);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4786 #ifdef FEAT_SYN_HL
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4787 copy_sub_off(&t->pim->subs.synt, &m->synt);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4788 #endif
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4789 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4790 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4791 else
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4792 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4793 result = (t->pim->result == NFA_PIM_MATCH);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4794 #ifdef ENABLE_LOG
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4795 fprintf(log_fd, "\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4796 fprintf(log_fd, "Using previous recursive nfa_regmatch() result, result == %d\n", t->pim->result);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4797 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
4798 fprintf(log_fd, "\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4799 #endif
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4800 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4801
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4802 /* for \@! it is a match when result is FALSE */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4803 if (result != t->pim->state->negated)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4804 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4805 /* Copy submatch info from the recursive call */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4806 copy_sub_off(&t->subs.norm, &t->pim->subs.norm);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4807 #ifdef FEAT_SYN_HL
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4808 copy_sub_off(&t->subs.synt, &t->pim->subs.synt);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4809 #endif
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4810 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4811 else
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4812 /* look-behind match failed, don't add the state */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4813 continue;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4814 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4815
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4816 addstate(ll, add_state, &t->subs, add_off);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4817 if (add_count > 0)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4818 nextlist->t[ll->n - 1].count = add_count;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4819 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4820
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4821 } /* for (thislist = thislist; thislist->state; thislist++) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4822
4557
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
4823 /* Look for the start of a match in the current position by adding the
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
4824 * start state to the list of states.
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
4825 * The first found match is the leftmost one, thus the order of states
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
4826 * matters!
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
4827 * Do not add the start state in recursive calls of nfa_regmatch(),
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
4828 * because recursive calls should only start in the first position.
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4829 * Unless "nfa_endp" is not NULL, then we match the end position.
4557
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
4830 * 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
4831 if (nfa_match == FALSE
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4832 && ((start->c == NFA_MOPEN
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4833 && reglnum == 0
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4834 && clen != 0
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4835 && (ireg_maxcol == 0
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4836 || (colnr_T)(reginput - regline) < ireg_maxcol))
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4837 || (nfa_endp != NULL
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4838 && (REG_MULTI
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4839 ? (reglnum < nfa_endp->se_u.pos.lnum
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4840 || (reglnum == nfa_endp->se_u.pos.lnum
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
4841 && (int)(reginput - regline)
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4842 < nfa_endp->se_u.pos.col))
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4843 : reginput < nfa_endp->se_u.ptr))))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4844 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4845 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4846 fprintf(log_fd, "(---) STARTSTATE\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4847 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4848 addstate(nextlist, start, m, clen);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4849 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4850
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4851 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4852 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
4853 {
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4854 int i;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4855
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4856 for (i = 0; i < thislist->n; i++)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4857 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
4858 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4859 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4860 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4861
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4862 nextchar:
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4863 /* Advance to the next character, or advance to the next line, or
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4864 * finish. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4865 if (clen != 0)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
4866 reginput += clen;
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4867 else if (go_to_nextline || (nfa_endp != NULL && REG_MULTI
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4868 && reglnum < nfa_endp->se_u.pos.lnum))
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4869 reg_nextline();
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4870 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4871 break;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4872 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4873
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4874 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4875 if (log_fd != stderr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4876 fclose(log_fd);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4877 log_fd = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4878 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4879
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4880 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4881 /* Free memory */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4882 vim_free(list[0].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4883 vim_free(list[1].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4884 vim_free(list[2].t);
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4885 vim_free(listids);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4886 ga_clear(&pimlist);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4887 #undef ADD_POS_NEG_STATE
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
4888 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4889 fclose(debug);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4890 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4891
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4892 return nfa_match;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4893 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4894
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4895 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4896 * Try match of "prog" with at regline["col"].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4897 * Returns 0 for failure, number of lines contained in the match otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4898 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4899 static long
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4900 nfa_regtry(prog, col)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4901 nfa_regprog_T *prog;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4902 colnr_T col;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4903 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4904 int i;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4905 regsubs_T subs, m;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4906 nfa_state_T *start = prog->start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4907 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4908 FILE *f;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4909 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4910
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4911 reginput = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4912 need_clear_subexpr = TRUE;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4913 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4914 /* Clear the external match subpointers if necessary. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4915 if (prog->reghasz == REX_SET)
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4916 {
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4917 nfa_has_zsubexpr = TRUE;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4918 need_clear_zsubexpr = TRUE;
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4919 }
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4920 else
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4921 nfa_has_zsubexpr = FALSE;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4922 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4923
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4924 #ifdef ENABLE_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
4925 f = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4926 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4927 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4928 fprintf(f, "\n\n\n\n\n\n\t\t=======================================================\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4929 fprintf(f, " =======================================================\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4930 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4931 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4932 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4933 fprintf(f, "\tInput text is \"%s\" \n", reginput);
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4934 fprintf(f, " =======================================================\n\n");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
4935 nfa_print_state(f, start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4936 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4937 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4938 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4939 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4940 EMSG(_("Could not open temporary log file for writing "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4941 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4942
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4943 clear_sub(&subs.norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4944 clear_sub(&m.norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4945 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4946 clear_sub(&subs.synt);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4947 clear_sub(&m.synt);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4948 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4949
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4950 if (nfa_regmatch(prog, start, &subs, &m) == FALSE)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4951 return 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4952
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4953 cleanup_subexpr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4954 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4955 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4956 for (i = 0; i < subs.norm.in_use; i++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4957 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4958 reg_startpos[i] = subs.norm.list.multi[i].start;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4959 reg_endpos[i] = subs.norm.list.multi[i].end;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4960 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4961
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4962 if (reg_startpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4963 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4964 reg_startpos[0].lnum = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4965 reg_startpos[0].col = col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4966 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4967 if (reg_endpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4968 {
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
4969 /* pattern has a \ze but it didn't match, use current end */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4970 reg_endpos[0].lnum = reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4971 reg_endpos[0].col = (int)(reginput - regline);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4972 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4973 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4974 /* Use line number of "\ze". */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4975 reglnum = reg_endpos[0].lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4976 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4977 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4978 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4979 for (i = 0; i < subs.norm.in_use; i++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4980 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4981 reg_startp[i] = subs.norm.list.line[i].start;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4982 reg_endp[i] = subs.norm.list.line[i].end;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4983 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4984
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4985 if (reg_startp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4986 reg_startp[0] = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4987 if (reg_endp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4988 reg_endp[0] = reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4989 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4990
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4991 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4992 /* Package any found \z(...\) matches for export. Default is none. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4993 unref_extmatch(re_extmatch_out);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4994 re_extmatch_out = NULL;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4995
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4996 if (prog->reghasz == REX_SET)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4997 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4998 cleanup_zsubexpr();
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4999 re_extmatch_out = make_extmatch();
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5000 for (i = 0; i < subs.synt.in_use; i++)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5001 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5002 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5003 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5004 struct multipos *mpos = &subs.synt.list.multi[i];
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5005
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5006 /* Only accept single line matches. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5007 if (mpos->start.lnum >= 0 && mpos->start.lnum == mpos->end.lnum)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5008 re_extmatch_out->matches[i] =
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5009 vim_strnsave(reg_getline(mpos->start.lnum)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5010 + mpos->start.col,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5011 mpos->end.col - mpos->start.col);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5012 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5013 else
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 struct linepos *lpos = &subs.synt.list.line[i];
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5016
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5017 if (lpos->start != NULL && lpos->end != NULL)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5018 re_extmatch_out->matches[i] =
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5019 vim_strnsave(lpos->start,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5020 (int)(lpos->end - lpos->start));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5021 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5022 }
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 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5025
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5026 return 1 + reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5027 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5028
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5029 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5030 * Match a regexp against a string ("line" points to the string) or multiple
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5031 * lines ("line" is NULL, use reg_getline()).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5032 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5033 * Returns 0 for failure, number of lines contained in the match otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5034 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5035 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5036 nfa_regexec_both(line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5037 char_u *line;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5038 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5039 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5040 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5041 long retval = 0L;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5042 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5043
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5044 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5045 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5046 prog = (nfa_regprog_T *)reg_mmatch->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5047 line = reg_getline((linenr_T)0); /* relative to the cursor */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5048 reg_startpos = reg_mmatch->startpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5049 reg_endpos = reg_mmatch->endpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5050 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5051 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5052 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5053 prog = (nfa_regprog_T *)reg_match->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5054 reg_startp = reg_match->startp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5055 reg_endp = reg_match->endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5056 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5057
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5058 /* Be paranoid... */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5059 if (prog == NULL || line == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5060 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5061 EMSG(_(e_null));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5062 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5063 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5064
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5065 /* If the start column is past the maximum column: no need to try. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5066 if (ireg_maxcol > 0 && col >= ireg_maxcol)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5067 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5068
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5069 /* If pattern contains "\c" or "\C": overrule value of ireg_ic */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5070 if (prog->regflags & RF_ICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5071 ireg_ic = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5072 else if (prog->regflags & RF_NOICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5073 ireg_ic = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5074
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5075 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5076 /* If pattern contains "\Z" overrule value of ireg_icombine */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5077 if (prog->regflags & RF_ICOMBINE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5078 ireg_icombine = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5079 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5080
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5081 regline = line;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5082 reglnum = 0; /* relative to line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5083
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
5084 nfa_has_zend = prog->has_zend;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
5085 nfa_has_backref = prog->has_backref;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
5086 nfa_nsubexpr = prog->nsubexp;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5087 nfa_listid = 1;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5088 nfa_alt_listid = 2;
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5089 #ifdef DEBUG
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5090 nfa_regengine.expr = prog->pattern;
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5091 #endif
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
5092
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5093 nstate = prog->nstate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5094 for (i = 0; i < nstate; ++i)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5095 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5096 prog->state[i].id = i;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5097 prog->state[i].lastlist[0] = 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5098 prog->state[i].lastlist[1] = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5099 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5100
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5101 retval = nfa_regtry(prog, col);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5102
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5103 #ifdef DEBUG
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5104 nfa_regengine.expr = NULL;
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5105 #endif
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5106
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5107 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5108 return retval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5109 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5110
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5111 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5112 * Compile a regular expression into internal code for the NFA matcher.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5113 * Returns the program in allocated space. Returns NULL for an error.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5114 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5115 static regprog_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5116 nfa_regcomp(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5117 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5118 int re_flags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5119 {
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5120 nfa_regprog_T *prog = NULL;
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
5121 size_t prog_size;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5122 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5123
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5124 if (expr == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5125 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5126
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5127 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5128 nfa_regengine.expr = expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5129 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5130
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5131 init_class_tab();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5132
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5133 if (nfa_regcomp_start(expr, re_flags) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5134 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5135
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5136 /* Build postfix form of the regexp. Needed to build the NFA
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5137 * (and count its size). */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5138 postfix = re2post();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5139 if (postfix == NULL)
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5140 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5141 /* TODO: only give this error for debugging? */
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5142 if (post_ptr >= post_end)
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5143 EMSGN("Internal error: estimated max number of states insufficient: %ld", post_end - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5144 goto fail; /* Cascaded (syntax?) error */
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5145 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5146
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5147 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5148 * In order to build the NFA, we parse the input regexp twice:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5149 * 1. first pass to count size (so we can allocate space)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5150 * 2. second to emit code
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5151 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5152 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5153 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
5154 FILE *f = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5155
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5156 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5157 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5158 fprintf(f, "\n*****************************\n\n\n\n\tCompiling regexp \"%s\" ... hold on !\n", expr);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5159 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5160 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5161 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5162 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5163
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5164 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5165 * PASS 1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5166 * Count number of NFA states in "nstate". Do not build the NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5167 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5168 post2nfa(postfix, post_ptr, TRUE);
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5169
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5170 /* Space for compiled regexp */
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5171 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate;
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5172 prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5173 if (prog == NULL)
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5174 goto fail;
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
5175 vim_memset(prog, 0, prog_size);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5176 state_ptr = prog->state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5177
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5178 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5179 * PASS 2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5180 * Build the NFA
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5181 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5182 prog->start = post2nfa(postfix, post_ptr, FALSE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5183 if (prog->start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5184 goto fail;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5185
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5186 prog->regflags = regflags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5187 prog->engine = &nfa_regengine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5188 prog->nstate = nstate;
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
5189 prog->has_zend = nfa_has_zend;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
5190 prog->has_backref = nfa_has_backref;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
5191 prog->nsubexp = regnpar;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5192 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5193 nfa_postfix_dump(expr, OK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5194 nfa_dump(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5195 #endif
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5196 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5197 /* Remember whether this pattern has any \z specials in it. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5198 prog->reghasz = re_has_z;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5199 #endif
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5200 #ifdef DEBUG
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5201 prog->pattern = vim_strsave(expr); /* memory will leak */
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5202 nfa_regengine.expr = NULL;
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5203 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5204
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5205 out:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5206 vim_free(post_start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5207 post_start = post_ptr = post_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5208 state_ptr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5209 return (regprog_T *)prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5210
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5211 fail:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5212 vim_free(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5213 prog = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5214 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5215 nfa_postfix_dump(expr, FAIL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5216 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5217 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5218 nfa_regengine.expr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5219 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5220 goto out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5221 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5222
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5223
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5224 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5225 * Match a regexp against a string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5226 * "rmp->regprog" is a compiled regexp as returned by nfa_regcomp().
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5227 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5228 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5229 * Return TRUE if there is a match, FALSE if not.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5230 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5231 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5232 nfa_regexec(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5233 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5234 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5235 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5236 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5237 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5238 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5239 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5240 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5241 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5242 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5243 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5244 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5245 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5246 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5247 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5248 return (nfa_regexec_both(line, col) != 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5249 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5250
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5251 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5252 || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5253
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5254 static int nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5255
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5256 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5257 * Like nfa_regexec(), but consider a "\n" in "line" to be a line break.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5258 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5259 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5260 nfa_regexec_nl(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5261 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5262 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5263 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5264 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5265 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5266 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5267 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5268 reg_line_lbr = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5269 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5270 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5271 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5272 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5273 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5274 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5275 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5276 return (nfa_regexec_both(line, col) != 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5277 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5278 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5279
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5280
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5281 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5282 * Match a regexp against multiple lines.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5283 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5284 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5285 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5286 * Return zero if there is no match. Return number of lines contained in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5287 * match otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5288 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5289 * Note: the body is the same as bt_regexec() except for nfa_regexec_both()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5290 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5291 * ! Also NOTE : match may actually be in another line. e.g.:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5292 * when r.e. is \nc, cursor is at 'a' and the text buffer looks like
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5293 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5294 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5295 * |a |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5296 * |b |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5297 * |c |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5298 * | |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5299 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5300 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5301 * then nfa_regexec_multi() returns 3. while the original
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5302 * vim_regexec_multi() returns 0 and a second call at line 2 will return 2.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5303 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5304 * FIXME if this behavior is not compatible.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5305 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5306 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5307 nfa_regexec_multi(rmp, win, buf, lnum, col, tm)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5308 regmmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5309 win_T *win; /* window in which to search or NULL */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5310 buf_T *buf; /* buffer in which to search */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5311 linenr_T lnum; /* nr of line to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5312 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5313 proftime_T *tm UNUSED; /* timeout limit or NULL */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5314 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5315 reg_match = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5316 reg_mmatch = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5317 reg_buf = buf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5318 reg_win = win;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5319 reg_firstlnum = lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5320 reg_maxline = reg_buf->b_ml.ml_line_count - lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5321 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5322 ireg_ic = rmp->rmm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5323 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5324 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5325 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5326 ireg_maxcol = rmp->rmm_maxcol;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5327
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
5328 return nfa_regexec_both(NULL, col);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5329 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5330
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5331 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5332 # undef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5333 #endif