annotate src/regexp_nfa.c @ 5251:2e63b6c763f7 v7.4b.002

updated for version 7.4b.002 Problem: Crash searching for \%(\%(\|\d\|-\|\.\)*\|\*\). (Marcin Szamotulski) Also for \(\)*. Solution: Do add a state for opening parenthesis, so that we can check if it was added before at the same position.
author Bram Moolenaar <bram@vim.org>
date Thu, 01 Aug 2013 15:45:52 +0200
parents a08fa2919f2b
children ea876fe91483
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 */
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
37
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
38 NFA_START_COLL, /* [abc] start */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
39 NFA_END_COLL, /* [abc] end */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
40 NFA_START_NEG_COLL, /* [^abc] start */
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
41 NFA_END_NEG_COLL, /* [^abc] end (postfix only) */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
42 NFA_RANGE, /* range of the two previous items
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
43 * (postfix only) */
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
44 NFA_RANGE_MIN, /* low end of a range */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
45 NFA_RANGE_MAX, /* high end of a range */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
46
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
47 NFA_CONCAT, /* concatenate two previous items (postfix
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
48 * only) */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
49 NFA_OR, /* \| (postfix only) */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
50 NFA_STAR, /* greedy * (posfix only) */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
51 NFA_STAR_NONGREEDY, /* non-greedy * (postfix only) */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
52 NFA_QUEST, /* greedy \? (postfix only) */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
53 NFA_QUEST_NONGREEDY, /* non-greedy \? (postfix only) */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 NFA_BOL, /* ^ Begin line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 NFA_EOL, /* $ End line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 NFA_BOW, /* \< Begin word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 NFA_EOW, /* \> End word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 NFA_BOF, /* \%^ Begin file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 NFA_EOF, /* \%$ End file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 NFA_NEWL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 NFA_ZSTART, /* Used for \zs */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 NFA_ZEND, /* Used for \ze */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 NFA_NOPEN, /* Start of subexpression marked with \%( */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 NFA_NCLOSE, /* End of subexpr. marked with \%( ... \) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 NFA_START_INVISIBLE,
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
67 NFA_START_INVISIBLE_FIRST,
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
68 NFA_START_INVISIBLE_NEG,
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
69 NFA_START_INVISIBLE_NEG_FIRST,
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
70 NFA_START_INVISIBLE_BEFORE,
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
71 NFA_START_INVISIBLE_BEFORE_FIRST,
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
72 NFA_START_INVISIBLE_BEFORE_NEG,
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
73 NFA_START_INVISIBLE_BEFORE_NEG_FIRST,
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
74 NFA_START_PATTERN,
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 NFA_END_INVISIBLE,
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
76 NFA_END_INVISIBLE_NEG,
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
77 NFA_END_PATTERN,
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 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
79 composing multibyte char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 NFA_END_COMPOSING, /* End of a composing char in the NFA */
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
81 NFA_OPT_CHARS, /* \%[abc] */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 /* 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
84 NFA_PREV_ATOM_NO_WIDTH, /* Used for \@= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 NFA_PREV_ATOM_NO_WIDTH_NEG, /* Used for \@! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 NFA_PREV_ATOM_JUST_BEFORE, /* Used for \@<= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 NFA_PREV_ATOM_JUST_BEFORE_NEG, /* Used for \@<! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 NFA_PREV_ATOM_LIKE_PATTERN, /* Used for \@> */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
90 NFA_BACKREF1, /* \1 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
91 NFA_BACKREF2, /* \2 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
92 NFA_BACKREF3, /* \3 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
93 NFA_BACKREF4, /* \4 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
94 NFA_BACKREF5, /* \5 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
95 NFA_BACKREF6, /* \6 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
96 NFA_BACKREF7, /* \7 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
97 NFA_BACKREF8, /* \8 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
98 NFA_BACKREF9, /* \9 */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
99 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
100 NFA_ZREF1, /* \z1 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
101 NFA_ZREF2, /* \z2 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
102 NFA_ZREF3, /* \z3 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
103 NFA_ZREF4, /* \z4 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
104 NFA_ZREF5, /* \z5 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
105 NFA_ZREF6, /* \z6 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
106 NFA_ZREF7, /* \z7 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
107 NFA_ZREF8, /* \z8 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
108 NFA_ZREF9, /* \z9 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
109 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
110 NFA_SKIP, /* Skip characters */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
111
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 NFA_MOPEN,
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
113 NFA_MOPEN1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
114 NFA_MOPEN2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
115 NFA_MOPEN3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
116 NFA_MOPEN4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
117 NFA_MOPEN5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
118 NFA_MOPEN6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
119 NFA_MOPEN7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
120 NFA_MOPEN8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
121 NFA_MOPEN9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
122
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
123 NFA_MCLOSE,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
124 NFA_MCLOSE1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
125 NFA_MCLOSE2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
126 NFA_MCLOSE3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
127 NFA_MCLOSE4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
128 NFA_MCLOSE5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
129 NFA_MCLOSE6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
130 NFA_MCLOSE7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
131 NFA_MCLOSE8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
132 NFA_MCLOSE9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
133
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
134 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
135 NFA_ZOPEN,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
136 NFA_ZOPEN1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
137 NFA_ZOPEN2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
138 NFA_ZOPEN3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
139 NFA_ZOPEN4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
140 NFA_ZOPEN5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
141 NFA_ZOPEN6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
142 NFA_ZOPEN7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
143 NFA_ZOPEN8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
144 NFA_ZOPEN9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
145
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
146 NFA_ZCLOSE,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
147 NFA_ZCLOSE1,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
148 NFA_ZCLOSE2,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
149 NFA_ZCLOSE3,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
150 NFA_ZCLOSE4,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
151 NFA_ZCLOSE5,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
152 NFA_ZCLOSE6,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
153 NFA_ZCLOSE7,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
154 NFA_ZCLOSE8,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
155 NFA_ZCLOSE9,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
156 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 /* NFA_FIRST_NL */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
159 NFA_ANY, /* Match any one character. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 NFA_IDENT, /* Match identifier char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 NFA_SIDENT, /* Match identifier char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 NFA_KWORD, /* Match keyword char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 NFA_SKWORD, /* Match word char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 NFA_FNAME, /* Match file name char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 NFA_SFNAME, /* Match file name char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 NFA_PRINT, /* Match printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 NFA_SPRINT, /* Match printable char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 NFA_WHITE, /* Match whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 NFA_NWHITE, /* Match non-whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 NFA_DIGIT, /* Match digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 NFA_NDIGIT, /* Match non-digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 NFA_HEX, /* Match hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 NFA_NHEX, /* Match non-hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 NFA_OCTAL, /* Match octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 NFA_NOCTAL, /* Match non-octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 NFA_WORD, /* Match word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 NFA_NWORD, /* Match non-word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
178 NFA_HEAD, /* Match head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 NFA_NHEAD, /* Match non-head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
180 NFA_ALPHA, /* Match alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 NFA_NALPHA, /* Match non-alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182 NFA_LOWER, /* Match lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
183 NFA_NLOWER, /* Match non-lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
184 NFA_UPPER, /* Match uppercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 NFA_NUPPER, /* Match non-uppercase char */
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
186
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
187 NFA_CURSOR, /* Match cursor pos */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
188 NFA_LNUM, /* Match line number */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
189 NFA_LNUM_GT, /* Match > line number */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
190 NFA_LNUM_LT, /* Match < line number */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
191 NFA_COL, /* Match cursor column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
192 NFA_COL_GT, /* Match > cursor column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
193 NFA_COL_LT, /* Match < cursor column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
194 NFA_VCOL, /* Match cursor virtual column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
195 NFA_VCOL_GT, /* Match > cursor virtual column */
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
196 NFA_VCOL_LT, /* Match < cursor virtual column */
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
197 NFA_MARK, /* Match mark */
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
198 NFA_MARK_GT, /* Match > mark */
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
199 NFA_MARK_LT, /* Match < mark */
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4728
diff changeset
200 NFA_VISUAL, /* Match Visual area */
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
201
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 NFA_FIRST_NL = NFA_ANY + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 NFA_LAST_NL = NFA_NUPPER + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 /* Character classes [:alnum:] etc */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 NFA_CLASS_ALNUM,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 NFA_CLASS_ALPHA,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 NFA_CLASS_BLANK,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 NFA_CLASS_CNTRL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 NFA_CLASS_DIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 NFA_CLASS_GRAPH,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 NFA_CLASS_LOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 NFA_CLASS_PRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 NFA_CLASS_PUNCT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 NFA_CLASS_SPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216 NFA_CLASS_UPPER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 NFA_CLASS_XDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 NFA_CLASS_TAB,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 NFA_CLASS_RETURN,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 NFA_CLASS_BACKSPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 NFA_CLASS_ESCAPE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 /* Keep in sync with classchars. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 static int nfa_classcodes[] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 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
227 NFA_FNAME, NFA_SFNAME, NFA_PRINT, NFA_SPRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 NFA_WHITE, NFA_NWHITE, NFA_DIGIT, NFA_NDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 NFA_HEX, NFA_NHEX, NFA_OCTAL, NFA_NOCTAL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 NFA_WORD, NFA_NWORD, NFA_HEAD, NFA_NHEAD,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 NFA_ALPHA, NFA_NALPHA, NFA_LOWER, NFA_NLOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 NFA_UPPER, NFA_NUPPER
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235 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
236
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
237 /* NFA regexp \ze operator encountered. */
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
238 static int nfa_has_zend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
240 /* NFA regexp \1 .. \9 encountered. */
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
241 static int nfa_has_backref;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
242
4720
bd6bef0bd0fb updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents: 4718
diff changeset
243 #ifdef FEAT_SYN_HL
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
244 /* NFA regexp has \z( ), set zsubexpr. */
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
245 static int nfa_has_zsubexpr;
4720
bd6bef0bd0fb updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents: 4718
diff changeset
246 #endif
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
247
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
248 /* 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
249 * the whole match (subexpr 0) is used. */
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
250 static int nfa_nsubexpr;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
251
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252 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
253 static int *post_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 static int *post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
256 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
257 * executing. */
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
258 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
259
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
260 /* 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
261 static save_se_T *nfa_endp = NULL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
263 /* 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
264 * 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
265 * all the states. */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
266 static int nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
267 static int nfa_alt_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
268
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
269 /* 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
270 static int nfa_ll_index = 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
271
4770
b20dbf3a5370 updated for version 7.3.1132
Bram Moolenaar <bram@vim.org>
parents: 4768
diff changeset
272 static int nfa_regcomp_start __ARGS((char_u *expr, int re_flags));
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
273 static int nfa_get_reganch __ARGS((nfa_state_T *start, int depth));
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
274 static int nfa_get_regstart __ARGS((nfa_state_T *start, int depth));
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
275 static char_u *nfa_get_match_text __ARGS((nfa_state_T *start));
4938
bcb84438bb5b updated for version 7.3.1214
Bram Moolenaar <bram@vim.org>
parents: 4924
diff changeset
276 static int realloc_post_list __ARGS((void));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 static int nfa_recognize_char_class __ARGS((char_u *start, char_u *end, int extra_newl));
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
278 static int nfa_emit_equi_class __ARGS((int c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 static int nfa_regatom __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 static int nfa_regpiece __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281 static int nfa_regconcat __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 static int nfa_regbranch __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 static int nfa_reg __ARGS((int paren));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 static void nfa_set_code __ARGS((int c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 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
287 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
288 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
289 static void nfa_dump __ARGS((nfa_regprog_T *prog));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291 static int *re2post __ARGS((void));
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
292 static nfa_state_T *alloc_state __ARGS((int c, nfa_state_T *out, nfa_state_T *out1));
4997
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
293 static void st_error __ARGS((int *postfix, int *end, int *p));
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
294 static int nfa_max_width __ARGS((nfa_state_T *startstate, int depth));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size));
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
296 static void nfa_postprocess __ARGS((nfa_regprog_T *prog));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297 static int check_char_class __ARGS((int class, int c));
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
298 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
299 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
300 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
301 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
302 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
303 static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags));
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
304 static void nfa_regfree __ARGS((regprog_T *prog));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 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
306 static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
307 static int match_follows __ARGS((nfa_state_T *startstate, int depth));
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
308 static int failure_chance __ARGS((nfa_state_T *state, int depth));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
309
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
310 /* helper functions used when doing re2post() ... regatom() parsing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
311 #define EMIT(c) do { \
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
312 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
313 return FAIL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 *post_ptr++ = c; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 } while (0)
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 * Initialize internal variables before NFA compilation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 * Return OK on success, FAIL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
321 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322 nfa_regcomp_start(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 int re_flags; /* see vim_regcomp() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
326 size_t postfix_size;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
327 int nstate_max;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 nstate = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 istate = 0;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
331 /* A reasonable estimation for maximum size */
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
332 nstate_max = (int)(STRLEN(expr) + 1) * 25;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
333
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
334 /* 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
335 * 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
336 nstate_max += 1000;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
337
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
338 /* Size for postfix representation of expr. */
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
339 postfix_size = sizeof(int) * nstate_max;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
340
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
341 post_start = (int *)lalloc(postfix_size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
342 if (post_start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 post_ptr = post_start;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
345 post_end = post_start + nstate_max;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
346 nfa_has_zend = FALSE;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
347 nfa_has_backref = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
348
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
349 /* shared with BT engine */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 regcomp_start(expr, re_flags);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 /*
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
356 * Figure out if the NFA state list starts with an anchor, must match at start
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
357 * of the line.
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
358 */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
359 static int
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
360 nfa_get_reganch(start, depth)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
361 nfa_state_T *start;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
362 int depth;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
363 {
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
364 nfa_state_T *p = start;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
365
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
366 if (depth > 4)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
367 return 0;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
368
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
369 while (p != NULL)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
370 {
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
371 switch (p->c)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
372 {
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
373 case NFA_BOL:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
374 case NFA_BOF:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
375 return 1; /* yes! */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
376
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
377 case NFA_ZSTART:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
378 case NFA_ZEND:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
379 case NFA_CURSOR:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
380 case NFA_VISUAL:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
381
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
382 case NFA_MOPEN:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
383 case NFA_MOPEN1:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
384 case NFA_MOPEN2:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
385 case NFA_MOPEN3:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
386 case NFA_MOPEN4:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
387 case NFA_MOPEN5:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
388 case NFA_MOPEN6:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
389 case NFA_MOPEN7:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
390 case NFA_MOPEN8:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
391 case NFA_MOPEN9:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
392 case NFA_NOPEN:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
393 #ifdef FEAT_SYN_HL
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
394 case NFA_ZOPEN:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
395 case NFA_ZOPEN1:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
396 case NFA_ZOPEN2:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
397 case NFA_ZOPEN3:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
398 case NFA_ZOPEN4:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
399 case NFA_ZOPEN5:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
400 case NFA_ZOPEN6:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
401 case NFA_ZOPEN7:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
402 case NFA_ZOPEN8:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
403 case NFA_ZOPEN9:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
404 #endif
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
405 p = p->out;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
406 break;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
407
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
408 case NFA_SPLIT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
409 return nfa_get_reganch(p->out, depth + 1)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
410 && nfa_get_reganch(p->out1, depth + 1);
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
411
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
412 default:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
413 return 0; /* noooo */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
414 }
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
415 }
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
416 return 0;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
417 }
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
418
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
419 /*
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
420 * Figure out if the NFA state list starts with a character which must match
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
421 * at start of the match.
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
422 */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
423 static int
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
424 nfa_get_regstart(start, depth)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
425 nfa_state_T *start;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
426 int depth;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
427 {
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
428 nfa_state_T *p = start;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
429
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
430 if (depth > 4)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
431 return 0;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
432
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
433 while (p != NULL)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
434 {
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
435 switch (p->c)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
436 {
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
437 /* all kinds of zero-width matches */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
438 case NFA_BOL:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
439 case NFA_BOF:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
440 case NFA_BOW:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
441 case NFA_EOW:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
442 case NFA_ZSTART:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
443 case NFA_ZEND:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
444 case NFA_CURSOR:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
445 case NFA_VISUAL:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
446 case NFA_LNUM:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
447 case NFA_LNUM_GT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
448 case NFA_LNUM_LT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
449 case NFA_COL:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
450 case NFA_COL_GT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
451 case NFA_COL_LT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
452 case NFA_VCOL:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
453 case NFA_VCOL_GT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
454 case NFA_VCOL_LT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
455 case NFA_MARK:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
456 case NFA_MARK_GT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
457 case NFA_MARK_LT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
458
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
459 case NFA_MOPEN:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
460 case NFA_MOPEN1:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
461 case NFA_MOPEN2:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
462 case NFA_MOPEN3:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
463 case NFA_MOPEN4:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
464 case NFA_MOPEN5:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
465 case NFA_MOPEN6:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
466 case NFA_MOPEN7:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
467 case NFA_MOPEN8:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
468 case NFA_MOPEN9:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
469 case NFA_NOPEN:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
470 #ifdef FEAT_SYN_HL
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
471 case NFA_ZOPEN:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
472 case NFA_ZOPEN1:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
473 case NFA_ZOPEN2:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
474 case NFA_ZOPEN3:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
475 case NFA_ZOPEN4:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
476 case NFA_ZOPEN5:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
477 case NFA_ZOPEN6:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
478 case NFA_ZOPEN7:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
479 case NFA_ZOPEN8:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
480 case NFA_ZOPEN9:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
481 #endif
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
482 p = p->out;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
483 break;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
484
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
485 case NFA_SPLIT:
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
486 {
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
487 int c1 = nfa_get_regstart(p->out, depth + 1);
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
488 int c2 = nfa_get_regstart(p->out1, depth + 1);
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
489
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
490 if (c1 == c2)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
491 return c1; /* yes! */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
492 return 0;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
493 }
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
494
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
495 default:
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
496 if (p->c > 0)
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
497 return p->c; /* yes! */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
498 return 0;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
499 }
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
500 }
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
501 return 0;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
502 }
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
503
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
504 /*
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
505 * Figure out if the NFA state list contains just literal text and nothing
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
506 * else. If so return a string in allocated memory with what must match after
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
507 * regstart. Otherwise return NULL.
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
508 */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
509 static char_u *
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
510 nfa_get_match_text(start)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
511 nfa_state_T *start;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
512 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
513 nfa_state_T *p = start;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
514 int len = 0;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
515 char_u *ret;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
516 char_u *s;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
517
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
518 if (p->c != NFA_MOPEN)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
519 return NULL; /* just in case */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
520 p = p->out;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
521 while (p->c > 0)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
522 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
523 len += MB_CHAR2LEN(p->c);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
524 p = p->out;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
525 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
526 if (p->c != NFA_MCLOSE || p->out->c != NFA_MATCH)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
527 return NULL;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
528
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
529 ret = alloc(len);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
530 if (ret != NULL)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
531 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
532 len = 0;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
533 p = start->out->out; /* skip first char, it goes into regstart */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
534 s = ret;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
535 while (p->c > 0)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
536 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
537 #ifdef FEAT_MBYTE
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
538 if (has_mbyte)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
539 s += (*mb_char2bytes)(p->c, s);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
540 else
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
541 #endif
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
542 *s++ = p->c;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
543 p = p->out;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
544 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
545 *s = NUL;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
546 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
547 return ret;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
548 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
549
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
550 /*
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
551 * Allocate more space for post_start. Called when
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
552 * running above the estimated number of states.
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
553 */
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
554 static int
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
555 realloc_post_list()
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
556 {
4667
9e7ef781d494 updated for version 7.3.1081
Bram Moolenaar <bram@vim.org>
parents: 4661
diff changeset
557 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
558 int new_max = nstate_max + 1000;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
559 int *new_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
560 int *old_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
561
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
562 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
563 if (new_start == NULL)
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
564 return FAIL;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
565 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
566 old_start = post_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
567 post_start = new_start;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
568 post_ptr = new_start + (post_ptr - old_start);
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
569 post_end = post_start + new_max;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
570 vim_free(old_start);
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
571 return OK;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
572 }
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
573
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
574 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
575 * 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
576 * character class in expanded form. For example [0-9].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
577 * 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
578 * On failure, return 0 (=FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
579 * 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
580 * to the closing brace.
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 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
583 nfa_recognize_char_class(start, end, extra_newl)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
584 char_u *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
585 char_u *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
586 int extra_newl;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
587 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
588 # define CLASS_not 0x80
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
589 # define CLASS_af 0x40
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
590 # define CLASS_AF 0x20
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
591 # define CLASS_az 0x10
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
592 # define CLASS_AZ 0x08
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
593 # define CLASS_o7 0x04
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
594 # define CLASS_o9 0x02
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
595 # define CLASS_underscore 0x01
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
596
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
597 int newl = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
598 char_u *p;
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
599 int config = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
600
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
601 if (extra_newl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
602 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
603
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
604 if (*end != ']')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
605 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606 p = start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 if (*p == '^')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
609 config |= CLASS_not;
4720
bd6bef0bd0fb updated for version 7.3.1107
Bram Moolenaar <bram@vim.org>
parents: 4718
diff changeset
610 p++;
4444
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
613 while (p < end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
614 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615 if (p + 2 < end && *(p + 1) == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
616 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
617 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
618 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
619 case '0':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 if (*(p + 2) == '9')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
621 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
622 config |= CLASS_o9;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
623 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
624 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
625 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
626 if (*(p + 2) == '7')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
628 config |= CLASS_o7;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629 break;
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 case 'a':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
632 if (*(p + 2) == 'z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
633 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
634 config |= CLASS_az;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
635 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
636 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
637 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
638 if (*(p + 2) == 'f')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
639 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
640 config |= CLASS_af;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
641 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
642 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
643 case 'A':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
644 if (*(p + 2) == 'Z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
645 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
646 config |= CLASS_AZ;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
647 break;
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 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 if (*(p + 2) == 'F')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
652 config |= CLASS_AF;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
653 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
654 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
655 /* FALLTHROUGH */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
656 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
657 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
658 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
659 p += 3;
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 else if (p + 1 < end && *p == '\\' && *(p + 1) == 'n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
662 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
663 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
664 p += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
665 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 else if (*p == '_')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
668 config |= CLASS_underscore;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
669 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
670 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
671 else if (*p == '\n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
672 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
673 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 } /* while (p < end) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
679
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
680 if (p != end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
682
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
683 if (newl == TRUE)
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
684 extra_newl = ADD_NL;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
685
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
686 switch (config)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
687 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
688 case CLASS_o9:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
689 return extra_newl + NFA_DIGIT;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
690 case CLASS_not | CLASS_o9:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
691 return extra_newl + NFA_NDIGIT;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
692 case CLASS_af | CLASS_AF | CLASS_o9:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
693 return extra_newl + NFA_HEX;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
694 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
695 return extra_newl + NFA_NHEX;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
696 case CLASS_o7:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
697 return extra_newl + NFA_OCTAL;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
698 case CLASS_not | CLASS_o7:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
699 return extra_newl + NFA_NOCTAL;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
700 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
701 return extra_newl + NFA_WORD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
702 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
703 return extra_newl + NFA_NWORD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
704 case CLASS_az | CLASS_AZ | CLASS_underscore:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
705 return extra_newl + NFA_HEAD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
706 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
707 return extra_newl + NFA_NHEAD;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
708 case CLASS_az | CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
709 return extra_newl + NFA_ALPHA;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
710 case CLASS_not | CLASS_az | CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
711 return extra_newl + NFA_NALPHA;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
712 case CLASS_az:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
713 return extra_newl + NFA_LOWER;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
714 case CLASS_not | CLASS_az:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
715 return extra_newl + NFA_NLOWER;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
716 case CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
717 return extra_newl + NFA_UPPER;
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
718 case CLASS_not | CLASS_AZ:
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
719 return extra_newl + NFA_NUPPER;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
720 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
721 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
722 }
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
725 * Produce the bytes for equivalence class "c".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
726 * Currently only handles latin1, latin9 and utf-8.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
727 * 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
728 * equivalent to 'a OR b OR c'
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 * 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
731 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732 static int
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
733 nfa_emit_equi_class(c)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
734 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
735 {
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
736 #define EMIT2(c) EMIT(c); EMIT(NFA_CONCAT);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
737
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
738 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
739 if (enc_utf8 || STRCMP(p_enc, "latin1") == 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740 || STRCMP(p_enc, "iso-8859-15") == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
741 #endif
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 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
744 {
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
745 case 'A': case 0300: case 0301: case 0302:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
746 case 0303: case 0304: case 0305:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
747 EMIT2('A'); EMIT2(0300); EMIT2(0301);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
748 EMIT2(0302); EMIT2(0303); EMIT2(0304);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
749 EMIT2(0305);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
751
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
752 case 'C': case 0307:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
753 EMIT2('C'); EMIT2(0307);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
756 case 'E': case 0310: case 0311: case 0312: case 0313:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
757 EMIT2('E'); EMIT2(0310); EMIT2(0311);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
758 EMIT2(0312); EMIT2(0313);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
759 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
760
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
761 case 'I': case 0314: case 0315: case 0316: case 0317:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
762 EMIT2('I'); EMIT2(0314); EMIT2(0315);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
763 EMIT2(0316); EMIT2(0317);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
764 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
765
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
766 case 'N': case 0321:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
767 EMIT2('N'); EMIT2(0321);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
768 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
769
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
770 case 'O': case 0322: case 0323: case 0324: case 0325:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
771 case 0326:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
772 EMIT2('O'); EMIT2(0322); EMIT2(0323);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
773 EMIT2(0324); EMIT2(0325); EMIT2(0326);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
774 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
775
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
776 case 'U': case 0331: case 0332: case 0333: case 0334:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
777 EMIT2('U'); EMIT2(0331); EMIT2(0332);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
778 EMIT2(0333); EMIT2(0334);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
781 case 'Y': case 0335:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
782 EMIT2('Y'); EMIT2(0335);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
784
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
785 case 'a': case 0340: case 0341: case 0342:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
786 case 0343: case 0344: case 0345:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
787 EMIT2('a'); EMIT2(0340); EMIT2(0341);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
788 EMIT2(0342); EMIT2(0343); EMIT2(0344);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
789 EMIT2(0345);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
790 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
791
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
792 case 'c': case 0347:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
793 EMIT2('c'); EMIT2(0347);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
796 case 'e': case 0350: case 0351: case 0352: case 0353:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
797 EMIT2('e'); EMIT2(0350); EMIT2(0351);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
798 EMIT2(0352); EMIT2(0353);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
799 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
800
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
801 case 'i': case 0354: case 0355: case 0356: case 0357:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
802 EMIT2('i'); EMIT2(0354); EMIT2(0355);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
803 EMIT2(0356); EMIT2(0357);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
804 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
805
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
806 case 'n': case 0361:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
807 EMIT2('n'); EMIT2(0361);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
808 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
809
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
810 case 'o': case 0362: case 0363: case 0364: case 0365:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
811 case 0366:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
812 EMIT2('o'); EMIT2(0362); EMIT2(0363);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
813 EMIT2(0364); EMIT2(0365); EMIT2(0366);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
814 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
815
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
816 case 'u': case 0371: case 0372: case 0373: case 0374:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
817 EMIT2('u'); EMIT2(0371); EMIT2(0372);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
818 EMIT2(0373); EMIT2(0374);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
819 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
820
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
821 case 'y': case 0375: case 0377:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
822 EMIT2('y'); EMIT2(0375); EMIT2(0377);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
823 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
824
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
825 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
826 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
827 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
828 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
829
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
830 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
831 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
832 #undef EMIT2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
833 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
834
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
835 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
836 * Code to parse regular expression.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
837 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
838 * 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
839 * minimize surprise and keep the syntax consistent.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
840 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
841
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
842 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
843 * Parse the lowest level.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
844 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
845 * 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
846 * 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
847 * 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
848 * is only for syntax highlighting.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
849 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
850 * atom ::= ordinary-atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
851 * or \( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
852 * or \%( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
853 * or \z( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
854 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
855 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
856 nfa_regatom()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
857 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
858 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
859 int charclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
860 int equiclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
861 int collclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
862 int got_coll_char;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
863 char_u *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
864 char_u *endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
865 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
866 char_u *old_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
867 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
868 int extra = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
869 int emit_range;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
870 int negated;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
871 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
872 int startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
873 int endc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
874 int oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
875
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
876 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
877 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
878 {
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
879 case NUL:
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
880 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
881
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
882 case Magic('^'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
883 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
884 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
885
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
886 case Magic('$'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
887 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
888 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
889 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
890 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
891 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
892
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
893 case Magic('<'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
894 EMIT(NFA_BOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
895 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
896
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
897 case Magic('>'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
898 EMIT(NFA_EOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
899 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
900
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
901 case Magic('_'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
902 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
903 if (c == '^') /* "\_^" is start-of-line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
904 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
905 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
906 break;
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 if (c == '$') /* "\_$" is end-of-line */
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 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
911 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
912 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
913 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
914 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
915 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
916
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
917 extra = ADD_NL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
918
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
919 /* "\_[" is collection plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
920 if (c == '[')
4517
9a2183bd8295 updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents: 4515
diff changeset
921 goto collection;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
922
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
923 /* "\_x" is character class plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
924 /*FALLTHROUGH*/
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
925
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
926 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
927 * Character classes.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
928 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
929 case Magic('.'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
930 case Magic('i'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
931 case Magic('I'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
932 case Magic('k'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
933 case Magic('K'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
934 case Magic('f'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
935 case Magic('F'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
936 case Magic('p'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
937 case Magic('P'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
938 case Magic('s'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
939 case Magic('S'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
940 case Magic('d'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
941 case Magic('D'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
942 case Magic('x'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
943 case Magic('X'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
944 case Magic('o'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
945 case Magic('O'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
946 case Magic('w'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
947 case Magic('W'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
948 case Magic('h'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
949 case Magic('H'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
950 case Magic('a'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
951 case Magic('A'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
952 case Magic('l'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
953 case Magic('L'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
954 case Magic('u'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
955 case Magic('U'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
956 p = vim_strchr(classchars, no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
957 if (p == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
958 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
959 EMSGN("INTERNAL: Unknown character class char: %ld", c);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
960 return FAIL;
4444
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 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
963 /* 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
964 * the composing char is matched here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
965 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr()))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
966 {
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
967 old_regparse = regparse;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
968 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
969 goto nfa_do_multibyte;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
970 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
971 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
972 EMIT(nfa_classcodes[p - classchars]);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
973 if (extra == ADD_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
974 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
975 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
976 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
977 regflags |= RF_HASNL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
978 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
979 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
980
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
981 case Magic('n'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
982 if (reg_string)
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
983 /* In a string "\n" matches a newline character. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
984 EMIT(NL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
985 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
986 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
987 /* 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
988 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
989 regflags |= RF_HASNL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
990 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
991 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
992
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
993 case Magic('('):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
994 if (nfa_reg(REG_PAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
995 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
996 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
997
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
998 case Magic('|'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
999 case Magic('&'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1000 case Magic(')'):
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
1001 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1002 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1003
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1004 case Magic('='):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1005 case Magic('?'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1006 case Magic('+'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1007 case Magic('@'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1008 case Magic('*'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1009 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1010 /* these should follow an atom, not form an atom */
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
1011 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1012 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1013
4714
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1014 case Magic('~'):
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1015 {
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1016 char_u *lp;
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1017
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1018 /* Previous substitute pattern.
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1019 * Generated as "\%(pattern\)". */
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1020 if (reg_prev_sub == NULL)
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1021 {
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1022 EMSG(_(e_nopresub));
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1023 return FAIL;
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1024 }
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1025 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
1026 {
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1027 EMIT(PTR2CHAR(lp));
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1028 if (lp != reg_prev_sub)
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1029 EMIT(NFA_CONCAT);
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1030 }
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1031 EMIT(NFA_NOPEN);
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1032 break;
fc4d7f02ea3a updated for version 7.3.1104
Bram Moolenaar <bram@vim.org>
parents: 4712
diff changeset
1033 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1034
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1035 case Magic('1'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1036 case Magic('2'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1037 case Magic('3'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1038 case Magic('4'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1039 case Magic('5'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1040 case Magic('6'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1041 case Magic('7'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1042 case Magic('8'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1043 case Magic('9'):
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1044 EMIT(NFA_BACKREF1 + (no_Magic(c) - '1'));
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1045 nfa_has_backref = TRUE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
1046 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1047
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1048 case Magic('z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1049 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1050 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1051 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1052 case 's':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1053 EMIT(NFA_ZSTART);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1054 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1055 case 'e':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1056 EMIT(NFA_ZEND);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1057 nfa_has_zend = TRUE;
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
1058 break;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1059 #ifdef FEAT_SYN_HL
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1060 case '1':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1061 case '2':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1062 case '3':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1063 case '4':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1064 case '5':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1065 case '6':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1066 case '7':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1067 case '8':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1068 case '9':
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1069 /* \z1...\z9 */
4688
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
1070 if (reg_do_extmatch != REX_USE)
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
1071 EMSG_RET_FAIL(_(e_z1_not_allowed));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1072 EMIT(NFA_ZREF1 + (no_Magic(c) - '1'));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1073 /* 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
1074 * change when \z1 .. \z9 matches or not. */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1075 re_has_z = REX_USE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1076 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1077 case '(':
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1078 /* \z( */
4688
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
1079 if (reg_do_extmatch != REX_SET)
371cc0c44097 updated for version 7.3.1091
Bram Moolenaar <bram@vim.org>
parents: 4686
diff changeset
1080 EMSG_RET_FAIL(_(e_z_not_allowed));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1081 if (nfa_reg(REG_ZPAREN) == FAIL)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1082 return FAIL; /* cascaded error */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1083 re_has_z = REX_SET;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1084 break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1085 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1086 default:
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
1087 EMSGN(_("E867: (NFA) Unknown operator '\\z%c'"),
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1088 no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1089 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1090 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1091 break;
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 case Magic('%'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1094 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1095 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1096 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1097 /* () without a back reference */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1098 case '(':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1099 if (nfa_reg(REG_NPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1100 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1101 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1102 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1103
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1104 case 'd': /* %d123 decimal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1105 case 'o': /* %o123 octal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1106 case 'x': /* %xab hex 2 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1107 case 'u': /* %uabcd hex 4 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1108 case 'U': /* %U1234abcd hex 8 */
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1109 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1110 int nr;
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1111
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1112 switch (c)
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1113 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1114 case 'd': nr = getdecchrs(); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1115 case 'o': nr = getoctchrs(); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1116 case 'x': nr = gethexchrs(2); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1117 case 'u': nr = gethexchrs(4); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1118 case 'U': nr = gethexchrs(8); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1119 default: nr = -1; break;
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1120 }
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1121
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1122 if (nr < 0)
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1123 EMSG2_RET_FAIL(
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1124 _("E678: Invalid character after %s%%[dxouU]"),
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1125 reg_magic == MAGIC_ALL);
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1126 /* TODO: what if a composing character follows? */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1127 EMIT(nr);
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1128 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1129 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1130
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1131 /* Catch \%^ and \%$ regardless of where they appear in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1132 * pattern -- regardless of whether or not it makes sense. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1133 case '^':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1134 EMIT(NFA_BOF);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1135 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1136
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1137 case '$':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1138 EMIT(NFA_EOF);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1139 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1140
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1141 case '#':
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1142 EMIT(NFA_CURSOR);
4444
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1145 case 'V':
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4728
diff changeset
1146 EMIT(NFA_VISUAL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1147 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1148
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1149 case '[':
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1150 {
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1151 int n;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1152
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1153 /* \%[abc] */
4944
613651492c19 updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents: 4938
diff changeset
1154 for (n = 0; (c = peekchr()) != ']'; ++n)
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1155 {
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1156 if (c == NUL)
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1157 EMSG2_RET_FAIL(_(e_missing_sb),
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1158 reg_magic == MAGIC_ALL);
4944
613651492c19 updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents: 4938
diff changeset
1159 /* recursive call! */
613651492c19 updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents: 4938
diff changeset
1160 if (nfa_regatom() == FAIL)
613651492c19 updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents: 4938
diff changeset
1161 return FAIL;
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1162 }
4944
613651492c19 updated for version 7.3.1217
Bram Moolenaar <bram@vim.org>
parents: 4938
diff changeset
1163 getchr(); /* get the ] */
4760
532a9855bd30 updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents: 4758
diff changeset
1164 if (n == 0)
532a9855bd30 updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents: 4758
diff changeset
1165 EMSG2_RET_FAIL(_(e_empty_sb),
532a9855bd30 updated for version 7.3.1127
Bram Moolenaar <bram@vim.org>
parents: 4758
diff changeset
1166 reg_magic == MAGIC_ALL);
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1167 EMIT(NFA_OPT_CHARS);
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1168 EMIT(n);
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1169 break;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1170 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1171
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1172 default:
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1173 {
4655
779ca415f8e1 updated for version 7.3.1075
Bram Moolenaar <bram@vim.org>
parents: 4651
diff changeset
1174 int n = 0;
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1175 int cmp = c;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1176
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1177 if (c == '<' || c == '>')
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1178 c = getchr();
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1179 while (VIM_ISDIGIT(c))
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1180 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1181 n = n * 10 + (c - '0');
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1182 c = getchr();
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1183 }
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1184 if (c == 'l' || c == 'c' || c == 'v')
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1185 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1186 if (c == 'l')
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1187 /* \%{n}l \%{n}<l \%{n}>l */
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1188 EMIT(cmp == '<' ? NFA_LNUM_LT :
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1189 cmp == '>' ? NFA_LNUM_GT : NFA_LNUM);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1190 else if (c == 'c')
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1191 /* \%{n}c \%{n}<c \%{n}>c */
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1192 EMIT(cmp == '<' ? NFA_COL_LT :
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1193 cmp == '>' ? NFA_COL_GT : NFA_COL);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1194 else
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1195 /* \%{n}v \%{n}<v \%{n}>v */
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1196 EMIT(cmp == '<' ? NFA_VCOL_LT :
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1197 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL);
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1198 EMIT(n);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1199 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1200 }
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1201 else if (c == '\'' && n == 0)
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1202 {
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1203 /* \%'m \%<'m \%>'m */
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1204 EMIT(cmp == '<' ? NFA_MARK_LT :
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1205 cmp == '>' ? NFA_MARK_GT : NFA_MARK);
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
1206 EMIT(getchr());
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1207 break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
1208 }
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
1209 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1210 EMSGN(_("E867: (NFA) Unknown operator '\\%%%c'"),
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1211 no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1212 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1213 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1214 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1215
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1216 case Magic('['):
4517
9a2183bd8295 updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents: 4515
diff changeset
1217 collection:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1218 /*
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1219 * [abc] uses NFA_START_COLL - NFA_END_COLL
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1220 * [^abc] uses NFA_START_NEG_COLL - NFA_END_NEG_COLL
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1221 * Each character is produced as a regular state, using
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1222 * NFA_CONCAT to bind them together.
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1223 * Besides normal characters there can be:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1224 * - character classes NFA_CLASS_*
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1225 * - ranges, two characters followed by NFA_RANGE.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1226 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1227
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1228 p = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1229 endp = skip_anyof(p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1230 if (*endp == ']')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1231 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1232 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1233 * Try to reverse engineer character classes. For example,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1234 * 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
1235 * and perform the necessary substitutions in the NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1236 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1237 result = nfa_recognize_char_class(regparse, endp,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1238 extra == ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1239 if (result != FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1240 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1241 if (result >= NFA_DIGIT && result <= NFA_NUPPER)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1242 EMIT(result);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1243 else /* must be char class + newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1244 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1245 EMIT(result - ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1246 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1247 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1248 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1249 regparse = endp;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1250 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1251 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1252 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1253 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1254 * Failed to recognize a character class. Use the simple
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1255 * 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
1256 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1257 startc = endc = oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1258 negated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1259 if (*regparse == '^') /* negated range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1260 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1261 negated = TRUE;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1262 mb_ptr_adv(regparse);
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1263 EMIT(NFA_START_NEG_COLL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1264 }
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1265 else
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1266 EMIT(NFA_START_COLL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1267 if (*regparse == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1268 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1269 startc = '-';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1270 EMIT(startc);
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1271 EMIT(NFA_CONCAT);
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1272 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1273 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1274 /* Emit the OR branches for each character in the [] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1275 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1276 while (regparse < endp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1277 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1278 oldstartc = startc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1279 startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1280 got_coll_char = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1281 if (*regparse == '[')
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 /* Check for [: :], [= =], [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1284 equiclass = collclass = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1285 charclass = get_char_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1286 if (charclass == CLASS_NONE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1287 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1288 equiclass = get_equi_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1289 if (equiclass == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1290 collclass = get_coll_element(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1291 }
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 /* Character class like [:alpha:] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1294 if (charclass != CLASS_NONE)
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 switch (charclass)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1297 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1298 case CLASS_ALNUM:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1299 EMIT(NFA_CLASS_ALNUM);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1300 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1301 case CLASS_ALPHA:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1302 EMIT(NFA_CLASS_ALPHA);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1303 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1304 case CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1305 EMIT(NFA_CLASS_BLANK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1306 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1307 case CLASS_CNTRL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1308 EMIT(NFA_CLASS_CNTRL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1309 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1310 case CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1311 EMIT(NFA_CLASS_DIGIT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1312 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1313 case CLASS_GRAPH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1314 EMIT(NFA_CLASS_GRAPH);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1315 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1316 case CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1317 EMIT(NFA_CLASS_LOWER);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1318 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1319 case CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1320 EMIT(NFA_CLASS_PRINT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1321 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1322 case CLASS_PUNCT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1323 EMIT(NFA_CLASS_PUNCT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1324 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1325 case CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1326 EMIT(NFA_CLASS_SPACE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1327 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1328 case CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1329 EMIT(NFA_CLASS_UPPER);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1330 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1331 case CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1332 EMIT(NFA_CLASS_XDIGIT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1333 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1334 case CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1335 EMIT(NFA_CLASS_TAB);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1336 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1337 case CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1338 EMIT(NFA_CLASS_RETURN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1339 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1340 case CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1341 EMIT(NFA_CLASS_BACKSPACE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1342 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1343 case CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1344 EMIT(NFA_CLASS_ESCAPE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1345 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1346 }
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1347 EMIT(NFA_CONCAT);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1348 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1349 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1350 /* Try equivalence class [=a=] and the like */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1351 if (equiclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1352 {
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1353 result = nfa_emit_equi_class(equiclass);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1354 if (result == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1355 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1356 /* should never happen */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1357 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
1358 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1359 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1360 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1361 /* Try collating class like [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1362 if (collclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1363 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1364 startc = collclass; /* allow [.a.]-x as a range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1365 /* 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
1366 * while loop. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1367 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1368 }
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1369 /* 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
1370 * start character. */
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1371 if (*regparse == '-' && oldstartc != -1)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1372 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1373 emit_range = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1374 startc = oldstartc;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1375 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1376 continue; /* reading the end of the range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1377 }
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 /* Now handle simple and escaped characters.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1380 * Only "\]", "\^", "\]" and "\\" are special in Vi. Vim
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1381 * 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
1382 * 'cpoptions' is not included.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1383 * Posix doesn't recognize backslash at all.
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 if (*regparse == '\\'
4744
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4742
diff changeset
1386 && !reg_cpo_bsl
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1387 && regparse + 1 <= endp
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1388 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
4744
a62695305e03 updated for version 7.3.1119
Bram Moolenaar <bram@vim.org>
parents: 4742
diff changeset
1389 || (!reg_cpo_lit
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1390 && vim_strchr(REGEXP_ABBR, regparse[1])
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1391 != NULL)
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 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1394 {
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1395 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1396
4507
9dbbddb2ed10 updated for version 7.3.1001
Bram Moolenaar <bram@vim.org>
parents: 4503
diff changeset
1397 if (*regparse == 'n')
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1398 startc = reg_string ? NL : NFA_NEWL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1399 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1400 if (*regparse == 'd'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1401 || *regparse == 'o'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1402 || *regparse == 'x'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1403 || *regparse == 'u'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1404 || *regparse == 'U'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1405 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1406 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1407 /* TODO(RE) This needs more testing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1408 startc = coll_get_char();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1409 got_coll_char = TRUE;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1410 mb_ptr_back(old_regparse, regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1411 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1412 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1413 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1414 /* \r,\t,\e,\b */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1415 startc = backslash_trans(*regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1416 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1417 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1418
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1419 /* Normal printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1420 if (startc == -1)
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1421 startc = PTR2CHAR(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1422
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1423 /* 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
1424 if (emit_range)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1425 {
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1426 endc = startc;
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1427 startc = oldstartc;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1428 if (startc > endc)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1429 EMSG_RET_FAIL(_(e_invrange));
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1430
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1431 if (endc > startc + 2)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1432 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1433 /* Emit a range instead of the sequence of
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1434 * individual characters. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1435 if (startc == 0)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1436 /* \x00 is translated to \x0a, start at \x01. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1437 EMIT(1);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1438 else
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1439 --post_ptr; /* remove NFA_CONCAT */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1440 EMIT(endc);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1441 EMIT(NFA_RANGE);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1442 EMIT(NFA_CONCAT);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1443 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1444 else
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1445 #ifdef FEAT_MBYTE
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1446 if (has_mbyte && ((*mb_char2len)(startc) > 1
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1447 || (*mb_char2len)(endc) > 1))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1448 {
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1449 /* Emit the characters in the range.
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1450 * "startc" was already emitted, so skip it.
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1451 * */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1452 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1453 {
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1454 EMIT(c);
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1455 EMIT(NFA_CONCAT);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1456 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1457 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1458 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1459 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1460 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1461 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1462 int alpha_only = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1463
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1464 /* for alphabetical range skip the gaps
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1465 * 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1466 if (isalpha(startc) && isalpha(endc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1467 alpha_only = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1468 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1469 /* Emit the range. "startc" was already emitted, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1470 * skip it. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1471 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1472 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1473 if (!alpha_only || isalpha(startc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1474 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1475 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1476 EMIT(c);
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1477 EMIT(NFA_CONCAT);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1478 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1479 }
4677
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1480 emit_range = FALSE;
c1622ff9ed8d updated for version 7.3.1086
Bram Moolenaar <bram@vim.org>
parents: 4675
diff changeset
1481 startc = -1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1482 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1483 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1484 {
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1485 /* This char (startc) is not part of a range. Just
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1486 * emit it.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1487 * Normally, simply emit startc. But if we get char
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1488 * 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
1489 * 0x0a.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1490 * This is needed to completely mimic the behaviour of
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1491 * the backtracking engine. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1492 if (startc == NFA_NEWL)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1493 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1494 /* Line break can't be matched as part of the
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1495 * collection, add an OR below. But not for negated
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1496 * range. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1497 if (!negated)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1498 extra = ADD_NL;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1499 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1500 else
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1501 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1502 if (got_coll_char == TRUE && startc == 0)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1503 EMIT(0x0a);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1504 else
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1505 EMIT(startc);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1506 EMIT(NFA_CONCAT);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1507 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1508 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1509
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1510 mb_ptr_adv(regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1511 } /* while (p < endp) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1512
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1513 mb_ptr_back(old_regparse, regparse);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1514 if (*regparse == '-') /* if last, '-' is just a char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1515 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1516 EMIT('-');
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1517 EMIT(NFA_CONCAT);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1518 }
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 /* skip the trailing ] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1521 regparse = endp;
4573
37e444aeb33b updated for version 7.3.1034
Bram Moolenaar <bram@vim.org>
parents: 4571
diff changeset
1522 mb_ptr_adv(regparse);
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1523
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1524 /* Mark end of the collection. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1525 if (negated == TRUE)
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1526 EMIT(NFA_END_NEG_COLL);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1527 else
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
1528 EMIT(NFA_END_COLL);
4615
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1529
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1530 /* \_[] also matches \n but it's not negated */
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1531 if (extra == ADD_NL)
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1532 {
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1533 EMIT(reg_string ? NL : NFA_NEWL);
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1534 EMIT(NFA_OR);
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1535 }
5679b8ddd8cc updated for version 7.3.1055
Bram Moolenaar <bram@vim.org>
parents: 4583
diff changeset
1536
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1537 return OK;
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1538 } /* if exists closing ] */
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1539
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1540 if (reg_strict)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1541 EMSG_RET_FAIL(_(e_missingbracket));
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1542 /* FALLTHROUGH */
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1543
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1544 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1545 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1546 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1547 int plen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1548
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1549 nfa_do_multibyte:
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1550 /* 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
1551 if (enc_utf8 && ((*mb_char2len)(c)
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1552 != (plen = (*mb_ptr2len)(old_regparse))
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1553 || utf_iscomposing(c)))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1554 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1555 int i = 0;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1556
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
1557 /* 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
1558 * or more composing characters.
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1559 * 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
1560 * 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
1561 * 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
1562 * building the postfix form, not the NFA itself;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1563 * 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
1564 * 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
1565 for (;;)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1566 {
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1567 EMIT(c);
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1568 if (i > 0)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1569 EMIT(NFA_CONCAT);
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1570 if ((i += utf_char2len(c)) >= plen)
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1571 break;
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1572 c = utf_ptr2char(old_regparse + i);
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1573 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1574 EMIT(NFA_COMPOSING);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1575 regparse = old_regparse + plen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1576 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1577 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1578 #endif
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 c = no_Magic(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1581 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1582 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1583 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1584 }
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 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1588 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1589
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 * Parse something followed by possible [*+=].
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 * 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
1594 * 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
1595 * characters: "", "a", "aa", etc.
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 * piece ::= atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1598 * or atom multi
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 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1601 nfa_regpiece()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1602 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1603 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1604 int op;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1605 int ret;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1606 long minval, maxval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1607 int greedy = TRUE; /* Braces are prefixed with '-' ? */
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1608 parse_state_T old_state;
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1609 parse_state_T new_state;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1610 int c2;
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1611 int old_post_pos;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1612 int my_post_start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1613 int quest;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1614
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1615 /* 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
1616 * next. */
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1617 save_parse_state(&old_state);
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1618
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1619 /* 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
1620 my_post_start = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1621
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1622 ret = nfa_regatom();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1623 if (ret == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1624 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1625
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1626 op = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1627 if (re_multi_type(op) == NOT_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1628 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1629
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1630 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1631 switch (op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1632 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1633 case Magic('*'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1634 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1635 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1636
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1637 case Magic('+'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1638 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1639 * 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
1640 * 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
1641 * 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
1642 * 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
1643 * string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1644 * The submatch will the empty string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1645 *
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1646 * 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
1647 * <atom>+ with <atom><atom>*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1648 */
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1649 restore_parse_state(&old_state);
4444
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 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1652 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1653 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1654 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1655 skipchr(); /* skip the \+ */
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1658 case Magic('@'):
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1659 c2 = getdecchrs();
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1660 op = no_Magic(getchr());
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1661 i = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1662 switch(op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1663 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1664 case '=':
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1665 /* \@= */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1666 i = NFA_PREV_ATOM_NO_WIDTH;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1667 break;
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
1668 case '!':
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1669 /* \@! */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1670 i = NFA_PREV_ATOM_NO_WIDTH_NEG;
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
1671 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1672 case '<':
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1673 op = no_Magic(getchr());
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1674 if (op == '=')
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1675 /* \@<= */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1676 i = NFA_PREV_ATOM_JUST_BEFORE;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1677 else if (op == '!')
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1678 /* \@<! */
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1679 i = NFA_PREV_ATOM_JUST_BEFORE_NEG;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1680 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1681 case '>':
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
1682 /* \@> */
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
1683 i = NFA_PREV_ATOM_LIKE_PATTERN;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
1684 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1685 }
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1686 if (i == 0)
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1687 {
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1688 EMSGN(_("E869: (NFA) Unknown operator '\\@%c'"), op);
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1689 return FAIL;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1690 }
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1691 EMIT(i);
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1692 if (i == NFA_PREV_ATOM_JUST_BEFORE
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1693 || i == NFA_PREV_ATOM_JUST_BEFORE_NEG)
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
1694 EMIT(c2);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1695 break;
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 case Magic('?'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1698 case Magic('='):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1699 EMIT(NFA_QUEST);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1700 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1701
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1702 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1703 /* a{2,5} will expand to 'aaa?a?a?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1704 * 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
1705 * version of '?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1706 * \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
1707 * parenthesis have the same id
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1708 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1709
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1710 greedy = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1711 c2 = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1712 if (c2 == '-' || c2 == Magic('-'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1713 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1714 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1715 greedy = FALSE;
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 if (!read_limits(&minval, &maxval))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1718 EMSG_RET_FAIL(_("E870: (NFA regexp) Error reading repetition limits"));
4762
47906f888725 updated for version 7.3.1128
Bram Moolenaar <bram@vim.org>
parents: 4760
diff changeset
1719
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1720 /* <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
1721 * <atom>* */
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1722 if (minval == 0 && maxval == MAX_LIMIT)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1723 {
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1724 if (greedy)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1725 /* \{}, \{0,} */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1726 EMIT(NFA_STAR);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1727 else
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1728 /* \{-}, \{-0,} */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1729 EMIT(NFA_STAR_NONGREEDY);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1730 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1731 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1732
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1733 /* Special case: x{0} or x{-0} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1734 if (maxval == 0)
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 /* 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
1737 post_ptr = post_start + my_post_start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1738 /* NFA_SKIP_CHAR has 0-length and works everywhere */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1739 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1740 return OK;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1743 /* Ignore previous call to nfa_regatom() */
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1744 post_ptr = post_start + my_post_start;
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1745 /* 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
1746 save_parse_state(&new_state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1747
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1748 quest = (greedy == TRUE? NFA_QUEST : NFA_QUEST_NONGREEDY);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1749 for (i = 0; i < maxval; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1750 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1751 /* Goto beginning of the repeated atom */
4679
4d92b873acef updated for version 7.3.1087
Bram Moolenaar <bram@vim.org>
parents: 4677
diff changeset
1752 restore_parse_state(&old_state);
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1753 old_post_pos = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1754 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1755 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1756 /* after "minval" times, atoms are optional */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1757 if (i + 1 > minval)
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1758 {
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1759 if (maxval == MAX_LIMIT)
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1760 {
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1761 if (greedy)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1762 EMIT(NFA_STAR);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1763 else
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1764 EMIT(NFA_STAR_NONGREEDY);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
1765 }
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1766 else
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1767 EMIT(quest);
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1768 }
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1769 if (old_post_pos != my_post_start)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1770 EMIT(NFA_CONCAT);
4673
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1771 if (i + 1 > minval && maxval == MAX_LIMIT)
05d57d7c2d55 updated for version 7.3.1084
Bram Moolenaar <bram@vim.org>
parents: 4671
diff changeset
1772 break;
4444
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 /* 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
1776 restore_parse_state(&new_state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1777 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1778
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1779 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1780
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1781
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1782 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1783 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1784 } /* end switch */
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 if (re_multi_type(peekchr()) != NOT_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1787 /* Can't have a multi follow a multi. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1788 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
1789
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1790 return OK;
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1794 * 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
1795 * 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
1796 * "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
1797 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1798 * concat ::= piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1799 * or piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1800 * or piece piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1801 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1802 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1803 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1804 nfa_regconcat()
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 int cont = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1807 int first = TRUE;
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 while (cont)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1810 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1811 switch (peekchr())
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1812 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1813 case NUL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1814 case Magic('|'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1815 case Magic('&'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1816 case Magic(')'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1817 cont = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1818 break;
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 case Magic('Z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1821 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1822 regflags |= RF_ICOMBINE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1823 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1824 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1825 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1826 case Magic('c'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1827 regflags |= RF_ICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1828 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1829 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1830 case Magic('C'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1831 regflags |= RF_NOICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1832 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1833 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1834 case Magic('v'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1835 reg_magic = MAGIC_ALL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1836 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1837 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1838 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1839 case Magic('m'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1840 reg_magic = MAGIC_ON;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1841 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1842 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1843 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1844 case Magic('M'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1845 reg_magic = MAGIC_OFF;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1846 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1847 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1848 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1849 case Magic('V'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1850 reg_magic = MAGIC_NONE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1851 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1852 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1853 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1854
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1855 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1856 if (nfa_regpiece() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1857 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1858 if (first == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1859 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1860 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1861 first = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1862 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1863 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1864 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1865
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1866 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1867 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1868
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1869 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1870 * 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
1871 * 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
1872 * position. Examples:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1873 * "foobeep\&..." matches "foo" in "foobeep".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1874 * ".*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
1875 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1876 * branch ::= concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1877 * or concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1878 * or concat \& concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1879 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1880 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1881 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1882 nfa_regbranch()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1883 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1884 int ch;
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1885 int old_post_pos;
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1886
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1887 old_post_pos = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1888
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1889 /* First branch, possibly the only one */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1890 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1891 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1892
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1893 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1894 /* Try next concats */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1895 while (ch == Magic('&'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1896 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1897 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1898 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1899 EMIT(NFA_PREV_ATOM_NO_WIDTH);
4651
f10f63aaec5c updated for version 7.3.1073
Bram Moolenaar <bram@vim.org>
parents: 4649
diff changeset
1900 old_post_pos = (int)(post_ptr - post_start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1901 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1902 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1903 /* 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
1904 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
1905 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1906 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1907 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1908 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1909
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1910 /* 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
1911 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
1912 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1913
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1914 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1915 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1916
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1917 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1918 * 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
1919 * 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
1920 * "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
1921 * is used.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1922 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1923 * pattern ::= branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1924 * or branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1925 * or branch \| branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1926 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1927 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1928 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1929 nfa_reg(paren)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1930 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
1931 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1932 int parno = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1933
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1934 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1935 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1936 if (regnpar >= NSUBEXP) /* Too many `(' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1937 EMSG_RET_FAIL(_("E872: (NFA regexp) Too many '('"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1938 parno = regnpar++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1939 }
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1940 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1941 else if (paren == REG_ZPAREN)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1942 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1943 /* Make a ZOPEN node. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1944 if (regnzpar >= NSUBEXP)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1945 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
1946 parno = regnzpar++;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1947 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1948 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1949
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1950 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1951 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1952
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1953 while (peekchr() == Magic('|'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1954 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1955 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1956 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1957 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1958 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1959 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1960
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1961 /* Check for proper termination. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1962 if (paren != REG_NOPAREN && getchr() != Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1963 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1964 if (paren == REG_NPAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1965 EMSG2_RET_FAIL(_(e_unmatchedpp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1966 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1967 EMSG2_RET_FAIL(_(e_unmatchedp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1968 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1969 else if (paren == REG_NOPAREN && peekchr() != NUL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1970 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1971 if (peekchr() == Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1972 EMSG2_RET_FAIL(_(e_unmatchedpar), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1973 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1974 EMSG_RET_FAIL(_("E873: (NFA regexp) proper termination error"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1975 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1976 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1977 * 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
1978 * parentheses.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1979 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1980 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1981 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1982 had_endbrace[parno] = TRUE; /* have seen the close paren */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1983 EMIT(NFA_MOPEN + parno);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1984 }
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1985 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1986 else if (paren == REG_ZPAREN)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1987 EMIT(NFA_ZOPEN + parno);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
1988 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1989
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1990 return OK;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1993 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1994 static char_u code[50];
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 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1997 nfa_set_code(c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1998 int c;
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 int addnl = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2001
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2002 if (c >= NFA_FIRST_NL && c <= NFA_LAST_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2003 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2004 addnl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2005 c -= ADD_NL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2006 }
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 STRCPY(code, "");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2009 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2010 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2011 case NFA_MATCH: STRCPY(code, "NFA_MATCH "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2012 case NFA_SPLIT: STRCPY(code, "NFA_SPLIT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2013 case NFA_CONCAT: STRCPY(code, "NFA_CONCAT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2014 case NFA_NEWL: STRCPY(code, "NFA_NEWL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2015 case NFA_ZSTART: STRCPY(code, "NFA_ZSTART"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2016 case NFA_ZEND: STRCPY(code, "NFA_ZEND"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2017
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2018 case NFA_BACKREF1: STRCPY(code, "NFA_BACKREF1"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2019 case NFA_BACKREF2: STRCPY(code, "NFA_BACKREF2"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2020 case NFA_BACKREF3: STRCPY(code, "NFA_BACKREF3"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2021 case NFA_BACKREF4: STRCPY(code, "NFA_BACKREF4"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2022 case NFA_BACKREF5: STRCPY(code, "NFA_BACKREF5"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2023 case NFA_BACKREF6: STRCPY(code, "NFA_BACKREF6"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2024 case NFA_BACKREF7: STRCPY(code, "NFA_BACKREF7"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2025 case NFA_BACKREF8: STRCPY(code, "NFA_BACKREF8"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2026 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
2027 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2028 case NFA_ZREF1: STRCPY(code, "NFA_ZREF1"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2029 case NFA_ZREF2: STRCPY(code, "NFA_ZREF2"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2030 case NFA_ZREF3: STRCPY(code, "NFA_ZREF3"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2031 case NFA_ZREF4: STRCPY(code, "NFA_ZREF4"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2032 case NFA_ZREF5: STRCPY(code, "NFA_ZREF5"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2033 case NFA_ZREF6: STRCPY(code, "NFA_ZREF6"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2034 case NFA_ZREF7: STRCPY(code, "NFA_ZREF7"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2035 case NFA_ZREF8: STRCPY(code, "NFA_ZREF8"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2036 case NFA_ZREF9: STRCPY(code, "NFA_ZREF9"); break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2037 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2038 case NFA_SKIP: STRCPY(code, "NFA_SKIP"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2039
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2040 case NFA_PREV_ATOM_NO_WIDTH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2041 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
2042 case NFA_PREV_ATOM_NO_WIDTH_NEG:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
2043 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
2044 case NFA_PREV_ATOM_JUST_BEFORE:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2045 STRCPY(code, "NFA_PREV_ATOM_JUST_BEFORE"); break;
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2046 case NFA_PREV_ATOM_JUST_BEFORE_NEG:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2047 STRCPY(code, "NFA_PREV_ATOM_JUST_BEFORE_NEG"); break;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
2048 case NFA_PREV_ATOM_LIKE_PATTERN:
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
2049 STRCPY(code, "NFA_PREV_ATOM_LIKE_PATTERN"); break;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
2050
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
2051 case NFA_NOPEN: STRCPY(code, "NFA_NOPEN"); break;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
2052 case NFA_NCLOSE: STRCPY(code, "NFA_NCLOSE"); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2053 case NFA_START_INVISIBLE: STRCPY(code, "NFA_START_INVISIBLE"); break;
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2054 case NFA_START_INVISIBLE_FIRST:
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2055 STRCPY(code, "NFA_START_INVISIBLE_FIRST"); break;
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
2056 case NFA_START_INVISIBLE_NEG:
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
2057 STRCPY(code, "NFA_START_INVISIBLE_NEG"); break;
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2058 case NFA_START_INVISIBLE_NEG_FIRST:
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2059 STRCPY(code, "NFA_START_INVISIBLE_NEG_FIRST"); break;
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2060 case NFA_START_INVISIBLE_BEFORE:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
2061 STRCPY(code, "NFA_START_INVISIBLE_BEFORE"); break;
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2062 case NFA_START_INVISIBLE_BEFORE_FIRST:
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2063 STRCPY(code, "NFA_START_INVISIBLE_BEFORE_FIRST"); break;
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
2064 case NFA_START_INVISIBLE_BEFORE_NEG:
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
2065 STRCPY(code, "NFA_START_INVISIBLE_BEFORE_NEG"); break;
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2066 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST:
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
2067 STRCPY(code, "NFA_START_INVISIBLE_BEFORE_NEG_FIRST"); break;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
2068 case NFA_START_PATTERN: STRCPY(code, "NFA_START_PATTERN"); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2069 case NFA_END_INVISIBLE: STRCPY(code, "NFA_END_INVISIBLE"); break;
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
2070 case NFA_END_INVISIBLE_NEG: STRCPY(code, "NFA_END_INVISIBLE_NEG"); break;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
2071 case NFA_END_PATTERN: STRCPY(code, "NFA_END_PATTERN"); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2072
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2073 case NFA_COMPOSING: STRCPY(code, "NFA_COMPOSING"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2074 case NFA_END_COMPOSING: STRCPY(code, "NFA_END_COMPOSING"); break;
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
2075 case NFA_OPT_CHARS: STRCPY(code, "NFA_OPT_CHARS"); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2076
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2077 case NFA_MOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2078 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2079 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2080 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2081 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2082 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2083 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2084 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2085 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2086 case NFA_MOPEN9:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2087 STRCPY(code, "NFA_MOPEN(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2088 code[10] = c - NFA_MOPEN + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2089 break;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2090 case NFA_MCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2091 case NFA_MCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2092 case NFA_MCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2093 case NFA_MCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2094 case NFA_MCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2095 case NFA_MCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2096 case NFA_MCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2097 case NFA_MCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2098 case NFA_MCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2099 case NFA_MCLOSE9:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2100 STRCPY(code, "NFA_MCLOSE(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2101 code[11] = c - NFA_MCLOSE + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2102 break;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2103 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2104 case NFA_ZOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2105 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2106 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2107 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2108 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2109 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2110 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2111 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2112 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2113 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2114 STRCPY(code, "NFA_ZOPEN(x)");
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2115 code[10] = c - NFA_ZOPEN + '0';
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2116 break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2117 case NFA_ZCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2118 case NFA_ZCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2119 case NFA_ZCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2120 case NFA_ZCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2121 case NFA_ZCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2122 case NFA_ZCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2123 case NFA_ZCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2124 case NFA_ZCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2125 case NFA_ZCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2126 case NFA_ZCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2127 STRCPY(code, "NFA_ZCLOSE(x)");
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2128 code[11] = c - NFA_ZCLOSE + '0';
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2129 break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
2130 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2131 case NFA_EOL: STRCPY(code, "NFA_EOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2132 case NFA_BOL: STRCPY(code, "NFA_BOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2133 case NFA_EOW: STRCPY(code, "NFA_EOW "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2134 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
2135 case NFA_EOF: STRCPY(code, "NFA_EOF "); break;
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
2136 case NFA_BOF: STRCPY(code, "NFA_BOF "); break;
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2137 case NFA_LNUM: STRCPY(code, "NFA_LNUM "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2138 case NFA_LNUM_GT: STRCPY(code, "NFA_LNUM_GT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2139 case NFA_LNUM_LT: STRCPY(code, "NFA_LNUM_LT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2140 case NFA_COL: STRCPY(code, "NFA_COL "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2141 case NFA_COL_GT: STRCPY(code, "NFA_COL_GT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2142 case NFA_COL_LT: STRCPY(code, "NFA_COL_LT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2143 case NFA_VCOL: STRCPY(code, "NFA_VCOL "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2144 case NFA_VCOL_GT: STRCPY(code, "NFA_VCOL_GT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2145 case NFA_VCOL_LT: STRCPY(code, "NFA_VCOL_LT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2146 case NFA_MARK: STRCPY(code, "NFA_MARK "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2147 case NFA_MARK_GT: STRCPY(code, "NFA_MARK_GT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2148 case NFA_MARK_LT: STRCPY(code, "NFA_MARK_LT "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2149 case NFA_CURSOR: STRCPY(code, "NFA_CURSOR "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2150 case NFA_VISUAL: STRCPY(code, "NFA_VISUAL "); break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
2151
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2152 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
2153 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
2154 case NFA_QUEST: STRCPY(code, "NFA_QUEST"); break;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2155 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
2156 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
2157 case NFA_OR: STRCPY(code, "NFA_OR"); break;
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2158
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2159 case NFA_START_COLL: STRCPY(code, "NFA_START_COLL"); break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2160 case NFA_END_COLL: STRCPY(code, "NFA_END_COLL"); break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2161 case NFA_START_NEG_COLL: STRCPY(code, "NFA_START_NEG_COLL"); break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2162 case NFA_END_NEG_COLL: STRCPY(code, "NFA_END_NEG_COLL"); break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2163 case NFA_RANGE: STRCPY(code, "NFA_RANGE"); break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2164 case NFA_RANGE_MIN: STRCPY(code, "NFA_RANGE_MIN"); break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2165 case NFA_RANGE_MAX: STRCPY(code, "NFA_RANGE_MAX"); break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2166
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2167 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
2168 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
2169 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
2170 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
2171 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
2172 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
2173 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
2174 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
2175 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
2176 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
2177 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
2178 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
2179 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
2180 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
2181 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
2182 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
2183
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2184 case NFA_ANY: STRCPY(code, "NFA_ANY"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2185 case NFA_IDENT: STRCPY(code, "NFA_IDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2186 case NFA_SIDENT:STRCPY(code, "NFA_SIDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2187 case NFA_KWORD: STRCPY(code, "NFA_KWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2188 case NFA_SKWORD:STRCPY(code, "NFA_SKWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2189 case NFA_FNAME: STRCPY(code, "NFA_FNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2190 case NFA_SFNAME:STRCPY(code, "NFA_SFNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2191 case NFA_PRINT: STRCPY(code, "NFA_PRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2192 case NFA_SPRINT:STRCPY(code, "NFA_SPRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2193 case NFA_WHITE: STRCPY(code, "NFA_WHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2194 case NFA_NWHITE:STRCPY(code, "NFA_NWHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2195 case NFA_DIGIT: STRCPY(code, "NFA_DIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2196 case NFA_NDIGIT:STRCPY(code, "NFA_NDIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2197 case NFA_HEX: STRCPY(code, "NFA_HEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2198 case NFA_NHEX: STRCPY(code, "NFA_NHEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2199 case NFA_OCTAL: STRCPY(code, "NFA_OCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2200 case NFA_NOCTAL:STRCPY(code, "NFA_NOCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2201 case NFA_WORD: STRCPY(code, "NFA_WORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2202 case NFA_NWORD: STRCPY(code, "NFA_NWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2203 case NFA_HEAD: STRCPY(code, "NFA_HEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2204 case NFA_NHEAD: STRCPY(code, "NFA_NHEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2205 case NFA_ALPHA: STRCPY(code, "NFA_ALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2206 case NFA_NALPHA:STRCPY(code, "NFA_NALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2207 case NFA_LOWER: STRCPY(code, "NFA_LOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2208 case NFA_NLOWER:STRCPY(code, "NFA_NLOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2209 case NFA_UPPER: STRCPY(code, "NFA_UPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2210 case NFA_NUPPER:STRCPY(code, "NFA_NUPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2211
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2212 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2213 STRCPY(code, "CHAR(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2214 code[5] = c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2215 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2216
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2217 if (addnl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2218 STRCAT(code, " + NEWLINE ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2219
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2220 }
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 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2223 static FILE *log_fd;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2224
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 * Print the postfix notation of the current regexp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2227 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2228 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2229 nfa_postfix_dump(expr, retval)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2230 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2231 int retval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2232 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2233 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2234 FILE *f;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2235
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2236 f = fopen(NFA_REGEXP_DUMP_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2237 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2238 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2239 fprintf(f, "\n-------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2240 if (retval == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2241 fprintf(f, ">>> NFA engine failed ... \n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2242 else if (retval == OK)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2243 fprintf(f, ">>> NFA engine succeeded !\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2244 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
2245 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
2246 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2247 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2248 fprintf(f, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2249 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2250 fprintf(f, "\"\nPostfix notation (int): ");
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2251 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
2252 fprintf(f, "%d ", *p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2253 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2254 fclose(f);
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 }
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2259 * Print the NFA starting with a root node "state".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2260 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2261 static void
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2262 nfa_print_state(debugf, state)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2263 FILE *debugf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2264 nfa_state_T *state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2265 {
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2266 garray_T indent;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2267
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2268 ga_init2(&indent, 1, 64);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2269 ga_append(&indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2270 nfa_print_state2(debugf, state, &indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2271 ga_clear(&indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2272 }
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2273
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2274 static void
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2275 nfa_print_state2(debugf, state, indent)
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2276 FILE *debugf;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2277 nfa_state_T *state;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2278 garray_T *indent;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2279 {
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2280 char_u *p;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2281
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2282 if (state == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2283 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2284
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2285 fprintf(debugf, "(%2d)", abs(state->id));
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2286
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2287 /* Output indent */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2288 p = (char_u *)indent->ga_data;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2289 if (indent->ga_len >= 3)
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2290 {
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2291 int last = indent->ga_len - 3;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2292 char_u save[2];
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2293
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2294 STRNCPY(save, &p[last], 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2295 STRNCPY(&p[last], "+-", 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2296 fprintf(debugf, " %s", p);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2297 STRNCPY(&p[last], save, 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2298 }
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2299 else
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2300 fprintf(debugf, " %s", p);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2301
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2302 nfa_set_code(state->c);
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
2303 fprintf(debugf, "%s (%d) (id=%d) val=%d\n",
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2304 code,
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2305 state->c,
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2306 abs(state->id),
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2307 state->val);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2308 if (state->id < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2309 return;
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 state->id = abs(state->id) * -1;
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2312
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2313 /* grow indent for state->out */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2314 indent->ga_len -= 1;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2315 if (state->out1)
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
2316 ga_concat(indent, (char_u *)"| ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2317 else
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
2318 ga_concat(indent, (char_u *)" ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2319 ga_append(indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2320
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2321 nfa_print_state2(debugf, state->out, indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2322
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2323 /* replace last part of indent for state->out1 */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2324 indent->ga_len -= 3;
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
2325 ga_concat(indent, (char_u *)" ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2326 ga_append(indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2327
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2328 nfa_print_state2(debugf, state->out1, indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2329
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2330 /* shrink indent */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2331 indent->ga_len -= 3;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2332 ga_append(indent, '\0');
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2333 }
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2336 * Print the NFA state machine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2337 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2338 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2339 nfa_dump(prog)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2340 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2341 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2342 FILE *debugf = fopen(NFA_REGEXP_DUMP_LOG, "a");
4444
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 if (debugf != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2345 {
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
2346 nfa_print_state(debugf, prog->start);
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2347
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
2348 if (prog->reganch)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
2349 fprintf(debugf, "reganch: %d\n", prog->reganch);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
2350 if (prog->regstart != NUL)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
2351 fprintf(debugf, "regstart: %c (decimal: %d)\n",
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
2352 prog->regstart, prog->regstart);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
2353 if (prog->match_text != NULL)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
2354 fprintf(debugf, "match_text: \"%s\"\n", prog->match_text);
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
2355
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2356 fclose(debugf);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2357 }
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 #endif /* ENABLE_LOG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2360 #endif /* DEBUG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2361
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2362 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2363 * 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
2364 * Return the postfix string on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2365 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2366 static int *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2367 re2post()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2368 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2369 if (nfa_reg(REG_NOPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2370 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2371 EMIT(NFA_MOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2372 return post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2373 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2374
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2375 /* 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
2376
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2377 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2378 * 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
2379 * if c == MATCH, no arrows out; matching state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2380 * 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
2381 * 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
2382 */
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 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
2385
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2386 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2387 * Allocate and initialize nfa_state_T.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2388 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2389 static nfa_state_T *
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2390 alloc_state(c, out, out1)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2391 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2392 nfa_state_T *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2393 nfa_state_T *out1;
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 nfa_state_T *s;
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 if (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2398 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2399
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2400 s = &state_ptr[istate++];
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 s->c = c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2403 s->out = out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2404 s->out1 = out1;
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2405 s->val = 0;
4444
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 s->id = istate;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
2408 s->lastlist[0] = 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
2409 s->lastlist[1] = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2410
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2411 return s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2412 }
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2415 * 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
2416 * Frag_T.start points at the start state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2417 * 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
2418 * next state for this fragment.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2419 */
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2420
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2421 /* 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
2422 * uninitialized, we use the pointers themselves
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2423 * as storage for the Ptrlists. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2424 typedef union Ptrlist Ptrlist;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2425 union Ptrlist
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2426 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2427 Ptrlist *next;
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2428 nfa_state_T *s;
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2429 };
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2430
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2431 struct Frag
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2432 {
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2433 nfa_state_T *start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2434 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2435 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2436 typedef struct Frag Frag_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2437
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2438 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
2439 static Ptrlist *list1 __ARGS((nfa_state_T **outp));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2440 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
2441 static Ptrlist *append __ARGS((Ptrlist *l1, Ptrlist *l2));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2442 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
2443 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
2444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2445 /*
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2446 * Initialize a Frag_T struct and return it.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2447 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2448 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2449 frag(start, out)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2450 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2451 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2452 {
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2453 Frag_T n;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2454
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2455 n.start = start;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2456 n.out = out;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2457 return n;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2458 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2459
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2460 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2461 * Create singleton list containing just outp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2462 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2463 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2464 list1(outp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2465 nfa_state_T **outp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2466 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2467 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2468
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2469 l = (Ptrlist *)outp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2470 l->next = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2471 return l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2472 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2473
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2474 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2475 * 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
2476 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2477 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2478 patch(l, s)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2479 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2480 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2481 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2482 Ptrlist *next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2483
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2484 for (; l; l = next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2485 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2486 next = l->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2487 l->s = s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2488 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2489 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2490
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2491
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2492 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2493 * 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
2494 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2495 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2496 append(l1, l2)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2497 Ptrlist *l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2498 Ptrlist *l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2499 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2500 Ptrlist *oldl1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2501
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2502 oldl1 = l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2503 while (l1->next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2504 l1 = l1->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2505 l1->next = l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2506 return oldl1;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2509 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2510 * Stack used for transforming postfix form into NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2511 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2512 static Frag_T empty;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2513
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2514 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2515 st_error(postfix, end, p)
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2516 int *postfix UNUSED;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2517 int *end UNUSED;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2518 int *p UNUSED;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2519 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2520 #ifdef NFA_REGEXP_ERROR_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2521 FILE *df;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2522 int *p2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2523
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2524 df = fopen(NFA_REGEXP_ERROR_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2525 if (df)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2526 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2527 fprintf(df, "Error popping the stack!\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2528 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2529 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
2530 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2531 fprintf(df, "Postfix form is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2532 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2533 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2534 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2535 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2536 fprintf(df, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2537 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2538 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2539 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2540 for (p2 = postfix; p2 <= p; p2 ++)
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 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2543 fprintf(df, "%s, ", code);
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 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2546 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2547 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2548 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2549 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2550 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2551 for (p2 = postfix; p2 <= p; p2 ++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2552 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2553 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2554 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2555 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2556 fprintf(df, "\n--------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2557 fclose(df);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2558 }
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2559 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2560 EMSG(_("E874: (NFA) Could not pop the stack !"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2561 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2562
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2563 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2564 * Push an item onto the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2565 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2566 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2567 st_push(s, p, stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2568 Frag_T s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2569 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2570 Frag_T *stack_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2571 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2572 Frag_T *stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2573
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2574 if (stackp >= stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2575 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2576 *stackp = s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2577 *p = *p + 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2578 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2579
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2580 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2581 * Pop an item from the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2582 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2583 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2584 st_pop(p, stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2585 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2586 Frag_T *stack;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2587 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2588 Frag_T *stackp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2589
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2590 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2591 stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2592 if (stackp < stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2593 return empty;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2594 return **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2595 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2596
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2597 /*
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2598 * Estimate the maximum byte length of anything matching "state".
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2599 * When unknown or unlimited return -1.
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2600 */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2601 static int
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2602 nfa_max_width(startstate, depth)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2603 nfa_state_T *startstate;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2604 int depth;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2605 {
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2606 int l, r;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2607 nfa_state_T *state = startstate;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2608 int len = 0;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2609
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2610 /* detect looping in a NFA_SPLIT */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2611 if (depth > 4)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2612 return -1;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2613
4958
0a379dea13c9 updated for version 7.3.1224
Bram Moolenaar <bram@vim.org>
parents: 4944
diff changeset
2614 while (state != NULL)
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2615 {
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2616 switch (state->c)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2617 {
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2618 case NFA_END_INVISIBLE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2619 case NFA_END_INVISIBLE_NEG:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2620 /* the end, return what we have */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2621 return len;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2622
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2623 case NFA_SPLIT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2624 /* two alternatives, use the maximum */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2625 l = nfa_max_width(state->out, depth + 1);
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2626 r = nfa_max_width(state->out1, depth + 1);
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2627 if (l < 0 || r < 0)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2628 return -1;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2629 return len + (l > r ? l : r);
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2630
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2631 case NFA_ANY:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2632 case NFA_START_COLL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2633 case NFA_START_NEG_COLL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2634 /* matches some character, including composing chars */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2635 #ifdef FEAT_MBYTE
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2636 if (enc_utf8)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2637 len += MB_MAXBYTES;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2638 else if (has_mbyte)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2639 len += 2;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2640 else
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2641 #endif
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2642 ++len;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2643 if (state->c != NFA_ANY)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2644 {
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2645 /* skip over the characters */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2646 state = state->out1->out;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2647 continue;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2648 }
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2649 break;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2650
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2651 case NFA_DIGIT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2652 case NFA_WHITE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2653 case NFA_HEX:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2654 case NFA_OCTAL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2655 /* ascii */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2656 ++len;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2657 break;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2658
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2659 case NFA_IDENT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2660 case NFA_SIDENT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2661 case NFA_KWORD:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2662 case NFA_SKWORD:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2663 case NFA_FNAME:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2664 case NFA_SFNAME:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2665 case NFA_PRINT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2666 case NFA_SPRINT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2667 case NFA_NWHITE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2668 case NFA_NDIGIT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2669 case NFA_NHEX:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2670 case NFA_NOCTAL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2671 case NFA_WORD:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2672 case NFA_NWORD:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2673 case NFA_HEAD:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2674 case NFA_NHEAD:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2675 case NFA_ALPHA:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2676 case NFA_NALPHA:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2677 case NFA_LOWER:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2678 case NFA_NLOWER:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2679 case NFA_UPPER:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2680 case NFA_NUPPER:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2681 /* possibly non-ascii */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2682 #ifdef FEAT_MBYTE
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2683 if (has_mbyte)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2684 len += 3;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2685 else
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2686 #endif
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2687 ++len;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2688 break;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2689
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2690 case NFA_START_INVISIBLE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2691 case NFA_START_INVISIBLE_NEG:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2692 case NFA_START_INVISIBLE_BEFORE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2693 case NFA_START_INVISIBLE_BEFORE_NEG:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2694 /* zero-width, out1 points to the END state */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2695 state = state->out1->out;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2696 continue;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2697
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2698 case NFA_BACKREF1:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2699 case NFA_BACKREF2:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2700 case NFA_BACKREF3:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2701 case NFA_BACKREF4:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2702 case NFA_BACKREF5:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2703 case NFA_BACKREF6:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2704 case NFA_BACKREF7:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2705 case NFA_BACKREF8:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2706 case NFA_BACKREF9:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2707 #ifdef FEAT_SYN_HL
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2708 case NFA_ZREF1:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2709 case NFA_ZREF2:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2710 case NFA_ZREF3:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2711 case NFA_ZREF4:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2712 case NFA_ZREF5:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2713 case NFA_ZREF6:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2714 case NFA_ZREF7:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2715 case NFA_ZREF8:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2716 case NFA_ZREF9:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2717 #endif
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2718 case NFA_NEWL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2719 case NFA_SKIP:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2720 /* unknown width */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2721 return -1;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2722
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2723 case NFA_BOL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2724 case NFA_EOL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2725 case NFA_BOF:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2726 case NFA_EOF:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2727 case NFA_BOW:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2728 case NFA_EOW:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2729 case NFA_MOPEN:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2730 case NFA_MOPEN1:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2731 case NFA_MOPEN2:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2732 case NFA_MOPEN3:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2733 case NFA_MOPEN4:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2734 case NFA_MOPEN5:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2735 case NFA_MOPEN6:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2736 case NFA_MOPEN7:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2737 case NFA_MOPEN8:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2738 case NFA_MOPEN9:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2739 #ifdef FEAT_SYN_HL
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2740 case NFA_ZOPEN:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2741 case NFA_ZOPEN1:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2742 case NFA_ZOPEN2:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2743 case NFA_ZOPEN3:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2744 case NFA_ZOPEN4:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2745 case NFA_ZOPEN5:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2746 case NFA_ZOPEN6:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2747 case NFA_ZOPEN7:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2748 case NFA_ZOPEN8:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2749 case NFA_ZOPEN9:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2750 case NFA_ZCLOSE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2751 case NFA_ZCLOSE1:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2752 case NFA_ZCLOSE2:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2753 case NFA_ZCLOSE3:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2754 case NFA_ZCLOSE4:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2755 case NFA_ZCLOSE5:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2756 case NFA_ZCLOSE6:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2757 case NFA_ZCLOSE7:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2758 case NFA_ZCLOSE8:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2759 case NFA_ZCLOSE9:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2760 #endif
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2761 case NFA_MCLOSE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2762 case NFA_MCLOSE1:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2763 case NFA_MCLOSE2:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2764 case NFA_MCLOSE3:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2765 case NFA_MCLOSE4:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2766 case NFA_MCLOSE5:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2767 case NFA_MCLOSE6:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2768 case NFA_MCLOSE7:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2769 case NFA_MCLOSE8:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2770 case NFA_MCLOSE9:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2771 case NFA_NOPEN:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2772 case NFA_NCLOSE:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2773
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2774 case NFA_LNUM_GT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2775 case NFA_LNUM_LT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2776 case NFA_COL_GT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2777 case NFA_COL_LT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2778 case NFA_VCOL_GT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2779 case NFA_VCOL_LT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2780 case NFA_MARK_GT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2781 case NFA_MARK_LT:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2782 case NFA_VISUAL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2783 case NFA_LNUM:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2784 case NFA_CURSOR:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2785 case NFA_COL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2786 case NFA_VCOL:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2787 case NFA_MARK:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2788
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2789 case NFA_ZSTART:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2790 case NFA_ZEND:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2791 case NFA_OPT_CHARS:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2792 case NFA_SKIP_CHAR:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2793 case NFA_START_PATTERN:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2794 case NFA_END_PATTERN:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2795 case NFA_COMPOSING:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2796 case NFA_END_COMPOSING:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2797 /* zero-width */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2798 break;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2799
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2800 default:
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2801 if (state->c < 0)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2802 /* don't know what this is */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2803 return -1;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2804 /* normal character */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2805 len += MB_CHAR2LEN(state->c);
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2806 break;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2807 }
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2808
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2809 /* normal way to continue */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2810 state = state->out;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2811 }
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2812
4958
0a379dea13c9 updated for version 7.3.1224
Bram Moolenaar <bram@vim.org>
parents: 4944
diff changeset
2813 /* unrecognized, "cannot happen" */
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2814 return -1;
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2815 }
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
2816
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
2817 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2818 * Convert a postfix form into its equivalent NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2819 * Return the NFA start state on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2820 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2821 static nfa_state_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2822 post2nfa(postfix, end, nfa_calc_size)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2823 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2824 int *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2825 int nfa_calc_size;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2826 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2827 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2828 int mopen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2829 int mclose;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2830 Frag_T *stack = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2831 Frag_T *stackp = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2832 Frag_T *stack_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2833 Frag_T e1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2834 Frag_T e2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2835 Frag_T e;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2836 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2837 nfa_state_T *s1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2838 nfa_state_T *matchstate;
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2839 nfa_state_T *ret = NULL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2840
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2841 if (postfix == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2842 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2843
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2844 #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
2845 #define POP() st_pop(&stackp, stack); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2846 if (stackp < stack) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2847 { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2848 st_error(postfix, end, p); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2849 return NULL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2850 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2851
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2852 if (nfa_calc_size == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2853 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2854 /* 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
2855 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
2856 stackp = stack;
4462
a63361b90979 updated for version 7.3.979
Bram Moolenaar <bram@vim.org>
parents: 4460
diff changeset
2857 stack_end = stack + (nstate + 1);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2858 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2859
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2860 for (p = postfix; p < end; ++p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2861 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2862 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2863 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2864 case NFA_CONCAT:
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2865 /* Concatenation.
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2866 * Pay attention: this operator does not exist in the r.e. itself
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2867 * (it is implicit, really). It is added when r.e. is translated
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2868 * to postfix form in re2post(). */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2869 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2870 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2871 /* nstate += 0; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2872 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2873 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2874 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2875 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2876 patch(e1.out, e2.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2877 PUSH(frag(e1.start, e2.out));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2878 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2879
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2880 case NFA_OR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2881 /* Alternation */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2882 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2883 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2884 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2885 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2886 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2887 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2888 e1 = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2889 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
2890 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2891 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2892 PUSH(frag(s, append(e1.out, e2.out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2893 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2894
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2895 case NFA_STAR:
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2896 /* Zero or more, prefer more */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2897 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2898 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2899 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2900 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2901 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2902 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2903 s = alloc_state(NFA_SPLIT, e.start, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2904 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2905 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2906 patch(e.out, s);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2907 PUSH(frag(s, list1(&s->out1)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2908 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2909
4675
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2910 case NFA_STAR_NONGREEDY:
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2911 /* Zero or more, prefer zero */
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2912 if (nfa_calc_size == TRUE)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2913 {
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2914 nstate++;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2915 break;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2916 }
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2917 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2918 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
2919 if (s == NULL)
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2920 goto theend;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2921 patch(e.out, s);
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2922 PUSH(frag(s, list1(&s->out)));
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2923 break;
811a4c9b51d8 updated for version 7.3.1085
Bram Moolenaar <bram@vim.org>
parents: 4673
diff changeset
2924
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2925 case NFA_QUEST:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2926 /* one or zero atoms=> greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2927 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2928 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2929 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2930 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2931 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2932 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2933 s = alloc_state(NFA_SPLIT, e.start, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2934 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2935 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2936 PUSH(frag(s, append(e.out, list1(&s->out1))));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2937 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2938
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2939 case NFA_QUEST_NONGREEDY:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2940 /* zero or one atoms => non-greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2941 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2942 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2943 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2944 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2945 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2946 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2947 s = alloc_state(NFA_SPLIT, NULL, e.start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2948 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2949 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2950 PUSH(frag(s, append(e.out, list1(&s->out))));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2951 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2952
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2953 case NFA_END_COLL:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2954 case NFA_END_NEG_COLL:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2955 /* On the stack is the sequence starting with NFA_START_COLL or
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2956 * NFA_START_NEG_COLL and all possible characters. Patch it to
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2957 * add the output to the start. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2958 if (nfa_calc_size == TRUE)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2959 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2960 nstate++;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2961 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2962 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2963 e = POP();
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2964 s = alloc_state(NFA_END_COLL, NULL, NULL);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2965 if (s == NULL)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2966 goto theend;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2967 patch(e.out, s);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2968 e.start->out1 = s;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2969 PUSH(frag(e.start, list1(&s->out)));
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2970 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2971
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2972 case NFA_RANGE:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2973 /* Before this are two characters, the low and high end of a
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2974 * range. Turn them into two states with MIN and MAX. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2975 if (nfa_calc_size == TRUE)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2976 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2977 /* nstate += 0; */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2978 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2979 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2980 e2 = POP();
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2981 e1 = POP();
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2982 e2.start->val = e2.start->c;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2983 e2.start->c = NFA_RANGE_MAX;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2984 e1.start->val = e1.start->c;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2985 e1.start->c = NFA_RANGE_MIN;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2986 patch(e1.out, e2.start);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2987 PUSH(frag(e1.start, e2.out));
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2988 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
2989
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2990 case NFA_SKIP_CHAR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2991 /* Symbol of 0-length, Used in a repetition
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2992 * with max/min count of 0 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2993 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2994 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2995 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2996 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2997 }
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
2998 s = alloc_state(NFA_SKIP_CHAR, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2999 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3000 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3001 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3002 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3003
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3004 case NFA_OPT_CHARS:
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3005 {
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3006 int n;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3007
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3008 /* \%[abc] */
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3009 n = *++p; /* get number of characters */
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3010 if (nfa_calc_size == TRUE)
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3011 {
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3012 nstate += n;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3013 break;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3014 }
4758
b25a1b2e3175 updated for version 7.3.1126
Bram Moolenaar <bram@vim.org>
parents: 4756
diff changeset
3015 s = NULL; /* avoid compiler warning */
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3016 e1.out = NULL; /* stores list with out1's */
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3017 s1 = NULL; /* previous NFA_SPLIT to connect to */
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3018 while (n-- > 0)
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3019 {
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3020 e = POP(); /* get character */
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3021 s = alloc_state(NFA_SPLIT, e.start, NULL);
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3022 if (s == NULL)
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3023 goto theend;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3024 if (e1.out == NULL)
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3025 e1 = e;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3026 patch(e.out, s1);
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3027 append(e1.out, list1(&s->out1));
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3028 s1 = s;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3029 }
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3030 PUSH(frag(s, e1.out));
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3031 break;
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3032 }
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3033
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3034 case NFA_PREV_ATOM_NO_WIDTH:
4661
0dce3d812e7a updated for version 7.3.1078
Bram Moolenaar <bram@vim.org>
parents: 4657
diff changeset
3035 case NFA_PREV_ATOM_NO_WIDTH_NEG:
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
3036 case NFA_PREV_ATOM_JUST_BEFORE:
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
3037 case NFA_PREV_ATOM_JUST_BEFORE_NEG:
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3038 case NFA_PREV_ATOM_LIKE_PATTERN:
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3039 {
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3040 int before = (*p == NFA_PREV_ATOM_JUST_BEFORE
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3041 || *p == NFA_PREV_ATOM_JUST_BEFORE_NEG);
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3042 int pattern = (*p == NFA_PREV_ATOM_LIKE_PATTERN);
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3043 int start_state;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3044 int end_state;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3045 int n = 0;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3046 nfa_state_T *zend;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3047 nfa_state_T *skip;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3048
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3049 switch (*p)
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3050 {
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3051 case NFA_PREV_ATOM_NO_WIDTH:
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3052 start_state = NFA_START_INVISIBLE;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3053 end_state = NFA_END_INVISIBLE;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3054 break;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3055 case NFA_PREV_ATOM_NO_WIDTH_NEG:
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3056 start_state = NFA_START_INVISIBLE_NEG;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3057 end_state = NFA_END_INVISIBLE_NEG;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3058 break;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3059 case NFA_PREV_ATOM_JUST_BEFORE:
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3060 start_state = NFA_START_INVISIBLE_BEFORE;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3061 end_state = NFA_END_INVISIBLE;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3062 break;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3063 case NFA_PREV_ATOM_JUST_BEFORE_NEG:
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3064 start_state = NFA_START_INVISIBLE_BEFORE_NEG;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3065 end_state = NFA_END_INVISIBLE_NEG;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3066 break;
4819
8c4324e6f477 updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents: 4815
diff changeset
3067 default: /* NFA_PREV_ATOM_LIKE_PATTERN: */
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3068 start_state = NFA_START_PATTERN;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3069 end_state = NFA_END_PATTERN;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
3070 break;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3071 }
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3072
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3073 if (before)
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3074 n = *++p; /* get the count */
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3075
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3076 /* 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
3077 * 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
3078 * The \@<= operator: match for the preceding atom.
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
3079 * The \@<! operator: no match for the preceding atom.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3080 * 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
3081 * END_INVISIBLE, similarly to MOPEN. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3082
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3083 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3084 {
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3085 nstate += pattern ? 4 : 2;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3086 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3087 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3088 e = POP();
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3089 s1 = alloc_state(end_state, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3090 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3091 goto theend;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3092
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3093 s = alloc_state(start_state, e.start, s1);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3094 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3095 goto theend;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3096 if (pattern)
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
3097 {
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3098 /* NFA_ZEND -> NFA_END_PATTERN -> NFA_SKIP -> what follows. */
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3099 skip = alloc_state(NFA_SKIP, NULL, NULL);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3100 zend = alloc_state(NFA_ZEND, s1, NULL);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3101 s1->out= skip;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3102 patch(e.out, zend);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3103 PUSH(frag(s, list1(&skip->out)));
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
3104 }
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3105 else
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3106 {
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3107 patch(e.out, s1);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3108 PUSH(frag(s, list1(&s1->out)));
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3109 if (before)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3110 {
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3111 if (n <= 0)
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3112 /* See if we can guess the maximum width, it avoids a
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3113 * lot of pointless tries. */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3114 n = nfa_max_width(e.start, 0);
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3115 s->val = n; /* store the count */
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
3116 }
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3117 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3118 break;
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3119 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3120
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3121 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3122 case NFA_COMPOSING: /* char with composing char */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3123 #if 0
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3124 /* TODO */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3125 if (regflags & RF_ICOMBINE)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3126 {
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3127 /* use the base character only */
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3128 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3129 #endif
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3130 /* FALLTHROUGH */
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3131 #endif
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3132
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3133 case NFA_MOPEN: /* \( \) Submatch */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3134 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3135 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3136 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3137 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3138 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3139 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3140 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3141 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3142 case NFA_MOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3143 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3144 case NFA_ZOPEN: /* \z( \) Submatch */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3145 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3146 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3147 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3148 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3149 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3150 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3151 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3152 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3153 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3154 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3155 case NFA_NOPEN: /* \%( \) "Invisible Submatch" */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3156 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3157 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3158 nstate += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3159 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3160 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3161
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3162 mopen = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3163 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3164 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3165 case NFA_NOPEN: mclose = NFA_NCLOSE; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3166 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3167 case NFA_ZOPEN: mclose = NFA_ZCLOSE; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3168 case NFA_ZOPEN1: mclose = NFA_ZCLOSE1; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3169 case NFA_ZOPEN2: mclose = NFA_ZCLOSE2; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3170 case NFA_ZOPEN3: mclose = NFA_ZCLOSE3; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3171 case NFA_ZOPEN4: mclose = NFA_ZCLOSE4; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3172 case NFA_ZOPEN5: mclose = NFA_ZCLOSE5; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3173 case NFA_ZOPEN6: mclose = NFA_ZCLOSE6; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3174 case NFA_ZOPEN7: mclose = NFA_ZCLOSE7; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3175 case NFA_ZOPEN8: mclose = NFA_ZCLOSE8; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3176 case NFA_ZOPEN9: mclose = NFA_ZCLOSE9; break;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3177 #endif
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3178 #ifdef FEAT_MBYTE
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3179 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
3180 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3181 default:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3182 /* NFA_MOPEN, NFA_MOPEN1 .. NFA_MOPEN9 */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3183 mclose = *p + NSUBEXP;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3184 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3185 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3186
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3187 /* Allow "NFA_MOPEN" as a valid postfix representation for
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3188 * 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
3189 * NFA_MOPEN -> NFA_MCLOSE. Note that this also allows
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3190 * empty groups of parenthesis, and empty mbyte chars */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3191 if (stackp == stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3192 {
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
3193 s = alloc_state(mopen, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3194 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3195 goto theend;
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
3196 s1 = alloc_state(mclose, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3197 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3198 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3199 patch(list1(&s->out), s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3200 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3201 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3202 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3203
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3204 /* 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
3205 * 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
3206 e = POP();
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
3207 s = alloc_state(mopen, e.start, NULL); /* `(' */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3208 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3209 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3210
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
3211 s1 = alloc_state(mclose, NULL, NULL); /* `)' */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3212 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3213 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3214 patch(e.out, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3215
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3216 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3217 if (mopen == NFA_COMPOSING)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3218 /* COMPOSING->out1 = END_COMPOSING */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3219 patch(list1(&s->out1), s1);
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3220 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3221
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3222 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3223 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3224
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3225 case NFA_BACKREF1:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3226 case NFA_BACKREF2:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3227 case NFA_BACKREF3:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3228 case NFA_BACKREF4:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3229 case NFA_BACKREF5:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3230 case NFA_BACKREF6:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3231 case NFA_BACKREF7:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3232 case NFA_BACKREF8:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3233 case NFA_BACKREF9:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3234 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3235 case NFA_ZREF1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3236 case NFA_ZREF2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3237 case NFA_ZREF3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3238 case NFA_ZREF4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3239 case NFA_ZREF5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3240 case NFA_ZREF6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3241 case NFA_ZREF7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3242 case NFA_ZREF8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3243 case NFA_ZREF9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3244 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3245 if (nfa_calc_size == TRUE)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3246 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3247 nstate += 2;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3248 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3249 }
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
3250 s = alloc_state(*p, NULL, NULL);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3251 if (s == NULL)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3252 goto theend;
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
3253 s1 = alloc_state(NFA_SKIP, NULL, NULL);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3254 if (s1 == NULL)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3255 goto theend;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3256 patch(list1(&s->out), s1);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3257 PUSH(frag(s, list1(&s1->out)));
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3258 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3259
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3260 case NFA_LNUM:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3261 case NFA_LNUM_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3262 case NFA_LNUM_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3263 case NFA_VCOL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3264 case NFA_VCOL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3265 case NFA_VCOL_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3266 case NFA_COL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3267 case NFA_COL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3268 case NFA_COL_LT:
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
3269 case NFA_MARK:
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
3270 case NFA_MARK_GT:
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
3271 case NFA_MARK_LT:
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3272 {
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3273 int n = *++p; /* lnum, col or mark name */
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3274
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3275 if (nfa_calc_size == TRUE)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3276 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3277 nstate += 1;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3278 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3279 }
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3280 s = alloc_state(p[-1], NULL, NULL);
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3281 if (s == NULL)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3282 goto theend;
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3283 s->val = n;
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3284 PUSH(frag(s, list1(&s->out)));
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3285 break;
4740
97560c16ca99 updated for version 7.3.1117
Bram Moolenaar <bram@vim.org>
parents: 4738
diff changeset
3286 }
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
3287
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3288 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3289 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3290 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3291 /* Operands */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3292 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3293 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
3294 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3295 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3296 }
4696
ed4e689bbea1 updated for version 7.3.1095
Bram Moolenaar <bram@vim.org>
parents: 4694
diff changeset
3297 s = alloc_state(*p, NULL, NULL);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3298 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3299 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3300 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3301 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3302
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3303 } /* switch(*p) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3304
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3305 } /* for(p = postfix; *p; ++p) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3306
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3307 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3308 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
3309 nstate++;
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3310 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
3311 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3312
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3313 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3314 if (stackp != stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3315 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
3316
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3317 if (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3318 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
3319
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3320 matchstate = &state_ptr[istate++]; /* the match state */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3321 matchstate->c = NFA_MATCH;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3322 matchstate->out = matchstate->out1 = NULL;
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
3323 matchstate->id = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3324
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3325 patch(e.out, matchstate);
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3326 ret = e.start;
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3327
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3328 theend:
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3329 vim_free(stack);
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
3330 return ret;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3331
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3332 #undef POP1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3333 #undef PUSH1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3334 #undef POP2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3335 #undef PUSH2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3336 #undef POP
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3337 #undef PUSH
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3338 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3339
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3340 /*
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3341 * After building the NFA program, inspect it to add optimization hints.
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3342 */
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3343 static void
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3344 nfa_postprocess(prog)
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3345 nfa_regprog_T *prog;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3346 {
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3347 int i;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3348 int c;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3349
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3350 for (i = 0; i < prog->nstate; ++i)
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3351 {
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3352 c = prog->state[i].c;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3353 if (c == NFA_START_INVISIBLE
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3354 || c == NFA_START_INVISIBLE_NEG
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3355 || c == NFA_START_INVISIBLE_BEFORE
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3356 || c == NFA_START_INVISIBLE_BEFORE_NEG)
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3357 {
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3358 int directly;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3359
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3360 /* Do it directly when what follows is possibly the end of the
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3361 * match. */
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3362 if (match_follows(prog->state[i].out1->out, 0))
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3363 directly = TRUE;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3364 else
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3365 {
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3366 int ch_invisible = failure_chance(prog->state[i].out, 0);
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3367 int ch_follows = failure_chance(prog->state[i].out1->out, 0);
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3368
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3369 /* Postpone when the invisible match is expensive or has a
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3370 * lower chance of failing. */
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3371 if (c == NFA_START_INVISIBLE_BEFORE
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3372 || c == NFA_START_INVISIBLE_BEFORE_NEG)
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3373 {
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3374 /* "before" matches are very expensive when
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3375 * unbounded, always prefer what follows then,
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3376 * unless what follows will always match.
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3377 * Otherwise strongly prefer what follows. */
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3378 if (prog->state[i].val <= 0 && ch_follows > 0)
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3379 directly = FALSE;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3380 else
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3381 directly = ch_follows * 10 < ch_invisible;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3382 }
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3383 else
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3384 {
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3385 /* normal invisible, first do the one with the
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3386 * highest failure chance */
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3387 directly = ch_follows < ch_invisible;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3388 }
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3389 }
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3390 if (directly)
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3391 /* switch to the _FIRST state */
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3392 ++prog->state[i].c;
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3393 }
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3394 }
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3395 }
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3396
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3397 /****************************************************************
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3398 * NFA execution code.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3399 ****************************************************************/
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3400
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3401 typedef struct
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3402 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3403 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
3404
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3405 /* 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
3406 union
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3407 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3408 struct multipos
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3409 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3410 lpos_T start;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3411 lpos_T end;
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3412 } multi[NSUBEXP];
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3413 struct linepos
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3414 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3415 char_u *start;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3416 char_u *end;
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3417 } line[NSUBEXP];
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3418 } list;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3419 } regsub_T;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3420
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3421 typedef struct
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3422 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3423 regsub_T norm; /* \( .. \) matches */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3424 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3425 regsub_T synt; /* \z( .. \) matches */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3426 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3427 } regsubs_T;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3428
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3429 /* nfa_pim_T stores a Postponed Invisible Match. */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3430 typedef struct nfa_pim_S nfa_pim_T;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3431 struct nfa_pim_S
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3432 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3433 int result; /* NFA_PIM_*, see below */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3434 nfa_state_T *state; /* the invisible match start state */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3435 regsubs_T subs; /* submatch info, only party used */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3436 union
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3437 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3438 lpos_T pos;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3439 char_u *ptr;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3440 } end; /* where the match must end */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3441 };
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3442
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3443 /* Values for done in nfa_pim_T. */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3444 #define NFA_PIM_UNUSED 0 /* pim not used */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3445 #define NFA_PIM_TODO 1 /* pim not done yet */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3446 #define NFA_PIM_MATCH 2 /* pim executed, matches */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3447 #define NFA_PIM_NOMATCH 3 /* pim executed, no match */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3448
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3449
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3450 /* 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
3451 typedef struct
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3452 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3453 nfa_state_T *state;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3454 int count;
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3455 nfa_pim_T pim; /* if pim.result != NFA_PIM_UNUSED: postponed
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3456 * invisible match */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3457 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
3458 } nfa_thread_T;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3459
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3460 /* 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
3461 typedef struct
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3462 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3463 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
3464 int n; /* nr of states currently in "t" */
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3465 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
3466 int id; /* ID of the list */
5227
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
3467 int has_pim; /* TRUE when any state has a PIM */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3468 } nfa_list_T;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3469
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3470 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3471 static void log_subsexpr __ARGS((regsubs_T *subs));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3472 static void log_subexpr __ARGS((regsub_T *sub));
4997
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
3473 static char *pim_info __ARGS((nfa_pim_T *pim));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3474
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3475 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3476 log_subsexpr(subs)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3477 regsubs_T *subs;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3478 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3479 log_subexpr(&subs->norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3480 # ifdef FEAT_SYN_HL
4770
b20dbf3a5370 updated for version 7.3.1132
Bram Moolenaar <bram@vim.org>
parents: 4768
diff changeset
3481 if (nfa_has_zsubexpr)
b20dbf3a5370 updated for version 7.3.1132
Bram Moolenaar <bram@vim.org>
parents: 4768
diff changeset
3482 log_subexpr(&subs->synt);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3483 # endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3484 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3485
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3486 static void
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3487 log_subexpr(sub)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3488 regsub_T *sub;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3489 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3490 int j;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3491
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3492 for (j = 0; j < sub->in_use; j++)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3493 if (REG_MULTI)
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3494 fprintf(log_fd, "*** group %d, start: c=%d, l=%d, end: c=%d, l=%d\n",
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3495 j,
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3496 sub->list.multi[j].start.col,
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3497 (int)sub->list.multi[j].start.lnum,
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3498 sub->list.multi[j].end.col,
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
3499 (int)sub->list.multi[j].end.lnum);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3500 else
4746
d1376091d18b updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents: 4744
diff changeset
3501 {
d1376091d18b updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents: 4744
diff changeset
3502 char *s = (char *)sub->list.line[j].start;
d1376091d18b updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents: 4744
diff changeset
3503 char *e = (char *)sub->list.line[j].end;
d1376091d18b updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents: 4744
diff changeset
3504
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
3505 fprintf(log_fd, "*** group %d, start: \"%s\", end: \"%s\"\n",
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3506 j,
4746
d1376091d18b updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents: 4744
diff changeset
3507 s == NULL ? "NULL" : s,
d1376091d18b updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents: 4744
diff changeset
3508 e == NULL ? "NULL" : e);
d1376091d18b updated for version 7.3.1120
Bram Moolenaar <bram@vim.org>
parents: 4744
diff changeset
3509 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3510 }
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3511
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3512 static char *
4997
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
3513 pim_info(pim)
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
3514 nfa_pim_T *pim;
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3515 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3516 static char buf[30];
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3517
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3518 if (pim == NULL || pim->result == NFA_PIM_UNUSED)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3519 buf[0] = NUL;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3520 else
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3521 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3522 sprintf(buf, " PIM col %d", REG_MULTI ? (int)pim->end.pos.col
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3523 : (int)(pim->end.ptr - reginput));
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3524 }
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3525 return buf;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3526 }
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3527
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3528 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3529
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3530 /* 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
3531 static int nfa_match;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3532
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3533 static void copy_pim __ARGS((nfa_pim_T *to, nfa_pim_T *from));
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3534 static void clear_sub __ARGS((regsub_T *sub));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3535 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
3536 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
3537 static int sub_equal __ARGS((regsub_T *sub1, regsub_T *sub2));
4997
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
3538 static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
5212
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3539 static int has_state_with_pos __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs, nfa_pim_T *pim));
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3540 static int pim_equal __ARGS((nfa_pim_T *one, nfa_pim_T *two));
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3541 static int state_in_list __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs));
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3542 static regsubs_T *addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsubs_T *subs_arg, nfa_pim_T *pim, int off));
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
3543 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
3544
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3545 /*
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3546 * Copy postponed invisible match info from "from" to "to".
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3547 */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3548 static void
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3549 copy_pim(to, from)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3550 nfa_pim_T *to;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3551 nfa_pim_T *from;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3552 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3553 to->result = from->result;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3554 to->state = from->state;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3555 copy_sub(&to->subs.norm, &from->subs.norm);
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3556 #ifdef FEAT_SYN_HL
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3557 if (nfa_has_zsubexpr)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3558 copy_sub(&to->subs.synt, &from->subs.synt);
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3559 #endif
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3560 to->end = from->end;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3561 }
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3562
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3563 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3564 clear_sub(sub)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3565 regsub_T *sub;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3566 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3567 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3568 /* Use 0xff to set lnum to -1 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3569 vim_memset(sub->list.multi, 0xff,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3570 sizeof(struct multipos) * nfa_nsubexpr);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3571 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3572 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
3573 sub->in_use = 0;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3574 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3575
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3576 /*
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3577 * Copy the submatches from "from" to "to".
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3578 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3579 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3580 copy_sub(to, from)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3581 regsub_T *to;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3582 regsub_T *from;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3583 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3584 to->in_use = from->in_use;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3585 if (from->in_use > 0)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3586 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3587 /* Copy the match start and end positions. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3588 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3589 mch_memmove(&to->list.multi[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3590 &from->list.multi[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3591 sizeof(struct multipos) * from->in_use);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3592 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3593 mch_memmove(&to->list.line[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3594 &from->list.line[0],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3595 sizeof(struct linepos) * from->in_use);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3596 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3597 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3598
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3599 /*
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3600 * Like copy_sub() but exclude the main match.
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3601 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3602 static void
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3603 copy_sub_off(to, from)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3604 regsub_T *to;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3605 regsub_T *from;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3606 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3607 if (to->in_use < from->in_use)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3608 to->in_use = from->in_use;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3609 if (from->in_use > 1)
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 /* Copy the match start and end positions. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3612 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3613 mch_memmove(&to->list.multi[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3614 &from->list.multi[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3615 sizeof(struct multipos) * (from->in_use - 1));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3616 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3617 mch_memmove(&to->list.line[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3618 &from->list.line[1],
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3619 sizeof(struct linepos) * (from->in_use - 1));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3620 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3621 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3622
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3623 /*
4893
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3624 * Return TRUE if "sub1" and "sub2" have the same start positions.
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3625 */
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3626 static int
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3627 sub_equal(sub1, sub2)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3628 regsub_T *sub1;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3629 regsub_T *sub2;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3630 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3631 int i;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3632 int todo;
4893
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3633 linenr_T s1;
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3634 linenr_T s2;
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3635 char_u *sp1;
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3636 char_u *sp2;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3637
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3638 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
3639 if (REG_MULTI)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3640 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3641 for (i = 0; i < todo; ++i)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3642 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3643 if (i < sub1->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3644 s1 = sub1->list.multi[i].start.lnum;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3645 else
5006
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3646 s1 = -1;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3647 if (i < sub2->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3648 s2 = sub2->list.multi[i].start.lnum;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3649 else
5006
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3650 s2 = -1;
4893
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3651 if (s1 != s2)
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3652 return FALSE;
5006
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3653 if (s1 != -1 && sub1->list.multi[i].start.col
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3654 != sub2->list.multi[i].start.col)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3655 return FALSE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3656 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3657 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3658 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3659 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3660 for (i = 0; i < todo; ++i)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3661 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3662 if (i < sub1->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3663 sp1 = sub1->list.line[i].start;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3664 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3665 sp1 = NULL;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3666 if (i < sub2->in_use)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3667 sp2 = sub2->list.line[i].start;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3668 else
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3669 sp2 = NULL;
4893
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3670 if (sp1 != sp2)
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3671 return FALSE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3672 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3673 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3674
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3675 return TRUE;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3676 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3677
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3678 #ifdef ENABLE_LOG
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3679 static void
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3680 report_state(char *action,
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3681 regsub_T *sub,
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3682 nfa_state_T *state,
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3683 int lid,
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3684 nfa_pim_T *pim)
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3685 {
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3686 int col;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3687
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3688 if (sub->in_use <= 0)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3689 col = -1;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3690 else if (REG_MULTI)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3691 col = sub->list.multi[0].start.col;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3692 else
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3693 col = (int)(sub->list.line[0].start - regline);
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3694 nfa_set_code(state->c);
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3695 fprintf(log_fd, "> %s state %d to list %d. char %d: %s (start col %d)%s\n",
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3696 action, abs(state->id), lid, state->c, code, col,
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3697 pim_info(pim));
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3698 }
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3699 #endif
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
3700
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3701 /*
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3702 * Return TRUE if the same state is already in list "l" with the same
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3703 * positions as "subs".
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3704 */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3705 static int
5212
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3706 has_state_with_pos(l, state, subs, pim)
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3707 nfa_list_T *l; /* runtime state list */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3708 nfa_state_T *state; /* state to update */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3709 regsubs_T *subs; /* pointers to subexpressions */
5212
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3710 nfa_pim_T *pim; /* postponed match or NULL */
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3711 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3712 nfa_thread_T *thread;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3713 int i;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3714
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3715 for (i = 0; i < l->n; ++i)
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3716 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3717 thread = &l->t[i];
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3718 if (thread->state->id == state->id
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3719 && sub_equal(&thread->subs.norm, &subs->norm)
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3720 #ifdef FEAT_SYN_HL
4893
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3721 && (!nfa_has_zsubexpr
07b9c48a30e9 updated for version 7.3.1192
Bram Moolenaar <bram@vim.org>
parents: 4891
diff changeset
3722 || sub_equal(&thread->subs.synt, &subs->synt))
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3723 #endif
5212
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3724 && pim_equal(&thread->pim, pim))
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3725 return TRUE;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3726 }
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3727 return FALSE;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3728 }
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3729
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3730 /*
5212
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3731 * Return TRUE if "one" and "two" are equal. That includes when both are not
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3732 * set.
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3733 */
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3734 static int
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3735 pim_equal(one, two)
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3736 nfa_pim_T *one;
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3737 nfa_pim_T *two;
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3738 {
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3739 int one_unused = (one == NULL || one->result == NFA_PIM_UNUSED);
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3740 int two_unused = (two == NULL || two->result == NFA_PIM_UNUSED);
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3741
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3742 if (one_unused)
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3743 /* one is unused: equal when two is also unused */
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3744 return two_unused;
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3745 if (two_unused)
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3746 /* one is used and two is not: not equal */
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3747 return FALSE;
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3748 /* compare the position */
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3749 if (REG_MULTI)
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3750 return one->end.pos.lnum == two->end.pos.lnum
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3751 && one->end.pos.col == two->end.pos.col;
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3752 return one->end.ptr == two->end.ptr;
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3753 }
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3754
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3755 /*
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3756 * Return TRUE if "state" leads to a NFA_MATCH without advancing the input.
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3757 */
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3758 static int
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3759 match_follows(startstate, depth)
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3760 nfa_state_T *startstate;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3761 int depth;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3762 {
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3763 nfa_state_T *state = startstate;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3764
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3765 /* avoid too much recursion */
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3766 if (depth > 10)
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3767 return FALSE;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3768
5184
c6dd0c545e5c updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents: 5074
diff changeset
3769 while (state != NULL)
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3770 {
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3771 switch (state->c)
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3772 {
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3773 case NFA_MATCH:
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3774 case NFA_MCLOSE:
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3775 case NFA_END_INVISIBLE:
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3776 case NFA_END_INVISIBLE_NEG:
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
3777 case NFA_END_PATTERN:
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3778 return TRUE;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3779
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3780 case NFA_SPLIT:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3781 return match_follows(state->out, depth + 1)
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3782 || match_follows(state->out1, depth + 1);
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3783
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3784 case NFA_START_INVISIBLE:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3785 case NFA_START_INVISIBLE_FIRST:
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3786 case NFA_START_INVISIBLE_BEFORE:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3787 case NFA_START_INVISIBLE_BEFORE_FIRST:
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3788 case NFA_START_INVISIBLE_NEG:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3789 case NFA_START_INVISIBLE_NEG_FIRST:
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3790 case NFA_START_INVISIBLE_BEFORE_NEG:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
3791 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST:
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3792 case NFA_COMPOSING:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3793 /* skip ahead to next state */
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3794 state = state->out1->out;
5184
c6dd0c545e5c updated for version 7.4a.018
Bram Moolenaar <bram@vim.org>
parents: 5074
diff changeset
3795 continue;
4809
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3796
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3797 case NFA_ANY:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3798 case NFA_IDENT:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3799 case NFA_SIDENT:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3800 case NFA_KWORD:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3801 case NFA_SKWORD:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3802 case NFA_FNAME:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3803 case NFA_SFNAME:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3804 case NFA_PRINT:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3805 case NFA_SPRINT:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3806 case NFA_WHITE:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3807 case NFA_NWHITE:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3808 case NFA_DIGIT:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3809 case NFA_NDIGIT:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3810 case NFA_HEX:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3811 case NFA_NHEX:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3812 case NFA_OCTAL:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3813 case NFA_NOCTAL:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3814 case NFA_WORD:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3815 case NFA_NWORD:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3816 case NFA_HEAD:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3817 case NFA_NHEAD:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3818 case NFA_ALPHA:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3819 case NFA_NALPHA:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3820 case NFA_LOWER:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3821 case NFA_NLOWER:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3822 case NFA_UPPER:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3823 case NFA_NUPPER:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3824 case NFA_START_COLL:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3825 case NFA_START_NEG_COLL:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3826 case NFA_NEWL:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3827 /* state will advance input */
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3828 return FALSE;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3829
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3830 default:
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3831 if (state->c > 0)
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3832 /* state will advance input */
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3833 return FALSE;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3834
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3835 /* Others: zero-width or possibly zero-width, might still find
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3836 * a match at the same position, keep looking. */
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3837 break;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3838 }
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3839 state = state->out;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3840 }
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3841 return FALSE;
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3842 }
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3843
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3844
4d7e3df04256 updated for version 7.3.1151
Bram Moolenaar <bram@vim.org>
parents: 4807
diff changeset
3845 /*
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3846 * Return TRUE if "state" is already in list "l".
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3847 */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3848 static int
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3849 state_in_list(l, state, subs)
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3850 nfa_list_T *l; /* runtime state list */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3851 nfa_state_T *state; /* state to update */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3852 regsubs_T *subs; /* pointers to subexpressions */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3853 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3854 if (state->lastlist[nfa_ll_index] == l->id)
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3855 {
5212
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3856 if (!nfa_has_backref || has_state_with_pos(l, state, subs, NULL))
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3857 return TRUE;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3858 }
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3859 return FALSE;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3860 }
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3861
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3862 /*
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3863 * Add "state" and possibly what follows to state list ".".
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3864 * Returns "subs_arg", possibly copied into temp_subs.
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3865 */
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3866
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3867 static regsubs_T *
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3868 addstate(l, state, subs_arg, pim, off)
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3869 nfa_list_T *l; /* runtime state list */
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3870 nfa_state_T *state; /* state to update */
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3871 regsubs_T *subs_arg; /* pointers to subexpressions */
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3872 nfa_pim_T *pim; /* postponed look-behind match */
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3873 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
3874 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3875 int subidx;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3876 nfa_thread_T *thread;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3877 lpos_T save_lpos;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3878 int save_in_use;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3879 char_u *save_ptr;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3880 int i;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3881 regsub_T *sub;
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3882 regsubs_T *subs = subs_arg;
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3883 static regsubs_T temp_subs;
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3884 #ifdef ENABLE_LOG
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3885 int did_print = FALSE;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3886 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3887
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3888 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3889 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3890 case NFA_NCLOSE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3891 case NFA_MCLOSE:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3892 case NFA_MCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3893 case NFA_MCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3894 case NFA_MCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3895 case NFA_MCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3896 case NFA_MCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3897 case NFA_MCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3898 case NFA_MCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3899 case NFA_MCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3900 case NFA_MCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3901 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3902 case NFA_ZCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3903 case NFA_ZCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3904 case NFA_ZCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3905 case NFA_ZCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3906 case NFA_ZCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3907 case NFA_ZCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3908 case NFA_ZCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3909 case NFA_ZCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3910 case NFA_ZCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3911 case NFA_ZCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3912 #endif
5251
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3913 case NFA_MOPEN:
4748
4b9503f0c7d3 updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents: 4746
diff changeset
3914 case NFA_ZEND:
4815
6419ee8098c8 updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents: 4813
diff changeset
3915 case NFA_SPLIT:
6419ee8098c8 updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents: 4813
diff changeset
3916 case NFA_SKIP_CHAR:
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3917 /* 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
3918 * "out1" may be added below. */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3919 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3920
5251
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3921 case NFA_BOL:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3922 case NFA_BOF:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3923 /* "^" won't match past end-of-line, don't bother trying.
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3924 * Except when at the end of the line, or when we are going to the
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3925 * next line for a look-behind match. */
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3926 if (reginput > regline
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3927 && *reginput != NUL
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3928 && (nfa_endp == NULL
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3929 || !REG_MULTI
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3930 || reglnum == nfa_endp->se_u.pos.lnum))
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3931 goto skip_add;
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3932 /* FALLTHROUGH */
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3933
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3934 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3935 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3936 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3937 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3938 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3939 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3940 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3941 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3942 case NFA_MOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3943 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3944 case NFA_ZOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3945 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3946 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3947 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3948 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3949 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3950 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3951 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3952 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3953 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
3954 #endif
5251
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3955 case NFA_NOPEN:
4748
4b9503f0c7d3 updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents: 4746
diff changeset
3956 case NFA_ZSTART:
5251
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3957 /* These nodes need to be added so that we can bail out when it
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3958 * was added to this list before at the same position to avoid an
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
3959 * endless loop for "\(\)*" */
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
3960
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3961 default:
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
3962 if (state->lastlist[nfa_ll_index] == l->id)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3963 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3964 /* This state is already in the list, don't add it again,
5006
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3965 * unless it is an MOPEN that is used for a backreference or
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3966 * when there is a PIM. */
5227
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
3967 if (!nfa_has_backref && pim == NULL && !l->has_pim)
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3968 {
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3969 skip_add:
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3970 #ifdef ENABLE_LOG
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3971 nfa_set_code(state->c);
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3972 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
3973 abs(state->id), l->id, state->c, code);
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3974 #endif
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3975 return subs;
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
3976 }
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3977
4815
6419ee8098c8 updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents: 4813
diff changeset
3978 /* Do not add the state again when it exists with the same
6419ee8098c8 updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents: 4813
diff changeset
3979 * positions. */
5212
2741b46e96bf updated for version 7.4a.032
Bram Moolenaar <bram@vim.org>
parents: 5210
diff changeset
3980 if (has_state_with_pos(l, state, subs, pim))
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
3981 goto skip_add;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3982 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3983
5006
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3984 /* When there are backreferences or PIMs the number of states may
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3985 * be (a lot) bigger than anticipated. */
f451d60ab8ec updated for version 7.3.1247
Bram Moolenaar <bram@vim.org>
parents: 4997
diff changeset
3986 if (l->n == l->len)
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3987 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3988 int newlen = l->len * 3 / 2 + 50;
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
3989
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3990 if (subs != &temp_subs)
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3991 {
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3992 /* "subs" may point into the current array, need to make a
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3993 * copy before it becomes invalid. */
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3994 copy_sub(&temp_subs.norm, &subs->norm);
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3995 #ifdef FEAT_SYN_HL
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3996 if (nfa_has_zsubexpr)
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3997 copy_sub(&temp_subs.synt, &subs->synt);
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3998 #endif
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
3999 subs = &temp_subs;
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4000 }
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4001
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
4002 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
4003 l->len = newlen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4004 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4005
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4006 /* add the state to the list */
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4007 state->lastlist[nfa_ll_index] = l->id;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
4008 thread = &l->t[l->n++];
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
4009 thread->state = state;
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4010 if (pim == NULL)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4011 thread->pim.result = NFA_PIM_UNUSED;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4012 else
5227
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
4013 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4014 copy_pim(&thread->pim, pim);
5227
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
4015 l->has_pim = TRUE;
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
4016 }
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4017 copy_sub(&thread->subs.norm, &subs->norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4018 #ifdef FEAT_SYN_HL
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4019 if (nfa_has_zsubexpr)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4020 copy_sub(&thread->subs.synt, &subs->synt);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4021 #endif
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4022 #ifdef ENABLE_LOG
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4023 report_state("Adding", &thread->subs.norm, state, l->id, pim);
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4024 did_print = TRUE;
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4025 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4026 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4027
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4028 #ifdef ENABLE_LOG
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
4029 if (!did_print)
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4030 report_state("Processing", &subs->norm, state, l->id, pim);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4031 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4032 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4033 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4034 case NFA_MATCH:
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4035 nfa_match = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4036 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4037
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4038 case NFA_SPLIT:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4039 /* order matters here */
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4040 subs = addstate(l, state->out, subs, pim, off);
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4041 subs = addstate(l, state->out1, subs, pim, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4042 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4043
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4044 case NFA_SKIP_CHAR:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4045 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4046 case NFA_NCLOSE:
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4047 subs = addstate(l, state->out, subs, pim, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4048 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4049
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4050 case NFA_MOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4051 case NFA_MOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4052 case NFA_MOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4053 case NFA_MOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4054 case NFA_MOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4055 case NFA_MOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4056 case NFA_MOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4057 case NFA_MOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4058 case NFA_MOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4059 case NFA_MOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4060 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4061 case NFA_ZOPEN:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4062 case NFA_ZOPEN1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4063 case NFA_ZOPEN2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4064 case NFA_ZOPEN3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4065 case NFA_ZOPEN4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4066 case NFA_ZOPEN5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4067 case NFA_ZOPEN6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4068 case NFA_ZOPEN7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4069 case NFA_ZOPEN8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4070 case NFA_ZOPEN9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4071 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4072 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4073 if (state->c == NFA_ZSTART)
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4074 {
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4075 subidx = 0;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4076 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4077 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4078 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4079 else if (state->c >= NFA_ZOPEN)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4080 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4081 subidx = state->c - NFA_ZOPEN;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4082 sub = &subs->synt;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4083 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4084 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4085 else
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4086 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4087 subidx = state->c - NFA_MOPEN;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4088 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4089 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4090
5210
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4091 /* avoid compiler warnings */
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4092 save_ptr = NULL;
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4093 save_lpos.lnum = 0;
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4094 save_lpos.col = 0;
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4095
4815
6419ee8098c8 updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents: 4813
diff changeset
4096 /* Set the position (with "off" added) in the subexpression. Save
6419ee8098c8 updated for version 7.3.1154
Bram Moolenaar <bram@vim.org>
parents: 4813
diff changeset
4097 * and restore it when it was in use. Otherwise fill any gap. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4098 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4099 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4100 if (subidx < sub->in_use)
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4101 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4102 save_lpos = sub->list.multi[subidx].start;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4103 save_in_use = -1;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4104 }
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4105 else
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4106 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4107 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4108 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
4109 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4110 sub->list.multi[i].start.lnum = -1;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4111 sub->list.multi[i].end.lnum = -1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4112 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4113 sub->in_use = subidx + 1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4114 }
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4115 if (off == -1)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4116 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4117 sub->list.multi[subidx].start.lnum = reglnum + 1;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4118 sub->list.multi[subidx].start.col = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4119 }
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4120 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4121 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4122 sub->list.multi[subidx].start.lnum = reglnum;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4123 sub->list.multi[subidx].start.col =
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4124 (colnr_T)(reginput - regline + off);
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4125 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4126 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4127 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4128 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4129 if (subidx < sub->in_use)
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4130 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4131 save_ptr = sub->list.line[subidx].start;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4132 save_in_use = -1;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4133 }
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4134 else
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4135 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4136 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4137 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
4138 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4139 sub->list.line[i].start = NULL;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4140 sub->list.line[i].end = NULL;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4141 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4142 sub->in_use = subidx + 1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4143 }
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4144 sub->list.line[subidx].start = reginput + off;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4145 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4146
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4147 subs = addstate(l, state->out, subs, pim, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4148
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4149 if (save_in_use == -1)
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4150 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4151 if (REG_MULTI)
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4152 sub->list.multi[subidx].start = save_lpos;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4153 else
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4154 sub->list.line[subidx].start = save_ptr;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4155 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4156 else
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4157 sub->in_use = save_in_use;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4158 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4159
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4160 case NFA_MCLOSE:
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4161 if (nfa_has_zend)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4162 {
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
4163 /* 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
4164 * encountered end will be set in nfa_regtry(). */
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4165 subs = addstate(l, state->out, subs, pim, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4166 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4167 }
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4168 case NFA_MCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4169 case NFA_MCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4170 case NFA_MCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4171 case NFA_MCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4172 case NFA_MCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4173 case NFA_MCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4174 case NFA_MCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4175 case NFA_MCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4176 case NFA_MCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4177 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4178 case NFA_ZCLOSE:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4179 case NFA_ZCLOSE1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4180 case NFA_ZCLOSE2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4181 case NFA_ZCLOSE3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4182 case NFA_ZCLOSE4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4183 case NFA_ZCLOSE5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4184 case NFA_ZCLOSE6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4185 case NFA_ZCLOSE7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4186 case NFA_ZCLOSE8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4187 case NFA_ZCLOSE9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4188 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4189 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4190 if (state->c == NFA_ZEND)
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4191 {
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4192 subidx = 0;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4193 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4194 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4195 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4196 else if (state->c >= NFA_ZCLOSE)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4197 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4198 subidx = state->c - NFA_ZCLOSE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4199 sub = &subs->synt;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4200 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4201 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4202 else
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4203 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4204 subidx = state->c - NFA_MCLOSE;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4205 sub = &subs->norm;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4206 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4207
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
4208 /* 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
4209 * has done that. */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4210 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4211 if (sub->in_use <= subidx)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4212 sub->in_use = subidx + 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4213 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4214 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4215 save_lpos = sub->list.multi[subidx].end;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4216 if (off == -1)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4217 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4218 sub->list.multi[subidx].end.lnum = reglnum + 1;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4219 sub->list.multi[subidx].end.col = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4220 }
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4221 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4222 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4223 sub->list.multi[subidx].end.lnum = reglnum;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4224 sub->list.multi[subidx].end.col =
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4225 (colnr_T)(reginput - regline + off);
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
4226 }
5210
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4227 /* avoid compiler warnings */
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4228 save_ptr = NULL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4229 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4230 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4231 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4232 save_ptr = sub->list.line[subidx].end;
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4233 sub->list.line[subidx].end = reginput + off;
5210
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4234 /* avoid compiler warnings */
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4235 save_lpos.lnum = 0;
839ebe7c1b2f updated for version 7.4a.031
Bram Moolenaar <bram@vim.org>
parents: 5188
diff changeset
4236 save_lpos.col = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4237 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4238
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4239 subs = addstate(l, state->out, subs, pim, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4240
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4241 if (REG_MULTI)
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4242 sub->list.multi[subidx].end = save_lpos;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4243 else
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4244 sub->list.line[subidx].end = save_ptr;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4245 sub->in_use = save_in_use;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4246 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4247 }
5074
1cacf785299e updated for version 7.3.1280
Bram Moolenaar <bram@vim.org>
parents: 5058
diff changeset
4248 return subs;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4249 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4250
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4251 /*
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4252 * 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
4253 * 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
4254 * 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
4255 * matters for alternatives.
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4256 */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4257 static void
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4258 addstate_here(l, state, subs, pim, ip)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4259 nfa_list_T *l; /* runtime state list */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4260 nfa_state_T *state; /* state to update */
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4261 regsubs_T *subs; /* pointers to subexpressions */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4262 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
4263 int *ip;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4264 {
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4265 int tlen = l->n;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4266 int count;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4267 int listidx = *ip;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4268
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4269 /* first add the state(s) at the end, so that we know how many there are */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4270 addstate(l, state, subs, pim, 0);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4271
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4272 /* 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
4273 if (listidx + 1 == tlen)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4274 return;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4275
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4276 /* 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
4277 count = l->n - tlen;
4924
6ae32a64e153 updated for version 7.3.1207
Bram Moolenaar <bram@vim.org>
parents: 4897
diff changeset
4278 if (count == 0)
6ae32a64e153 updated for version 7.3.1207
Bram Moolenaar <bram@vim.org>
parents: 4897
diff changeset
4279 return; /* no state got added */
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
4280 if (count == 1)
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
4281 {
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
4282 /* overwrite the current state */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4283 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
4284 }
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
4285 else if (count > 1)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4286 {
5058
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4287 if (l->n + count - 1 >= l->len)
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4288 {
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4289 /* not enough space to move the new states, reallocate the list
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4290 * and move the states to the right position */
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4291 nfa_thread_T *newl;
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4292
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4293 l->len = l->len * 3 / 2 + 50;
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4294 newl = (nfa_thread_T *)alloc(l->len * sizeof(nfa_thread_T));
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4295 if (newl == NULL)
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4296 return;
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4297 mch_memmove(&(newl[0]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4298 &(l->t[0]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4299 sizeof(nfa_thread_T) * listidx);
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4300 mch_memmove(&(newl[listidx]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4301 &(l->t[l->n - count]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4302 sizeof(nfa_thread_T) * count);
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4303 mch_memmove(&(newl[listidx + count]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4304 &(l->t[listidx + 1]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4305 sizeof(nfa_thread_T) * (l->n - count - listidx - 1));
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4306 vim_free(l->t);
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4307 l->t = newl;
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4308 }
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4309 else
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4310 {
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4311 /* make space for new states, then move them from the
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4312 * end to the current position */
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4313 mch_memmove(&(l->t[listidx + count]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4314 &(l->t[listidx + 1]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4315 sizeof(nfa_thread_T) * (l->n - listidx - 1));
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4316 mch_memmove(&(l->t[listidx]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4317 &(l->t[l->n - 1]),
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4318 sizeof(nfa_thread_T) * count);
a00cd1839ac4 updated for version 7.3.1272
Bram Moolenaar <bram@vim.org>
parents: 5029
diff changeset
4319 }
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4320 }
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4321 --l->n;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4322 *ip = listidx - 1;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4323 }
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4324
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
4325 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4326 * Check character class "class" against current character c.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4327 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4328 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4329 check_char_class(class, c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4330 int class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4331 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4332 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4333 switch (class)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4334 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4335 case NFA_CLASS_ALNUM:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
4336 if (c >= 1 && c <= 255 && isalnum(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4337 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4338 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4339 case NFA_CLASS_ALPHA:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
4340 if (c >= 1 && c <= 255 && isalpha(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4341 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4342 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4343 case NFA_CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4344 if (c == ' ' || c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4345 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4346 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4347 case NFA_CLASS_CNTRL:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
4348 if (c >= 1 && c <= 255 && iscntrl(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4349 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4350 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4351 case NFA_CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4352 if (VIM_ISDIGIT(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4353 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4354 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4355 case NFA_CLASS_GRAPH:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
4356 if (c >= 1 && c <= 255 && isgraph(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4357 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4358 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4359 case NFA_CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4360 if (MB_ISLOWER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4361 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4362 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4363 case NFA_CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4364 if (vim_isprintc(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4365 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4366 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4367 case NFA_CLASS_PUNCT:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
4368 if (c >= 1 && c <= 255 && ispunct(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4369 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4370 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4371 case NFA_CLASS_SPACE:
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
4372 if ((c >= 9 && c <= 13) || (c == ' '))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4373 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4374 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4375 case NFA_CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4376 if (MB_ISUPPER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4377 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4378 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4379 case NFA_CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4380 if (vim_isxdigit(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4381 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4382 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4383 case NFA_CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4384 if (c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4385 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4386 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4387 case NFA_CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4388 if (c == '\r')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4389 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4390 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4391 case NFA_CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4392 if (c == '\b')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4393 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4394 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4395 case NFA_CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4396 if (c == '\033')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4397 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4398 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4399
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4400 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4401 /* should not be here :P */
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
4402 EMSGN("E877: (NFA regexp) Invalid character class: %ld", class);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
4403 return FAIL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4404 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4405 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4406 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4407
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4408 /*
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4409 * Check for a match with subexpression "subidx".
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4410 * Return TRUE if it matches.
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4411 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4412 static int
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4413 match_backref(sub, subidx, bytelen)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4414 regsub_T *sub; /* pointers to subexpressions */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4415 int subidx;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4416 int *bytelen; /* out: length of match in bytes */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4417 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4418 int len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4419
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4420 if (sub->in_use <= subidx)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4421 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4422 retempty:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4423 /* backref was not set, match an empty string */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4424 *bytelen = 0;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4425 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4426 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4427
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4428 if (REG_MULTI)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4429 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4430 if (sub->list.multi[subidx].start.lnum < 0
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4431 || sub->list.multi[subidx].end.lnum < 0)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4432 goto retempty;
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4433 if (sub->list.multi[subidx].start.lnum == reglnum
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4434 && sub->list.multi[subidx].end.lnum == reglnum)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4435 {
4891
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4436 len = sub->list.multi[subidx].end.col
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4437 - sub->list.multi[subidx].start.col;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4438 if (cstrncmp(regline + sub->list.multi[subidx].start.col,
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4439 reginput, &len) == 0)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4440 {
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4441 *bytelen = len;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4442 return TRUE;
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4443 }
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4444 }
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4445 else
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4446 {
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4447 if (match_with_backref(
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4448 sub->list.multi[subidx].start.lnum,
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4449 sub->list.multi[subidx].start.col,
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4450 sub->list.multi[subidx].end.lnum,
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4451 sub->list.multi[subidx].end.col,
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4452 bytelen) == RA_MATCH)
4c42efb4c098 updated for version 7.3.1191
Bram Moolenaar <bram@vim.org>
parents: 4887
diff changeset
4453 return TRUE;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4454 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4455 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4456 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4457 {
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4458 if (sub->list.line[subidx].start == NULL
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4459 || sub->list.line[subidx].end == NULL)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4460 goto retempty;
4577
b22bff1a6af8 updated for version 7.3.1036
Bram Moolenaar <bram@vim.org>
parents: 4573
diff changeset
4461 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
4462 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
4463 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4464 *bytelen = len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4465 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4466 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4467 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4468 return FALSE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4469 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
4470
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4471 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4472
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4473 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
4474
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4475 /*
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4476 * Check for a match with \z subexpression "subidx".
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4477 * Return TRUE if it matches.
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4478 */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4479 static int
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4480 match_zref(subidx, bytelen)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4481 int subidx;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4482 int *bytelen; /* out: length of match in bytes */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4483 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4484 int len;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4485
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4486 cleanup_zsubexpr();
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4487 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
4488 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4489 /* backref was not set, match an empty string */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4490 *bytelen = 0;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4491 return TRUE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4492 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4493
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4494 len = (int)STRLEN(re_extmatch_in->matches[subidx]);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4495 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
4496 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4497 *bytelen = len;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4498 return TRUE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4499 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4500 return FALSE;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4501 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4502 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
4503
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4504 /*
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4505 * 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
4506 * Also reset the IDs to zero.
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4507 * Only used for the recursive value lastlist[1].
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4508 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4509 static void
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4510 nfa_save_listids(prog, list)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4511 nfa_regprog_T *prog;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4512 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4513 {
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4514 int i;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4515 nfa_state_T *p;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4516
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4517 /* 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
4518 p = &prog->state[0];
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4519 for (i = prog->nstate; --i >= 0; )
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4520 {
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4521 list[i] = p->lastlist[1];
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4522 p->lastlist[1] = 0;
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4523 ++p;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4524 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4525 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4526
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 * Restore list IDs from "list" to all NFA states.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4529 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4530 static void
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4531 nfa_restore_listids(prog, list)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4532 nfa_regprog_T *prog;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4533 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4534 {
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4535 int i;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4536 nfa_state_T *p;
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4537
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4538 p = &prog->state[0];
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4539 for (i = prog->nstate; --i >= 0; )
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4540 {
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4541 p->lastlist[1] = list[i];
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4542 ++p;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4543 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4544 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4545
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4546 static int
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4547 nfa_re_num_cmp(val, op, pos)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4548 long_u val;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4549 int op;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4550 long_u pos;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4551 {
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4552 if (op == 1) return pos > val;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4553 if (op == 2) return pos < val;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4554 return val == pos;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4555 }
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
4556
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4557 static int recursive_regmatch __ARGS((nfa_state_T *state, nfa_pim_T *pim, nfa_regprog_T *prog, regsubs_T *submatch, regsubs_T *m, int **listids));
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
4558 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
4559
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4560 /*
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4561 * Recursively call nfa_regmatch()
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4562 * "pim" is NULL or contains info about a Postponed Invisible Match (start
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4563 * position).
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4564 */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4565 static int
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4566 recursive_regmatch(state, pim, prog, submatch, m, listids)
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4567 nfa_state_T *state;
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4568 nfa_pim_T *pim;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4569 nfa_regprog_T *prog;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4570 regsubs_T *submatch;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4571 regsubs_T *m;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4572 int **listids;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4573 {
4887
dc78a26f6f64 updated for version 7.3.1189
Bram Moolenaar <bram@vim.org>
parents: 4879
diff changeset
4574 int save_reginput_col = (int)(reginput - regline);
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4575 int save_reglnum = reglnum;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4576 int save_nfa_match = nfa_match;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4577 int save_nfa_listid = nfa_listid;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4578 save_se_T *save_nfa_endp = nfa_endp;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4579 save_se_T endpos;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4580 save_se_T *endposp = NULL;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4581 int result;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4582 int need_restore = FALSE;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4583
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4584 if (pim != NULL)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4585 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4586 /* start at the position where the postponed match was */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4587 if (REG_MULTI)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4588 reginput = regline + pim->end.pos.col;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4589 else
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4590 reginput = pim->end.ptr;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4591 }
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4592
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
4593 if (state->c == NFA_START_INVISIBLE_BEFORE
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
4594 || state->c == NFA_START_INVISIBLE_BEFORE_FIRST
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
4595 || state->c == NFA_START_INVISIBLE_BEFORE_NEG
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
4596 || state->c == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4597 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4598 /* The recursive match must end at the current position. When "pim" is
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4599 * not NULL it specifies the current position. */
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4600 endposp = &endpos;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4601 if (REG_MULTI)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4602 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4603 if (pim == NULL)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4604 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4605 endpos.se_u.pos.col = (int)(reginput - regline);
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4606 endpos.se_u.pos.lnum = reglnum;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4607 }
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4608 else
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4609 endpos.se_u.pos = pim->end.pos;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4610 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4611 else
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4612 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4613 if (pim == NULL)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4614 endpos.se_u.ptr = reginput;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4615 else
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4616 endpos.se_u.ptr = pim->end.ptr;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
4617 }
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4618
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4619 /* 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
4620 * start of the previous line, to try matching "\@<=" or
5188
fa76be660fa9 updated for version 7.4a.020
Bram Moolenaar <bram@vim.org>
parents: 5184
diff changeset
4621 * not matching "\@<!". This is very inefficient, limit the number of
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
4622 * bytes if possible. */
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4623 if (state->val <= 0)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4624 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4625 if (REG_MULTI)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4626 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4627 regline = reg_getline(--reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4628 if (regline == NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4629 /* can't go before the first line */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4630 regline = reg_getline(++reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4631 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4632 reginput = regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4633 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4634 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4635 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4636 if (REG_MULTI && (int)(reginput - regline) < state->val)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4637 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4638 /* 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
4639 * previous line. */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4640 regline = reg_getline(--reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4641 if (regline == NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4642 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4643 /* can't go before the first line */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4644 regline = reg_getline(++reglnum);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4645 reginput = regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4646 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4647 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4648 reginput = regline + STRLEN(regline);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4649 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4650 if ((int)(reginput - regline) >= state->val)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4651 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4652 reginput -= state->val;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4653 #ifdef FEAT_MBYTE
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4654 if (has_mbyte)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4655 reginput -= mb_head_off(regline, reginput);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4656 #endif
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4657 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4658 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4659 reginput = regline;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4660 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4661 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4662
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4663 #ifdef ENABLE_LOG
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4664 if (log_fd != stderr)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4665 fclose(log_fd);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4666 log_fd = NULL;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4667 #endif
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4668 /* 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
4669 * 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
4670 if (nfa_ll_index == 1)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4671 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4672 /* 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
4673 * values and clear them. */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4674 if (*listids == NULL)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4675 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4676 *listids = (int *)lalloc(sizeof(int) * nstate, TRUE);
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4677 if (*listids == NULL)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4678 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4679 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
4680 return 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4681 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4682 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4683 nfa_save_listids(prog, *listids);
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4684 need_restore = TRUE;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4685 /* any value of nfa_listid will do */
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4686 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4687 else
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4688 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4689 /* 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
4690 * 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
4691 * 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
4692 ++nfa_ll_index;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4693 if (nfa_listid <= nfa_alt_listid)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4694 nfa_listid = nfa_alt_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4695 }
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4696
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4697 /* 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
4698 * 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
4699 nfa_endp = endposp;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4700 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
4701
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4702 if (need_restore)
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4703 nfa_restore_listids(prog, *listids);
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4704 else
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4705 {
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4706 --nfa_ll_index;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4707 nfa_alt_listid = nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4708 }
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4709
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4710 /* restore position in input text */
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4711 reglnum = save_reglnum;
4877
9e36c6b1ebf4 updated for version 7.3.1184
Bram Moolenaar <bram@vim.org>
parents: 4845
diff changeset
4712 if (REG_MULTI)
9e36c6b1ebf4 updated for version 7.3.1184
Bram Moolenaar <bram@vim.org>
parents: 4845
diff changeset
4713 regline = reg_getline(reglnum);
4887
dc78a26f6f64 updated for version 7.3.1189
Bram Moolenaar <bram@vim.org>
parents: 4879
diff changeset
4714 reginput = regline + save_reginput_col;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4715 nfa_match = save_nfa_match;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4716 nfa_endp = save_nfa_endp;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
4717 nfa_listid = save_nfa_listid;
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4718
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4719 #ifdef ENABLE_LOG
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4720 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4721 if (log_fd != NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4722 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4723 fprintf(log_fd, "****************************\n");
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4724 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
4725 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
4726 fprintf(log_fd, "****************************\n");
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4727 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4728 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4729 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4730 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
4731 log_fd = stderr;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4732 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4733 #endif
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4734
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4735 return result;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4736 }
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4737
4801
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4738 static int skip_to_start __ARGS((int c, colnr_T *colp));
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4739 static long find_match_text __ARGS((colnr_T startcol, int regstart, char_u *match_text));
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4740
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4741 /*
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4742 * Estimate the chance of a match with "state" failing.
4821
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
4743 * empty match: 0
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4744 * NFA_ANY: 1
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4745 * specific character: 99
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4746 */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4747 static int
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4748 failure_chance(state, depth)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4749 nfa_state_T *state;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4750 int depth;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4751 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4752 int c = state->c;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4753 int l, r;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4754
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4755 /* detect looping */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4756 if (depth > 4)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4757 return 1;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4758
4742
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4759 switch (c)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4760 {
4742
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4761 case NFA_SPLIT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4762 if (state->out->c == NFA_SPLIT || state->out1->c == NFA_SPLIT)
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4763 /* avoid recursive stuff */
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4764 return 1;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4765 /* two alternatives, use the lowest failure chance */
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4766 l = failure_chance(state->out, depth + 1);
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4767 r = failure_chance(state->out1, depth + 1);
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4768 return l < r ? l : r;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4769
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4770 case NFA_ANY:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4771 /* matches anything, unlikely to fail */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4772 return 1;
4821
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
4773
4742
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4774 case NFA_MATCH:
4821
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
4775 case NFA_MCLOSE:
4742
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4776 /* empty match works always */
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4777 return 0;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4778
4897
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4779 case NFA_START_INVISIBLE:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4780 case NFA_START_INVISIBLE_FIRST:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4781 case NFA_START_INVISIBLE_NEG:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4782 case NFA_START_INVISIBLE_NEG_FIRST:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4783 case NFA_START_INVISIBLE_BEFORE:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4784 case NFA_START_INVISIBLE_BEFORE_FIRST:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4785 case NFA_START_INVISIBLE_BEFORE_NEG:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4786 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4787 case NFA_START_PATTERN:
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4788 /* recursive regmatch is expensive, use low failure chance */
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4789 return 5;
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
4790
4742
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4791 case NFA_BOL:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4792 case NFA_EOL:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4793 case NFA_BOF:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4794 case NFA_EOF:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4795 case NFA_NEWL:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4796 return 99;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4797
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4798 case NFA_BOW:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4799 case NFA_EOW:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4800 return 90;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4801
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4802 case NFA_MOPEN:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4803 case NFA_MOPEN1:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4804 case NFA_MOPEN2:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4805 case NFA_MOPEN3:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4806 case NFA_MOPEN4:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4807 case NFA_MOPEN5:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4808 case NFA_MOPEN6:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4809 case NFA_MOPEN7:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4810 case NFA_MOPEN8:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4811 case NFA_MOPEN9:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4812 #ifdef FEAT_SYN_HL
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4813 case NFA_ZOPEN:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4814 case NFA_ZOPEN1:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4815 case NFA_ZOPEN2:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4816 case NFA_ZOPEN3:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4817 case NFA_ZOPEN4:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4818 case NFA_ZOPEN5:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4819 case NFA_ZOPEN6:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4820 case NFA_ZOPEN7:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4821 case NFA_ZOPEN8:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4822 case NFA_ZOPEN9:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4823 case NFA_ZCLOSE:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4824 case NFA_ZCLOSE1:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4825 case NFA_ZCLOSE2:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4826 case NFA_ZCLOSE3:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4827 case NFA_ZCLOSE4:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4828 case NFA_ZCLOSE5:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4829 case NFA_ZCLOSE6:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4830 case NFA_ZCLOSE7:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4831 case NFA_ZCLOSE8:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4832 case NFA_ZCLOSE9:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4833 #endif
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4834 case NFA_NOPEN:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4835 case NFA_MCLOSE1:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4836 case NFA_MCLOSE2:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4837 case NFA_MCLOSE3:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4838 case NFA_MCLOSE4:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4839 case NFA_MCLOSE5:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4840 case NFA_MCLOSE6:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4841 case NFA_MCLOSE7:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4842 case NFA_MCLOSE8:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4843 case NFA_MCLOSE9:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4844 case NFA_NCLOSE:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4845 return failure_chance(state->out, depth + 1);
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4846
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4847 case NFA_BACKREF1:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4848 case NFA_BACKREF2:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4849 case NFA_BACKREF3:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4850 case NFA_BACKREF4:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4851 case NFA_BACKREF5:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4852 case NFA_BACKREF6:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4853 case NFA_BACKREF7:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4854 case NFA_BACKREF8:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4855 case NFA_BACKREF9:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4856 #ifdef FEAT_SYN_HL
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4857 case NFA_ZREF1:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4858 case NFA_ZREF2:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4859 case NFA_ZREF3:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4860 case NFA_ZREF4:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4861 case NFA_ZREF5:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4862 case NFA_ZREF6:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4863 case NFA_ZREF7:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4864 case NFA_ZREF8:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4865 case NFA_ZREF9:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4866 #endif
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4867 /* backreferences don't match in many places */
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4868 return 94;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4869
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4870 case NFA_LNUM_GT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4871 case NFA_LNUM_LT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4872 case NFA_COL_GT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4873 case NFA_COL_LT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4874 case NFA_VCOL_GT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4875 case NFA_VCOL_LT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4876 case NFA_MARK_GT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4877 case NFA_MARK_LT:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4878 case NFA_VISUAL:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4879 /* before/after positions don't match very often */
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4880 return 85;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4881
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4882 case NFA_LNUM:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4883 return 90;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4884
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4885 case NFA_CURSOR:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4886 case NFA_COL:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4887 case NFA_VCOL:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4888 case NFA_MARK:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4889 /* specific positions rarely match */
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4890 return 98;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4891
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4892 case NFA_COMPOSING:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4893 return 95;
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4894
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4895 default:
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4896 if (c > 0)
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4897 /* character match fails often */
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4898 return 95;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4899 }
4742
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4900
6a706ca7a889 updated for version 7.3.1118
Bram Moolenaar <bram@vim.org>
parents: 4740
diff changeset
4901 /* something else, includes character classes */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4902 return 50;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4903 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
4904
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
4905 /*
4801
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4906 * Skip until the char "c" we know a match must start with.
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4907 */
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4908 static int
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4909 skip_to_start(c, colp)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4910 int c;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4911 colnr_T *colp;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4912 {
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4913 char_u *s;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4914
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4915 /* Used often, do some work to avoid call overhead. */
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4916 if (!ireg_ic
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4917 #ifdef FEAT_MBYTE
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4918 && !has_mbyte
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4919 #endif
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4920 )
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4921 s = vim_strbyte(regline + *colp, c);
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4922 else
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4923 s = cstrchr(regline + *colp, c);
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4924 if (s == NULL)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4925 return FAIL;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4926 *colp = (int)(s - regline);
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4927 return OK;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4928 }
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4929
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
4930 /*
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4931 * Check for a match with match_text.
4807
3dbd251777de updated for version 7.3.1150
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
4932 * Called after skip_to_start() has found regstart.
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4933 * Returns zero for no match, 1 for a match.
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4934 */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4935 static long
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4936 find_match_text(startcol, regstart, match_text)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4937 colnr_T startcol;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4938 int regstart;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4939 char_u *match_text;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4940 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4941 colnr_T col = startcol;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4942 int c1, c2;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4943 int len1, len2;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4944 int match;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4945
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4946 for (;;)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4947 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4948 match = TRUE;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4949 len2 = MB_CHAR2LEN(regstart); /* skip regstart */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4950 for (len1 = 0; match_text[len1] != NUL; len1 += MB_CHAR2LEN(c1))
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4951 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4952 c1 = PTR2CHAR(match_text + len1);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4953 c2 = PTR2CHAR(regline + col + len2);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4954 if (c1 != c2 && (!ireg_ic || MB_TOLOWER(c1) != MB_TOLOWER(c2)))
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4955 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4956 match = FALSE;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4957 break;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4958 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4959 len2 += MB_CHAR2LEN(c2);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4960 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4961 if (match
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4962 #ifdef FEAT_MBYTE
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4963 /* check that no composing char follows */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4964 && !(enc_utf8
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4965 && utf_iscomposing(PTR2CHAR(regline + col + len2)))
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4966 #endif
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4967 )
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4968 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4969 cleanup_subexpr();
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4970 if (REG_MULTI)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4971 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4972 reg_startpos[0].lnum = reglnum;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4973 reg_startpos[0].col = col;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4974 reg_endpos[0].lnum = reglnum;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4975 reg_endpos[0].col = col + len2;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4976 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4977 else
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4978 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4979 reg_startp[0] = regline + col;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4980 reg_endp[0] = regline + col + len2;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4981 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4982 return 1L;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4983 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4984
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4985 /* Try finding regstart after the current match. */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4986 col += MB_CHAR2LEN(regstart); /* skip regstart */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4987 if (skip_to_start(regstart, &col) == FAIL)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4988 break;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4989 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4990 return 0L;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4991 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4992
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
4993 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4994 * Main matching routine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4995 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4996 * Run NFA to determine whether it matches reginput.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4997 *
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
4998 * 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
4999 *
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5000 * Return TRUE if there is a match, FALSE otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5001 * Note: Caller must ensure that: start != NULL.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5002 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5003 static int
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
5004 nfa_regmatch(prog, start, submatch, m)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
5005 nfa_regprog_T *prog;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5006 nfa_state_T *start;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5007 regsubs_T *submatch;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5008 regsubs_T *m;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5009 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5010 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5011 int size = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5012 int flag = 0;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
5013 int go_to_nextline = FALSE;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
5014 nfa_thread_T *t;
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5015 nfa_list_T list[2];
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5016 int listidx;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
5017 nfa_list_T *thislist;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
5018 nfa_list_T *nextlist;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5019 int *listids = NULL;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5020 nfa_state_T *add_state;
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5021 int add_here;
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5022 int add_count;
4819
8c4324e6f477 updated for version 7.3.1156
Bram Moolenaar <bram@vim.org>
parents: 4815
diff changeset
5023 int add_off = 0;
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5024 int toplevel = start->c == NFA_MOPEN;
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
5025 #ifdef NFA_REGEXP_DEBUG_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
5026 FILE *debug = fopen(NFA_REGEXP_DEBUG_LOG, "a");
4444
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 if (debug == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5029 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
5030 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
5031 return FALSE;
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 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
5034 nfa_match = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5035
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
5036 /* Allocate memory for the lists of nodes. */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
5037 size = (nstate + 1) * sizeof(nfa_thread_T);
4768
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
5038 list[0].t = (nfa_thread_T *)lalloc(size, TRUE);
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
5039 list[0].len = nstate + 1;
4768
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
5040 list[1].t = (nfa_thread_T *)lalloc(size, TRUE);
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
5041 list[1].len = nstate + 1;
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5042 if (list[0].t == NULL || list[1].t == NULL)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5043 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5044
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5045 #ifdef ENABLE_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
5046 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5047 if (log_fd != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5048 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5049 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5050 nfa_set_code(start->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5051 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
5052 abs(start->id), code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5053 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5054 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5055 else
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 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
5058 log_fd = stderr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5059 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5060 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5061
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5062 thislist = &list[0];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5063 thislist->n = 0;
5227
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
5064 thislist->has_pim = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5065 nextlist = &list[1];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5066 nextlist->n = 0;
5227
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
5067 nextlist->has_pim = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5068 #ifdef ENABLE_LOG
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5069 fprintf(log_fd, "(---) STARTSTATE first\n");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5070 #endif
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5071 thislist->id = nfa_listid + 1;
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5072
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5073 /* Inline optimized code for addstate(thislist, start, m, 0) if we know
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5074 * it's the first MOPEN. */
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5075 if (toplevel)
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5076 {
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5077 if (REG_MULTI)
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5078 {
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5079 m->norm.list.multi[0].start.lnum = reglnum;
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5080 m->norm.list.multi[0].start.col = (colnr_T)(reginput - regline);
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5081 }
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5082 else
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5083 m->norm.list.line[0].start = reginput;
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5084 m->norm.in_use = 1;
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5085 addstate(thislist, start->out, m, NULL, 0);
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5086 }
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
5087 else
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5088 addstate(thislist, start, m, NULL, 0);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5089
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5090 #define ADD_STATE_IF_MATCH(state) \
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5091 if (result) { \
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5092 add_state = state->out; \
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5093 add_off = clen; \
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5094 }
4444
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5097 * Run for each character.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5098 */
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5099 for (;;)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5100 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5101 int curc;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5102 int clen;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5103
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5104 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5105 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5106 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5107 curc = (*mb_ptr2char)(reginput);
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5108 clen = (*mb_ptr2len)(reginput);
4444
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 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5111 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5112 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5113 curc = *reginput;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5114 clen = 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5115 }
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5116 if (curc == NUL)
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5117 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5118 clen = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5119 go_to_nextline = FALSE;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5120 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5121
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5122 /* swap lists */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5123 thislist = &list[flag];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5124 nextlist = &list[flag ^= 1];
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5125 nextlist->n = 0; /* clear nextlist */
5227
a08fa2919f2b updated for version 7.4a.039
Bram Moolenaar <bram@vim.org>
parents: 5221
diff changeset
5126 nextlist->has_pim = FALSE;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5127 ++nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5128 thislist->id = nfa_listid;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
5129 nextlist->id = nfa_listid + 1;
4444
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 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5132 fprintf(log_fd, "------------------------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5133 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
5134 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
5135 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
5136 {
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5137 int i;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5138
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5139 for (i = 0; i < thislist->n; i++)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5140 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
5141 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5142 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5143 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5144
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
5145 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5146 fprintf(debug, "\n-------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5147 #endif
4480
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
5148 /*
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
5149 * 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
5150 */
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5151 if (thislist->n == 0)
4480
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
5152 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5153
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5154 /* compute nextlist */
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5155 for (listidx = 0; listidx < thislist->n; ++listidx)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5156 {
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5157 t = &thislist->t[listidx];
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5158
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
5159 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5160 nfa_set_code(t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5161 fprintf(debug, "%s, ", code);
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 #ifdef ENABLE_LOG
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
5164 {
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
5165 int col;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
5166
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5167 if (t->subs.norm.in_use <= 0)
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
5168 col = -1;
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
5169 else if (REG_MULTI)
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5170 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
5171 else
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
5172 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
5173 nfa_set_code(t->state->c);
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5174 fprintf(log_fd, "(%d) char %d %s (start col %d)%s ... \n",
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5175 abs(t->state->id), (int)t->state->c, code, col,
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5176 pim_info(&t->pim));
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
5177 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5178 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5179
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5180 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5181 * Handle the possible codes of the current state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5182 * The most important is NFA_MATCH.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5183 */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5184 add_state = NULL;
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5185 add_here = FALSE;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5186 add_count = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5187 switch (t->state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5188 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5189 case NFA_MATCH:
4567
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
5190 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
5191 nfa_match = TRUE;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5192 copy_sub(&submatch->norm, &t->subs.norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5193 #ifdef FEAT_SYN_HL
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
5194 if (nfa_has_zsubexpr)
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
5195 copy_sub(&submatch->synt, &t->subs.synt);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5196 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5197 #ifdef ENABLE_LOG
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5198 log_subsexpr(&t->subs);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5199 #endif
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5200 /* 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
5201 * 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
5202 * 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
5203 * correct. */
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5204 if (nextlist->n == 0)
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
5205 clen = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5206 goto nextchar;
4567
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
5207 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5208
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5209 case NFA_END_INVISIBLE:
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5210 case NFA_END_INVISIBLE_NEG:
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5211 case NFA_END_PATTERN:
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5212 /*
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5213 * 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
5214 * NFA_START_INVISIBLE_BEFORE node.
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
5215 * They surround a zero-width group, used with "\@=", "\&",
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
5216 * "\@!", "\@<=" and "\@<!".
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5217 * 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
5218 * 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
5219 * 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
5220 * in the position in "nfa_endp".
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5221 * 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
5222 */
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
5223 #ifdef ENABLE_LOG
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5224 if (nfa_endp != NULL)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5225 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5226 if (REG_MULTI)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5227 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
5228 (int)reglnum,
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5229 (int)nfa_endp->se_u.pos.lnum,
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5230 (int)(reginput - regline),
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5231 nfa_endp->se_u.pos.col);
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5232 else
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5233 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
5234 (int)(reginput - regline),
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5235 (int)(nfa_endp->se_u.ptr - reginput));
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5236 }
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
5237 #endif
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5238 /* If "nfa_endp" is set it's only a match if it ends at
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5239 * "nfa_endp" */
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5240 if (nfa_endp != NULL && (REG_MULTI
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5241 ? (reglnum != nfa_endp->se_u.pos.lnum
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5242 || (int)(reginput - regline)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5243 != nfa_endp->se_u.pos.col)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5244 : reginput != nfa_endp->se_u.ptr))
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5245 break;
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5246
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5247 /* do not set submatches for \@! */
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5248 if (t->state->c != NFA_END_INVISIBLE_NEG)
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5249 {
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5250 copy_sub(&m->norm, &t->subs.norm);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5251 #ifdef FEAT_SYN_HL
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5252 if (nfa_has_zsubexpr)
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5253 copy_sub(&m->synt, &t->subs.synt);
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5254 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5255 }
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5256 #ifdef ENABLE_LOG
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5257 fprintf(log_fd, "Match found:\n");
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5258 log_subsexpr(m);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5259 #endif
4716
a804309e7327 updated for version 7.3.1105
Bram Moolenaar <bram@vim.org>
parents: 4714
diff changeset
5260 nfa_match = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5261 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5262
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5263 case NFA_START_INVISIBLE:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5264 case NFA_START_INVISIBLE_FIRST:
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5265 case NFA_START_INVISIBLE_NEG:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5266 case NFA_START_INVISIBLE_NEG_FIRST:
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
5267 case NFA_START_INVISIBLE_BEFORE:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5268 case NFA_START_INVISIBLE_BEFORE_FIRST:
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5269 case NFA_START_INVISIBLE_BEFORE_NEG:
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5270 case NFA_START_INVISIBLE_BEFORE_NEG_FIRST:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5271 {
4821
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
5272 #ifdef ENABLE_LOG
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
5273 fprintf(log_fd, "Failure chance invisible: %d, what follows: %d\n",
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
5274 failure_chance(t->state->out, 0),
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
5275 failure_chance(t->state->out1->out, 0));
2f1ee97f5f23 updated for version 7.3.1157
Bram Moolenaar <bram@vim.org>
parents: 4819
diff changeset
5276 #endif
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5277 /* Do it directly if there already is a PIM or when
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5278 * nfa_postprocess() detected it will work better. */
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5279 if (t->pim.result != NFA_PIM_UNUSED
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5280 || t->state->c == NFA_START_INVISIBLE_FIRST
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5281 || t->state->c == NFA_START_INVISIBLE_NEG_FIRST
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5282 || t->state->c == NFA_START_INVISIBLE_BEFORE_FIRST
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5283 || t->state->c == NFA_START_INVISIBLE_BEFORE_NEG_FIRST)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5284 {
5029
c9e2ccc53f2e updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents: 5006
diff changeset
5285 int in_use = m->norm.in_use;
c9e2ccc53f2e updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents: 5006
diff changeset
5286
4997
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
5287 /* Copy submatch info for the recursive call, so that
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
5288 * \1 can be matched. */
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
5289 copy_sub_off(&m->norm, &t->subs.norm);
8a7d3a73adab updated for version 7.3.1243
Bram Moolenaar <bram@vim.org>
parents: 4958
diff changeset
5290
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5291 /*
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5292 * First try matching the invisible match, then what
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5293 * follows.
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5294 */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5295 result = recursive_regmatch(t->state, NULL, prog,
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5296 submatch, m, &listids);
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5297
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5298 /* for \@! and \@<! it is a match when the result is
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5299 * FALSE */
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5300 if (result != (t->state->c == NFA_START_INVISIBLE_NEG
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5301 || t->state->c == NFA_START_INVISIBLE_NEG_FIRST
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5302 || t->state->c
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5303 == NFA_START_INVISIBLE_BEFORE_NEG
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5304 || t->state->c
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
5305 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST))
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5306 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5307 /* Copy submatch info from the recursive call */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5308 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
5309 #ifdef FEAT_SYN_HL
4768
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
5310 if (nfa_has_zsubexpr)
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
5311 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
5312 #endif
4657
93b7ed814bec updated for version 7.3.1076
Bram Moolenaar <bram@vim.org>
parents: 4655
diff changeset
5313
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5314 /* t->state->out1 is the corresponding
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5315 * 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
5316 * list (zero-width match). */
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5317 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5318 add_state = t->state->out1->out;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5319 }
5029
c9e2ccc53f2e updated for version 7.3.1258
Bram Moolenaar <bram@vim.org>
parents: 5006
diff changeset
5320 m->norm.in_use = in_use;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5321 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5322 else
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5323 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5324 nfa_pim_T pim;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5325
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5326 /*
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5327 * First try matching what follows. Only if a match
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5328 * is found verify the invisible match matches. Add a
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5329 * nfa_pim_T to the following states, it contains info
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5330 * about the invisible match.
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5331 */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5332 pim.state = t->state;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5333 pim.result = NFA_PIM_TODO;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5334 pim.subs.norm.in_use = 0;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5335 #ifdef FEAT_SYN_HL
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5336 pim.subs.synt.in_use = 0;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5337 #endif
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5338 if (REG_MULTI)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5339 {
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5340 pim.end.pos.col = (int)(reginput - regline);
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5341 pim.end.pos.lnum = reglnum;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5342 }
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5343 else
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5344 pim.end.ptr = reginput;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5345
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5346 /* t->state->out1 is the corresponding END_INVISIBLE
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5347 * 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
5348 * match). */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5349 addstate_here(thislist, t->state->out1->out, &t->subs,
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5350 &pim, &listidx);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5351 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5352 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5353 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5354
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5355 case NFA_START_PATTERN:
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5356 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5357 nfa_state_T *skip = NULL;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5358 #ifdef ENABLE_LOG
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5359 int skip_lid = 0;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5360 #endif
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5361
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5362 /* There is no point in trying to match the pattern if the
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5363 * output state is not going to be added to the list. */
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5364 if (state_in_list(nextlist, t->state->out1->out, &t->subs))
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5365 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5366 skip = t->state->out1->out;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5367 #ifdef ENABLE_LOG
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5368 skip_lid = nextlist->id;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5369 #endif
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5370 }
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5371 else if (state_in_list(nextlist,
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5372 t->state->out1->out->out, &t->subs))
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5373 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5374 skip = t->state->out1->out->out;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5375 #ifdef ENABLE_LOG
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5376 skip_lid = nextlist->id;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5377 #endif
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5378 }
4897
91136a41f83f updated for version 7.3.1194
Bram Moolenaar <bram@vim.org>
parents: 4893
diff changeset
5379 else if (state_in_list(thislist,
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5380 t->state->out1->out->out, &t->subs))
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5381 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5382 skip = t->state->out1->out->out;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5383 #ifdef ENABLE_LOG
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5384 skip_lid = thislist->id;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5385 #endif
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5386 }
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5387 if (skip != NULL)
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5388 {
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5389 #ifdef ENABLE_LOG
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5390 nfa_set_code(skip->c);
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5391 fprintf(log_fd, "> Not trying to match pattern, output state %d is already in list %d. char %d: %s\n",
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5392 abs(skip->id), skip_lid, skip->c, code);
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5393 #endif
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5394 break;
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5395 }
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5396
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5397 /* First try matching the pattern. */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
5398 result = recursive_regmatch(t->state, NULL, prog,
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5399 submatch, m, &listids);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5400 if (result)
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5401 {
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5402 int bytelen;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5403
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5404 #ifdef ENABLE_LOG
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5405 fprintf(log_fd, "NFA_START_PATTERN matches:\n");
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5406 log_subsexpr(m);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5407 #endif
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5408 /* Copy submatch info from the recursive call */
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5409 copy_sub_off(&t->subs.norm, &m->norm);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5410 #ifdef FEAT_SYN_HL
4768
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
5411 if (nfa_has_zsubexpr)
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
5412 copy_sub_off(&t->subs.synt, &m->synt);
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5413 #endif
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5414 /* Now we need to skip over the matched text and then
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5415 * continue with what follows. */
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5416 if (REG_MULTI)
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5417 /* TODO: multi-line match */
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5418 bytelen = m->norm.list.multi[0].end.col
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5419 - (int)(reginput - regline);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5420 else
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5421 bytelen = (int)(m->norm.list.line[0].end - reginput);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5422
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5423 #ifdef ENABLE_LOG
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5424 fprintf(log_fd, "NFA_START_PATTERN length: %d\n", bytelen);
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5425 #endif
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5426 if (bytelen == 0)
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5427 {
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5428 /* empty match, output of corresponding
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5429 * NFA_END_PATTERN/NFA_SKIP to be used at current
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5430 * position */
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5431 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5432 add_state = t->state->out1->out->out;
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5433 }
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5434 else if (bytelen <= clen)
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5435 {
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5436 /* match current character, output of corresponding
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5437 * NFA_END_PATTERN to be used at next position. */
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5438 add_state = t->state->out1->out->out;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5439 add_off = clen;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5440 }
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5441 else
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5442 {
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5443 /* skip over the matched characters, set character
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5444 * count in NFA_SKIP */
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5445 add_state = t->state->out1->out;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5446 add_off = bytelen;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5447 add_count = bytelen - clen;
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5448 }
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5449 }
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5450 break;
4787
7fde662e1db2 updated for version 7.3.1140
Bram Moolenaar <bram@vim.org>
parents: 4785
diff changeset
5451 }
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
5452
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5453 case NFA_BOL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5454 if (reginput == regline)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5455 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5456 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5457 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5458 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5459 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5460
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5461 case NFA_EOL:
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5462 if (curc == NUL)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5463 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5464 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5465 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5466 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5467 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5468
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5469 case NFA_BOW:
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5470 result = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5471
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5472 if (curc == NUL)
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5473 result = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5474 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5475 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5476 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5477 int this_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5478
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5479 /* 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
5480 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
5481 if (this_class <= 1)
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5482 result = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5483 else if (reg_prev_class() == this_class)
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5484 result = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5485 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5486 #endif
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5487 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
5488 || (reginput > regline
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
5489 && vim_iswordc_buf(reginput[-1], reg_buf)))
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5490 result = FALSE;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5491 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5492 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5493 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5494 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5495 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5496 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5497
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5498 case NFA_EOW:
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5499 result = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5500 if (reginput == regline)
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5501 result = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5502 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5503 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5504 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5505 int this_class, prev_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5506
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5507 /* 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
5508 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
5509 prev_class = reg_prev_class();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5510 if (this_class == prev_class
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5511 || prev_class == 0 || prev_class == 1)
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5512 result = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5513 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5514 #endif
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
5515 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
5516 || (reginput[0] != NUL
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5517 && vim_iswordc_buf(curc, reg_buf)))
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5518 result = FALSE;
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
5519 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5520 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5521 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5522 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5523 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5524 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5525
4671
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5526 case NFA_BOF:
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5527 if (reglnum == 0 && reginput == regline
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5528 && (!REG_MULTI || reg_firstlnum == 1))
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5529 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5530 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5531 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5532 }
4671
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5533 break;
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5534
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5535 case NFA_EOF:
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5536 if (reglnum == reg_maxline && curc == NUL)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5537 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5538 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5539 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5540 }
4671
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5541 break;
b3c59716e700 updated for version 7.3.1083
Bram Moolenaar <bram@vim.org>
parents: 4669
diff changeset
5542
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
5543 #ifdef FEAT_MBYTE
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5544 case NFA_COMPOSING:
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
5545 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5546 int mc = curc;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
5547 int len = 0;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
5548 nfa_state_T *end;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
5549 nfa_state_T *sta;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5550 int cchars[MAX_MCO];
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5551 int ccount = 0;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5552 int j;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5553
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5554 sta = t->state->out;
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
5555 len = 0;
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5556 if (utf_iscomposing(sta->c))
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5557 {
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5558 /* Only match composing character(s), ignore base
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5559 * character. Used for ".{composing}" and "{composing}"
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5560 * (no preceding character). */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5561 len += mb_char2len(mc);
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5562 }
4551
f0c37f5cf4ea updated for version 7.3.1023
Bram Moolenaar <bram@vim.org>
parents: 4549
diff changeset
5563 if (ireg_icombine && len == 0)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5564 {
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5565 /* If \Z was present, then ignore composing characters.
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
5566 * When ignoring the base character this always matches. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5567 if (len == 0 && sta->c != curc)
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
5568 result = FAIL;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5569 else
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5570 result = OK;
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
5571 while (sta->c != NFA_END_COMPOSING)
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
5572 sta = sta->out;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5573 }
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5574
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5575 /* Check base character matches first, unless ignored. */
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5576 else if (len > 0 || mc == sta->c)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5577 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5578 if (len == 0)
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
5579 {
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
5580 len += mb_char2len(mc);
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
5581 sta = sta->out;
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
5582 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5583
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5584 /* 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
5585 * Get them into cchars[] first. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5586 while (len < clen)
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5587 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5588 mc = mb_ptr2char(reginput + len);
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5589 cchars[ccount++] = mc;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5590 len += mb_char2len(mc);
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5591 if (ccount == MAX_MCO)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5592 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5593 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5594
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5595 /* 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
5596 * 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
5597 * composing chars are matched. */
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5598 result = OK;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5599 while (sta->c != NFA_END_COMPOSING)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5600 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5601 for (j = 0; j < ccount; ++j)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5602 if (cchars[j] == sta->c)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5603 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5604 if (j == ccount)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5605 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5606 result = FAIL;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5607 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5608 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5609 sta = sta->out;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5610 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5611 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5612 else
4525
36ddcf4cecbc updated for version 7.3.1010
Bram Moolenaar <bram@vim.org>
parents: 4517
diff changeset
5613 result = FAIL;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
5614
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
5615 end = t->state->out1; /* NFA_END_COMPOSING */
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5616 ADD_STATE_IF_MATCH(end);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5617 break;
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
5618 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
5619 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5620
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5621 case NFA_NEWL:
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5622 if (curc == NUL && !reg_line_lbr && REG_MULTI
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5623 && reglnum <= reg_maxline)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5624 {
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5625 go_to_nextline = TRUE;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5626 /* 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
5627 * at the start of the next line. */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5628 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5629 add_off = -1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5630 }
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5631 else if (curc == '\n' && reg_line_lbr)
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5632 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5633 /* 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
5634 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5635 add_off = 1;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
5636 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5637 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5638
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5639 case NFA_START_COLL:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5640 case NFA_START_NEG_COLL:
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5641 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5642 /* What follows is a list of characters, until NFA_END_COLL.
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5643 * One of them must match or none of them must match. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5644 nfa_state_T *state;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5645 int result_if_matched;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5646 int c1, c2;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5647
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5648 /* Never match EOL. If it's part of the collection it is added
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5649 * as a separate state with an OR. */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5650 if (curc == NUL)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5651 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5652
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5653 state = t->state->out;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5654 result_if_matched = (t->state->c == NFA_START_COLL);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5655 for (;;)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5656 {
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5657 if (state->c == NFA_END_COLL)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5658 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5659 result = !result_if_matched;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5660 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5661 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5662 if (state->c == NFA_RANGE_MIN)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5663 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5664 c1 = state->val;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5665 state = state->out; /* advance to NFA_RANGE_MAX */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5666 c2 = state->val;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5667 #ifdef ENABLE_LOG
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5668 fprintf(log_fd, "NFA_RANGE_MIN curc=%d c1=%d c2=%d\n",
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5669 curc, c1, c2);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5670 #endif
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5671 if (curc >= c1 && curc <= c2)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5672 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5673 result = result_if_matched;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5674 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5675 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5676 if (ireg_ic)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5677 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5678 int curc_low = MB_TOLOWER(curc);
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5679 int done = FALSE;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5680
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5681 for ( ; c1 <= c2; ++c1)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5682 if (MB_TOLOWER(c1) == curc_low)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5683 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5684 result = result_if_matched;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5685 done = TRUE;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5686 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5687 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5688 if (done)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5689 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5690 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5691 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5692 else if (state->c < 0 ? check_char_class(state->c, curc)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5693 : (curc == state->c
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5694 || (ireg_ic && MB_TOLOWER(curc)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5695 == MB_TOLOWER(state->c))))
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5696 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5697 result = result_if_matched;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5698 break;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5699 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5700 state = state->out;
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5701 }
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5702 if (result)
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5703 {
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5704 /* next state is in out of the NFA_END_COLL, out1 of
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5705 * START points to the END state */
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5706 add_state = t->state->out1->out;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5707 add_off = clen;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5708 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5709 break;
4781
c02c7df9bdc9 updated for version 7.3.1137
Bram Moolenaar <bram@vim.org>
parents: 4772
diff changeset
5710 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5711
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5712 case NFA_ANY:
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
5713 /* 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
5714 if (curc > 0)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5715 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5716 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5717 add_off = clen;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5718 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5719 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5720
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5721 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5722 * 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
5723 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5724 case NFA_IDENT: /* \i */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5725 result = vim_isIDc(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5726 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5727 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5728
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5729 case NFA_SIDENT: /* \I */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5730 result = !VIM_ISDIGIT(curc) && vim_isIDc(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5731 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5732 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5733
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5734 case NFA_KWORD: /* \k */
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
5735 result = vim_iswordp_buf(reginput, reg_buf);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5736 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5737 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5738
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5739 case NFA_SKWORD: /* \K */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5740 result = !VIM_ISDIGIT(curc)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5741 && vim_iswordp_buf(reginput, reg_buf);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5742 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5743 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5744
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5745 case NFA_FNAME: /* \f */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5746 result = vim_isfilec(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5747 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5748 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5749
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5750 case NFA_SFNAME: /* \F */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5751 result = !VIM_ISDIGIT(curc) && vim_isfilec(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5752 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5753 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5754
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5755 case NFA_PRINT: /* \p */
5221
9982ec574beb updated for version 7.4a.036
Bram Moolenaar <bram@vim.org>
parents: 5212
diff changeset
5756 result = vim_isprintc(PTR2CHAR(reginput));
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5757 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5758 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5759
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5760 case NFA_SPRINT: /* \P */
5221
9982ec574beb updated for version 7.4a.036
Bram Moolenaar <bram@vim.org>
parents: 5212
diff changeset
5761 result = !VIM_ISDIGIT(curc) && vim_isprintc(PTR2CHAR(reginput));
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5762 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5763 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5764
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5765 case NFA_WHITE: /* \s */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5766 result = vim_iswhite(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5767 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5768 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5769
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5770 case NFA_NWHITE: /* \S */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5771 result = curc != NUL && !vim_iswhite(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5772 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5773 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5774
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5775 case NFA_DIGIT: /* \d */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5776 result = ri_digit(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5777 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5778 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5779
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5780 case NFA_NDIGIT: /* \D */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5781 result = curc != NUL && !ri_digit(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5782 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5783 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5784
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5785 case NFA_HEX: /* \x */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5786 result = ri_hex(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5787 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5788 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5789
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5790 case NFA_NHEX: /* \X */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5791 result = curc != NUL && !ri_hex(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5792 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5793 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5794
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5795 case NFA_OCTAL: /* \o */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5796 result = ri_octal(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5797 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5798 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5799
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5800 case NFA_NOCTAL: /* \O */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5801 result = curc != NUL && !ri_octal(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5802 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5803 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5804
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5805 case NFA_WORD: /* \w */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5806 result = ri_word(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5807 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5808 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5809
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5810 case NFA_NWORD: /* \W */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5811 result = curc != NUL && !ri_word(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5812 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5813 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5814
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5815 case NFA_HEAD: /* \h */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5816 result = ri_head(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5817 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5818 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5819
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5820 case NFA_NHEAD: /* \H */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5821 result = curc != NUL && !ri_head(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5822 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5823 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5824
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5825 case NFA_ALPHA: /* \a */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5826 result = ri_alpha(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5827 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5828 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5829
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5830 case NFA_NALPHA: /* \A */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5831 result = curc != NUL && !ri_alpha(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5832 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5833 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5834
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5835 case NFA_LOWER: /* \l */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5836 result = ri_lower(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5837 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5838 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5839
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5840 case NFA_NLOWER: /* \L */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5841 result = curc != NUL && !ri_lower(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5842 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5843 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5844
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5845 case NFA_UPPER: /* \u */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5846 result = ri_upper(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5847 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5848 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5849
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5850 case NFA_NUPPER: /* \U */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
5851 result = curc != NUL && !ri_upper(curc);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
5852 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5853 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5854
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5855 case NFA_BACKREF1:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5856 case NFA_BACKREF2:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5857 case NFA_BACKREF3:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5858 case NFA_BACKREF4:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5859 case NFA_BACKREF5:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5860 case NFA_BACKREF6:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5861 case NFA_BACKREF7:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5862 case NFA_BACKREF8:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5863 case NFA_BACKREF9:
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5864 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5865 case NFA_ZREF1:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5866 case NFA_ZREF2:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5867 case NFA_ZREF3:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5868 case NFA_ZREF4:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5869 case NFA_ZREF5:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5870 case NFA_ZREF6:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5871 case NFA_ZREF7:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5872 case NFA_ZREF8:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5873 case NFA_ZREF9:
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5874 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5875 /* \1 .. \9 \z1 .. \z9 */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5876 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5877 int subidx;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5878 int bytelen;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5879
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5880 if (t->state->c <= NFA_BACKREF9)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5881 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5882 subidx = t->state->c - NFA_BACKREF1 + 1;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5883 result = match_backref(&t->subs.norm, subidx, &bytelen);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5884 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5885 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5886 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5887 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5888 subidx = t->state->c - NFA_ZREF1 + 1;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5889 result = match_zref(subidx, &bytelen);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5890 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5891 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
5892
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5893 if (result)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5894 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5895 if (bytelen == 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5896 {
4692
08fbb1ce1bc5 updated for version 7.3.1093
Bram Moolenaar <bram@vim.org>
parents: 4690
diff changeset
5897 /* 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
5898 * used next */
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5899 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5900 add_state = t->state->out->out;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5901 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5902 else if (bytelen <= clen)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5903 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5904 /* match current character, jump ahead to out of
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5905 * NFA_SKIP */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5906 add_state = t->state->out->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5907 add_off = clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5908 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5909 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5910 {
4728
43de4ebbe7ad updated for version 7.3.1111
Bram Moolenaar <bram@vim.org>
parents: 4726
diff changeset
5911 /* skip over the matched characters, set character
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5912 * count in NFA_SKIP */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5913 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5914 add_off = bytelen;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5915 add_count = bytelen - clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5916 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5917 }
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
5918 break;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5919 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5920 case NFA_SKIP:
4748
4b9503f0c7d3 updated for version 7.3.1121
Bram Moolenaar <bram@vim.org>
parents: 4746
diff changeset
5921 /* character of previous matching \1 .. \9 or \@> */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5922 if (t->count - clen <= 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5923 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5924 /* end of match, go to what follows */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5925 add_state = t->state->out;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5926 add_off = clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5927 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5928 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5929 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5930 /* add state again with decremented count */
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5931 add_state = t->state;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5932 add_off = 0;
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
5933 add_count = t->count - clen;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5934 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
5935 break;
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
5936
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5937 case NFA_LNUM:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5938 case NFA_LNUM_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5939 case NFA_LNUM_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5940 result = (REG_MULTI &&
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5941 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
5942 (long_u)(reglnum + reg_firstlnum)));
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5943 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5944 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5945 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5946 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5947 }
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5948 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5949
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5950 case NFA_COL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5951 case NFA_COL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5952 case NFA_COL_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5953 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
5954 (long_u)(reginput - regline) + 1);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5955 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5956 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5957 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5958 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5959 }
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5960 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5961
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5962 case NFA_VCOL:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5963 case NFA_VCOL_GT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5964 case NFA_VCOL_LT:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5965 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
5966 (long_u)win_linetabsize(
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5967 reg_win == NULL ? curwin : reg_win,
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5968 regline, (colnr_T)(reginput - regline)) + 1);
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5969 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5970 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5971 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5972 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5973 }
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5974 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
5975
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5976 case NFA_MARK:
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5977 case NFA_MARK_GT:
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5978 case NFA_MARK_LT:
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5979 {
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5980 pos_T *pos = getmark_buf(reg_buf, t->state->val, FALSE);
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5981
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5982 /* Compare the mark position to the match position. */
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5983 result = (pos != NULL /* mark doesn't exist */
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5984 && pos->lnum > 0 /* mark isn't set in reg_buf */
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5985 && (pos->lnum == reglnum + reg_firstlnum
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5986 ? (pos->col == (colnr_T)(reginput - regline)
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5987 ? t->state->c == NFA_MARK
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5988 : (pos->col < (colnr_T)(reginput - regline)
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5989 ? t->state->c == NFA_MARK_GT
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5990 : t->state->c == NFA_MARK_LT))
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5991 : (pos->lnum < reglnum + reg_firstlnum
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5992 ? t->state->c == NFA_MARK_GT
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5993 : t->state->c == NFA_MARK_LT)));
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5994 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5995 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5996 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5997 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
5998 }
4732
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
5999 break;
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
6000 }
0798b096bab3 updated for version 7.3.1113
Bram Moolenaar <bram@vim.org>
parents: 4730
diff changeset
6001
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6002 case NFA_CURSOR:
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6003 result = (reg_win != NULL
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6004 && (reglnum + reg_firstlnum == reg_win->w_cursor.lnum)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6005 && ((colnr_T)(reginput - regline)
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6006 == reg_win->w_cursor.col));
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6007 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6008 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6009 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6010 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6011 }
4583
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6012 break;
321cfbef9431 updated for version 7.3.1039
Bram Moolenaar <bram@vim.org>
parents: 4579
diff changeset
6013
4756
96f3348f9f11 updated for version 7.3.1125
Bram Moolenaar <bram@vim.org>
parents: 4750
diff changeset
6014 case NFA_VISUAL:
4738
66a9e8fa6f45 updated for version 7.3.1116
Bram Moolenaar <bram@vim.org>
parents: 4734
diff changeset
6015 #ifdef FEAT_VISUAL
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4728
diff changeset
6016 result = reg_match_visual();
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4728
diff changeset
6017 if (result)
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6018 {
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6019 add_here = TRUE;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6020 add_state = t->state->out;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6021 }
4756
96f3348f9f11 updated for version 7.3.1125
Bram Moolenaar <bram@vim.org>
parents: 4750
diff changeset
6022 #endif
4730
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4728
diff changeset
6023 break;
749e2b2755d5 updated for version 7.3.1112
Bram Moolenaar <bram@vim.org>
parents: 4728
diff changeset
6024
5251
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6025 case NFA_MOPEN1:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6026 case NFA_MOPEN2:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6027 case NFA_MOPEN3:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6028 case NFA_MOPEN4:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6029 case NFA_MOPEN5:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6030 case NFA_MOPEN6:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6031 case NFA_MOPEN7:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6032 case NFA_MOPEN8:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6033 case NFA_MOPEN9:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6034 #ifdef FEAT_SYN_HL
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6035 case NFA_ZOPEN:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6036 case NFA_ZOPEN1:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6037 case NFA_ZOPEN2:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6038 case NFA_ZOPEN3:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6039 case NFA_ZOPEN4:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6040 case NFA_ZOPEN5:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6041 case NFA_ZOPEN6:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6042 case NFA_ZOPEN7:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6043 case NFA_ZOPEN8:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6044 case NFA_ZOPEN9:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6045 #endif
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6046 case NFA_NOPEN:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6047 case NFA_ZSTART:
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6048 /* These states are only added to be able to bail out when
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6049 * they are added again, nothing is to be done. */
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6050 break;
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6051
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6052 default: /* regular character */
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6053 {
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6054 int c = t->state->c;
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6055
5251
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6056 #ifdef DEBUG
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
6057 if (c < 0)
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6058 EMSGN("INTERNAL: Negative state char: %ld", c);
5251
2e63b6c763f7 updated for version 7.4b.002
Bram Moolenaar <bram@vim.org>
parents: 5227
diff changeset
6059 #endif
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6060 result = (c == curc);
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6061
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6062 if (!result && ireg_ic)
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6063 result = MB_TOLOWER(c) == MB_TOLOWER(curc);
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
6064 #ifdef FEAT_MBYTE
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
6065 /* 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
6066 * 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
6067 * character uses NFA_COMPOSING above. */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
6068 if (result && enc_utf8 && !ireg_icombine
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
6069 && clen != utf_char2len(curc))
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
6070 result = FALSE;
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
6071 #endif
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
6072 ADD_STATE_IF_MATCH(t->state);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6073 break;
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
6074 }
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6075
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6076 } /* switch (t->state->c) */
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6077
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6078 if (add_state != NULL)
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6079 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6080 nfa_pim_T *pim;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6081
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6082 if (t->pim.result == NFA_PIM_UNUSED)
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6083 pim = NULL;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6084 else
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6085 pim = &t->pim;
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6086
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6087 /* Handle the postponed invisible match if the match might end
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6088 * without advancing and before the end of the line. */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6089 if (pim != NULL && (clen == 0 || match_follows(add_state, 0)))
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6090 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6091 if (pim->result == NFA_PIM_TODO)
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6092 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6093 #ifdef ENABLE_LOG
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6094 fprintf(log_fd, "\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6095 fprintf(log_fd, "==================================\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6096 fprintf(log_fd, "Postponed recursive nfa_regmatch()\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6097 fprintf(log_fd, "\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6098 #endif
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6099 result = recursive_regmatch(pim->state, pim,
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6100 prog, submatch, m, &listids);
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6101 pim->result = result ? NFA_PIM_MATCH : NFA_PIM_NOMATCH;
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
6102 /* for \@! and \@<! it is a match when the result is
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
6103 * FALSE */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6104 if (result != (pim->state->c == NFA_START_INVISIBLE_NEG
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6105 || pim->state->c == NFA_START_INVISIBLE_NEG_FIRST
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6106 || pim->state->c
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6107 == NFA_START_INVISIBLE_BEFORE_NEG
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6108 || pim->state->c
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6109 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST))
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6110 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6111 /* Copy submatch info from the recursive call */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6112 copy_sub_off(&pim->subs.norm, &m->norm);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6113 #ifdef FEAT_SYN_HL
4768
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
6114 if (nfa_has_zsubexpr)
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6115 copy_sub_off(&pim->subs.synt, &m->synt);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6116 #endif
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6117 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6118 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6119 else
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6120 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6121 result = (pim->result == NFA_PIM_MATCH);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6122 #ifdef ENABLE_LOG
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6123 fprintf(log_fd, "\n");
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6124 fprintf(log_fd, "Using previous recursive nfa_regmatch() result, result == %d\n", pim->result);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6125 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
6126 fprintf(log_fd, "\n");
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6127 #endif
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6128 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6129
4785
3b5a023a4543 updated for version 7.3.1139
Bram Moolenaar <bram@vim.org>
parents: 4783
diff changeset
6130 /* for \@! and \@<! it is a match when result is FALSE */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6131 if (result != (pim->state->c == NFA_START_INVISIBLE_NEG
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6132 || pim->state->c == NFA_START_INVISIBLE_NEG_FIRST
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6133 || pim->state->c
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6134 == NFA_START_INVISIBLE_BEFORE_NEG
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6135 || pim->state->c
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6136 == NFA_START_INVISIBLE_BEFORE_NEG_FIRST))
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6137 {
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6138 /* Copy submatch info from the recursive call */
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6139 copy_sub_off(&t->subs.norm, &pim->subs.norm);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6140 #ifdef FEAT_SYN_HL
4768
82e6588762e4 updated for version 7.3.1131
Bram Moolenaar <bram@vim.org>
parents: 4762
diff changeset
6141 if (nfa_has_zsubexpr)
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6142 copy_sub_off(&t->subs.synt, &pim->subs.synt);
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6143 #endif
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6144 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6145 else
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6146 /* 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
6147 continue;
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6148
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6149 /* Postponed invisible match was handled, don't add it to
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6150 * following states. */
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6151 pim = NULL;
4726
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6152 }
3849c811cc0b updated for version 7.3.1110
Bram Moolenaar <bram@vim.org>
parents: 4720
diff changeset
6153
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6154 if (add_here)
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6155 addstate_here(thislist, add_state, &t->subs, pim, &listidx);
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6156 else
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6157 {
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6158 addstate(nextlist, add_state, &t->subs, pim, add_off);
4799
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6159 if (add_count > 0)
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6160 nextlist->t[nextlist->n - 1].count = add_count;
e3f9e33fb28c updated for version 7.3.1146
Bram Moolenaar <bram@vim.org>
parents: 4797
diff changeset
6161 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6162 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6163
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6164 } /* for (thislist = thislist; thislist->state; thislist++) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6165
4557
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
6166 /* 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
6167 * start state to the list of states.
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
6168 * 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
6169 * matters!
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
6170 * 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
6171 * 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
6172 * 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
6173 * 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
6174 if (nfa_match == FALSE
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6175 && ((toplevel
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
6176 && reglnum == 0
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
6177 && clen != 0
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
6178 && (ireg_maxcol == 0
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
6179 || (colnr_T)(reginput - regline) < ireg_maxcol))
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
6180 || (nfa_endp != NULL
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
6181 && (REG_MULTI
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
6182 ? (reglnum < nfa_endp->se_u.pos.lnum
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
6183 || (reglnum == nfa_endp->se_u.pos.lnum
4682
2f51ee8825db updated for version 7.3.1088
Bram Moolenaar <bram@vim.org>
parents: 4679
diff changeset
6184 && (int)(reginput - regline)
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
6185 < nfa_endp->se_u.pos.col))
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
6186 : reginput < nfa_endp->se_u.ptr))))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6187 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6188 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6189 fprintf(log_fd, "(---) STARTSTATE\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6190 #endif
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6191 /* Inline optimized code for addstate() if we know the state is
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6192 * the first MOPEN. */
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6193 if (toplevel)
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6194 {
4801
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6195 int add = TRUE;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6196 int c;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6197
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6198 if (prog->regstart != NUL && clen != 0)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6199 {
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6200 if (nextlist->n == 0)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6201 {
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6202 colnr_T col = (colnr_T)(reginput - regline) + clen;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6203
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6204 /* Nextlist is empty, we can skip ahead to the
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6205 * character that must appear at the start. */
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6206 if (skip_to_start(prog->regstart, &col) == FAIL)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6207 break;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6208 #ifdef ENABLE_LOG
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6209 fprintf(log_fd, " Skipping ahead %d bytes to regstart\n",
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6210 col - ((colnr_T)(reginput - regline) + clen));
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6211 #endif
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6212 reginput = regline + col - clen;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6213 }
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6214 else
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6215 {
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6216 /* Checking if the required start character matches is
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6217 * cheaper than adding a state that won't match. */
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6218 c = PTR2CHAR(reginput + clen);
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6219 if (c != prog->regstart && (!ireg_ic || MB_TOLOWER(c)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6220 != MB_TOLOWER(prog->regstart)))
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6221 {
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6222 #ifdef ENABLE_LOG
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6223 fprintf(log_fd, " Skipping start state, regstart does not match\n");
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6224 #endif
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6225 add = FALSE;
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6226 }
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6227 }
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6228 }
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6229
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6230 if (add)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6231 {
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6232 if (REG_MULTI)
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6233 m->norm.list.multi[0].start.col =
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6234 (colnr_T)(reginput - regline) + clen;
4801
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6235 else
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6236 m->norm.list.line[0].start = reginput + clen;
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6237 addstate(nextlist, start->out, m, NULL, clen);
4801
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6238 }
4797
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6239 }
a30e3762957d updated for version 7.3.1145
Bram Moolenaar <bram@vim.org>
parents: 4787
diff changeset
6240 else
4813
bc3f4804cf47 updated for version 7.3.1153
Bram Moolenaar <bram@vim.org>
parents: 4811
diff changeset
6241 addstate(nextlist, start, m, NULL, clen);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6242 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6243
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6244 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6245 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
6246 {
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
6247 int i;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
6248
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
6249 for (i = 0; i < thislist->n; i++)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
6250 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
6251 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6252 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6253 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6254
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6255 nextchar:
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
6256 /* 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
6257 * finish. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
6258 if (clen != 0)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
6259 reginput += clen;
4694
efc4fb311d5d updated for version 7.3.1094
Bram Moolenaar <bram@vim.org>
parents: 4692
diff changeset
6260 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
6261 && reglnum < nfa_endp->se_u.pos.lnum))
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
6262 reg_nextline();
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
6263 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
6264 break;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
6265 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6266
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6267 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6268 if (log_fd != stderr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6269 fclose(log_fd);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6270 log_fd = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6271 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6272
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6273 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6274 /* Free memory */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6275 vim_free(list[0].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6276 vim_free(list[1].t);
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
6277 vim_free(listids);
4783
47222d8b1e94 updated for version 7.3.1138
Bram Moolenaar <bram@vim.org>
parents: 4781
diff changeset
6278 #undef ADD_STATE_IF_MATCH
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
6279 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6280 fclose(debug);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6281 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6282
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
6283 return nfa_match;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6284 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6285
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6286 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6287 * Try match of "prog" with at regline["col"].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6288 * 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
6289 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6290 static long
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6291 nfa_regtry(prog, col)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6292 nfa_regprog_T *prog;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6293 colnr_T col;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6294 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6295 int i;
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6296 regsubs_T subs, m;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6297 nfa_state_T *start = prog->start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6298 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6299 FILE *f;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6300 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6301
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6302 reginput = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6303
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6304 #ifdef ENABLE_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
6305 f = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6306 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6307 {
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
6308 fprintf(f, "\n\n\t=======================================================\n");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6309 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6310 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6311 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6312 fprintf(f, "\tInput text is \"%s\" \n", reginput);
4750
7793e737ec87 updated for version 7.3.1122
Bram Moolenaar <bram@vim.org>
parents: 4748
diff changeset
6313 fprintf(f, "\t=======================================================\n\n");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
6314 nfa_print_state(f, start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6315 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6316 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6317 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6318 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6319 EMSG(_("Could not open temporary log file for writing "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6320 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6321
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6322 clear_sub(&subs.norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6323 clear_sub(&m.norm);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6324 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6325 clear_sub(&subs.synt);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6326 clear_sub(&m.synt);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6327 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6328
4712
832bf8136d86 updated for version 7.3.1103
Bram Moolenaar <bram@vim.org>
parents: 4696
diff changeset
6329 if (nfa_regmatch(prog, start, &subs, &m) == FALSE)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6330 return 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6331
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6332 cleanup_subexpr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6333 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6334 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6335 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
6336 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6337 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
6338 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
6339 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6340
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6341 if (reg_startpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6342 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6343 reg_startpos[0].lnum = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6344 reg_startpos[0].col = col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6345 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6346 if (reg_endpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6347 {
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
6348 /* 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
6349 reg_endpos[0].lnum = reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6350 reg_endpos[0].col = (int)(reginput - regline);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6351 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6352 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6353 /* Use line number of "\ze". */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6354 reglnum = reg_endpos[0].lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6355 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6356 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6357 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6358 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
6359 {
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6360 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
6361 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
6362 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6363
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6364 if (reg_startp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6365 reg_startp[0] = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6366 if (reg_endp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6367 reg_endp[0] = reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6368 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6369
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6370 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6371 /* 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
6372 unref_extmatch(re_extmatch_out);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6373 re_extmatch_out = NULL;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6374
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6375 if (prog->reghasz == REX_SET)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6376 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6377 cleanup_zsubexpr();
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6378 re_extmatch_out = make_extmatch();
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6379 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
6380 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6381 if (REG_MULTI)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6382 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6383 struct multipos *mpos = &subs.synt.list.multi[i];
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6384
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6385 /* Only accept single line matches. */
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6386 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
6387 re_extmatch_out->matches[i] =
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6388 vim_strnsave(reg_getline(mpos->start.lnum)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6389 + mpos->start.col,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6390 mpos->end.col - mpos->start.col);
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6391 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6392 else
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6393 {
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6394 struct linepos *lpos = &subs.synt.list.line[i];
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6395
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6396 if (lpos->start != NULL && lpos->end != NULL)
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6397 re_extmatch_out->matches[i] =
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6398 vim_strnsave(lpos->start,
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6399 (int)(lpos->end - lpos->start));
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6400 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6401 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6402 }
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6403 #endif
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6404
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6405 return 1 + reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6406 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6407
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6408 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6409 * 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
6410 * lines ("line" is NULL, use reg_getline()).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6411 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6412 * 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
6413 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6414 static long
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6415 nfa_regexec_both(line, startcol)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6416 char_u *line;
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6417 colnr_T startcol; /* column to start looking for match */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6418 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6419 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6420 long retval = 0L;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6421 int i;
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6422 colnr_T col = startcol;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6423
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6424 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6425 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6426 prog = (nfa_regprog_T *)reg_mmatch->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6427 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
6428 reg_startpos = reg_mmatch->startpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6429 reg_endpos = reg_mmatch->endpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6430 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6431 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6432 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6433 prog = (nfa_regprog_T *)reg_match->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6434 reg_startp = reg_match->startp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6435 reg_endp = reg_match->endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6436 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6437
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6438 /* Be paranoid... */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6439 if (prog == NULL || line == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6440 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6441 EMSG(_(e_null));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6442 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6443 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6445 /* 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
6446 if (prog->regflags & RF_ICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6447 ireg_ic = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6448 else if (prog->regflags & RF_NOICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6449 ireg_ic = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6450
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6451 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6452 /* If pattern contains "\Z" overrule value of ireg_icombine */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6453 if (prog->regflags & RF_ICOMBINE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6454 ireg_icombine = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6455 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6456
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6457 regline = line;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6458 reglnum = 0; /* relative to line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6459
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
6460 nfa_has_zend = prog->has_zend;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
6461 nfa_has_backref = prog->has_backref;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
6462 nfa_nsubexpr = prog->nsubexp;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
6463 nfa_listid = 1;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
6464 nfa_alt_listid = 2;
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6465 #ifdef DEBUG
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6466 nfa_regengine.expr = prog->pattern;
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6467 #endif
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
6468
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6469 if (prog->reganch && col > 0)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6470 return 0L;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6471
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6472 need_clear_subexpr = TRUE;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6473 #ifdef FEAT_SYN_HL
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6474 /* Clear the external match subpointers if necessary. */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6475 if (prog->reghasz == REX_SET)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6476 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6477 nfa_has_zsubexpr = TRUE;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6478 need_clear_zsubexpr = TRUE;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6479 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6480 else
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6481 nfa_has_zsubexpr = FALSE;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6482 #endif
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6483
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6484 if (prog->regstart != NUL)
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6485 {
4801
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6486 /* Skip ahead until a character we know the match must start with.
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6487 * When there is none there is no match. */
3cd3cc1e9119 updated for version 7.3.1147
Bram Moolenaar <bram@vim.org>
parents: 4799
diff changeset
6488 if (skip_to_start(prog->regstart, &col) == FAIL)
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6489 return 0L;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6490
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6491 /* If match_text is set it contains the full text that must match.
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6492 * Nothing else to try. Doesn't handle combining chars well. */
4811
9909e44879b9 updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents: 4809
diff changeset
6493 if (prog->match_text != NULL
9909e44879b9 updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents: 4809
diff changeset
6494 #ifdef FEAT_MBYTE
9909e44879b9 updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents: 4809
diff changeset
6495 && !ireg_icombine
9909e44879b9 updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents: 4809
diff changeset
6496 #endif
9909e44879b9 updated for version 7.3.1152
Bram Moolenaar <bram@vim.org>
parents: 4809
diff changeset
6497 )
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6498 return find_match_text(col, prog->regstart, prog->match_text);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6499 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6500
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6501 /* If the start column is past the maximum column: no need to try. */
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6502 if (ireg_maxcol > 0 && col >= ireg_maxcol)
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6503 goto theend;
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6504
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6505 nstate = prog->nstate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6506 for (i = 0; i < nstate; ++i)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6507 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6508 prog->state[i].id = i;
4718
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
6509 prog->state[i].lastlist[0] = 0;
ec72bb4a0fc2 updated for version 7.3.1106
Bram Moolenaar <bram@vim.org>
parents: 4716
diff changeset
6510 prog->state[i].lastlist[1] = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6511 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6512
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6513 retval = nfa_regtry(prog, col);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6514
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6515 #ifdef DEBUG
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6516 nfa_regengine.expr = NULL;
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6517 #endif
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6518
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6519 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6520 return retval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6521 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6522
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6523 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6524 * 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
6525 * 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
6526 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6527 static regprog_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6528 nfa_regcomp(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6529 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6530 int re_flags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6531 {
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
6532 nfa_regprog_T *prog = NULL;
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
6533 size_t prog_size;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6534 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6535
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6536 if (expr == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6537 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6538
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6539 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6540 nfa_regengine.expr = expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6541 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6542
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6543 init_class_tab();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6544
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6545 if (nfa_regcomp_start(expr, re_flags) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6546 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6547
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6548 /* 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
6549 * (and count its size). */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6550 postfix = re2post();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6551 if (postfix == NULL)
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
6552 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
6553 /* TODO: only give this error for debugging? */
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
6554 if (post_ptr >= post_end)
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
6555 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
6556 goto fail; /* Cascaded (syntax?) error */
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
6557 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6558
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6559 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6560 * 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
6561 * 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
6562 * 2. second to emit code
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6563 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6564 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6565 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
6566 FILE *f = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6567
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6568 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6569 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6570 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
6571 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6572 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6573 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6574 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6575
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6576 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6577 * PASS 1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6578 * 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
6579 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6580 post2nfa(postfix, post_ptr, TRUE);
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
6581
4837
05b8436873d4 updated for version 7.3.1165
Bram Moolenaar <bram@vim.org>
parents: 4821
diff changeset
6582 /* allocate the regprog with space for the compiled regexp */
05b8436873d4 updated for version 7.3.1165
Bram Moolenaar <bram@vim.org>
parents: 4821
diff changeset
6583 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * (nstate - 1);
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
6584 prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
6585 if (prog == NULL)
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
6586 goto fail;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6587 state_ptr = prog->state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6588
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6589 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6590 * PASS 2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6591 * Build the NFA
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6592 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6593 prog->start = post2nfa(postfix, post_ptr, FALSE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6594 if (prog->start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6595 goto fail;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6596
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6597 prog->regflags = regflags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6598 prog->engine = &nfa_regengine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6599 prog->nstate = nstate;
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
6600 prog->has_zend = nfa_has_zend;
4647
857f6c53f117 updated for version 7.3.1071
Bram Moolenaar <bram@vim.org>
parents: 4615
diff changeset
6601 prog->has_backref = nfa_has_backref;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
6602 prog->nsubexp = regnpar;
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6603
4845
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6604 nfa_postprocess(prog);
a83fb2bd8c8e updated for version 7.3.1169
Bram Moolenaar <bram@vim.org>
parents: 4837
diff changeset
6605
4772
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6606 prog->reganch = nfa_get_reganch(prog->start, 0);
03375ccf28a2 updated for version 7.3.1133
Bram Moolenaar <bram@vim.org>
parents: 4770
diff changeset
6607 prog->regstart = nfa_get_regstart(prog->start, 0);
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6608 prog->match_text = nfa_get_match_text(prog->start);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6609
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6610 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6611 nfa_postfix_dump(expr, OK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6612 nfa_dump(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6613 #endif
4686
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6614 #ifdef FEAT_SYN_HL
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6615 /* 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
6616 prog->reghasz = re_has_z;
8db697ae406a updated for version 7.3.1090
Bram Moolenaar <bram@vim.org>
parents: 4682
diff changeset
6617 #endif
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6618 #ifdef DEBUG
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6619 prog->pattern = vim_strsave(expr);
4690
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6620 nfa_regengine.expr = NULL;
9d97a0c045ef updated for version 7.3.1092
Bram Moolenaar <bram@vim.org>
parents: 4688
diff changeset
6621 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6622
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6623 out:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6624 vim_free(post_start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6625 post_start = post_ptr = post_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6626 state_ptr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6627 return (regprog_T *)prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6628
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6629 fail:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6630 vim_free(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6631 prog = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6632 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6633 nfa_postfix_dump(expr, FAIL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6634 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6635 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6636 nfa_regengine.expr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6637 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6638 goto out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6639 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6640
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6641 /*
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6642 * Free a compiled regexp program, returned by nfa_regcomp().
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6643 */
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6644 static void
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6645 nfa_regfree(prog)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6646 regprog_T *prog;
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6647 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6648 if (prog != NULL)
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6649 {
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6650 vim_free(((nfa_regprog_T *)prog)->match_text);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6651 #ifdef DEBUG
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6652 vim_free(((nfa_regprog_T *)prog)->pattern);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6653 #endif
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6654 vim_free(prog);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6655 }
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4801
diff changeset
6656 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6657
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6658 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6659 * Match a regexp against a string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6660 * "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
6661 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6662 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6663 * 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
6664 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6665 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6666 nfa_regexec(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6667 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6668 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6669 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6670 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6671 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6672 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6673 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6674 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6675 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6676 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6677 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6678 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6679 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6680 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6681 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6682 return (nfa_regexec_both(line, col) != 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6683 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6684
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6685 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6686 || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6687
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6688 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
6689
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6690 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6691 * 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
6692 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6693 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6694 nfa_regexec_nl(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6695 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6696 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6697 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6698 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6699 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6700 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6701 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6702 reg_line_lbr = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6703 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6704 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6705 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6706 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6707 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6708 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6709 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6710 return (nfa_regexec_both(line, col) != 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6711 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6712 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6713
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6714
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6715 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6716 * Match a regexp against multiple lines.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6717 * "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
6718 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6719 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6720 * 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
6721 * match otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6722 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6723 * 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
6724 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6725 * ! 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
6726 * 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
6727 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6728 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6729 * |a |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6730 * |b |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6731 * |c |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6732 * | |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6733 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6734 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6735 * then nfa_regexec_multi() returns 3. while the original
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6736 * 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
6737 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6738 * FIXME if this behavior is not compatible.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6739 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6740 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6741 nfa_regexec_multi(rmp, win, buf, lnum, col, tm)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6742 regmmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6743 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
6744 buf_T *buf; /* buffer in which to search */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6745 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
6746 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6747 proftime_T *tm UNUSED; /* timeout limit or NULL */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6748 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6749 reg_match = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6750 reg_mmatch = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6751 reg_buf = buf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6752 reg_win = win;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6753 reg_firstlnum = lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6754 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
6755 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6756 ireg_ic = rmp->rmm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6757 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6758 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6759 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6760 ireg_maxcol = rmp->rmm_maxcol;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6761
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
6762 return nfa_regexec_both(NULL, col);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6763 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6764
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6765 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6766 # undef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6767 #endif