annotate src/regexp_nfa.c @ 4572:ef476bdc9274

Added tag v7-3-1033 for changeset b2a8e3a66f8c
author Bram Moolenaar <bram@vim.org>
date Tue, 28 May 2013 22:03:20 +0200
parents b2a8e3a66f8c
children 37e444aeb33b
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 /* Upper limit allowed for {m,n} repetitions handled by NFA */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 #define NFA_BRACES_MAXLIMIT 10
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 /* For allocating space for the postfix representation */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 #define NFA_POSTFIX_MULTIPLIER (NFA_BRACES_MAXLIMIT + 2)*2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 enum
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 NFA_SPLIT = -1024,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 NFA_MATCH,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 NFA_SKIP_CHAR, /* matches a 0-length char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 NFA_END_NEG_RANGE, /* Used when expanding [^ab] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 NFA_CONCAT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 NFA_OR,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 NFA_STAR,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 NFA_PLUS,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 NFA_QUEST,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 NFA_QUEST_NONGREEDY, /* Non-greedy version of \? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 NFA_NOT, /* used for [^ab] negated char ranges */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 NFA_BOL, /* ^ Begin line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 NFA_EOL, /* $ End line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 NFA_BOW, /* \< Begin word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 NFA_EOW, /* \> End word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 NFA_BOF, /* \%^ Begin file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 NFA_EOF, /* \%$ End file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 NFA_NEWL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 NFA_ZSTART, /* Used for \zs */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 NFA_ZEND, /* Used for \ze */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 NFA_NOPEN, /* Start of subexpression marked with \%( */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 NFA_NCLOSE, /* End of subexpr. marked with \%( ... \) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 NFA_START_INVISIBLE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 NFA_END_INVISIBLE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65 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
66 composing multibyte char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 NFA_END_COMPOSING, /* End of a composing char in the NFA */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 /* 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
70 NFA_PREV_ATOM_NO_WIDTH, /* Used for \@= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 NFA_PREV_ATOM_NO_WIDTH_NEG, /* Used for \@! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 NFA_PREV_ATOM_JUST_BEFORE, /* Used for \@<= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 NFA_PREV_ATOM_JUST_BEFORE_NEG, /* Used for \@<! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 NFA_PREV_ATOM_LIKE_PATTERN, /* Used for \@> */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
76 NFA_BACKREF1, /* \1 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
77 NFA_BACKREF2, /* \2 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
78 NFA_BACKREF3, /* \3 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
79 NFA_BACKREF4, /* \4 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
80 NFA_BACKREF5, /* \5 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
81 NFA_BACKREF6, /* \6 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
82 NFA_BACKREF7, /* \7 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
83 NFA_BACKREF8, /* \8 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
84 NFA_BACKREF9, /* \9 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
85 NFA_SKIP, /* Skip characters */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
86
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 NFA_MOPEN,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 NFA_MCLOSE = NFA_MOPEN + NSUBEXP,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 /* NFA_FIRST_NL */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 NFA_ANY = NFA_MCLOSE + NSUBEXP, /* Match any one character. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 NFA_ANYOF, /* Match any character in this string. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 NFA_ANYBUT, /* Match any character not in this string. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 NFA_IDENT, /* Match identifier char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 NFA_SIDENT, /* Match identifier char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 NFA_KWORD, /* Match keyword char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 NFA_SKWORD, /* Match word char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 NFA_FNAME, /* Match file name char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 NFA_SFNAME, /* Match file name char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 NFA_PRINT, /* Match printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 NFA_SPRINT, /* Match printable char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 NFA_WHITE, /* Match whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 NFA_NWHITE, /* Match non-whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 NFA_DIGIT, /* Match digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 NFA_NDIGIT, /* Match non-digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 NFA_HEX, /* Match hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 NFA_NHEX, /* Match non-hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 NFA_OCTAL, /* Match octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 NFA_NOCTAL, /* Match non-octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 NFA_WORD, /* Match word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 NFA_NWORD, /* Match non-word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 NFA_HEAD, /* Match head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 NFA_NHEAD, /* Match non-head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 NFA_ALPHA, /* Match alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 NFA_NALPHA, /* Match non-alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 NFA_LOWER, /* Match lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 NFA_NLOWER, /* Match non-lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 NFA_UPPER, /* Match uppercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 NFA_NUPPER, /* Match non-uppercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 NFA_FIRST_NL = NFA_ANY + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 NFA_LAST_NL = NFA_NUPPER + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 /* Character classes [:alnum:] etc */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 NFA_CLASS_ALNUM,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 NFA_CLASS_ALPHA,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 NFA_CLASS_BLANK,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 NFA_CLASS_CNTRL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 NFA_CLASS_DIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 NFA_CLASS_GRAPH,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 NFA_CLASS_LOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 NFA_CLASS_PRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 NFA_CLASS_PUNCT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 NFA_CLASS_SPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 NFA_CLASS_UPPER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 NFA_CLASS_XDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 NFA_CLASS_TAB,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137 NFA_CLASS_RETURN,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 NFA_CLASS_BACKSPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 NFA_CLASS_ESCAPE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 /* Keep in sync with classchars. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 static int nfa_classcodes[] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 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
145 NFA_FNAME, NFA_SFNAME, NFA_PRINT, NFA_SPRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 NFA_WHITE, NFA_NWHITE, NFA_DIGIT, NFA_NDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 NFA_HEX, NFA_NHEX, NFA_OCTAL, NFA_NOCTAL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 NFA_WORD, NFA_NWORD, NFA_HEAD, NFA_NHEAD,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 NFA_ALPHA, NFA_NALPHA, NFA_LOWER, NFA_NLOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 NFA_UPPER, NFA_NUPPER
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 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
154
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 * NFA errors can be of 3 types:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 * *** NFA runtime errors, when something unknown goes wrong. The NFA fails
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 * silently and revert the to backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 * syntax_error = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 * *** Regexp syntax errors, when the input regexp is not syntactically correct.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
161 * The NFA engine displays an error message, and nothing else happens.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
162 * syntax_error = TRUE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
163 * *** Unsupported features, when the input regexp uses an operator that is not
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 * implemented in the NFA. The NFA engine fails silently, and reverts to the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 * old backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 * syntax_error = FALSE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 * "The NFA fails" means that "compiling the regexp with the NFA fails":
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 * nfa_regcomp() returns FAIL.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 static int syntax_error = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 /* NFA regexp \ze operator encountered. */
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
173 static int nfa_has_zend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
175 /* 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
176 * the whole match (subexpr 0) is used. */
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
177 static int nfa_nsubexpr;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
178
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
179 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
180 static int *post_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
181 static int *post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
182
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
183 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
184 * executing. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
185 static int istate; /* Index in the state vector, used in new_state() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
186
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
187
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 static int nfa_regcomp_start __ARGS((char_u*expr, int re_flags));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189 static int nfa_recognize_char_class __ARGS((char_u *start, char_u *end, int extra_newl));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 static int nfa_emit_equi_class __ARGS((int c, int neg));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 static void nfa_inc __ARGS((char_u **p));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 static void nfa_dec __ARGS((char_u **p));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 static int nfa_regatom __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 static int nfa_regpiece __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 static int nfa_regconcat __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 static int nfa_regbranch __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 static int nfa_reg __ARGS((int paren));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 static void nfa_set_code __ARGS((int c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 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
201 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
202 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
203 static void nfa_dump __ARGS((nfa_regprog_T *prog));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 static int *re2post __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 static nfa_state_T *new_state __ARGS((int c, nfa_state_T *out, nfa_state_T *out1));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207 static nfa_state_T *post2nfa __ARGS((int *postfix, int *end, int nfa_calc_size));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 static int check_char_class __ARGS((int class, int c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 static void st_error __ARGS((int *postfix, int *end, int *p));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 static void nfa_save_listids __ARGS((nfa_state_T *start, int *list));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 static void nfa_restore_listids __ARGS((nfa_state_T *start, int *list));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 static void nfa_set_null_listids __ARGS((nfa_state_T *start));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 static void nfa_set_neg_listids __ARGS((nfa_state_T *start));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 static long nfa_regtry __ARGS((nfa_state_T *start, colnr_T col));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 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
216 static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217 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
218 static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 /* helper functions used when doing re2post() ... regatom() parsing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 #define EMIT(c) do { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 if (post_ptr >= post_end) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 return FAIL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 *post_ptr++ = c; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 } while (0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
227 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 * Initialize internal variables before NFA compilation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 * Return OK on success, FAIL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232 nfa_regcomp_start(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
233 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
234 int re_flags; /* see vim_regcomp() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
235 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
236 size_t postfix_size;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
237 int nstate_max;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
238
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239 nstate = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
240 istate = 0;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
241 /* A reasonable estimation for maximum size */
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
242 nstate_max = (int)(STRLEN(expr) + 1) * NFA_POSTFIX_MULTIPLIER;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
244 /* Some items blow up in size, such as [A-z]. Add more space for that.
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
245 * TODO: some patterns may still fail. */
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
246 nstate_max += 1000;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
247
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
248 /* Size for postfix representation of expr. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 postfix_size = sizeof(*post_start) * nstate_max;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
250
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 post_start = (int *)lalloc(postfix_size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252 if (post_start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 vim_memset(post_start, 0, postfix_size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 post_ptr = post_start;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
256 post_end = post_start + nstate_max;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257 nfa_has_zend = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 regcomp_start(expr, re_flags);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
260
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
265 * 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
266 * character class in expanded form. For example [0-9].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 * 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
268 * On failure, return 0 (=FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269 * 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
270 * to the closing brace.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
272 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 nfa_recognize_char_class(start, end, extra_newl)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 char_u *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 char_u *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276 int extra_newl;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 /* Each of these variables takes up a char in "config[]",
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 * in the order they are here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
281 int not = FALSE, af = FALSE, AF = FALSE, az = FALSE, AZ = FALSE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 o7 = FALSE, o9 = FALSE, underscore = FALSE, newl = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 char_u *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 #define NCONFIGS 16
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 int classid[NCONFIGS] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 NFA_DIGIT, NFA_NDIGIT, NFA_HEX, NFA_NHEX,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 NFA_OCTAL, NFA_NOCTAL, NFA_WORD, NFA_NWORD,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288 NFA_HEAD, NFA_NHEAD, NFA_ALPHA, NFA_NALPHA,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289 NFA_LOWER, NFA_NLOWER, NFA_UPPER, NFA_NUPPER
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 };
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
291 char_u myconfig[10];
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
292 char_u config[NCONFIGS][9] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293 "000000100", /* digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 "100000100", /* non digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 "011000100", /* hex-digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296 "111000100", /* non hex-digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297 "000001000", /* octal-digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
298 "100001000", /* [^0-7] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299 "000110110", /* [0-9A-Za-z_] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300 "100110110", /* [^0-9A-Za-z_] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
301 "000110010", /* head of word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
302 "100110010", /* not head of word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 "000110000", /* alphabetic char a-z */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304 "100110000", /* non alphabetic char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 "000100000", /* lowercase letter */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 "100100000", /* non lowercase */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
307 "000010000", /* uppercase */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
308 "100010000" /* non uppercase */
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
311 if (extra_newl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
312 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
313
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 if (*end != ']')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 p = start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317 if (*p == '^')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
318 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
319 not = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
321 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
322
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 while (p < end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
324 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
325 if (p + 2 < end && *(p + 1) == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 switch (*p)
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 case '0':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 if (*(p + 2) == '9')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
331 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
332 o9 = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
333 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
334 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
336 if (*(p + 2) == '7')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 o7 = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
340 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
341 case 'a':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
342 if (*(p + 2) == 'z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 az = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
345 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
346 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
347 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
348 if (*(p + 2) == 'f')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 af = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 case 'A':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 if (*(p + 2) == 'Z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 AZ = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
358 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
359 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
360 if (*(p + 2) == 'F')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
361 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
362 AF = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
363 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
364 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
365 /* FALLTHROUGH */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
366 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
367 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
368 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
369 p += 3;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
370 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
371 else if (p + 1 < end && *p == '\\' && *(p + 1) == 'n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
372 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
373 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
374 p += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
375 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
376 else if (*p == '_')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
377 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
378 underscore = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 else if (*p == '\n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
382 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
383 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
384 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
385 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
387 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
388 } /* while (p < end) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
389
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390 if (p != end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 /* build the config that represents the ranges we gathered */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
394 STRCPY(myconfig, "000000000");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395 if (not == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396 myconfig[0] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 if (af == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398 myconfig[1] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399 if (AF == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 myconfig[2] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401 if (az == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
402 myconfig[3] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 if (AZ == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404 myconfig[4] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
405 if (o7 == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
406 myconfig[5] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
407 if (o9 == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
408 myconfig[6] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
409 if (underscore == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
410 myconfig[7] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411 if (newl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413 myconfig[8] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414 extra_newl = ADD_NL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
415 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
416 /* try to recognize character classes */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417 for (i = 0; i < NCONFIGS; i++)
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
418 if (STRNCMP(myconfig, config[i], 8) == 0)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 return classid[i] + extra_newl;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
420
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
421 /* fallthrough => no success so far */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
423
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
424 #undef NCONFIGS
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
428 * Produce the bytes for equivalence class "c".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
429 * Currently only handles latin1, latin9 and utf-8.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 * 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
431 * equivalent to 'a OR b OR c'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
432 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433 * 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
434 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
435 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
436 nfa_emit_equi_class(c, neg)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438 int neg;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
439 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
440 int first = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
441 int glue = neg == TRUE ? NFA_CONCAT : NFA_OR;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
442 #define EMIT2(c) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
443 EMIT(c); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
444 if (neg == TRUE) { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
445 EMIT(NFA_NOT); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
446 } \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
447 if (first == FALSE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
448 EMIT(glue); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
449 else \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
450 first = FALSE; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
451
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
452 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
453 if (enc_utf8 || STRCMP(p_enc, "latin1") == 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
454 || STRCMP(p_enc, "iso-8859-15") == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
455 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
459 case 'A': case '\300': case '\301': case '\302':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460 case '\303': case '\304': case '\305':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
461 EMIT2('A'); EMIT2('\300'); EMIT2('\301');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
462 EMIT2('\302'); EMIT2('\303'); EMIT2('\304');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
463 EMIT2('\305');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
464 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
465
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
466 case 'C': case '\307':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
467 EMIT2('C'); EMIT2('\307');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
468 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
469
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
470 case 'E': case '\310': case '\311': case '\312': case '\313':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
471 EMIT2('E'); EMIT2('\310'); EMIT2('\311');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
472 EMIT2('\312'); EMIT2('\313');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
473 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
474
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
475 case 'I': case '\314': case '\315': case '\316': case '\317':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
476 EMIT2('I'); EMIT2('\314'); EMIT2('\315');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
477 EMIT2('\316'); EMIT2('\317');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
478 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
479
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
480 case 'N': case '\321':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
481 EMIT2('N'); EMIT2('\321');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
482 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
483
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
484 case 'O': case '\322': case '\323': case '\324': case '\325':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
485 case '\326':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
486 EMIT2('O'); EMIT2('\322'); EMIT2('\323');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
487 EMIT2('\324'); EMIT2('\325'); EMIT2('\326');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
488 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
489
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
490 case 'U': case '\331': case '\332': case '\333': case '\334':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
491 EMIT2('U'); EMIT2('\331'); EMIT2('\332');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
492 EMIT2('\333'); EMIT2('\334');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
493 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
494
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
495 case 'Y': case '\335':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
496 EMIT2('Y'); EMIT2('\335');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
497 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
498
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
499 case 'a': case '\340': case '\341': case '\342':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
500 case '\343': case '\344': case '\345':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
501 EMIT2('a'); EMIT2('\340'); EMIT2('\341');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
502 EMIT2('\342'); EMIT2('\343'); EMIT2('\344');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
503 EMIT2('\345');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
504 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
505
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
506 case 'c': case '\347':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
507 EMIT2('c'); EMIT2('\347');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
508 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
509
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
510 case 'e': case '\350': case '\351': case '\352': case '\353':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
511 EMIT2('e'); EMIT2('\350'); EMIT2('\351');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
512 EMIT2('\352'); EMIT2('\353');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
513 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
514
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
515 case 'i': case '\354': case '\355': case '\356': case '\357':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
516 EMIT2('i'); EMIT2('\354'); EMIT2('\355');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
517 EMIT2('\356'); EMIT2('\357');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
518 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
519
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
520 case 'n': case '\361':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
521 EMIT2('n'); EMIT2('\361');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
522 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
523
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
524 case 'o': case '\362': case '\363': case '\364': case '\365':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
525 case '\366':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
526 EMIT2('o'); EMIT2('\362'); EMIT2('\363');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
527 EMIT2('\364'); EMIT2('\365'); EMIT2('\366');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530 case 'u': case '\371': case '\372': case '\373': case '\374':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 EMIT2('u'); EMIT2('\371'); EMIT2('\372');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
532 EMIT2('\373'); EMIT2('\374');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
533 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
534
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
535 case 'y': case '\375': case '\377':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
536 EMIT2('y'); EMIT2('\375'); EMIT2('\377');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
537 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
538
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
539 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
540 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
541 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
542 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
543
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
544 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
545 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
546 #undef EMIT2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
547 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
548
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
549 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
550 * Code to parse regular expression.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
551 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
552 * 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
553 * minimize surprise and keep the syntax consistent.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
554 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
555
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
556 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
557 * Increments the pointer "p" by one (multi-byte) character.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
558 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
559 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
560 nfa_inc(p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
561 char_u **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
562 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
563 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
564 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
565 mb_ptr2char_adv(p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
566 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
567 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
568 *p = *p + 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
569 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
570
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
571 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
572 * Decrements the pointer "p" by one (multi-byte) character.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
573 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
574 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
575 nfa_dec(p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
576 char_u **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
577 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
578 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
579 char_u *p2, *oldp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
580
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
581 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
582 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
583 oldp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
584 /* Try to find the multibyte char that advances to the current
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
585 * position. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
586 do
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
587 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
588 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
589 p2 = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
590 mb_ptr2char_adv(&p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
591 } while (p2 != oldp);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
592 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
593 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
594 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
595 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
596 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
597
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
598 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
599 * Parse the lowest level.
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 * 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
602 * 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
603 * 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
604 * is only for syntax highlighting.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
605 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606 * atom ::= ordinary-atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 * or \( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 * or \%( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
609 * or \z( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
610 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
611 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
612 nfa_regatom()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
613 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
614 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615 int charclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
616 int equiclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
617 int collclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
618 int got_coll_char;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
619 char_u *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 char_u *endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
621 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
622 char_u *old_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
623 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
624 int extra = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
625 int first;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
626 int emit_range;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 int negated;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
628 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629 int startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
630 int endc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
631 int oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
632 int cpo_lit; /* 'cpoptions' contains 'l' flag */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
633 int cpo_bsl; /* 'cpoptions' contains '\' flag */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
634 int glue; /* ID that will "glue" nodes together */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
635
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
636 cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
637 cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
638
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
639 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
640 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
641 {
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
642 case NUL:
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
643 syntax_error = TRUE;
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
644 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
645
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
646 case Magic('^'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
647 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
648 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
649
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 case Magic('$'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
652 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
653 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
654 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
655 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
656
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
657 case Magic('<'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
658 EMIT(NFA_BOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
659 break;
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 case Magic('>'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
662 EMIT(NFA_EOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
663 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
664
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
665 case Magic('_'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 if (c == '^') /* "\_^" is start-of-line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
668 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
669 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
670 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
671 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
672 if (c == '$') /* "\_$" is end-of-line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
673 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 break;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 extra = ADD_NL;
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 /* "\_[" is collection plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
684 if (c == '[')
4517
9a2183bd8295 updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents: 4515
diff changeset
685 goto collection;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
686
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
687 /* "\_x" is character class plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
688 /*FALLTHROUGH*/
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
689
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
690 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 * Character classes.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
692 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
693 case Magic('.'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
694 case Magic('i'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
695 case Magic('I'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
696 case Magic('k'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
697 case Magic('K'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
698 case Magic('f'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
699 case Magic('F'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
700 case Magic('p'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
701 case Magic('P'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
702 case Magic('s'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
703 case Magic('S'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
704 case Magic('d'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
705 case Magic('D'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
706 case Magic('x'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
707 case Magic('X'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
708 case Magic('o'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
709 case Magic('O'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
710 case Magic('w'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
711 case Magic('W'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
712 case Magic('h'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
713 case Magic('H'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
714 case Magic('a'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
715 case Magic('A'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
716 case Magic('l'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
717 case Magic('L'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
718 case Magic('u'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
719 case Magic('U'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
720 p = vim_strchr(classchars, no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
721 if (p == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
722 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
723 EMSGN("INTERNAL: Unknown character class char: %ld", c);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
724 return FAIL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
725 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
726 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
727 /* 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
728 * the composing char is matched here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr()))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
730 {
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
731 old_regparse = regparse;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
733 goto nfa_do_multibyte;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
734 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
735 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
736 EMIT(nfa_classcodes[p - classchars]);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
737 if (extra == ADD_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
738 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
739 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
741 regflags |= RF_HASNL;
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 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
744
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
745 case Magic('n'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
746 if (reg_string)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
747 /* In a string "\n" matches a newline character. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
748 EMIT(NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
749 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
751 /* 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
752 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
753 regflags |= RF_HASNL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
756
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
757 case Magic('('):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
758 if (nfa_reg(REG_PAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
759 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
760 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
761
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
762 case Magic('|'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
763 case Magic('&'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
764 case Magic(')'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
765 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
766 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
767 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
768
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
769 case Magic('='):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
770 case Magic('?'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
771 case Magic('+'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
772 case Magic('@'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
773 case Magic('*'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
774 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
775 /* these should follow an atom, not form an atom */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
776 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
777 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
778 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780 case Magic('~'): /* previous substitute pattern */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
781 /* TODO: Not supported yet */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
782 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
784 case Magic('1'): EMIT(NFA_BACKREF1); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
785 case Magic('2'): EMIT(NFA_BACKREF2); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
786 case Magic('3'): EMIT(NFA_BACKREF3); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
787 case Magic('4'): EMIT(NFA_BACKREF4); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
788 case Magic('5'): EMIT(NFA_BACKREF5); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
789 case Magic('6'): EMIT(NFA_BACKREF6); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
790 case Magic('7'): EMIT(NFA_BACKREF7); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
791 case Magic('8'): EMIT(NFA_BACKREF8); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
792 case Magic('9'): EMIT(NFA_BACKREF9); break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
793
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794 case Magic('z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
796 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
797 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
798 case 's':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
799 EMIT(NFA_ZSTART);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
800 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
801 case 'e':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
802 EMIT(NFA_ZEND);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
803 nfa_has_zend = TRUE;
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
804 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
805 case '1':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
806 case '2':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
807 case '3':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
808 case '4':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
809 case '5':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
810 case '6':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
811 case '7':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
812 case '8':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
813 case '9':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
814 case '(':
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
815 /* TODO: \z1...\z9 and \z( not yet supported */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
816 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
817 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
818 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
819 EMSGN(_("E867: (NFA) Unknown operator '\\z%c'"),
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
820 no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
821 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
822 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
823 break;
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 case Magic('%'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
826 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
827 switch (c)
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 /* () without a back reference */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
830 case '(':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
831 if (nfa_reg(REG_NPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
832 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
833 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
834 break;
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 case 'd': /* %d123 decimal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
837 case 'o': /* %o123 octal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
838 case 'x': /* %xab hex 2 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
839 case 'u': /* %uabcd hex 4 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
840 case 'U': /* %U1234abcd hex 8 */
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
841 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
842 int nr;
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
843
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
844 switch (c)
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
845 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
846 case 'd': nr = getdecchrs(); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
847 case 'o': nr = getoctchrs(); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
848 case 'x': nr = gethexchrs(2); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
849 case 'u': nr = gethexchrs(4); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
850 case 'U': nr = gethexchrs(8); break;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
851 default: nr = -1; break;
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
852 }
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
853
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
854 if (nr < 0)
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
855 EMSG2_RET_FAIL(
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
856 _("E678: Invalid character after %s%%[dxouU]"),
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
857 reg_magic == MAGIC_ALL);
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
858 /* TODO: what if a composing character follows? */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
859 EMIT(nr);
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
860 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
861 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
862
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
863 /* Catch \%^ and \%$ regardless of where they appear in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
864 * pattern -- regardless of whether or not it makes sense. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
865 case '^':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
866 EMIT(NFA_BOF);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
867 /* TODO: Not yet supported */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
868 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
869 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
870
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
871 case '$':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
872 EMIT(NFA_EOF);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
873 /* TODO: Not yet supported */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
874 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
875 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
876
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
877 case '#':
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
878 /* TODO: not supported yet */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
879 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
880 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
881
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
882 case 'V':
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
883 /* TODO: not supported yet */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
884 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
885 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
886
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
887 case '[':
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
888 /* TODO: \%[abc] not supported yet */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
889 return FAIL;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
890
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
891 case '0':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
892 case '1':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
893 case '2':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
894 case '3':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
895 case '4':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
896 case '5':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
897 case '6':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
898 case '7':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
899 case '8':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
900 case '9':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
901 case '<':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
902 case '>':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
903 case '\'':
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
904 /* TODO: not supported yet */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
905 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
906
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
907 default:
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
908 syntax_error = TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
909 EMSGN(_("E867: (NFA) Unknown operator '\\%%%c'"),
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
910 no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
911 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
912 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
913 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
914
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
915 case Magic('['):
4517
9a2183bd8295 updated for version 7.3.1006
Bram Moolenaar <bram@vim.org>
parents: 4515
diff changeset
916 collection:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
917 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
918 * Glue is emitted between several atoms from the [].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
919 * It is either NFA_OR, or NFA_CONCAT.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
920 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
921 * [abc] expands to 'a b NFA_OR c NFA_OR' (in postfix notation)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
922 * [^abc] expands to 'a NFA_NOT b NFA_NOT NFA_CONCAT c NFA_NOT
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
923 * NFA_CONCAT NFA_END_NEG_RANGE NFA_CONCAT' (in postfix
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
924 * notation)
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
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 /* Emit negation atoms, if needed.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
930 * The CONCAT below merges the NOT with the previous node. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
931 #define TRY_NEG() \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
932 if (negated == TRUE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
933 { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
934 EMIT(NFA_NOT); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
935 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
936
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
937 /* Emit glue between important nodes : CONCAT or OR. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
938 #define EMIT_GLUE() \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
939 if (first == FALSE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
940 EMIT(glue); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
941 else \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
942 first = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
943
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
944 p = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
945 endp = skip_anyof(p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
946 if (*endp == ']')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
947 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
948 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
949 * Try to reverse engineer character classes. For example,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
950 * 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
951 * and perform the necessary substitutions in the NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
952 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
953 result = nfa_recognize_char_class(regparse, endp,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
954 extra == ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
955 if (result != FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
956 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
957 if (result >= NFA_DIGIT && result <= NFA_NUPPER)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
958 EMIT(result);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
959 else /* must be char class + newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
960 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
961 EMIT(result - ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
962 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
963 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
964 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
965 regparse = endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
966 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
967 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
968 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
969 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
970 * Failed to recognize a character class. Use the simple
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
971 * 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
972 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
973 startc = endc = oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
974 first = TRUE; /* Emitting first atom in this sequence? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
975 negated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
976 glue = NFA_OR;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
977 if (*regparse == '^') /* negated range */
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 negated = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
980 glue = NFA_CONCAT;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
981 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
982 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
983 if (*regparse == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
984 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
985 startc = '-';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
986 EMIT(startc);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
987 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
988 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
989 nfa_inc(&regparse);
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 /* Emit the OR branches for each character in the [] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
992 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
993 while (regparse < endp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
994 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
995 oldstartc = startc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
996 startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
997 got_coll_char = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
998 if (*regparse == '[')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
999 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1000 /* Check for [: :], [= =], [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1001 equiclass = collclass = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1002 charclass = get_char_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1003 if (charclass == CLASS_NONE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1004 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1005 equiclass = get_equi_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1006 if (equiclass == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1007 collclass = get_coll_element(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1008 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1009
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1010 /* Character class like [:alpha:] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1011 if (charclass != CLASS_NONE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1012 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1013 switch (charclass)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1014 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1015 case CLASS_ALNUM:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1016 EMIT(NFA_CLASS_ALNUM);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1017 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1018 case CLASS_ALPHA:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1019 EMIT(NFA_CLASS_ALPHA);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1020 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1021 case CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1022 EMIT(NFA_CLASS_BLANK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1023 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1024 case CLASS_CNTRL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1025 EMIT(NFA_CLASS_CNTRL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1026 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1027 case CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1028 EMIT(NFA_CLASS_DIGIT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1029 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1030 case CLASS_GRAPH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1031 EMIT(NFA_CLASS_GRAPH);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1032 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1033 case CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1034 EMIT(NFA_CLASS_LOWER);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1035 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1036 case CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1037 EMIT(NFA_CLASS_PRINT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1038 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1039 case CLASS_PUNCT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1040 EMIT(NFA_CLASS_PUNCT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1041 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1042 case CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1043 EMIT(NFA_CLASS_SPACE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1044 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1045 case CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1046 EMIT(NFA_CLASS_UPPER);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1047 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1048 case CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1049 EMIT(NFA_CLASS_XDIGIT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1050 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1051 case CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1052 EMIT(NFA_CLASS_TAB);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1053 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1054 case CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1055 EMIT(NFA_CLASS_RETURN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1056 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1057 case CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1058 EMIT(NFA_CLASS_BACKSPACE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1059 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1060 case CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1061 EMIT(NFA_CLASS_ESCAPE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1062 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1063 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1064 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1065 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1066 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1067 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1068 /* Try equivalence class [=a=] and the like */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1069 if (equiclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1070 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1071 result = nfa_emit_equi_class(equiclass, negated);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1072 if (result == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1073 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1074 /* should never happen */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1075 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
1076 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1077 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1078 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1079 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1080 /* Try collating class like [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1081 if (collclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1082 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1083 startc = collclass; /* allow [.a.]-x as a range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1084 /* 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
1085 * while loop. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1086 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1087 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1088 /* Try a range like 'a-x' or '\t-z' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1089 if (*regparse == '-')
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 emit_range = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1092 startc = oldstartc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1093 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1094 continue; /* reading the end of the range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1095 }
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 /* Now handle simple and escaped characters.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1098 * Only "\]", "\^", "\]" and "\\" are special in Vi. Vim
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1099 * 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
1100 * 'cpoptions' is not included.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1101 * Posix doesn't recognize backslash at all.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1102 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1103 if (*regparse == '\\'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1104 && !cpo_bsl
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1105 && regparse + 1 <= endp
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1106 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1107 || (!cpo_lit
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1108 && vim_strchr(REGEXP_ABBR, regparse[1])
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1109 != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1110 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1111 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1112 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1113 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1114
4507
9dbbddb2ed10 updated for version 7.3.1001
Bram Moolenaar <bram@vim.org>
parents: 4503
diff changeset
1115 if (*regparse == 'n')
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1116 startc = reg_string ? NL : NFA_NEWL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1117 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1118 if (*regparse == 'd'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1119 || *regparse == 'o'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1120 || *regparse == 'x'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1121 || *regparse == 'u'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1122 || *regparse == 'U'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1123 )
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1124 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1125 /* TODO(RE) This needs more testing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1126 startc = coll_get_char();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1127 got_coll_char = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1128 nfa_dec(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1129 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1130 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1131 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1132 /* \r,\t,\e,\b */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1133 startc = backslash_trans(*regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1134 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1135 }
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 /* Normal printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1138 if (startc == -1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1139 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1140 startc = (*mb_ptr2char)(regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1141 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1142 startc = *regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1143 #endif
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 /* 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
1146 if (emit_range)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1147 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1148 endc = startc; startc = oldstartc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1149 if (startc > endc)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1150 EMSG_RET_FAIL(_(e_invrange));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1151 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1152 if (has_mbyte && ((*mb_char2len)(startc) > 1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1153 || (*mb_char2len)(endc) > 1))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1154 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1155 if (endc > startc + 256)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1156 EMSG_RET_FAIL(_(e_invrange));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1157 /* Emit the range. "startc" was already emitted, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1158 * skip it. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1159 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1160 {
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1161 EMIT(c);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1162 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1163 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1164 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1165 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1166 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1167 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1168 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1169 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1170 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1171 int alpha_only = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1172
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1173 /* for alphabetical range skip the gaps
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1174 * 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1175 if (isalpha(startc) && isalpha(endc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1176 alpha_only = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1177 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1178 /* Emit the range. "startc" was already emitted, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1179 * skip it. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1180 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1181 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1182 if (!alpha_only || isalpha(startc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1183 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1184 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1185 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1186 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1187 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1188 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1189 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1190 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1191 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1192 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1193 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1194 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1195 * This char (startc) is not part of a range. Just
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1196 * emit it.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1197 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1198 * Normally, simply emit startc. But if we get char
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1199 * 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
1200 * 0x0a.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1201 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1202 * This is needed to completely mimic the behaviour of
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1203 * the backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1204 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1205 if (got_coll_char == TRUE && startc == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1206 EMIT(0x0a);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1207 else
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1208 EMIT(startc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1209 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1210 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1211 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1212
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1213 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1214 } /* while (p < endp) */
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 nfa_dec(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1217 if (*regparse == '-') /* if last, '-' is just a char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1218 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1219 EMIT('-');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1220 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1221 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1222 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1223 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1224
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1225 if (extra == ADD_NL) /* \_[] also matches \n */
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 EMIT(reg_string ? NL : NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1228 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1229 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1230 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1231
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1232 /* skip the trailing ] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1233 regparse = endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1234 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1235 if (negated == TRUE)
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 /* Mark end of negated char range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1238 EMIT(NFA_END_NEG_RANGE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1239 EMIT(NFA_CONCAT);
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 return OK;
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1242 } /* if exists closing ] */
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1243
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1244 if (reg_strict)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1245 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1246 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1247 EMSG_RET_FAIL(_(e_missingbracket));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1248 }
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1249 /* FALLTHROUGH */
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1250
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1251 default:
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 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1254 int plen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1255
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1256 nfa_do_multibyte:
4543
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1257 /* 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
1258 if (enc_utf8 && ((*mb_char2len)(c)
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1259 != (plen = (*mb_ptr2len)(old_regparse))
08ac46980953 updated for version 7.3.1019
Bram Moolenaar <bram@vim.org>
parents: 4541
diff changeset
1260 || utf_iscomposing(c)))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1261 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1262 int i = 0;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
1263
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
1264 /* 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
1265 * or more composing characters.
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1266 * 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
1267 * 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
1268 * 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
1269 * building the postfix form, not the NFA itself;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1270 * 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
1271 * 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
1272 for (;;)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1273 {
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1274 EMIT(c);
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1275 if (i > 0)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1276 EMIT(NFA_CONCAT);
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
1277 if ((i += utf_char2len(c)) >= plen)
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1278 break;
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1279 c = utf_ptr2char(old_regparse + i);
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1280 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
1281 EMIT(NFA_COMPOSING);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1282 regparse = old_regparse + plen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1283 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1284 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1285 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1286 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1287 c = no_Magic(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1288 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1289 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1290 return OK;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1294 #undef TRY_NEG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1295 #undef EMIT_GLUE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1296
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1297 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1298 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1299
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1300 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1301 * Parse something followed by possible [*+=].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1302 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1303 * 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
1304 * 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
1305 * characters: "", "a", "aa", etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1306 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1307 * piece ::= atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1308 * or atom multi
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1309 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1310 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1311 nfa_regpiece()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1312 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1313 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1314 int op;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1315 int ret;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1316 long minval, maxval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1317 int greedy = TRUE; /* Braces are prefixed with '-' ? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1318 char_u *old_regparse, *new_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1319 int c2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1320 int *old_post_ptr, *my_post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1321 int old_regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1322 int quest;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1323
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1324 /* Save the current position in the regexp, so that we can use it if
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1325 * <atom>{m,n} is next. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1326 old_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1327 /* Save current number of open parenthesis, so we can use it if
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1328 * <atom>{m,n} is next */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1329 old_regnpar = regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1330 /* store current pos in the postfix form, for \{m,n} involving 0s */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1331 my_post_start = post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1332
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1333 ret = nfa_regatom();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1334 if (ret == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1335 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1336
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1337 op = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1338 if (re_multi_type(op) == NOT_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1339 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1340
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1341 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1342 switch (op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1343 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1344 case Magic('*'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1345 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1346 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1347
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1348 case Magic('+'):
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 * 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
1351 * 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
1352 * 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
1353 * 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
1354 * string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1355 * The submatch will the empty string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1356 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1357 * In order to be consistent with the old engine, we disable
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1358 * NFA_PLUS, and replace <atom>+ with <atom><atom>*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1359 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1360 /* EMIT(NFA_PLUS); */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1361 regnpar = old_regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1362 regparse = old_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1363 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1364 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1365 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1366 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1367 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1368 skipchr(); /* skip the \+ */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1369 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1370
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1371 case Magic('@'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1372 op = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1373 switch(op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1374 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1375 case '=':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1376 EMIT(NFA_PREV_ATOM_NO_WIDTH);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1377 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1378 case '!':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1379 case '<':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1380 case '>':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1381 /* Not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1382 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1383 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1384 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
1385 EMSGN(_("E869: (NFA) Unknown operator '\\@%c'"), op);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1386 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1387 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1388 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1389
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1390 case Magic('?'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1391 case Magic('='):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1392 EMIT(NFA_QUEST);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1393 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1394
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1395 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1396 /* a{2,5} will expand to 'aaa?a?a?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1397 * 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
1398 * version of '?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1399 * \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
1400 * parenthesis have the same id
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1401 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1402
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1403 greedy = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1404 c2 = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1405 if (c2 == '-' || c2 == Magic('-'))
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 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1408 greedy = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1409 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1410 if (!read_limits(&minval, &maxval))
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 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1413 EMSG_RET_FAIL(_("E870: (NFA regexp) Error reading repetition limits"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1414 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1415 /* <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
1416 * <atom>* */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1417 if (minval == 0 && maxval == MAX_LIMIT && greedy)
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 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1420 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1421 }
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 if (maxval > NFA_BRACES_MAXLIMIT)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1424 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1425 /* This would yield a huge automaton and use too much memory.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1426 * Revert to old engine */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1427 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1428 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1429
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1430 /* Special case: x{0} or x{-0} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1431 if (maxval == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1432 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1433 /* Ignore result of previous call to nfa_regatom() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1434 post_ptr = my_post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1435 /* NFA_SKIP_CHAR has 0-length and works everywhere */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1436 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1437 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1438 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1439
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1440 /* Ignore previous call to nfa_regatom() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1441 post_ptr = my_post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1442 /* Save pos after the repeated atom and the \{} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1443 new_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1445 quest = (greedy == TRUE? NFA_QUEST : NFA_QUEST_NONGREEDY);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1446 for (i = 0; i < maxval; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1447 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1448 /* Goto beginning of the repeated atom */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1449 regparse = old_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1450 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1451 /* Restore count of parenthesis */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1452 regnpar = old_regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1453 old_post_ptr = post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1454 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1455 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1456 /* after "minval" times, atoms are optional */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1457 if (i + 1 > minval)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1458 EMIT(quest);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1459 if (old_post_ptr != my_post_start)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1460 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1461 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1462
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1463 /* Go to just after the repeated atom and the \{} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1464 regparse = new_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1465 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1466
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1467 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1468
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1469
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1470 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1471 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1472 } /* end switch */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1473
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1474 if (re_multi_type(peekchr()) != NOT_MULTI)
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 /* Can't have a multi follow a multi. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1477 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1478 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
1479 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1480
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1481 return OK;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1484 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1485 * 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
1486 * 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
1487 * "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
1488 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1489 * concat ::= piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1490 * or piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1491 * or piece piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1492 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1493 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1494 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1495 nfa_regconcat()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1496 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1497 int cont = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1498 int first = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1499
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1500 while (cont)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1501 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1502 switch (peekchr())
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1503 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1504 case NUL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1505 case Magic('|'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1506 case Magic('&'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1507 case Magic(')'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1508 cont = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1509 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1510
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1511 case Magic('Z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1512 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1513 regflags |= RF_ICOMBINE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1514 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1515 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1516 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1517 case Magic('c'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1518 regflags |= RF_ICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1519 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1520 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1521 case Magic('C'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1522 regflags |= RF_NOICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1523 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1524 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1525 case Magic('v'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1526 reg_magic = MAGIC_ALL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1527 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1528 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1529 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1530 case Magic('m'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1531 reg_magic = MAGIC_ON;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1532 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1533 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1534 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1535 case Magic('M'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1536 reg_magic = MAGIC_OFF;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1537 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1538 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1539 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1540 case Magic('V'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1541 reg_magic = MAGIC_NONE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1542 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1543 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1544 break;
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 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1547 if (nfa_regpiece() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1548 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1549 if (first == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1550 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1551 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1552 first = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1553 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1554 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1555 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1556
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1557 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1558 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1559
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1560 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1561 * 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
1562 * 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
1563 * position. Examples:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1564 * "foobeep\&..." matches "foo" in "foobeep".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1565 * ".*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
1566 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1567 * branch ::= concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1568 * or concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1569 * or concat \& concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1570 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1571 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1572 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1573 nfa_regbranch()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1574 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1575 int ch;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1576 int *old_post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1577
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1578 old_post_ptr = post_ptr;
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 /* First branch, possibly the only one */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1581 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1582 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1583
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1584 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1585 /* Try next concats */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1586 while (ch == Magic('&'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1587 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1588 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1589 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1590 EMIT(NFA_PREV_ATOM_NO_WIDTH);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1591 old_post_ptr = post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1592 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1593 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1594 /* if concat is empty, skip a input char. But do emit a node */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1595 if (old_post_ptr == post_ptr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1596 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1597 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1598 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1599 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1600
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1601 /* Even if a branch is empty, emit one node for it */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1602 if (old_post_ptr == post_ptr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1603 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1604
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1605 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1606 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1607
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1608 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1609 * 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
1610 * 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
1611 * "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
1612 * is used.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1613 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1614 * pattern ::= branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1615 * or branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1616 * or branch \| branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1617 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1618 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1619 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1620 nfa_reg(paren)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1621 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
1622 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1623 int parno = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1624
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1625 #ifdef FEAT_SYN_HL
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1626 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1627 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1628 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1629 if (regnpar >= NSUBEXP) /* Too many `(' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1630 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1631 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1632 EMSG_RET_FAIL(_("E872: (NFA regexp) Too many '('"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1633 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1634 parno = regnpar++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1635 }
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 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1638 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1639
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1640 while (peekchr() == Magic('|'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1641 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1642 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1643 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1644 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1645 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1646 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1647
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1648 /* Check for proper termination. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1649 if (paren != REG_NOPAREN && getchr() != Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1650 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1651 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1652 if (paren == REG_NPAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1653 EMSG2_RET_FAIL(_(e_unmatchedpp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1654 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1655 EMSG2_RET_FAIL(_(e_unmatchedp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1656 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1657 else if (paren == REG_NOPAREN && peekchr() != NUL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1658 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1659 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1660 if (peekchr() == Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1661 EMSG2_RET_FAIL(_(e_unmatchedpar), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1662 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1663 EMSG_RET_FAIL(_("E873: (NFA regexp) proper termination error"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1664 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1665 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1666 * 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
1667 * parentheses.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1668 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1669 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1670 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1671 had_endbrace[parno] = TRUE; /* have seen the close paren */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1672 EMIT(NFA_MOPEN + parno);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1673 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1674
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1675 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1676 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1677
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1678 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1679 static char_u code[50];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1680
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1681 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1682 nfa_set_code(c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1683 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1684 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1685 int addnl = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1686
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1687 if (c >= NFA_FIRST_NL && c <= NFA_LAST_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1688 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1689 addnl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1690 c -= ADD_NL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1691 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1692
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1693 STRCPY(code, "");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1694 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1695 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1696 case NFA_MATCH: STRCPY(code, "NFA_MATCH "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1697 case NFA_SPLIT: STRCPY(code, "NFA_SPLIT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1698 case NFA_CONCAT: STRCPY(code, "NFA_CONCAT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1699 case NFA_NEWL: STRCPY(code, "NFA_NEWL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1700 case NFA_ZSTART: STRCPY(code, "NFA_ZSTART"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1701 case NFA_ZEND: STRCPY(code, "NFA_ZEND"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1702
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1703 case NFA_BACKREF1: STRCPY(code, "NFA_BACKREF1"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1704 case NFA_BACKREF2: STRCPY(code, "NFA_BACKREF2"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1705 case NFA_BACKREF3: STRCPY(code, "NFA_BACKREF3"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1706 case NFA_BACKREF4: STRCPY(code, "NFA_BACKREF4"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1707 case NFA_BACKREF5: STRCPY(code, "NFA_BACKREF5"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1708 case NFA_BACKREF6: STRCPY(code, "NFA_BACKREF6"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1709 case NFA_BACKREF7: STRCPY(code, "NFA_BACKREF7"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1710 case NFA_BACKREF8: STRCPY(code, "NFA_BACKREF8"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1711 case NFA_BACKREF9: STRCPY(code, "NFA_BACKREF9"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1712 case NFA_SKIP: STRCPY(code, "NFA_SKIP"); break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
1713
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1714 case NFA_PREV_ATOM_NO_WIDTH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1715 STRCPY(code, "NFA_PREV_ATOM_NO_WIDTH"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1716 case NFA_NOPEN: STRCPY(code, "NFA_MOPEN_INVISIBLE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1717 case NFA_NCLOSE: STRCPY(code, "NFA_MCLOSE_INVISIBLE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1718 case NFA_START_INVISIBLE: STRCPY(code, "NFA_START_INVISIBLE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1719 case NFA_END_INVISIBLE: STRCPY(code, "NFA_END_INVISIBLE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1720
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1721 case NFA_COMPOSING: STRCPY(code, "NFA_COMPOSING"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1722 case NFA_END_COMPOSING: STRCPY(code, "NFA_END_COMPOSING"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1723
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1724 case NFA_MOPEN + 0:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1725 case NFA_MOPEN + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1726 case NFA_MOPEN + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1727 case NFA_MOPEN + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1728 case NFA_MOPEN + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1729 case NFA_MOPEN + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1730 case NFA_MOPEN + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1731 case NFA_MOPEN + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1732 case NFA_MOPEN + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1733 case NFA_MOPEN + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1734 STRCPY(code, "NFA_MOPEN(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1735 code[10] = c - NFA_MOPEN + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1736 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1737 case NFA_MCLOSE + 0:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1738 case NFA_MCLOSE + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1739 case NFA_MCLOSE + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1740 case NFA_MCLOSE + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1741 case NFA_MCLOSE + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1742 case NFA_MCLOSE + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1743 case NFA_MCLOSE + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1744 case NFA_MCLOSE + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1745 case NFA_MCLOSE + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1746 case NFA_MCLOSE + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1747 STRCPY(code, "NFA_MCLOSE(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1748 code[11] = c - NFA_MCLOSE + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1749 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1750 case NFA_EOL: STRCPY(code, "NFA_EOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1751 case NFA_BOL: STRCPY(code, "NFA_BOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1752 case NFA_EOW: STRCPY(code, "NFA_EOW "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1753 case NFA_BOW: STRCPY(code, "NFA_BOW "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1754 case NFA_STAR: STRCPY(code, "NFA_STAR "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1755 case NFA_PLUS: STRCPY(code, "NFA_PLUS "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1756 case NFA_NOT: STRCPY(code, "NFA_NOT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1757 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
1758 case NFA_OR: STRCPY(code, "NFA_OR"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1759 case NFA_QUEST: STRCPY(code, "NFA_QUEST"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1760 case NFA_QUEST_NONGREEDY: STRCPY(code, "NFA_QUEST_NON_GREEDY"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1761 case NFA_END_NEG_RANGE: STRCPY(code, "NFA_END_NEG_RANGE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1762 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
1763 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
1764 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
1765 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
1766 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
1767 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
1768 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
1769 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
1770 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
1771 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
1772 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
1773 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
1774 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
1775 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
1776 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
1777 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
1778
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1779 case NFA_ANY: STRCPY(code, "NFA_ANY"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1780 case NFA_IDENT: STRCPY(code, "NFA_IDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1781 case NFA_SIDENT:STRCPY(code, "NFA_SIDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1782 case NFA_KWORD: STRCPY(code, "NFA_KWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1783 case NFA_SKWORD:STRCPY(code, "NFA_SKWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1784 case NFA_FNAME: STRCPY(code, "NFA_FNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1785 case NFA_SFNAME:STRCPY(code, "NFA_SFNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1786 case NFA_PRINT: STRCPY(code, "NFA_PRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1787 case NFA_SPRINT:STRCPY(code, "NFA_SPRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1788 case NFA_WHITE: STRCPY(code, "NFA_WHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1789 case NFA_NWHITE:STRCPY(code, "NFA_NWHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1790 case NFA_DIGIT: STRCPY(code, "NFA_DIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1791 case NFA_NDIGIT:STRCPY(code, "NFA_NDIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1792 case NFA_HEX: STRCPY(code, "NFA_HEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1793 case NFA_NHEX: STRCPY(code, "NFA_NHEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1794 case NFA_OCTAL: STRCPY(code, "NFA_OCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1795 case NFA_NOCTAL:STRCPY(code, "NFA_NOCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1796 case NFA_WORD: STRCPY(code, "NFA_WORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1797 case NFA_NWORD: STRCPY(code, "NFA_NWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1798 case NFA_HEAD: STRCPY(code, "NFA_HEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1799 case NFA_NHEAD: STRCPY(code, "NFA_NHEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1800 case NFA_ALPHA: STRCPY(code, "NFA_ALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1801 case NFA_NALPHA:STRCPY(code, "NFA_NALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1802 case NFA_LOWER: STRCPY(code, "NFA_LOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1803 case NFA_NLOWER:STRCPY(code, "NFA_NLOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1804 case NFA_UPPER: STRCPY(code, "NFA_UPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1805 case NFA_NUPPER:STRCPY(code, "NFA_NUPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1806
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1807 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1808 STRCPY(code, "CHAR(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1809 code[5] = c;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1812 if (addnl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1813 STRCAT(code, " + NEWLINE ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1814
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1815 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1816
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1817 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1818 static FILE *log_fd;
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1821 * Print the postfix notation of the current regexp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1822 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1823 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1824 nfa_postfix_dump(expr, retval)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1825 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1826 int retval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1827 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1828 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1829 FILE *f;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1830
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
1831 f = fopen(NFA_REGEXP_DUMP_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1832 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1833 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1834 fprintf(f, "\n-------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1835 if (retval == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1836 fprintf(f, ">>> NFA engine failed ... \n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1837 else if (retval == OK)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1838 fprintf(f, ">>> NFA engine succeeded !\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1839 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
1840 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
1841 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1842 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1843 fprintf(f, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1844 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1845 fprintf(f, "\"\nPostfix notation (int): ");
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
1846 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
1847 fprintf(f, "%d ", *p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1848 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1849 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1850 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1851 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1852
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1853 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1854 * Print the NFA starting with a root node "state".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1855 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1856 static void
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1857 nfa_print_state(debugf, state)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1858 FILE *debugf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1859 nfa_state_T *state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1860 {
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1861 garray_T indent;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1862
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1863 ga_init2(&indent, 1, 64);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1864 ga_append(&indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1865 nfa_print_state2(debugf, state, &indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1866 ga_clear(&indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1867 }
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1868
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1869 static void
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1870 nfa_print_state2(debugf, state, indent)
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1871 FILE *debugf;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1872 nfa_state_T *state;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1873 garray_T *indent;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1874 {
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1875 char_u *p;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1876
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1877 if (state == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1878 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1879
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1880 fprintf(debugf, "(%2d)", abs(state->id));
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1881
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1882 /* Output indent */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1883 p = (char_u *)indent->ga_data;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1884 if (indent->ga_len >= 3)
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1885 {
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1886 int last = indent->ga_len - 3;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1887 char_u save[2];
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1888
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1889 STRNCPY(save, &p[last], 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1890 STRNCPY(&p[last], "+-", 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1891 fprintf(debugf, " %s", p);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1892 STRNCPY(&p[last], save, 2);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1893 }
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1894 else
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1895 fprintf(debugf, " %s", p);
4444
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 nfa_set_code(state->c);
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1898 fprintf(debugf, "%s%s (%d) (id=%d)\n",
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1899 state->negated ? "NOT " : "", code, state->c, abs(state->id));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1900 if (state->id < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1901 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1902
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1903 state->id = abs(state->id) * -1;
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1904
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1905 /* grow indent for state->out */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1906 indent->ga_len -= 1;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1907 if (state->out1)
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
1908 ga_concat(indent, (char_u *)"| ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1909 else
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
1910 ga_concat(indent, (char_u *)" ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1911 ga_append(indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1912
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1913 nfa_print_state2(debugf, state->out, indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1914
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1915 /* replace last part of indent for state->out1 */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1916 indent->ga_len -= 3;
4537
5cc98a5898cf updated for version 7.3.1016
Bram Moolenaar <bram@vim.org>
parents: 4535
diff changeset
1917 ga_concat(indent, (char_u *)" ");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1918 ga_append(indent, '\0');
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1919
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1920 nfa_print_state2(debugf, state->out1, indent);
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1921
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1922 /* shrink indent */
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1923 indent->ga_len -= 3;
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1924 ga_append(indent, '\0');
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1925 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1926
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 * Print the NFA state machine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1929 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1930 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1931 nfa_dump(prog)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1932 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1933 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
1934 FILE *debugf = fopen(NFA_REGEXP_DUMP_LOG, "a");
4444
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 (debugf != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1937 {
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
1938 nfa_print_state(debugf, prog->start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1939 fclose(debugf);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1940 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1941 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1942 #endif /* ENABLE_LOG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1943 #endif /* DEBUG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1944
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1945 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1946 * 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
1947 * Return the postfix string on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1948 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1949 static int *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1950 re2post()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1951 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1952 if (nfa_reg(REG_NOPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1953 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1954 EMIT(NFA_MOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1955 return post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1956 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1957
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1958 /* 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
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 * 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
1962 * if c == MATCH, no arrows out; matching state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1963 * 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
1964 * 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
1965 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1966
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1967 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
1968
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1969 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1970 * Allocate and initialize nfa_state_T.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1971 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1972 static nfa_state_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1973 new_state(c, out, out1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1974 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1975 nfa_state_T *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1976 nfa_state_T *out1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1977 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1978 nfa_state_T *s;
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 (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1981 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1982
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1983 s = &state_ptr[istate++];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1984
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1985 s->c = c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1986 s->out = out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1987 s->out1 = out1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1988
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1989 s->id = istate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1990 s->lastlist = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1991 s->negated = FALSE;
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 return s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1994 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1995
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1996 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1997 * 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
1998 * Frag_T.start points at the start state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1999 * 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
2000 * next state for this fragment.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2001 */
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2002
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2003 /* 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
2004 * uninitialized, we use the pointers themselves
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2005 * as storage for the Ptrlists. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2006 typedef union Ptrlist Ptrlist;
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2007 union Ptrlist
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2008 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2009 Ptrlist *next;
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2010 nfa_state_T *s;
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2011 };
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2012
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2013 struct Frag
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2014 {
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
2015 nfa_state_T *start;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2016 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2017 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2018 typedef struct Frag Frag_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2019
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2020 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
2021 static Ptrlist *list1 __ARGS((nfa_state_T **outp));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2022 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
2023 static Ptrlist *append __ARGS((Ptrlist *l1, Ptrlist *l2));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2024 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
2025 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
2026
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2027 /*
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2028 * Initialize a Frag_T struct and return it.
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2029 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2030 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2031 frag(start, out)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2032 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2033 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2034 {
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2035 Frag_T n;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2036
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2037 n.start = start;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2038 n.out = out;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2039 return n;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2040 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2041
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2042 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2043 * Create singleton list containing just outp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2044 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2045 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2046 list1(outp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2047 nfa_state_T **outp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2048 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2049 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2050
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2051 l = (Ptrlist *)outp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2052 l->next = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2053 return l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2054 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2055
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2056 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2057 * 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
2058 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2059 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2060 patch(l, s)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2061 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2062 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2063 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2064 Ptrlist *next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2065
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2066 for (; l; l = next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2067 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2068 next = l->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2069 l->s = s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2070 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2071 }
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2074 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2075 * 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
2076 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2077 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2078 append(l1, l2)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2079 Ptrlist *l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2080 Ptrlist *l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2081 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2082 Ptrlist *oldl1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2083
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2084 oldl1 = l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2085 while (l1->next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2086 l1 = l1->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2087 l1->next = l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2088 return oldl1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2089 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2090
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2091 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2092 * Stack used for transforming postfix form into NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2093 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2094 static Frag_T empty;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2095
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2096 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2097 st_error(postfix, end, p)
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2098 int *postfix UNUSED;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2099 int *end UNUSED;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2100 int *p UNUSED;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2101 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2102 #ifdef NFA_REGEXP_ERROR_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2103 FILE *df;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2104 int *p2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2105
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2106 df = fopen(NFA_REGEXP_ERROR_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2107 if (df)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2108 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2109 fprintf(df, "Error popping the stack!\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2110 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2111 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
2112 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2113 fprintf(df, "Postfix form is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2114 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2115 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2116 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2117 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2118 fprintf(df, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2119 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2120 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2121 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2122 for (p2 = postfix; p2 <= p; p2 ++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2123 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2124 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2125 fprintf(df, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2126 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2127 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2128 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2129 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2130 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2131 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2132 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2133 for (p2 = postfix; p2 <= p; p2 ++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2134 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2135 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2136 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2137 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2138 fprintf(df, "\n--------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2139 fclose(df);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2140 }
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2141 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2142 EMSG(_("E874: (NFA) Could not pop the stack !"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2143 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2144
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2145 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2146 * Push an item onto the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2147 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2148 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2149 st_push(s, p, stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2150 Frag_T s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2151 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2152 Frag_T *stack_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2153 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2154 Frag_T *stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2155
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2156 if (stackp >= stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2157 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2158 *stackp = s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2159 *p = *p + 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2160 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2161
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2162 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2163 * Pop an item from the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2164 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2165 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2166 st_pop(p, stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2167 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2168 Frag_T *stack;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2169 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2170 Frag_T *stackp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2171
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2172 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2173 stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2174 if (stackp < stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2175 return empty;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2176 return **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2177 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2178
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2179 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2180 * Convert a postfix form into its equivalent NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2181 * Return the NFA start state on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2182 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2183 static nfa_state_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2184 post2nfa(postfix, end, nfa_calc_size)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2185 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2186 int *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2187 int nfa_calc_size;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2188 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2189 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2190 int mopen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2191 int mclose;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2192 Frag_T *stack = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2193 Frag_T *stackp = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2194 Frag_T *stack_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2195 Frag_T e1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2196 Frag_T e2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2197 Frag_T e;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2198 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2199 nfa_state_T *s1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2200 nfa_state_T *matchstate;
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2201 nfa_state_T *ret = NULL;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2202
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2203 if (postfix == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2204 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2205
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2206 #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
2207 #define POP() st_pop(&stackp, stack); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2208 if (stackp < stack) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2209 { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2210 st_error(postfix, end, p); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2211 return NULL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2212 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2213
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2214 if (nfa_calc_size == FALSE)
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 /* Allocate space for the stack. Max states on the stack : nstate */
4462
a63361b90979 updated for version 7.3.979
Bram Moolenaar <bram@vim.org>
parents: 4460
diff changeset
2217 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
2218 stackp = stack;
4462
a63361b90979 updated for version 7.3.979
Bram Moolenaar <bram@vim.org>
parents: 4460
diff changeset
2219 stack_end = stack + (nstate + 1);
4444
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 for (p = postfix; p < end; ++p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2223 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2224 switch (*p)
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 case NFA_CONCAT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2227 /* Catenation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2228 * Pay attention: this operator does not exist
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2229 * in the r.e. itself (it is implicit, really).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2230 * It is added when r.e. is translated to postfix
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2231 * form in re2post().
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 * No new state added here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2234 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2235 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2236 /* nstate += 0; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2237 break;
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 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2240 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2241 patch(e1.out, e2.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2242 PUSH(frag(e1.start, e2.out));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2243 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2244
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2245 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2246 /* Negation of a character */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2247 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2248 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2249 /* nstate += 0; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2250 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2251 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2252 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2253 e1.start->negated = TRUE;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2254 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2255 if (e1.start->c == NFA_COMPOSING)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2256 e1.start->out1->negated = TRUE;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2257 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2258 PUSH(e1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2259 break;
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 case NFA_OR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2262 /* Alternation */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2263 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2264 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2265 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2266 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2267 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2268 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2269 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2270 s = new_state(NFA_SPLIT, e1.start, e2.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2271 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2272 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2273 PUSH(frag(s, append(e1.out, e2.out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2274 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2275
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2276 case NFA_STAR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2277 /* Zero or more */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2278 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2279 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2280 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2281 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2282 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2283 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2284 s = new_state(NFA_SPLIT, e.start, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2285 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2286 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2287 patch(e.out, s);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2288 PUSH(frag(s, list1(&s->out1)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2289 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2290
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2291 case NFA_QUEST:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2292 /* one or zero atoms=> greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2293 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2294 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2295 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2296 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2297 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2298 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2299 s = new_state(NFA_SPLIT, e.start, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2300 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2301 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2302 PUSH(frag(s, append(e.out, list1(&s->out1))));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2303 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2304
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2305 case NFA_QUEST_NONGREEDY:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2306 /* zero or one atoms => non-greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2307 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2308 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2309 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2310 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2311 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2312 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2313 s = new_state(NFA_SPLIT, NULL, e.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2314 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2315 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2316 PUSH(frag(s, append(e.out, list1(&s->out))));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2317 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2318
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2319 case NFA_PLUS:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2320 /* One or more */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2321 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2322 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2323 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2324 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2325 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2326 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2327 s = new_state(NFA_SPLIT, e.start, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2328 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2329 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2330 patch(e.out, s);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2331 PUSH(frag(e.start, list1(&s->out1)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2332 break;
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 case NFA_SKIP_CHAR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2335 /* Symbol of 0-length, Used in a repetition
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2336 * with max/min count of 0 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2337 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2338 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2339 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2340 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2341 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2342 s = new_state(NFA_SKIP_CHAR, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2343 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2344 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2345 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2346 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2347
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2348 case NFA_PREV_ATOM_NO_WIDTH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2349 /* The \@= operator: match the preceding atom with 0 width.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2350 * Surrounds the preceding atom with START_INVISIBLE and
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2351 * END_INVISIBLE, similarly to MOPEN.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2352 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2353 /* TODO: Maybe this drops the speed? */
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2354 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2355
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2356 if (nfa_calc_size == TRUE)
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 nstate += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2359 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2360 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2361 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2362 s1 = new_state(NFA_END_INVISIBLE, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2363 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2364 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2365 patch(e.out, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2366
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2367 s = new_state(NFA_START_INVISIBLE, e.start, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2368 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2369 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2370 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2371 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2372
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2373 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2374 case NFA_COMPOSING: /* char with composing char */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2375 #if 0
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2376 /* TODO */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2377 if (regflags & RF_ICOMBINE)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2378 {
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
2379 /* use the base character only */
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2380 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2381 #endif
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2382 /* FALLTHROUGH */
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2383 #endif
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2384
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2385 case NFA_MOPEN + 0: /* Submatch */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2386 case NFA_MOPEN + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2387 case NFA_MOPEN + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2388 case NFA_MOPEN + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2389 case NFA_MOPEN + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2390 case NFA_MOPEN + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2391 case NFA_MOPEN + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2392 case NFA_MOPEN + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2393 case NFA_MOPEN + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2394 case NFA_MOPEN + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2395 case NFA_NOPEN: /* \%( "Invisible Submatch" */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2396 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2397 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2398 nstate += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2399 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2400 }
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 mopen = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2403 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2404 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2405 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2406 mclose = NFA_NCLOSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2407 break;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2408 #ifdef FEAT_MBYTE
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2409 case NFA_COMPOSING:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2410 mclose = NFA_END_COMPOSING;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2411 break;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2412 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2413 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2414 /* NFA_MOPEN(0) ... NFA_MOPEN(9) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2415 mclose = *p + NSUBEXP;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2416 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2417 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2418
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2419 /* Allow "NFA_MOPEN" as a valid postfix representation for
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2420 * 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
2421 * NFA_MOPEN -> NFA_MCLOSE. Note that this also allows
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2422 * empty groups of parenthesis, and empty mbyte chars */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2423 if (stackp == stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2424 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2425 s = new_state(mopen, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2426 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2427 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2428 s1 = new_state(mclose, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2429 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2430 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2431 patch(list1(&s->out), s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2432 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2433 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2434 }
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 /* 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
2437 * 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
2438 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2439 s = new_state(mopen, e.start, NULL); /* `(' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2440 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2441 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2442
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2443 s1 = new_state(mclose, NULL, NULL); /* `)' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2444 if (s1 == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2445 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2446 patch(e.out, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2447
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2448 #ifdef FEAT_MBYTE
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2449 if (mopen == NFA_COMPOSING)
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
2450 /* COMPOSING->out1 = END_COMPOSING */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2451 patch(list1(&s->out1), s1);
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
2452 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2453
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2454 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2455 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2456
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2457 case NFA_BACKREF1:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2458 case NFA_BACKREF2:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2459 case NFA_BACKREF3:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2460 case NFA_BACKREF4:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2461 case NFA_BACKREF5:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2462 case NFA_BACKREF6:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2463 case NFA_BACKREF7:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2464 case NFA_BACKREF8:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2465 case NFA_BACKREF9:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2466 if (nfa_calc_size == TRUE)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2467 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2468 nstate += 2;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2469 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2470 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2471 s = new_state(*p, NULL, NULL);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2472 if (s == NULL)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2473 goto theend;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2474 s1 = new_state(NFA_SKIP, NULL, NULL);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2475 if (s1 == NULL)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2476 goto theend;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2477 patch(list1(&s->out), s1);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2478 PUSH(frag(s, list1(&s1->out)));
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2479 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2480
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2481 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2482 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2483 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2484 /* Operands */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2485 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2486 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2487 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2488 break;
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 s = new_state(*p, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2491 if (s == NULL)
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2492 goto theend;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2493 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2494 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2495
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2496 } /* switch(*p) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2497
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2498 } /* for(p = postfix; *p; ++p) */
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 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2501 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2502 nstate++;
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2503 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
2504 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2505
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2506 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2507 if (stackp != stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2508 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
2509
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2510 if (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2511 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
2512
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2513 matchstate = &state_ptr[istate++]; /* the match state */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2514 matchstate->c = NFA_MATCH;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2515 matchstate->out = matchstate->out1 = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2516
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2517 patch(e.out, matchstate);
4484
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2518 ret = e.start;
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2519
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2520 theend:
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2521 vim_free(stack);
9a1d78f82826 updated for version 7.3.990
Bram Moolenaar <bram@vim.org>
parents: 4482
diff changeset
2522 return ret;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2523
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2524 #undef POP1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2525 #undef PUSH1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2526 #undef POP2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2527 #undef PUSH2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2528 #undef POP
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2529 #undef PUSH
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2530 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2531
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2532 /****************************************************************
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2533 * NFA execution code.
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
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2536 typedef struct
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2537 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2538 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
2539
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2540 /* When REG_MULTI is TRUE multilist is used, otherwise linelist. */
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2541 union
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2542 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2543 struct multipos
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2544 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2545 lpos_T start;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2546 lpos_T end;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2547 } multilist[NSUBEXP];
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2548 struct linepos
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2549 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2550 char_u *start;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2551 char_u *end;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2552 } linelist[NSUBEXP];
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2553 };
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2554 } regsub_T;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2555
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2556 /* 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
2557 typedef struct
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2558 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2559 nfa_state_T *state;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2560 int count;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2561 regsub_T sub; /* submatch info, only party used */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2562 } nfa_thread_T;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2563
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2564 /* 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
2565 typedef struct
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2566 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2567 nfa_thread_T *t; /* allocated array of states */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2568 int n; /* nr of states in "t" */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2569 int id; /* ID of the list */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2570 } nfa_list_T;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2571
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2572 #ifdef ENABLE_LOG
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2573 static void
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2574 log_subexpr(sub)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2575 regsub_T *sub;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2576 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2577 int j;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2578
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2579 for (j = 0; j < sub->in_use; j++)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2580 if (REG_MULTI)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2581 fprintf(log_fd, "\n *** group %d, start: c=%d, l=%d, end: c=%d, l=%d",
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2582 j,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2583 sub->multilist[j].start.col,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2584 (int)sub->multilist[j].start.lnum,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2585 sub->multilist[j].end.col,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2586 (int)sub->multilist[j].end.lnum);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2587 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2588 fprintf(log_fd, "\n *** group %d, start: \"%s\", end: \"%s\"",
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2589 j,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2590 (char *)sub->linelist[j].start,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2591 (char *)sub->linelist[j].end);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2592 fprintf(log_fd, "\n");
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2593 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2594 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2595
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2596 /* 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
2597 static int nfa_match;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2598
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2599 static void addstate __ARGS((nfa_list_T *l, nfa_state_T *state, regsub_T *sub, int off));
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2600 static void addstate_here __ARGS((nfa_list_T *l, nfa_state_T *state, regsub_T *sub, int *ip));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2601
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2602 static void
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2603 addstate(l, state, sub, off)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2604 nfa_list_T *l; /* runtime state list */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2605 nfa_state_T *state; /* state to update */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2606 regsub_T *sub; /* pointers to subexpressions */
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2607 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
2608 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2609 int subidx;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2610 nfa_thread_T *lastthread;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2611 lpos_T save_lpos;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2612 int save_in_use;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2613 char_u *save_ptr;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2614 int i;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2615
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2616 if (l == NULL || state == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2617 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2618
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2619 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2620 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2621 case NFA_SPLIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2622 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2623 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2624 case NFA_NCLOSE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2625 case NFA_MCLOSE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2626 case NFA_MCLOSE + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2627 case NFA_MCLOSE + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2628 case NFA_MCLOSE + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2629 case NFA_MCLOSE + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2630 case NFA_MCLOSE + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2631 case NFA_MCLOSE + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2632 case NFA_MCLOSE + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2633 case NFA_MCLOSE + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2634 case NFA_MCLOSE + 9:
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2635 /* 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
2636 * "out1" may be added below. */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2637 break;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2638
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2639 case NFA_MOPEN:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2640 case NFA_MOPEN + 1:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2641 case NFA_MOPEN + 2:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2642 case NFA_MOPEN + 3:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2643 case NFA_MOPEN + 4:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2644 case NFA_MOPEN + 5:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2645 case NFA_MOPEN + 6:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2646 case NFA_MOPEN + 7:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2647 case NFA_MOPEN + 8:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2648 case NFA_MOPEN + 9:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2649 /* These nodes do not need to be added, but we need to bail out
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2650 * when it was tried to be added to this list before. */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2651 if (state->lastlist == l->id)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2652 return;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2653 state->lastlist = l->id;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2654 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2655
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2656 default:
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2657 if (state->lastlist == l->id)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2658 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2659 /* This state is already in the list, don't add it again,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2660 * unless it is an MOPEN that is used for a backreference. */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2661 return;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2662 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2663
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2664 /* add the state to the list */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2665 state->lastlist = l->id;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2666 lastthread = &l->t[l->n++];
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2667 lastthread->state = state;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2668 lastthread->sub.in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2669 if (sub->in_use > 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2670 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2671 /* Copy the match start and end positions. */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2672 if (REG_MULTI)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2673 mch_memmove(&lastthread->sub.multilist[0],
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2674 &sub->multilist[0],
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2675 sizeof(struct multipos) * sub->in_use);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2676 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2677 mch_memmove(&lastthread->sub.linelist[0],
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2678 &sub->linelist[0],
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2679 sizeof(struct linepos) * sub->in_use);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2680 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2681 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2682
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2683 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2684 nfa_set_code(state->c);
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2685 fprintf(log_fd, "> Adding state %d to list. Character %d: %s\n",
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2686 abs(state->id), state->c, code);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2687 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2688 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2689 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2690 case NFA_MATCH:
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2691 nfa_match = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2692 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2693
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2694 case NFA_SPLIT:
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2695 addstate(l, state->out, sub, off);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2696 addstate(l, state->out1, sub, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2697 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2698
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2699 #if 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2700 case NFA_END_NEG_RANGE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2701 /* Nothing to handle here. nfa_regmatch() will take care of it */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2702 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2703
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2704 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2705 EMSG(_("E999: (NFA regexp internal error) Should not process NOT node !"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2706 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2707 fprintf(f, "\n\n>>> E999: Added state NFA_NOT to a list ... Something went wrong ! Why wasn't it processed already? \n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2708 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2709 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2710
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2711 case NFA_COMPOSING:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2712 /* nfa_regmatch() will match all the bytes of this composing char. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2713 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2714 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2715
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2716 case NFA_SKIP_CHAR:
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2717 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2718 case NFA_NCLOSE:
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2719 addstate(l, state->out, sub, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2720 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2721
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2722 /* If this state is reached, then a recursive call of nfa_regmatch()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2723 * succeeded. the next call saves the found submatches in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2724 * first state after the "invisible" branch. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2725 #if 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2726 case NFA_END_INVISIBLE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2727 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2728 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2729
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2730 case NFA_MOPEN + 0:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2731 case NFA_MOPEN + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2732 case NFA_MOPEN + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2733 case NFA_MOPEN + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2734 case NFA_MOPEN + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2735 case NFA_MOPEN + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2736 case NFA_MOPEN + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2737 case NFA_MOPEN + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2738 case NFA_MOPEN + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2739 case NFA_MOPEN + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2740 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2741 if (state->c == NFA_ZSTART)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2742 subidx = 0;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2743 else
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2744 subidx = state->c - NFA_MOPEN;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2745
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2746 /* Set the position (with "off") in the subexpression. Save and
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2747 * 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
2748 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2749 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2750 if (subidx < sub->in_use)
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2751 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2752 save_lpos = sub->multilist[subidx].start;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2753 save_in_use = -1;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2754 }
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2755 else
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2756 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2757 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2758 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
2759 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2760 sub->multilist[i].start.lnum = -1;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2761 sub->multilist[i].end.lnum = -1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2762 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2763 sub->in_use = subidx + 1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2764 }
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2765 if (off == -1)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2766 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2767 sub->multilist[subidx].start.lnum = reglnum + 1;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2768 sub->multilist[subidx].start.col = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2769 }
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2770 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2771 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2772 sub->multilist[subidx].start.lnum = reglnum;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2773 sub->multilist[subidx].start.col =
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2774 (colnr_T)(reginput - regline + off);
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2775 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2776 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2777 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2778 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2779 if (subidx < sub->in_use)
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2780 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2781 save_ptr = sub->linelist[subidx].start;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2782 save_in_use = -1;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2783 }
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2784 else
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2785 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2786 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2787 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
2788 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2789 sub->linelist[i].start = NULL;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2790 sub->linelist[i].end = NULL;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2791 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2792 sub->in_use = subidx + 1;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2793 }
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2794 sub->linelist[subidx].start = reginput + off;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2795 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2796
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2797 addstate(l, state->out, sub, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2798
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2799 if (save_in_use == -1)
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2800 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2801 if (REG_MULTI)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2802 sub->multilist[subidx].start = save_lpos;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2803 else
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2804 sub->linelist[subidx].start = save_ptr;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2805 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2806 else
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2807 sub->in_use = save_in_use;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2808 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2809
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2810 case NFA_MCLOSE + 0:
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
2811 if (nfa_has_zend)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2812 {
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
2813 /* 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
2814 * encountered end will be set in nfa_regtry(). */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2815 addstate(l, state->out, sub, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2816 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2817 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2818 case NFA_MCLOSE + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2819 case NFA_MCLOSE + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2820 case NFA_MCLOSE + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2821 case NFA_MCLOSE + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2822 case NFA_MCLOSE + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2823 case NFA_MCLOSE + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2824 case NFA_MCLOSE + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2825 case NFA_MCLOSE + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2826 case NFA_MCLOSE + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2827 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2828 if (state->c == NFA_ZEND)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2829 subidx = 0;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2830 else
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2831 subidx = state->c - NFA_MCLOSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2832
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
2833 /* 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
2834 * has done that. */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2835 save_in_use = sub->in_use;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2836 if (sub->in_use <= subidx)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2837 sub->in_use = subidx + 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2838 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2839 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2840 save_lpos = sub->multilist[subidx].end;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2841 if (off == -1)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2842 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2843 sub->multilist[subidx].end.lnum = reglnum + 1;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2844 sub->multilist[subidx].end.col = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2845 }
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2846 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2847 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2848 sub->multilist[subidx].end.lnum = reglnum;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2849 sub->multilist[subidx].end.col =
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
2850 (colnr_T)(reginput - regline + off);
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
2851 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2852 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2853 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2854 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2855 save_ptr = sub->linelist[subidx].end;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2856 sub->linelist[subidx].end = reginput + off;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2857 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2858
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2859 addstate(l, state->out, sub, off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2860
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2861 if (REG_MULTI)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2862 sub->multilist[subidx].end = save_lpos;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2863 else
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2864 sub->linelist[subidx].end = save_ptr;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2865 sub->in_use = save_in_use;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2866 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2867 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2868 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2869
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2870 /*
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2871 * 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
2872 * 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
2873 * 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
2874 * matters for alternatives.
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2875 */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2876 static void
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2877 addstate_here(l, state, sub, ip)
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2878 nfa_list_T *l; /* runtime state list */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2879 nfa_state_T *state; /* state to update */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2880 regsub_T *sub; /* pointers to subexpressions */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2881 int *ip;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2882 {
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2883 int tlen = l->n;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2884 int count;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2885 int i = *ip;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2886
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2887 /* first add the state(s) at the end, so that we know how many there are */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2888 addstate(l, state, sub, 0);
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2889
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2890 /* when "*ip" was at the end of the list, nothing to do */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2891 if (i + 1 == tlen)
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2892 return;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2893
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2894 /* 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
2895 count = l->n - tlen;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2896 if (count > 1)
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2897 {
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2898 /* make space for new states, then move them from the
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2899 * end to the current position */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2900 mch_memmove(&(l->t[i + count]),
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2901 &(l->t[i + 1]),
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2902 sizeof(nfa_thread_T) * (l->n - i - 1));
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2903 mch_memmove(&(l->t[i]),
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2904 &(l->t[l->n - 1]),
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2905 sizeof(nfa_thread_T) * count);
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2906 }
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2907 else
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2908 {
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2909 /* overwrite the current state */
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2910 l->t[i] = l->t[l->n - 1];
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2911 }
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2912 --l->n;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2913 *ip = i - 1;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2914 }
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2915
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
2916 /*
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2917 * Check character class "class" against current character c.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2918 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2919 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2920 check_char_class(class, c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2921 int class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2922 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2923 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2924 switch (class)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2925 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2926 case NFA_CLASS_ALNUM:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2927 if (c >= 1 && c <= 255 && isalnum(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2928 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2929 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2930 case NFA_CLASS_ALPHA:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2931 if (c >= 1 && c <= 255 && isalpha(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2932 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2933 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2934 case NFA_CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2935 if (c == ' ' || c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2936 return OK;
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 case NFA_CLASS_CNTRL:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2939 if (c >= 1 && c <= 255 && iscntrl(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2940 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2941 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2942 case NFA_CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2943 if (VIM_ISDIGIT(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2944 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2945 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2946 case NFA_CLASS_GRAPH:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2947 if (c >= 1 && c <= 255 && isgraph(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2948 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2949 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2950 case NFA_CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2951 if (MB_ISLOWER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2952 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2953 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2954 case NFA_CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2955 if (vim_isprintc(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2956 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2957 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2958 case NFA_CLASS_PUNCT:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2959 if (c >= 1 && c <= 255 && ispunct(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2960 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2961 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2962 case NFA_CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2963 if ((c >=9 && c <= 13) || (c == ' '))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2964 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2965 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2966 case NFA_CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2967 if (MB_ISUPPER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2968 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2969 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2970 case NFA_CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2971 if (vim_isxdigit(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2972 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2973 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2974 case NFA_CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2975 if (c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2976 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2977 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2978 case NFA_CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2979 if (c == '\r')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2980 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2981 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2982 case NFA_CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2983 if (c == '\b')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2984 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2985 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2986 case NFA_CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2987 if (c == '\033')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2988 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2989 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2990
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2991 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2992 /* should not be here :P */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2993 EMSG_RET_FAIL(_("E877: (NFA regexp) Invalid character class "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2994 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2995 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2996 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2997
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2998 static int match_backref __ARGS((regsub_T *sub, int subidx, int *bytelen));
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
2999
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3000 /*
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3001 * Check for a match with subexpression "subidx".
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3002 * return TRUE if it matches.
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3003 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3004 static int
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3005 match_backref(sub, subidx, bytelen)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3006 regsub_T *sub; /* pointers to subexpressions */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3007 int subidx;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3008 int *bytelen; /* out: length of match in bytes */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3009 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3010 int len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3011
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3012 if (sub->in_use <= subidx)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3013 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3014 retempty:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3015 /* backref was not set, match an empty string */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3016 *bytelen = 0;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3017 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3018 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3019
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3020 if (REG_MULTI)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3021 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3022 if (sub->multilist[subidx].start.lnum < 0
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3023 || sub->multilist[subidx].end.lnum < 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3024 goto retempty;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3025 /* TODO: line breaks */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3026 len = sub->multilist[subidx].end.col
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3027 - sub->multilist[subidx].start.col;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3028 if (cstrncmp(regline + sub->multilist[subidx].start.col,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3029 reginput, &len) == 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3030 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3031 *bytelen = len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3032 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3033 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3034 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3035 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3036 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3037 if (sub->linelist[subidx].start == NULL
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3038 || sub->linelist[subidx].end == NULL)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3039 goto retempty;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3040 len = (int)(sub->linelist[subidx].end - sub->linelist[subidx].start);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3041 if (cstrncmp(sub->linelist[subidx].start, reginput, &len) == 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3042 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3043 *bytelen = len;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3044 return TRUE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3045 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3046 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3047 return FALSE;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3048 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3049
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3050 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3051 * Set all NFA nodes' list ID equal to -1.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3052 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3053 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3054 nfa_set_neg_listids(start)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3055 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3056 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3057 if (start != NULL && start->lastlist >= 0)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3058 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3059 start->lastlist = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3060 nfa_set_neg_listids(start->out);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3061 nfa_set_neg_listids(start->out1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3062 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3063 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3064
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3065 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3066 * Set all NFA nodes' list ID equal to 0.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3067 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3068 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3069 nfa_set_null_listids(start)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3070 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3071 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3072 if (start != NULL && start->lastlist == -1)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3073 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3074 start->lastlist = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3075 nfa_set_null_listids(start->out);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3076 nfa_set_null_listids(start->out1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3077 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3078 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3079
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3080 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3081 * Save list IDs for all NFA states in "list".
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 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3084 nfa_save_listids(start, list)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3085 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3086 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3087 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3088 if (start != NULL && start->lastlist != -1)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3089 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3090 list[abs(start->id)] = start->lastlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3091 start->lastlist = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3092 nfa_save_listids(start->out, list);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3093 nfa_save_listids(start->out1, list);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3094 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3095 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3096
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3097 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3098 * Restore list IDs from "list" to all NFA states.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3099 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3100 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3101 nfa_restore_listids(start, list)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3102 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3103 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3104 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3105 if (start != NULL && start->lastlist == -1)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3106 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3107 start->lastlist = list[abs(start->id)];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3108 nfa_restore_listids(start->out, list);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3109 nfa_restore_listids(start->out1, list);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3110 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3111 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3112
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3113 static int nfa_regmatch __ARGS((nfa_state_T *start, regsub_T *submatch, regsub_T *m));
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3114
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3115 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3116 * Main matching routine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3117 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3118 * Run NFA to determine whether it matches reginput.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3119 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3120 * Return TRUE if there is a match, FALSE otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3121 * Note: Caller must ensure that: start != NULL.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3122 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3123 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3124 nfa_regmatch(start, submatch, m)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3125 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3126 regsub_T *submatch;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3127 regsub_T *m;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3128 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3129 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3130 int size = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3131 int flag = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3132 int old_reglnum = -1;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3133 int go_to_nextline = FALSE;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3134 nfa_thread_T *t;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3135 char_u *old_reginput = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3136 char_u *old_regline = NULL;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3137 nfa_list_T list[3];
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3138 nfa_list_T *listtbl[2][2];
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3139 nfa_list_T *ll;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3140 int listid = 1;
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3141 int listidx;
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3142 nfa_list_T *thislist;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3143 nfa_list_T *nextlist;
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3144 nfa_list_T *neglist;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3145 int *listids = NULL;
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
3146 #ifdef NFA_REGEXP_DEBUG_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3147 FILE *debug = fopen(NFA_REGEXP_DEBUG_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3148
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3149 if (debug == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3150 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3151 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
3152 return FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3153 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3154 #endif
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3155 nfa_match = FALSE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3156
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3157 /* Allocate memory for the lists of nodes. */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3158 size = (nstate + 1) * sizeof(nfa_thread_T);
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3159 list[0].t = (nfa_thread_T *)lalloc(size, TRUE);
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3160 list[1].t = (nfa_thread_T *)lalloc(size, TRUE);
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3161 list[2].t = (nfa_thread_T *)lalloc(size, TRUE);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3162 if (list[0].t == NULL || list[1].t == NULL || list[2].t == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3163 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3164 vim_memset(list[0].t, 0, size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3165 vim_memset(list[1].t, 0, size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3166 vim_memset(list[2].t, 0, size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3167
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3168 #ifdef ENABLE_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3169 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3170 if (log_fd != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3171 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3172 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3173 nfa_set_code(start->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3174 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
3175 abs(start->id), code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3176 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3177 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3178 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3179 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3180 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
3181 log_fd = stderr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3182 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3183 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3184
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3185 thislist = &list[0];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3186 thislist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3187 nextlist = &list[1];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3188 nextlist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3189 neglist = &list[2];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3190 neglist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3191 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3192 fprintf(log_fd, "(---) STARTSTATE\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3193 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3194 thislist->id = listid;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3195 addstate(thislist, start, m, 0);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3196
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3197 /* There are two cases when the NFA advances: 1. input char matches the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3198 * NFA node and 2. input char does not match the NFA node, but the next
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3199 * node is NFA_NOT. The following macro calls addstate() according to
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3200 * these rules. It is used A LOT, so use the "listtbl" table for speed */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3201 listtbl[0][0] = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3202 listtbl[0][1] = neglist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3203 listtbl[1][0] = nextlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3204 listtbl[1][1] = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3205 #define ADD_POS_NEG_STATE(node) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3206 ll = listtbl[result ? 1 : 0][node->negated]; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3207 if (ll != NULL) \
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3208 addstate(ll, node->out , &t->sub, clen);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3209
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3210
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3211 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3212 * Run for each character.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3213 */
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3214 for (;;)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3215 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3216 int curc;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3217 int clen;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3218
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3219 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3220 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3221 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3222 curc = (*mb_ptr2char)(reginput);
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3223 clen = (*mb_ptr2len)(reginput);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3224 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3225 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3226 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3227 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3228 curc = *reginput;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3229 clen = 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3230 }
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3231 if (curc == NUL)
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3232 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3233 clen = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3234 go_to_nextline = FALSE;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3235 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3236
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3237 /* swap lists */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3238 thislist = &list[flag];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3239 nextlist = &list[flag ^= 1];
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3240 nextlist->n = 0; /* clear nextlist */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3241 listtbl[1][0] = nextlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3242 ++listid;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3243 thislist->id = listid;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3244 nextlist->id = listid + 1;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3245 neglist->id = listid + 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3246
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3247 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3248 fprintf(log_fd, "------------------------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3249 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
3250 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
3251 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
3252 {
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3253 int i;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3254
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3255 for (i = 0; i < thislist->n; i++)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3256 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
3257 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3258 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3259 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3260
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
3261 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3262 fprintf(debug, "\n-------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3263 #endif
4480
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
3264 /*
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
3265 * 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
3266 */
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
3267 if (thislist->n == 0 && neglist->n == 0)
035fb0d5e7ce updated for version 7.3.988
Bram Moolenaar <bram@vim.org>
parents: 4470
diff changeset
3268 break;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3269
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3270 /* compute nextlist */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3271 for (listidx = 0; listidx < thislist->n || neglist->n > 0; ++listidx)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3272 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3273 if (neglist->n > 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3274 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3275 t = &neglist->t[0];
4468
dde1cf311be6 updated for version 7.3.982
Bram Moolenaar <bram@vim.org>
parents: 4464
diff changeset
3276 neglist->n--;
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3277 listidx--;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3278 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3279 else
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3280 t = &thislist->t[listidx];
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3281
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
3282 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3283 nfa_set_code(t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3284 fprintf(debug, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3285 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3286 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3287 nfa_set_code(t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3288 fprintf(log_fd, "(%d) %s, code %d ... \n", abs(t->state->id),
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3289 code, (int)t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3290 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3291
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3292 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3293 * Handle the possible codes of the current state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3294 * The most important is NFA_MATCH.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3295 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3296 switch (t->state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3297 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3298 case NFA_MATCH:
4567
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
3299 {
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
3300 int j;
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
3301
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3302 nfa_match = TRUE;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3303 submatch->in_use = t->sub.in_use;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3304 if (REG_MULTI)
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3305 for (j = 0; j < submatch->in_use; j++)
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3306 {
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3307 submatch->multilist[j].start =
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3308 t->sub.multilist[j].start;
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3309 submatch->multilist[j].end = t->sub.multilist[j].end;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3310 }
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3311 else
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3312 for (j = 0; j < submatch->in_use; j++)
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3313 {
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3314 submatch->linelist[j].start = t->sub.linelist[j].start;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3315 submatch->linelist[j].end = t->sub.linelist[j].end;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3316 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3317 #ifdef ENABLE_LOG
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3318 log_subexpr(&t->sub);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3319 #endif
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3320 /* 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
3321 * 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
3322 * 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
3323 * correct. */
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
3324 if (nextlist->n == 0 && neglist->n == 0)
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
3325 clen = 0;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3326 goto nextchar;
4567
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
3327 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3328
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3329 case NFA_END_INVISIBLE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3330 /* This is only encountered after a NFA_START_INVISIBLE node.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3331 * They surround a zero-width group, used with "\@=" and "\&".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3332 * 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
3333 * finished successfully, so return control to the parent
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3334 * nfa_regmatch(). Submatches are stored in *m, and used in
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3335 * the parent call. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3336 if (start->c == NFA_MOPEN + 0)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3337 addstate_here(thislist, t->state->out, &t->sub, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3338 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3339 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3340 *m = t->sub;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3341 nfa_match = TRUE;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3342 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3343 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3344
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3345 case NFA_START_INVISIBLE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3346 /* Save global variables, and call nfa_regmatch() to check if
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3347 * the current concat matches at this position. The concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3348 * ends with the node NFA_END_INVISIBLE */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3349 old_reginput = reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3350 old_regline = regline;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3351 old_reglnum = reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3352 if (listids == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3353 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3354 listids = (int *) lalloc(sizeof(int) * nstate, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3355 if (listids == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3356 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3357 EMSG(_("E878: (NFA) Could not allocate memory for branch traversal!"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3358 return 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3359 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3360 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3361 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3362 if (log_fd != stderr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3363 fclose(log_fd);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3364 log_fd = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3365 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3366 /* Have to clear the listid field of the NFA nodes, so that
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3367 * nfa_regmatch() and addstate() can run properly after
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3368 * recursion. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3369 nfa_save_listids(start, listids);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3370 nfa_set_null_listids(start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3371 result = nfa_regmatch(t->state->out, submatch, m);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3372 nfa_set_neg_listids(start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3373 nfa_restore_listids(start, listids);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3374
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3375 #ifdef ENABLE_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3376 log_fd = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3377 if (log_fd != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3378 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3379 fprintf(log_fd, "****************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3380 fprintf(log_fd, "FINISHED RUNNING nfa_regmatch() recursively\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3381 fprintf(log_fd, "MATCH = %s\n", result == TRUE ? "OK" : "FALSE");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3382 fprintf(log_fd, "****************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3383 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3384 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3385 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3386 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
3387 log_fd = stderr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3388 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3389 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3390 if (result == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3391 {
4567
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
3392 int j;
96c1a7850097 updated for version 7.3.1031
Bram Moolenaar <bram@vim.org>
parents: 4565
diff changeset
3393
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3394 /* Restore position in input text */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3395 reginput = old_reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3396 regline = old_regline;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3397 reglnum = old_reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3398 /* Copy submatch info from the recursive call */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3399 if (REG_MULTI)
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3400 for (j = 1; j < m->in_use; j++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3401 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3402 t->sub.multilist[j].start = m->multilist[j].start;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3403 t->sub.multilist[j].end = m->multilist[j].end;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3404 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3405 else
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3406 for (j = 1; j < m->in_use; j++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3407 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3408 t->sub.linelist[j].start = m->linelist[j].start;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3409 t->sub.linelist[j].end = m->linelist[j].end;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3410 }
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3411 t->sub.in_use = m->in_use;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3412
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3413 /* t->state->out1 is the corresponding END_INVISIBLE node */
4539
532c2e850256 updated for version 7.3.1017
Bram Moolenaar <bram@vim.org>
parents: 4537
diff changeset
3414 addstate_here(thislist, t->state->out1->out, &t->sub,
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3415 &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3416 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3417 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3418 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3419 /* continue with next input char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3420 reginput = old_reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3421 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3422 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3423
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3424 case NFA_BOL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3425 if (reginput == regline)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3426 addstate_here(thislist, t->state->out, &t->sub, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3427 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3428
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3429 case NFA_EOL:
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3430 if (curc == NUL)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3431 addstate_here(thislist, t->state->out, &t->sub, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3432 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3433
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3434 case NFA_BOW:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3435 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3436 int bow = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3437
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3438 if (curc == NUL)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3439 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3440 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3441 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3442 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3443 int this_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3445 /* 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
3446 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
3447 if (this_class <= 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3448 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3449 else if (reg_prev_class() == this_class)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3450 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3451 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3452 #endif
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3453 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
3454 || (reginput > regline
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
3455 && vim_iswordc_buf(reginput[-1], reg_buf)))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3456 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3457 if (bow)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3458 addstate_here(thislist, t->state->out, &t->sub, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3459 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3460 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3461
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3462 case NFA_EOW:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3463 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3464 int eow = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3465
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3466 if (reginput == regline)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3467 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3468 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3469 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3470 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3471 int this_class, prev_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3472
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3473 /* 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
3474 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
3475 prev_class = reg_prev_class();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3476 if (this_class == prev_class
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3477 || prev_class == 0 || prev_class == 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3478 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3479 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3480 #endif
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
3481 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
3482 || (reginput[0] != NUL
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3483 && vim_iswordc_buf(curc, reg_buf)))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3484 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3485 if (eow)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3486 addstate_here(thislist, t->state->out, &t->sub, &listidx);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3487 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3488 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3489
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3490 #ifdef FEAT_MBYTE
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3491 case NFA_COMPOSING:
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3492 {
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3493 int mc = curc;
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3494 int len = 0;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3495 nfa_state_T *end;
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3496 nfa_state_T *sta;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3497 int cchars[MAX_MCO];
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3498 int ccount = 0;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3499 int j;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3500
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3501 sta = t->state->out;
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3502 len = 0;
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3503 if (utf_iscomposing(sta->c))
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3504 {
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3505 /* Only match composing character(s), ignore base
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3506 * character. Used for ".{composing}" and "{composing}"
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3507 * (no preceding character). */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3508 len += mb_char2len(mc);
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3509 }
4551
f0c37f5cf4ea updated for version 7.3.1023
Bram Moolenaar <bram@vim.org>
parents: 4549
diff changeset
3510 if (ireg_icombine && len == 0)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3511 {
4535
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3512 /* If \Z was present, then ignore composing characters.
45f97c349537 updated for version 7.3.1015
Bram Moolenaar <bram@vim.org>
parents: 4533
diff changeset
3513 * When ignoring the base character this always matches. */
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3514 /* TODO: How about negated? */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3515 if (len == 0 && sta->c != curc)
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3516 result = FAIL;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3517 else
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3518 result = OK;
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3519 while (sta->c != NFA_END_COMPOSING)
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3520 sta = sta->out;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3521 }
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3522
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3523 /* Check base character matches first, unless ignored. */
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3524 else if (len > 0 || mc == sta->c)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3525 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3526 if (len == 0)
4529
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3527 {
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3528 len += mb_char2len(mc);
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3529 sta = sta->out;
432a6b8c7d93 updated for version 7.3.1012
Bram Moolenaar <bram@vim.org>
parents: 4527
diff changeset
3530 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3531
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3532 /* 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
3533 * Get them into cchars[] first. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3534 while (len < clen)
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3535 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3536 mc = mb_ptr2char(reginput + len);
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3537 cchars[ccount++] = mc;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3538 len += mb_char2len(mc);
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3539 if (ccount == MAX_MCO)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3540 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3541 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3542
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3543 /* 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
3544 * 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
3545 * composing chars are matched. */
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3546 result = OK;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3547 while (sta->c != NFA_END_COMPOSING)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3548 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3549 for (j = 0; j < ccount; ++j)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3550 if (cchars[j] == sta->c)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3551 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3552 if (j == ccount)
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3553 {
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3554 result = FAIL;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3555 break;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3556 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3557 sta = sta->out;
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3558 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3559 }
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3560 else
4525
36ddcf4cecbc updated for version 7.3.1010
Bram Moolenaar <bram@vim.org>
parents: 4517
diff changeset
3561 result = FAIL;
4547
fc997f05cbc7 updated for version 7.3.1021
Bram Moolenaar <bram@vim.org>
parents: 4543
diff changeset
3562
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3563 end = t->state->out1; /* NFA_END_COMPOSING */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3564 ADD_POS_NEG_STATE(end);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3565 break;
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3566 }
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3567 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3568
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3569 case NFA_NEWL:
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
3570 if (curc == NUL && !reg_line_lbr && REG_MULTI
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
3571 && reglnum <= reg_maxline)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3572 {
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3573 go_to_nextline = TRUE;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3574 /* 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
3575 * at the start of the next line. */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3576 addstate(nextlist, t->state->out, &t->sub, -1);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3577 }
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
3578 else if (curc == '\n' && reg_line_lbr)
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
3579 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
3580 /* match \n as if it is an ordinary character */
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3581 addstate(nextlist, t->state->out, &t->sub, 1);
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
3582 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3583 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3584
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3585 case NFA_CLASS_ALNUM:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3586 case NFA_CLASS_ALPHA:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3587 case NFA_CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3588 case NFA_CLASS_CNTRL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3589 case NFA_CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3590 case NFA_CLASS_GRAPH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3591 case NFA_CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3592 case NFA_CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3593 case NFA_CLASS_PUNCT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3594 case NFA_CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3595 case NFA_CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3596 case NFA_CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3597 case NFA_CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3598 case NFA_CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3599 case NFA_CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3600 case NFA_CLASS_ESCAPE:
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3601 result = check_char_class(t->state->c, curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3602 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3603 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3604
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3605 case NFA_END_NEG_RANGE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3606 /* This follows a series of negated nodes, like:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3607 * CHAR(x), NFA_NOT, CHAR(y), NFA_NOT etc. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3608 if (curc > 0)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3609 addstate(nextlist, t->state->out, &t->sub, clen);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3610 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3611
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3612 case NFA_ANY:
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3613 /* 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
3614 if (curc > 0)
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3615 addstate(nextlist, t->state->out, &t->sub, clen);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3616 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3617
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3618 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3619 * 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
3620 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3621 case NFA_IDENT: /* \i */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3622 result = vim_isIDc(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3623 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3624 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3625
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3626 case NFA_SIDENT: /* \I */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3627 result = !VIM_ISDIGIT(curc) && vim_isIDc(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3628 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3629 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3630
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3631 case NFA_KWORD: /* \k */
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
3632 result = vim_iswordp_buf(reginput, reg_buf);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3633 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3634 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3635
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3636 case NFA_SKWORD: /* \K */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3637 result = !VIM_ISDIGIT(curc)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3638 && vim_iswordp_buf(reginput, reg_buf);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3639 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3640 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3641
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3642 case NFA_FNAME: /* \f */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3643 result = vim_isfilec(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3644 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3645 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3646
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3647 case NFA_SFNAME: /* \F */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3648 result = !VIM_ISDIGIT(curc) && vim_isfilec(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3649 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3650 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3651
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3652 case NFA_PRINT: /* \p */
4470
ab5154170c3d updated for version 7.3.983
Bram Moolenaar <bram@vim.org>
parents: 4468
diff changeset
3653 result = ptr2cells(reginput) == 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3654 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3655 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3656
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3657 case NFA_SPRINT: /* \P */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3658 result = !VIM_ISDIGIT(curc) && ptr2cells(reginput) == 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3659 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3660 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3661
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3662 case NFA_WHITE: /* \s */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3663 result = vim_iswhite(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3664 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3665 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3666
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3667 case NFA_NWHITE: /* \S */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3668 result = curc != NUL && !vim_iswhite(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3669 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3670 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3671
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3672 case NFA_DIGIT: /* \d */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3673 result = ri_digit(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3674 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3675 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3676
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3677 case NFA_NDIGIT: /* \D */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3678 result = curc != NUL && !ri_digit(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3679 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3680 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3681
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3682 case NFA_HEX: /* \x */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3683 result = ri_hex(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3684 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3685 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3686
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3687 case NFA_NHEX: /* \X */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3688 result = curc != NUL && !ri_hex(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3689 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3690 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3691
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3692 case NFA_OCTAL: /* \o */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3693 result = ri_octal(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3694 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3695 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3696
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3697 case NFA_NOCTAL: /* \O */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3698 result = curc != NUL && !ri_octal(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3699 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3700 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3701
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3702 case NFA_WORD: /* \w */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3703 result = ri_word(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3704 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3705 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3706
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3707 case NFA_NWORD: /* \W */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3708 result = curc != NUL && !ri_word(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3709 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3710 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3711
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3712 case NFA_HEAD: /* \h */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3713 result = ri_head(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3714 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3715 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3716
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3717 case NFA_NHEAD: /* \H */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3718 result = curc != NUL && !ri_head(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3719 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3720 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3721
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3722 case NFA_ALPHA: /* \a */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3723 result = ri_alpha(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3724 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3725 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3726
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3727 case NFA_NALPHA: /* \A */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3728 result = curc != NUL && !ri_alpha(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3729 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3730 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3731
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3732 case NFA_LOWER: /* \l */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3733 result = ri_lower(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3734 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3735 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3736
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3737 case NFA_NLOWER: /* \L */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3738 result = curc != NUL && !ri_lower(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3739 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3740 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3741
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3742 case NFA_UPPER: /* \u */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3743 result = ri_upper(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3744 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3745 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3746
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3747 case NFA_NUPPER: /* \U */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3748 result = curc != NUL && !ri_upper(curc);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3749 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3750 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3751
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3752 case NFA_BACKREF1:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3753 case NFA_BACKREF2:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3754 case NFA_BACKREF3:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3755 case NFA_BACKREF4:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3756 case NFA_BACKREF5:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3757 case NFA_BACKREF6:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3758 case NFA_BACKREF7:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3759 case NFA_BACKREF8:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3760 case NFA_BACKREF9:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3761 /* \1 .. \9 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3762 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3763 int subidx = t->state->c - NFA_BACKREF1 + 1;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3764 int bytelen;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3765
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3766 result = match_backref(&t->sub, subidx, &bytelen);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3767 if (result)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3768 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3769 if (bytelen == 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3770 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3771 /* empty match always works, add NFA_SKIP with zero to
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3772 * be used next */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3773 addstate_here(thislist, t->state->out, &t->sub,
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3774 &listidx);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3775 thislist->t[listidx + 1].count = 0;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3776 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3777 else if (bytelen <= clen)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3778 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3779 /* match current character, jump ahead to out of
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3780 * NFA_SKIP */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3781 addstate(nextlist, t->state->out->out, &t->sub, clen);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3782 #ifdef ENABLE_LOG
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3783 log_subexpr(&nextlist->t[nextlist->n - 1].sub);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3784 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3785 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3786 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3787 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3788 /* skip ofer the matched characters, set character
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3789 * count in NFA_SKIP */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3790 addstate(nextlist, t->state->out, &t->sub, bytelen);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3791 nextlist->t[nextlist->n - 1].count = bytelen - clen;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3792 #ifdef ENABLE_LOG
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3793 log_subexpr(&nextlist->t[nextlist->n - 1].sub);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3794 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3795 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3796
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3797 }
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3798 break;
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3799 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3800 case NFA_SKIP:
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3801 /* charater of previous matching \1 .. \9 */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3802 if (t->count - clen <= 0)
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3803 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3804 /* end of match, go to what follows */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3805 addstate(nextlist, t->state->out, &t->sub, clen);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3806 #ifdef ENABLE_LOG
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3807 log_subexpr(&nextlist->t[nextlist->n - 1].sub);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3808 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3809 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3810 else
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3811 {
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3812 /* add state again with decremented count */
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3813 addstate(nextlist, t->state, &t->sub, 0);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3814 nextlist->t[nextlist->n - 1].count = t->count - clen;
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3815 #ifdef ENABLE_LOG
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3816 log_subexpr(&nextlist->t[nextlist->n - 1].sub);
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3817 #endif
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3818 }
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3819 break;
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3820
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3821 case NFA_SKIP_CHAR:
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3822 case NFA_ZSTART:
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
3823 case NFA_ZEND:
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3824 /* TODO: should not happen? */
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3825 break;
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3826
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3827 default: /* regular character */
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3828 {
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3829 int c = t->state->c;
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3830
4482
cd005ab15ef3 updated for version 7.3.989
Bram Moolenaar <bram@vim.org>
parents: 4480
diff changeset
3831 /* TODO: put this in #ifdef later */
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3832 if (c < -256)
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3833 EMSGN("INTERNAL: Negative state char: %ld", c);
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3834 if (is_Magic(c))
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3835 c = un_Magic(c);
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3836 result = (c == curc);
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3837
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3838 if (!result && ireg_ic)
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3839 result = MB_TOLOWER(c) == MB_TOLOWER(curc);
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3840 #ifdef FEAT_MBYTE
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3841 /* 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
3842 * 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
3843 * character uses NFA_COMPOSING above. */
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3844 if (result && enc_utf8 && !ireg_icombine
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3845 && clen != utf_char2len(curc))
4527
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3846 result = FALSE;
55bcaa1d2749 updated for version 7.3.1011
Bram Moolenaar <bram@vim.org>
parents: 4525
diff changeset
3847 #endif
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3848 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3849 break;
4559
04086e297563 updated for version 7.3.1027
Bram Moolenaar <bram@vim.org>
parents: 4557
diff changeset
3850 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3851 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3852
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3853 } /* for (thislist = thislist; thislist->state; thislist++) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3854
4557
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
3855 /* 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
3856 * start state to the list of states.
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
3857 * 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
3858 * matters!
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
3859 * 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
3860 * because recursive calls should only start in the first position.
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
3861 * Also don't start a match past the first line. */
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3862 if (nfa_match == FALSE && start->c == NFA_MOPEN + 0
4557
888c12c899e5 updated for version 7.3.1026
Bram Moolenaar <bram@vim.org>
parents: 4555
diff changeset
3863 && reglnum == 0 && clen != 0)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3864 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3865 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3866 fprintf(log_fd, "(---) STARTSTATE\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3867 #endif
4571
b2a8e3a66f8c updated for version 7.3.1033
Bram Moolenaar <bram@vim.org>
parents: 4569
diff changeset
3868 addstate(nextlist, start, m, clen);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3869 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3870
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3871 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3872 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
3873 {
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3874 int i;
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3875
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3876 for (i = 0; i < thislist->n; i++)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3877 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
3878 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3879 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3880 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3881
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3882 nextchar:
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3883 /* 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
3884 * finish. */
4549
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3885 if (clen != 0)
849180347ac3 updated for version 7.3.1022
Bram Moolenaar <bram@vim.org>
parents: 4547
diff changeset
3886 reginput += clen;
4515
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3887 else if (go_to_nextline)
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3888 reg_nextline();
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3889 else
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3890 break;
90e9917d4114 updated for version 7.3.1005
Bram Moolenaar <bram@vim.org>
parents: 4507
diff changeset
3891 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3892
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3893 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3894 if (log_fd != stderr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3895 fclose(log_fd);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3896 log_fd = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3897 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3898
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3899 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3900 /* Free memory */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3901 vim_free(list[0].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3902 vim_free(list[1].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3903 vim_free(list[2].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3904 list[0].t = list[1].t = list[2].t = NULL;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3905 vim_free(listids);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3906 #undef ADD_POS_NEG_STATE
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
3907 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3908 fclose(debug);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3909 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3910
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3911 return nfa_match;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3912 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3913
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3914 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3915 * Try match of "prog" with at regline["col"].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3916 * 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
3917 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3918 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3919 nfa_regtry(start, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3920 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3921 colnr_T col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3922 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3923 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3924 regsub_T sub, m;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3925 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3926 FILE *f;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3927 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3928
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3929 reginput = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3930 need_clear_subexpr = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3931
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3932 #ifdef ENABLE_LOG
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
3933 f = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3934 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3935 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3936 fprintf(f, "\n\n\n\n\n\n\t\t=======================================================\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3937 fprintf(f, " =======================================================\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3938 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3939 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3940 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3941 fprintf(f, "\tInput text is \"%s\" \n", reginput);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3942 fprintf(f, " =======================================================\n\n\n\n\n\n\n");
4533
6a2005efa02b updated for version 7.3.1014
Bram Moolenaar <bram@vim.org>
parents: 4531
diff changeset
3943 nfa_print_state(f, start);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3944 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3945 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3946 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3947 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3948 EMSG(_("Could not open temporary log file for writing "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3949 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3950
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3951 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3952 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3953 /* Use 0xff to set lnum to -1 */
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3954 vim_memset(sub.multilist, 0xff, sizeof(struct multipos) * nfa_nsubexpr);
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3955 vim_memset(m.multilist, 0xff, sizeof(struct multipos) * nfa_nsubexpr);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3956 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3957 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3958 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3959 vim_memset(sub.linelist, 0, sizeof(struct linepos) * nfa_nsubexpr);
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3960 vim_memset(m.linelist, 0, sizeof(struct linepos) * nfa_nsubexpr);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3961 }
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3962 sub.in_use = 0;
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3963 m.in_use = 0;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3964
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3965 if (nfa_regmatch(start, &sub, &m) == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3966 return 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3967
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3968 cleanup_subexpr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3969 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3970 {
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3971 for (i = 0; i < sub.in_use; i++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3972 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3973 reg_startpos[i] = sub.multilist[i].start;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3974 reg_endpos[i] = sub.multilist[i].end;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3975 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3976
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3977 if (reg_startpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3978 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3979 reg_startpos[0].lnum = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3980 reg_startpos[0].col = col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3981 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3982 if (reg_endpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3983 {
4569
f262fb02889d updated for version 7.3.1032
Bram Moolenaar <bram@vim.org>
parents: 4567
diff changeset
3984 /* 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
3985 reg_endpos[0].lnum = reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3986 reg_endpos[0].col = (int)(reginput - regline);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3987 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3988 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3989 /* Use line number of "\ze". */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3990 reglnum = reg_endpos[0].lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3991 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3992 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3993 {
4563
e7016af0cbf9 updated for version 7.3.1029
Bram Moolenaar <bram@vim.org>
parents: 4561
diff changeset
3994 for (i = 0; i < sub.in_use; i++)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3995 {
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3996 reg_startp[i] = sub.linelist[i].start;
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
3997 reg_endp[i] = sub.linelist[i].end;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3998 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3999
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4000 if (reg_startp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4001 reg_startp[0] = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4002 if (reg_endp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4003 reg_endp[0] = reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4004 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4005
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4006 return 1 + reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4007 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4008
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4009 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4010 * 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
4011 * lines ("line" is NULL, use reg_getline()).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4012 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4013 * 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
4014 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4015 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4016 nfa_regexec_both(line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4017 char_u *line;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4018 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4019 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4020 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4021 long retval = 0L;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4022 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4023
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4024 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4025 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4026 prog = (nfa_regprog_T *)reg_mmatch->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4027 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
4028 reg_startpos = reg_mmatch->startpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4029 reg_endpos = reg_mmatch->endpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4030 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4031 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4032 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4033 prog = (nfa_regprog_T *)reg_match->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4034 reg_startp = reg_match->startp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4035 reg_endp = reg_match->endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4036 }
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 /* Be paranoid... */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4039 if (prog == NULL || line == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4040 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4041 EMSG(_(e_null));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4042 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4043 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4044
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4045 /* If the start column is past the maximum column: no need to try. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4046 if (ireg_maxcol > 0 && col >= ireg_maxcol)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4047 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4048
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4049 /* 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
4050 if (prog->regflags & RF_ICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4051 ireg_ic = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4052 else if (prog->regflags & RF_NOICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4053 ireg_ic = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4054
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4055 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4056 /* If pattern contains "\Z" overrule value of ireg_icombine */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4057 if (prog->regflags & RF_ICOMBINE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4058 ireg_icombine = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4059 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4060
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4061 regline = line;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4062 reglnum = 0; /* relative to line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4063
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4064 nfa_has_zend = prog->has_zend;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4065 nfa_nsubexpr = prog->nsubexp;
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4066
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4067 nstate = prog->nstate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4068 for (i = 0; i < nstate; ++i)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4069 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4070 prog->state[i].id = i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4071 prog->state[i].lastlist = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4072 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4073
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4074 retval = nfa_regtry(prog->start, col);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4075
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4076 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4077 return retval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4078 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4079
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4080 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4081 * 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
4082 * 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
4083 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4084 static regprog_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4085 nfa_regcomp(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4086 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4087 int re_flags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4088 {
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4089 nfa_regprog_T *prog = NULL;
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
4090 size_t prog_size;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4091 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4092
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4093 if (expr == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4094 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4095
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4096 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4097 nfa_regengine.expr = expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4098 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4099
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4100 init_class_tab();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4101
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4102 if (nfa_regcomp_start(expr, re_flags) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4103 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4104
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4105 /* 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
4106 * (and count its size). */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4107 postfix = re2post();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4108 if (postfix == NULL)
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4109 {
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4110 /* TODO: only give this error for debugging? */
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4111 if (post_ptr >= post_end)
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4112 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
4113 goto fail; /* Cascaded (syntax?) error */
4555
b2946c06d1b6 updated for version 7.3.1025
Bram Moolenaar <bram@vim.org>
parents: 4553
diff changeset
4114 }
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4115
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4116 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4117 * 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
4118 * 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
4119 * 2. second to emit code
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4120 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4121 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4122 {
4531
1be43c095aff updated for version 7.3.1013
Bram Moolenaar <bram@vim.org>
parents: 4529
diff changeset
4123 FILE *f = fopen(NFA_REGEXP_RUN_LOG, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4124
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4125 if (f != NULL)
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 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
4128 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4129 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4130 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4131 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4132
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4133 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4134 * PASS 1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4135 * 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
4136 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4137 post2nfa(postfix, post_ptr, TRUE);
4541
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4138
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4139 /* Space for compiled regexp */
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4140 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate;
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4141 prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4142 if (prog == NULL)
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4143 goto fail;
80170d61a85c updated for version 7.3.1018
Bram Moolenaar <bram@vim.org>
parents: 4539
diff changeset
4144 vim_memset(prog, 0, prog_size);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4145 state_ptr = prog->state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4146
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4147 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4148 * PASS 2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4149 * Build the NFA
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4150 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4151 prog->start = post2nfa(postfix, post_ptr, FALSE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4152 if (prog->start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4153 goto fail;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4154
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4155 prog->regflags = regflags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4156 prog->engine = &nfa_regengine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4157 prog->nstate = nstate;
4553
7b835b2969af updated for version 7.3.1024
Bram Moolenaar <bram@vim.org>
parents: 4551
diff changeset
4158 prog->has_zend = nfa_has_zend;
4561
4d81fdda8f35 updated for version 7.3.1028
Bram Moolenaar <bram@vim.org>
parents: 4559
diff changeset
4159 prog->nsubexp = regnpar;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4160 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4161 nfa_postfix_dump(expr, OK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4162 nfa_dump(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4163 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4164
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4165 out:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4166 vim_free(post_start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4167 post_start = post_ptr = post_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4168 state_ptr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4169 return (regprog_T *)prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4170
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4171 fail:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4172 vim_free(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4173 prog = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4174 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4175 nfa_postfix_dump(expr, FAIL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4176 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4177 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4178 nfa_regengine.expr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4179 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4180 goto out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4181 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4182
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4183
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4184 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4185 * Match a regexp against a string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4186 * "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
4187 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4188 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4189 * 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
4190 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4191 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4192 nfa_regexec(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4193 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4194 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4195 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4196 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4197 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4198 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4199 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4200 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4201 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4202 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4203 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4204 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4205 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4206 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4207 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4208 return (nfa_regexec_both(line, col) != 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4209 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4210
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4211 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4212 || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4213
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4214 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
4215
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4216 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4217 * 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
4218 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4219 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4220 nfa_regexec_nl(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4221 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4222 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4223 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4224 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4225 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4226 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4227 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4228 reg_line_lbr = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4229 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4230 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4231 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4232 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4233 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4234 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4235 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4236 return (nfa_regexec_both(line, col) != 0);
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 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4239
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4242 * Match a regexp against multiple lines.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4243 * "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
4244 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4245 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4246 * 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
4247 * match otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4248 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4249 * 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
4250 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4251 * ! 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
4252 * 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
4253 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4254 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4255 * |a |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4256 * |b |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4257 * |c |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4258 * | |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4259 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4260 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4261 * then nfa_regexec_multi() returns 3. while the original
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4262 * 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
4263 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4264 * FIXME if this behavior is not compatible.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4265 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4266 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4267 nfa_regexec_multi(rmp, win, buf, lnum, col, tm)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4268 regmmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4269 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
4270 buf_T *buf; /* buffer in which to search */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4271 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
4272 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4273 proftime_T *tm UNUSED; /* timeout limit or NULL */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4274 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4275 reg_match = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4276 reg_mmatch = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4277 reg_buf = buf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4278 reg_win = win;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4279 reg_firstlnum = lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4280 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
4281 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4282 ireg_ic = rmp->rmm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4283 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4284 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4285 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4286 ireg_maxcol = rmp->rmm_maxcol;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4287
4503
e6e60d9da892 updated for version 7.3.999
Bram Moolenaar <bram@vim.org>
parents: 4484
diff changeset
4288 return nfa_regexec_both(NULL, col);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4289 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4290
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4291 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4292 # undef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4293 #endif