annotate src/regexp_nfa.c @ 4470:ab5154170c3d v7.3.983

updated for version 7.3.983 Problem: Uneccessary temp variable. Solution: Remove the variable.
author Bram Moolenaar <bram@vim.org>
date Tue, 21 May 2013 12:43:56 +0200
parents dde1cf311be6
children 035fb0d5e7ce
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9 /* Comment this out to disable log files. They can get pretty big */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 # define ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 # define LOG_NAME "log_nfarun.log"
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
12 # define NFA_REGEXP_DEBUG_LOG
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
13 # define NFA_REGEXP_DEBUG_LOG_NAME "nfa_regexp_debug.log"
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 /* 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
17 #define NFA_BRACES_MAXLIMIT 10
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 /* For allocating space for the postfix representation */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 #define NFA_POSTFIX_MULTIPLIER (NFA_BRACES_MAXLIMIT + 2)*2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 enum
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 NFA_SPLIT = -1024,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 NFA_MATCH,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 NFA_SKIP_CHAR, /* matches a 0-length char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 NFA_END_NEG_RANGE, /* Used when expanding [^ab] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 NFA_CONCAT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 NFA_OR,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 NFA_STAR,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 NFA_PLUS,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 NFA_QUEST,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 NFA_QUEST_NONGREEDY, /* Non-greedy version of \? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 NFA_NOT, /* used for [^ab] negated char ranges */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 NFA_BOL, /* ^ Begin line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 NFA_EOL, /* $ End line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 NFA_BOW, /* \< Begin word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 NFA_EOW, /* \> End word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 NFA_BOF, /* \%^ Begin file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 NFA_EOF, /* \%$ End file */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 NFA_NEWL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 NFA_ZSTART, /* Used for \zs */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 NFA_ZEND, /* Used for \ze */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 NFA_NOPEN, /* Start of subexpression marked with \%( */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 NFA_NCLOSE, /* End of subexpr. marked with \%( ... \) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 NFA_START_INVISIBLE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 NFA_END_INVISIBLE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 NFA_MULTIBYTE, /* Next nodes in NFA are part of the same
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 multibyte char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 NFA_END_MULTIBYTE, /* End of multibyte char in the NFA */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52 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
53 composing multibyte char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 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
55
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 /* 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
57 NFA_PREV_ATOM_NO_WIDTH, /* Used for \@= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 NFA_PREV_ATOM_NO_WIDTH_NEG, /* Used for \@! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 NFA_PREV_ATOM_JUST_BEFORE, /* Used for \@<= */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 NFA_PREV_ATOM_JUST_BEFORE_NEG, /* Used for \@<! */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 NFA_PREV_ATOM_LIKE_PATTERN, /* Used for \@> */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 NFA_MOPEN,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 NFA_MCLOSE = NFA_MOPEN + NSUBEXP,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 /* NFA_FIRST_NL */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 NFA_ANY = NFA_MCLOSE + NSUBEXP, /* Match any one character. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 NFA_ANYOF, /* Match any character in this string. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 NFA_ANYBUT, /* Match any character not in this string. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 NFA_IDENT, /* Match identifier char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 NFA_SIDENT, /* Match identifier char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 NFA_KWORD, /* Match keyword char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 NFA_SKWORD, /* Match word char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 NFA_FNAME, /* Match file name char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 NFA_SFNAME, /* Match file name char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 NFA_PRINT, /* Match printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 NFA_SPRINT, /* Match printable char but no digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 NFA_WHITE, /* Match whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 NFA_NWHITE, /* Match non-whitespace char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 NFA_DIGIT, /* Match digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81 NFA_NDIGIT, /* Match non-digit char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82 NFA_HEX, /* Match hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 NFA_NHEX, /* Match non-hex char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 NFA_OCTAL, /* Match octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 NFA_NOCTAL, /* Match non-octal char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 NFA_WORD, /* Match word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 NFA_NWORD, /* Match non-word char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 NFA_HEAD, /* Match head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 NFA_NHEAD, /* Match non-head char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 NFA_ALPHA, /* Match alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 NFA_NALPHA, /* Match non-alpha char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 NFA_LOWER, /* Match lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 NFA_NLOWER, /* Match non-lowercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 NFA_UPPER, /* Match uppercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 NFA_NUPPER, /* Match non-uppercase char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 NFA_FIRST_NL = NFA_ANY + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 NFA_LAST_NL = NFA_NUPPER + ADD_NL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 /* Character classes [:alnum:] etc */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 NFA_CLASS_ALNUM,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 NFA_CLASS_ALPHA,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 NFA_CLASS_BLANK,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 NFA_CLASS_CNTRL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 NFA_CLASS_DIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 NFA_CLASS_GRAPH,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 NFA_CLASS_LOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 NFA_CLASS_PRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 NFA_CLASS_PUNCT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 NFA_CLASS_SPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 NFA_CLASS_UPPER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 NFA_CLASS_XDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 NFA_CLASS_TAB,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 NFA_CLASS_RETURN,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 NFA_CLASS_BACKSPACE,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 NFA_CLASS_ESCAPE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 /* Keep in sync with classchars. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 static int nfa_classcodes[] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 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
121 NFA_FNAME, NFA_SFNAME, NFA_PRINT, NFA_SPRINT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122 NFA_WHITE, NFA_NWHITE, NFA_DIGIT, NFA_NDIGIT,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 NFA_HEX, NFA_NHEX, NFA_OCTAL, NFA_NOCTAL,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 NFA_WORD, NFA_NWORD, NFA_HEAD, NFA_NHEAD,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 NFA_ALPHA, NFA_NALPHA, NFA_LOWER, NFA_NLOWER,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 NFA_UPPER, NFA_NUPPER
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 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
130
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 * NFA errors can be of 3 types:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 * *** 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
134 * silently and revert the to backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 * syntax_error = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 * *** 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
137 * 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
138 * syntax_error = TRUE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 * *** 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
140 * 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
141 * old backtracking engine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 * syntax_error = FALSE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 * "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
144 * nfa_regcomp() returns FAIL.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 static int syntax_error = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 /* NFA regexp \ze operator encountered. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 static int nfa_has_zend = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 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
152 static int *post_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 static int *post_ptr;
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 static int nstate; /* Number of states in the NFA. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
156 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
157 static int nstate_max; /* Upper bound of estimated number of states. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
160 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
161 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
162 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
163 static void nfa_inc __ARGS((char_u **p));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
164 static void nfa_dec __ARGS((char_u **p));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
165 static int nfa_regatom __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 static int nfa_regpiece __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167 static int nfa_regconcat __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 static int nfa_regbranch __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
169 static int nfa_reg __ARGS((int paren));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
170 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
171 static void nfa_set_code __ARGS((int c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
172 static void nfa_postfix_dump __ARGS((char_u *expr, int retval));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
173 static void nfa_print_state __ARGS((FILE *debugf, nfa_state_T *state, int ident));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
174 static void nfa_dump __ARGS((nfa_regprog_T *prog));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
175 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
176 static int *re2post __ARGS((void));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 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
188 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
189 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
190
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 /* helper functions used when doing re2post() ... regatom() parsing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 #define EMIT(c) do { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
193 if (post_ptr >= post_end) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
194 return FAIL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
195 *post_ptr++ = c; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
196 } while (0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
198 #define EMIT_MBYTE(c) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
199 len = (*mb_char2bytes)(c, buf); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 EMIT(buf[0]); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201 for (i = 1; i < len; i++) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 EMIT(buf[i]); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 EMIT(NFA_CONCAT); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
205 } \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
206 EMIT(NFA_MULTIBYTE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
207
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
208 #define EMIT_COMPOSING_UTF(input) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
209 len = utfc_ptr2len(input); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
210 EMIT(input[0]); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
211 for (i = 1; i < len; i++) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
212 { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 EMIT(input[i]); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214 EMIT(NFA_CONCAT); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 } \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216 EMIT(NFA_COMPOSING);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
217
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
219 * Initialize internal variables before NFA compilation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
220 * Return OK on success, FAIL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
221 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
222 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
223 nfa_regcomp_start(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
224 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
225 int re_flags; /* see vim_regcomp() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
226 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
227 size_t postfix_size;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
229 nstate = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230 istate = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
231 /* A reasonable estimation for size */
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
232 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
233
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
234 /* 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
235 * TODO: some patterns may still fail. */
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
236 nstate_max += 1000;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
237
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
238 /* Size for postfix representation of expr. */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
239 postfix_size = sizeof(*post_start) * nstate_max;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
240
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
241 post_start = (int *)lalloc(postfix_size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
242 if (post_start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
244 vim_memset(post_start, 0, postfix_size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245 post_ptr = post_start;
4454
44b89b025cdf updated for version 7.3.975
Bram Moolenaar <bram@vim.org>
parents: 4450
diff changeset
246 post_end = post_start + nstate_max;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
247 nfa_has_zend = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
248
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
249 regcomp_start(expr, re_flags);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
250
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
251 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
253
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
255 * 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
256 * character class in expanded form. For example [0-9].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
257 * 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
258 * On failure, return 0 (=FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
259 * 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
260 * to the closing brace.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
261 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
262 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
263 nfa_recognize_char_class(start, end, extra_newl)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
264 char_u *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
265 char_u *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
266 int extra_newl;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
268 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
269 /* 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
270 * in the order they are here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
271 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
272 o7 = FALSE, o9 = FALSE, underscore = FALSE, newl = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
273 char_u *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
274 #define NCONFIGS 16
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
275 int classid[NCONFIGS] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
276 NFA_DIGIT, NFA_NDIGIT, NFA_HEX, NFA_NHEX,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
277 NFA_OCTAL, NFA_NOCTAL, NFA_WORD, NFA_NWORD,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
278 NFA_HEAD, NFA_NHEAD, NFA_ALPHA, NFA_NALPHA,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
279 NFA_LOWER, NFA_NLOWER, NFA_UPPER, NFA_NUPPER
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
280 };
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
281 char_u myconfig[10];
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 char_u config[NCONFIGS][9] = {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
283 "000000100", /* digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284 "100000100", /* non digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
285 "011000100", /* hex-digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
286 "111000100", /* non hex-digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
287 "000001000", /* octal-digit */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
288 "100001000", /* [^0-7] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
289 "000110110", /* [0-9A-Za-z_] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
290 "100110110", /* [^0-9A-Za-z_] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291 "000110010", /* head of word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
292 "100110010", /* not head of word */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
293 "000110000", /* alphabetic char a-z */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
294 "100110000", /* non alphabetic char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
295 "000100000", /* lowercase letter */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
296 "100100000", /* non lowercase */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297 "000010000", /* uppercase */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
298 "100010000" /* non uppercase */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
300
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
301 if (extra_newl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
302 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304 if (*end != ']')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306 p = start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
307 if (*p == '^')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
308 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
309 not = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
310 p ++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
311 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
312
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
313 while (p < end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
314 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315 if (p + 2 < end && *(p + 1) == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
316 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
317 switch (*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 case '0':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
320 if (*(p + 2) == '9')
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 o9 = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
323 break;
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 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
326 if (*(p + 2) == '7')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
327 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
328 o7 = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
329 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
330 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
331 case 'a':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
332 if (*(p + 2) == 'z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
333 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
334 az = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
335 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
336 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
337 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 if (*(p + 2) == 'f')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
340 af = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
341 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
342 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 case 'A':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
344 if (*(p + 2) == 'Z')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
345 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
346 AZ = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
347 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
348 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
349 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
350 if (*(p + 2) == 'F')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
351 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
352 AF = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
353 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
354 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
355 /* FALLTHROUGH */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
356 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357 return FAIL;
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 p += 3;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
360 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
361 else if (p + 1 < end && *p == '\\' && *(p + 1) == 'n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
362 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
363 newl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
364 p += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
365 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
366 else if (*p == '_')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
367 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
368 underscore = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
369 p ++;
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 == '\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 ++;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
377 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
378 } /* while (p < end) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
379
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
380 if (p != end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
381 return FAIL;
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 /* build the config that represents the ranges we gathered */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
384 STRCPY(myconfig, "000000000");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
385 if (not == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 myconfig[0] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
387 if (af == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
388 myconfig[1] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
389 if (AF == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
390 myconfig[2] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
391 if (az == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
392 myconfig[3] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
393 if (AZ == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
394 myconfig[4] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
395 if (o7 == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
396 myconfig[5] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
397 if (o9 == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
398 myconfig[6] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
399 if (underscore == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
400 myconfig[7] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
401 if (newl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
402 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
403 myconfig[8] = '1';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
404 extra_newl = ADD_NL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
405 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
406 /* try to recognize character classes */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
407 for (i = 0; i < NCONFIGS; i++)
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
408 if (STRNCMP(myconfig, config[i], 8) == 0)
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
409 return classid[i] + extra_newl;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
410
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
411 /* fallthrough => no success so far */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
412 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
413
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
414 #undef NCONFIGS
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
417 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
418 * Produce the bytes for equivalence class "c".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
419 * Currently only handles latin1, latin9 and utf-8.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
420 * 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
421 * equivalent to 'a OR b OR c'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
422 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
423 * 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
424 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
425 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
426 nfa_emit_equi_class(c, neg)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
427 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
428 int neg;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
429 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
430 int first = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
431 int glue = neg == TRUE ? NFA_CONCAT : NFA_OR;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
432 #define EMIT2(c) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
433 EMIT(c); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
434 if (neg == TRUE) { \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
435 EMIT(NFA_NOT); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
436 } \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
437 if (first == FALSE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
438 EMIT(glue); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
439 else \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
440 first = FALSE; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
441
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
442 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
443 if (enc_utf8 || STRCMP(p_enc, "latin1") == 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
444 || STRCMP(p_enc, "iso-8859-15") == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
445 #endif
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 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
448 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
449 case 'A': case '\300': case '\301': case '\302':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
450 case '\303': case '\304': case '\305':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
451 EMIT2('A'); EMIT2('\300'); EMIT2('\301');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
452 EMIT2('\302'); EMIT2('\303'); EMIT2('\304');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
453 EMIT2('\305');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
454 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
455
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
456 case 'C': case '\307':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
457 EMIT2('C'); EMIT2('\307');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
458 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
459
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460 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
461 EMIT2('E'); EMIT2('\310'); EMIT2('\311');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
462 EMIT2('\312'); EMIT2('\313');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
463 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
464
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
465 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
466 EMIT2('I'); EMIT2('\314'); EMIT2('\315');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
467 EMIT2('\316'); EMIT2('\317');
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 'N': case '\321':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
471 EMIT2('N'); EMIT2('\321');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
472 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
473
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
474 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
475 case '\326':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
476 EMIT2('O'); EMIT2('\322'); EMIT2('\323');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
477 EMIT2('\324'); EMIT2('\325'); EMIT2('\326');
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 'U': case '\331': case '\332': case '\333': case '\334':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
481 EMIT2('U'); EMIT2('\331'); EMIT2('\332');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
482 EMIT2('\333'); EMIT2('\334');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
483 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
484
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
485 case 'Y': case '\335':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
486 EMIT2('Y'); EMIT2('\335');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
487 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
488
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
489 case 'a': case '\340': case '\341': case '\342':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
490 case '\343': case '\344': case '\345':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
491 EMIT2('a'); EMIT2('\340'); EMIT2('\341');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
492 EMIT2('\342'); EMIT2('\343'); EMIT2('\344');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
493 EMIT2('\345');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
494 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
495
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
496 case 'c': case '\347':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
497 EMIT2('c'); EMIT2('\347');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
498 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
499
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
500 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
501 EMIT2('e'); EMIT2('\350'); EMIT2('\351');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
502 EMIT2('\352'); EMIT2('\353');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
503 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
504
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
505 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
506 EMIT2('i'); EMIT2('\354'); EMIT2('\355');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
507 EMIT2('\356'); EMIT2('\357');
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 'n': case '\361':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
511 EMIT2('n'); EMIT2('\361');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
512 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
513
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
514 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
515 case '\366':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
516 EMIT2('o'); EMIT2('\362'); EMIT2('\363');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
517 EMIT2('\364'); EMIT2('\365'); EMIT2('\366');
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 'u': case '\371': case '\372': case '\373': case '\374':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
521 EMIT2('u'); EMIT2('\371'); EMIT2('\372');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
522 EMIT2('\373'); EMIT2('\374');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
523 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
524
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
525 case 'y': case '\375': case '\377':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
526 EMIT2('y'); EMIT2('\375'); EMIT2('\377');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
527 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
528
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
529 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
530 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
531 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
532 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
533
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
534 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
535 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
536 #undef EMIT2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
537 }
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
540 * Code to parse regular expression.
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 * 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
543 * minimize surprise and keep the syntax consistent.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
544 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
545
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
546 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
547 * Increments the pointer "p" by one (multi-byte) character.
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 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
550 nfa_inc(p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
551 char_u **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
552 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
553 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
554 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
555 mb_ptr2char_adv(p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
556 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
557 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
558 *p = *p + 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
559 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
560
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
561 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
562 * Decrements the pointer "p" by one (multi-byte) character.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
563 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
564 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
565 nfa_dec(p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
566 char_u **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
567 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
568 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
569 char_u *p2, *oldp;
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 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
572 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
573 oldp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
574 /* 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
575 * position. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
576 do
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 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
579 p2 = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
580 mb_ptr2char_adv(&p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
581 } while (p2 != oldp);
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 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
584 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
585 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
586 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
587
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
588 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
589 * Parse the lowest level.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
590 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
591 * 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
592 * 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
593 * 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
594 * is only for syntax highlighting.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
595 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
596 * atom ::= ordinary-atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
597 * or \( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
598 * or \%( pattern \)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
599 * or \z( pattern \)
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 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
602 nfa_regatom()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
603 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
604 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
605 int charclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
606 int equiclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
607 int collclass;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
608 int got_coll_char;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
609 char_u *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
610 char_u *endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
611 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
612 char_u *old_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
613 int clen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
614 int len;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
615 static char_u buf[30];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
616 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
617 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
618 int extra = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
619 int first;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
620 int emit_range;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
621 int negated;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
622 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
623 int startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
624 int endc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
625 int oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
626 int cpo_lit; /* 'cpoptions' contains 'l' flag */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
627 int cpo_bsl; /* 'cpoptions' contains '\' flag */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
628 int glue; /* ID that will "glue" nodes together */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
629
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
630 cpo_lit = vim_strchr(p_cpo, CPO_LITERAL) != NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
631 cpo_bsl = vim_strchr(p_cpo, CPO_BACKSL) != NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
632
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
633 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
634
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
635 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
636 /* clen has the length of the current char, without composing chars */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
637 clen = (*mb_char2len)(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
638 if (has_mbyte && clen > 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
639 goto nfa_do_multibyte;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
640 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
641 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
642 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
643 case Magic('^'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
644 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
645 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
646
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
647 case Magic('$'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
648 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
649 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
650 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
651 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
652 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
653
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
654 case Magic('<'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
655 EMIT(NFA_BOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
656 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
657
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
658 case Magic('>'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
659 EMIT(NFA_EOW);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
660 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
661
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
662 case Magic('_'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
663 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
664 if (c == '^') /* "\_^" is start-of-line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
665 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
666 EMIT(NFA_BOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
667 break;
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 if (c == '$') /* "\_$" is end-of-line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
670 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
671 EMIT(NFA_EOL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
672 #if defined(FEAT_SYN_HL) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
673 had_eol = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
674 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
675 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
676 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
677
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
678 extra = ADD_NL;
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 /* "\_[" is collection plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
681 if (c == '[')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
682 /* TODO: make this work
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
683 * goto collection; */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
684 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
685
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
686 /* "\_x" is character class plus newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
687 /*FALLTHROUGH*/
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
688
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
689 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
690 * Character classes.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
691 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
692 case Magic('.'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
693 case Magic('i'):
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('k'):
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('f'):
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('p'):
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('s'):
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('d'):
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('x'):
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('o'):
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('w'):
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('h'):
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('a'):
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('l'):
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('u'):
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 p = vim_strchr(classchars, no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
720 if (p == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
721 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
722 return FAIL; /* runtime error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
723 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
724 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
725 /* 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
726 * the composing char is matched here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
727 if (enc_utf8 && c == Magic('.') && utf_iscomposing(peekchr()))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
728 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
729 c = getchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
730 goto nfa_do_multibyte;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
731 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
732 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
733 EMIT(nfa_classcodes[p - classchars]);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
734 if (extra == ADD_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
735 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
736 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
737 EMIT(NFA_OR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
738 regflags |= RF_HASNL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
739 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
740 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
741
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
742 case Magic('n'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
743 if (reg_string)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
744 /* In a string "\n" matches a newline character. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
745 EMIT(NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
746 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
747 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
748 /* 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
749 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
750 regflags |= RF_HASNL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
751 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
752 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
753
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
754 case Magic('('):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
755 if (nfa_reg(REG_PAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
756 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
757 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
758
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
759 case NUL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
760 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
761 EMSG_RET_FAIL(_("E865: (NFA) Regexp end encountered prematurely"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
762
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 case Magic(')'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
766 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
767 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
768 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
769
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 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
776 /* these should follow an atom, not form an atom */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
777 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
778 EMSGN(_(e_misplaced), no_Magic(c));
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
779 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
780
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
781 case Magic('~'): /* previous substitute pattern */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
782 /* Not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
783 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
784
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
785 case Magic('1'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
786 case Magic('2'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
787 case Magic('3'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
788 case Magic('4'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
789 case Magic('5'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
790 case Magic('6'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
791 case Magic('7'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
792 case Magic('8'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
793 case Magic('9'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
794 /* not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
795 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
796
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
797 case Magic('z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
798 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
799 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
800 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
801 case 's':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
802 EMIT(NFA_ZSTART);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
803 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
804 case 'e':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
805 EMIT(NFA_ZEND);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
806 nfa_has_zend = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
807 /* TODO: Currently \ze does not work properly. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
808 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
809 /* break; */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
810 case '1':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
811 case '2':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
812 case '3':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
813 case '4':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
814 case '5':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
815 case '6':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
816 case '7':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
817 case '8':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
818 case '9':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
819 case '(':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
820 /* \z1...\z9 and \z( not yet supported */
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 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
823 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
824 EMSGN(_("E867: (NFA) Unknown operator '\\z%c'"),
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
825 no_Magic(c));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
826 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
827 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
828 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
829
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
830 case Magic('%'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
831 c = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
832 switch (c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
833 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
834 /* () without a back reference */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
835 case '(':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
836 if (nfa_reg(REG_NPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
837 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
838 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
839 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
840
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
841 case 'd': /* %d123 decimal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
842 case 'o': /* %o123 octal */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
843 case 'x': /* %xab hex 2 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
844 case 'u': /* %uabcd hex 4 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
845 case 'U': /* %U1234abcd hex 8 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
846 /* Not yet supported */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
847 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
848
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
849 c = coll_get_char();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
850 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
851 if ((*mb_char2len)(c) > 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
852 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
853 EMIT_MBYTE(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
854 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
855 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
856 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
857 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
858 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
859
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
860 /* Catch \%^ and \%$ regardless of where they appear in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
861 * pattern -- regardless of whether or not it makes sense. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
862 case '^':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
863 EMIT(NFA_BOF);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
864 /* Not yet supported */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
865 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
866 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
867
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
868 case '$':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
869 EMIT(NFA_EOF);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
870 /* Not yet supported */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
871 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
872 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
873
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
874 case '#':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
875 /* not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
876 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
877 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
878
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
879 case 'V':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
880 /* not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
881 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
882 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
883
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
884 case '[':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
885 /* \%[abc] not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
886 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
887
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
888 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
889 /* not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
890 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
891 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
892 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
893
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
894 /* collection: */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
895 case Magic('['):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
896 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
897 * Glue is emitted between several atoms from the [].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
898 * It is either NFA_OR, or NFA_CONCAT.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
899 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
900 * [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
901 * [^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
902 * 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
903 * notation)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
904 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
905 */
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
908 /* Emit negation atoms, if needed.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
909 * 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
910 #define TRY_NEG() \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
911 if (negated == TRUE) \
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 EMIT(NFA_NOT); \
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
916 /* Emit glue between important nodes : CONCAT or OR. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
917 #define EMIT_GLUE() \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
918 if (first == FALSE) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
919 EMIT(glue); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
920 else \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
921 first = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
922
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
923 p = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
924 endp = skip_anyof(p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
925 if (*endp == ']')
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 * Try to reverse engineer character classes. For example,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
929 * 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
930 * and perform the necessary substitutions in the NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
931 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
932 result = nfa_recognize_char_class(regparse, endp,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
933 extra == ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
934 if (result != FAIL)
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 if (result >= NFA_DIGIT && result <= NFA_NUPPER)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
937 EMIT(result);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
938 else /* must be char class + newline */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
939 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
940 EMIT(result - ADD_NL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
941 EMIT(NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
942 EMIT(NFA_OR);
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 regparse = endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
945 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
946 return OK;
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 * Failed to recognize a character class. Use the simple
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
950 * 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
951 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
952 startc = endc = oldstartc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
953 first = TRUE; /* Emitting first atom in this sequence? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
954 negated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
955 glue = NFA_OR;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
956 if (*regparse == '^') /* negated range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
957 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
958 negated = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
959 glue = NFA_CONCAT;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
960 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
961 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
962 if (*regparse == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
963 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
964 startc = '-';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
965 EMIT(startc);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
966 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
967 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
968 nfa_inc(&regparse);
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 /* Emit the OR branches for each character in the [] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
971 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
972 while (regparse < endp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
973 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
974 oldstartc = startc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
975 startc = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
976 got_coll_char = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
977 if (*regparse == '[')
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 /* Check for [: :], [= =], [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
980 equiclass = collclass = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
981 charclass = get_char_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
982 if (charclass == CLASS_NONE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
983 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
984 equiclass = get_equi_class(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
985 if (equiclass == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
986 collclass = get_coll_element(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
987 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
988
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
989 /* Character class like [:alpha:] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
990 if (charclass != CLASS_NONE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
991 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
992 switch (charclass)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
993 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
994 case CLASS_ALNUM:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
995 EMIT(NFA_CLASS_ALNUM);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
996 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
997 case CLASS_ALPHA:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
998 EMIT(NFA_CLASS_ALPHA);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
999 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1000 case CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1001 EMIT(NFA_CLASS_BLANK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1002 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1003 case CLASS_CNTRL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1004 EMIT(NFA_CLASS_CNTRL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1005 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1006 case CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1007 EMIT(NFA_CLASS_DIGIT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1008 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1009 case CLASS_GRAPH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1010 EMIT(NFA_CLASS_GRAPH);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1011 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1012 case CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1013 EMIT(NFA_CLASS_LOWER);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1014 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1015 case CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1016 EMIT(NFA_CLASS_PRINT);
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_PUNCT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1019 EMIT(NFA_CLASS_PUNCT);
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_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1022 EMIT(NFA_CLASS_SPACE);
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_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1025 EMIT(NFA_CLASS_UPPER);
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_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1028 EMIT(NFA_CLASS_XDIGIT);
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_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1031 EMIT(NFA_CLASS_TAB);
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_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1034 EMIT(NFA_CLASS_RETURN);
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_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1037 EMIT(NFA_CLASS_BACKSPACE);
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_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1040 EMIT(NFA_CLASS_ESCAPE);
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 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1043 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1044 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1045 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1046 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1047 /* Try equivalence class [=a=] and the like */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1048 if (equiclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1049 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1050 result = nfa_emit_equi_class(equiclass, negated);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1051 if (result == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1052 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1053 /* should never happen */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1054 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
1055 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1056 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1057 continue;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1058 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1059 /* Try collating class like [. .] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1060 if (collclass != 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1061 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1062 startc = collclass; /* allow [.a.]-x as a range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1063 /* 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
1064 * while loop. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1065 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1066 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1067 /* Try a range like 'a-x' or '\t-z' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1068 if (*regparse == '-')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1069 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1070 emit_range = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1071 startc = oldstartc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1072 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1073 continue; /* reading the end of the range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1074 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1075
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1076 /* Now handle simple and escaped characters.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1077 * Only "\]", "\^", "\]" and "\\" are special in Vi. Vim
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1078 * 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
1079 * 'cpoptions' is not included.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1080 * Posix doesn't recognize backslash at all.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1081 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1082 if (*regparse == '\\'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1083 && !cpo_bsl
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1084 && regparse + 1 <= endp
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1085 && (vim_strchr(REGEXP_INRANGE, regparse[1]) != NULL
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1086 || (!cpo_lit
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1087 && vim_strchr(REGEXP_ABBR, regparse[1])
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1088 != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1089 )
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 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1092 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1093
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1094 if (*regparse == 'n' || *regparse == 'n')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1095 startc = reg_string ? NL : NFA_NEWL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1096 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1097 if (*regparse == 'd'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1098 || *regparse == 'o'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1099 || *regparse == 'x'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1100 || *regparse == 'u'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1101 || *regparse == 'U'
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 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1104 /* TODO(RE) This needs more testing */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1105 startc = coll_get_char();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1106 got_coll_char = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1107 nfa_dec(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1108 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1109 else
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 /* \r,\t,\e,\b */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1112 startc = backslash_trans(*regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1113 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1114 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1115
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1116 /* Normal printable char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1117 if (startc == -1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1118 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1119 startc = (*mb_ptr2char)(regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1120 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1121 startc = *regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1122 #endif
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 /* 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
1125 if (emit_range)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1126 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1127 endc = startc; startc = oldstartc;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1128 if (startc > endc)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1129 EMSG_RET_FAIL(_(e_invrange));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1130 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1131 if (has_mbyte && ((*mb_char2len)(startc) > 1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1132 || (*mb_char2len)(endc) > 1))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1133 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1134 if (endc > startc + 256)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1135 EMSG_RET_FAIL(_(e_invrange));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1136 /* Emit the range. "startc" was already emitted, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1137 * skip it. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1138 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1139 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1140 if ((*mb_char2len)(c) > 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1141 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1142 EMIT_MBYTE(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1143 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1144 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1145 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1146 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1147 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1148 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1149 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1150 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1151 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1152 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1153 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1154 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1155 int alpha_only = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1156
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1157 /* for alphabetical range skip the gaps
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1158 * 'i'-'j', 'r'-'s', 'I'-'J' and 'R'-'S'. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1159 if (isalpha(startc) && isalpha(endc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1160 alpha_only = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1161 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1162 /* Emit the range. "startc" was already emitted, so
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1163 * skip it. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1164 for (c = startc + 1; c <= endc; c++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1165 #ifdef EBCDIC
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1166 if (!alpha_only || isalpha(startc))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1167 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1168 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1169 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1170 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1171 EMIT_GLUE();
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 emit_range = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1174 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1175 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1176 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1177 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1178 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1179 * 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
1180 * emit it.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1181 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1182 * Normally, simply emit startc. But if we get char
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1183 * 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
1184 * 0x0a.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1185 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1186 * This is needed to completely mimic the behaviour of
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1187 * the backtracking engine.
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 if (got_coll_char == TRUE && startc == 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1190 EMIT(0x0a);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1191 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1192 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1193 if ((*mb_char2len)(startc) > 1)
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 EMIT_MBYTE(startc);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1196 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1197 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1198 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1199 EMIT(startc);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1200 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1201 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1202 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1203
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1204 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1205 } /* while (p < endp) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1206
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1207 nfa_dec(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1208 if (*regparse == '-') /* if last, '-' is just a char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1209 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1210 EMIT('-');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1211 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1212 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1213 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1214 nfa_inc(&regparse);
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 if (extra == ADD_NL) /* \_[] also matches \n */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1217 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1218 EMIT(reg_string ? NL : NFA_NEWL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1219 TRY_NEG();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1220 EMIT_GLUE();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1221 }
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 /* skip the trailing ] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1224 regparse = endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1225 nfa_inc(&regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1226 if (negated == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1227 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1228 /* Mark end of negated char range */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1229 EMIT(NFA_END_NEG_RANGE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1230 EMIT(NFA_CONCAT);
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 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1233 } /* if exists closing ] */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1234 else if (reg_strict)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1235 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1236 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1237 EMSG_RET_FAIL(_(e_missingbracket));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1238 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1239
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1240 /* FALLTHROUGH */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1241 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1242 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1243 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1244 int plen;
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 nfa_do_multibyte:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1247 /* length of current char, with composing chars,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1248 * from pointer */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1249 plen = (*mb_ptr2len)(old_regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1250 if (enc_utf8 && clen != plen)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1251 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1252 /* A composing character is always handled as a
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1253 * separate atom, surrounded by NFA_COMPOSING and
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1254 * NFA_END_COMPOSING. Note that right now we are
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1255 * building the postfix form, not the NFA itself;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1256 * a composing char could be: a, b, c, NFA_COMPOSING
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1257 * where 'a', 'b', 'c' are chars with codes > 256.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1258 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1259 EMIT_COMPOSING_UTF(old_regparse);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1260 regparse = old_regparse + plen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1261 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1262 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1263 /* A multi-byte character is always handled as a
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1264 * separate atom, surrounded by NFA_MULTIBYTE and
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1265 * NFA_END_MULTIBYTE */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1266 if (plen > 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1267 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1268 EMIT_MBYTE(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1269 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1270 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1271 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1272 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1273 c = no_Magic(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1274 EMIT(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1275 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1276 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1277 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1278 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1279
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1280 #undef TRY_NEG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1281 #undef EMIT_GLUE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1282
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1283 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1284 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1285
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1286 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1287 * Parse something followed by possible [*+=].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1288 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1289 * 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
1290 * 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
1291 * characters: "", "a", "aa", etc.
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 * piece ::= atom
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1294 * or atom multi
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1295 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1296 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1297 nfa_regpiece()
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 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1300 int op;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1301 int ret;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1302 long minval, maxval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1303 int greedy = TRUE; /* Braces are prefixed with '-' ? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1304 char_u *old_regparse, *new_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1305 int c2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1306 int *old_post_ptr, *my_post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1307 int old_regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1308 int quest;
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 /* 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
1311 * <atom>{m,n} is next. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1312 old_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1313 /* 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
1314 * <atom>{m,n} is next */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1315 old_regnpar = regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1316 /* 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
1317 my_post_start = post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1318
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1319 ret = nfa_regatom();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1320 if (ret == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1321 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1322
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1323 op = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1324 if (re_multi_type(op) == NOT_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1325 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1326
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1327 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1328 switch (op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1329 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1330 case Magic('*'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1331 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1332 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1333
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1334 case Magic('+'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1335 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1336 * 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
1337 * 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
1338 * 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
1339 * 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
1340 * string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1341 * The submatch will the empty string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1342 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1343 * 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
1344 * NFA_PLUS, and replace <atom>+ with <atom><atom>*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1345 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1346 /* EMIT(NFA_PLUS); */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1347 regnpar = old_regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1348 regparse = old_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1349 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1350 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1351 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1352 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1353 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1354 skipchr(); /* skip the \+ */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1355 break;
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 case Magic('@'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1358 op = no_Magic(getchr());
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1359 switch(op)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1360 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1361 case '=':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1362 EMIT(NFA_PREV_ATOM_NO_WIDTH);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1363 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1364 case '!':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1365 case '<':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1366 case '>':
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1367 /* Not supported yet */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1368 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1369 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1370 syntax_error = TRUE;
4450
09e1e574a52d updated for version 7.3.973
Bram Moolenaar <bram@vim.org>
parents: 4444
diff changeset
1371 EMSGN(_("E869: (NFA) Unknown operator '\\@%c'"), op);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1372 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1373 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1374 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1375
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1376 case Magic('?'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1377 case Magic('='):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1378 EMIT(NFA_QUEST);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1379 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1380
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1381 case Magic('{'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1382 /* a{2,5} will expand to 'aaa?a?a?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1383 * 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
1384 * version of '?'
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1385 * \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
1386 * parenthesis have the same id
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1389 greedy = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1390 c2 = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1391 if (c2 == '-' || c2 == Magic('-'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1392 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1393 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1394 greedy = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1395 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1396 if (!read_limits(&minval, &maxval))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1397 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1398 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1399 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
1400 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1401 /* <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
1402 * <atom>* */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1403 if (minval == 0 && maxval == MAX_LIMIT && greedy)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1404 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1405 EMIT(NFA_STAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1406 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1407 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1408
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1409 if (maxval > NFA_BRACES_MAXLIMIT)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1410 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1411 /* 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
1412 * Revert to old engine */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1413 return FAIL;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1416 /* Special case: x{0} or x{-0} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1417 if (maxval == 0)
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 /* Ignore result of previous call to nfa_regatom() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1420 post_ptr = my_post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1421 /* NFA_SKIP_CHAR has 0-length and works everywhere */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1422 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1423 return OK;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1426 /* Ignore previous call to nfa_regatom() */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1427 post_ptr = my_post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1428 /* Save pos after the repeated atom and the \{} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1429 new_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1430
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1431 new_regparse = regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1432 quest = (greedy == TRUE? NFA_QUEST : NFA_QUEST_NONGREEDY);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1433 for (i = 0; i < maxval; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1434 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1435 /* Goto beginning of the repeated atom */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1436 regparse = old_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1437 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1438 /* Restore count of parenthesis */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1439 regnpar = old_regnpar;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1440 old_post_ptr = post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1441 if (nfa_regatom() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1442 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1443 /* after "minval" times, atoms are optional */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1444 if (i + 1 > minval)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1445 EMIT(quest);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1446 if (old_post_ptr != my_post_start)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1447 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1448 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1449
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1450 /* Go to just after the repeated atom and the \{} */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1451 regparse = new_regparse;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1452 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1453
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1454 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1455
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1456
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1457 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1458 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1459 } /* end switch */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1460
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1461 if (re_multi_type(peekchr()) != NOT_MULTI)
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 /* Can't have a multi follow a multi. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1464 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1465 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
1466 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1467
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1468 return OK;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1471 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1472 * 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
1473 * 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
1474 * "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
1475 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1476 * concat ::= piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1477 * or piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1478 * or piece piece piece
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1479 * etc.
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 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1482 nfa_regconcat()
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 int cont = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1485 int first = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1486
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1487 while (cont)
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 switch (peekchr())
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1490 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1491 case NUL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1492 case Magic('|'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1493 case Magic('&'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1494 case Magic(')'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1495 cont = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1496 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1497
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1498 case Magic('Z'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1499 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1500 regflags |= RF_ICOMBINE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1501 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1502 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1503 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1504 case Magic('c'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1505 regflags |= RF_ICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1506 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1507 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1508 case Magic('C'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1509 regflags |= RF_NOICASE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1510 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1511 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1512 case Magic('v'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1513 reg_magic = MAGIC_ALL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1514 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1515 curchr = -1;
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('m'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1518 reg_magic = MAGIC_ON;
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 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1521 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1522 case Magic('M'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1523 reg_magic = MAGIC_OFF;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1524 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1525 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1526 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1527 case Magic('V'):
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1528 reg_magic = MAGIC_NONE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1529 skipchr_keepstart();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1530 curchr = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1531 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1532
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1533 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1534 if (nfa_regpiece() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1535 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1536 if (first == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1537 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1538 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1539 first = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1540 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1541 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1542 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1543
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1544 return OK;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1547 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1548 * 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
1549 * 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
1550 * position. Examples:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1551 * "foobeep\&..." matches "foo" in "foobeep".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1552 * ".*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
1553 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1554 * branch ::= concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1555 * or concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1556 * or concat \& concat \& concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1557 * etc.
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 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1560 nfa_regbranch()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1561 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1562 int ch;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1563 int *old_post_ptr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1564
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1565 old_post_ptr = post_ptr;
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 /* First branch, possibly the only one */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1568 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1569 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1570
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1571 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1572 /* Try next concats */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1573 while (ch == Magic('&'))
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 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1576 EMIT(NFA_NOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1577 EMIT(NFA_PREV_ATOM_NO_WIDTH);
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 if (nfa_regconcat() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1580 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1581 /* 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
1582 if (old_post_ptr == post_ptr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1583 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1584 EMIT(NFA_CONCAT);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1585 ch = peekchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1586 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1587
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1588 /* 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
1589 if (old_post_ptr == post_ptr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1590 EMIT(NFA_SKIP_CHAR);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1591
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1592 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1593 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1594
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1595 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1596 * 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
1597 * 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
1598 * "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
1599 * is used.
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 * pattern ::= branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1602 * or branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1603 * or branch \| branch \| branch
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1604 * etc.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1605 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1606 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1607 nfa_reg(paren)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1608 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
1609 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1610 int parno = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1611
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1612 #ifdef FEAT_SYN_HL
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1613 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1614 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1615 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1616 if (regnpar >= NSUBEXP) /* Too many `(' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1617 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1618 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1619 EMSG_RET_FAIL(_("E872: (NFA regexp) Too many '('"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1620 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1621 parno = regnpar++;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1624 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1625 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1626
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1627 while (peekchr() == Magic('|'))
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 skipchr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1630 if (nfa_regbranch() == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1631 return FAIL; /* cascaded error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1632 EMIT(NFA_OR);
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1635 /* Check for proper termination. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1636 if (paren != REG_NOPAREN && getchr() != Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1637 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1638 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1639 if (paren == REG_NPAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1640 EMSG2_RET_FAIL(_(e_unmatchedpp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1641 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1642 EMSG2_RET_FAIL(_(e_unmatchedp), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1643 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1644 else if (paren == REG_NOPAREN && peekchr() != NUL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1645 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1646 syntax_error = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1647 if (peekchr() == Magic(')'))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1648 EMSG2_RET_FAIL(_(e_unmatchedpar), reg_magic == MAGIC_ALL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1649 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1650 EMSG_RET_FAIL(_("E873: (NFA regexp) proper termination error"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1651 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1652 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1653 * 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
1654 * parentheses.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1655 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1656 if (paren == REG_PAREN)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1657 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1658 had_endbrace[parno] = TRUE; /* have seen the close paren */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1659 EMIT(NFA_MOPEN + parno);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1660 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1661
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1662 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1663 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1664
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1665 typedef struct
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1666 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1667 char_u *start[NSUBEXP];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1668 char_u *end[NSUBEXP];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1669 lpos_T startpos[NSUBEXP];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1670 lpos_T endpos[NSUBEXP];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1671 } regsub_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1672
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1673 static int nfa_regmatch __ARGS((nfa_state_T *start, regsub_T *submatch, regsub_T *m));
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 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1676 static char_u code[50];
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 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1679 nfa_set_code(c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1680 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1681 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1682 int addnl = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1683
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1684 if (c >= NFA_FIRST_NL && c <= NFA_LAST_NL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1685 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1686 addnl = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1687 c -= ADD_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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1690 STRCPY(code, "");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1691 switch (c)
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 case NFA_MATCH: STRCPY(code, "NFA_MATCH "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1694 case NFA_SPLIT: STRCPY(code, "NFA_SPLIT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1695 case NFA_CONCAT: STRCPY(code, "NFA_CONCAT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1696 case NFA_NEWL: STRCPY(code, "NFA_NEWL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1697 case NFA_ZSTART: STRCPY(code, "NFA_ZSTART"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1698 case NFA_ZEND: STRCPY(code, "NFA_ZEND"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1699
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1700 case NFA_PREV_ATOM_NO_WIDTH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1701 STRCPY(code, "NFA_PREV_ATOM_NO_WIDTH"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1702 case NFA_NOPEN: STRCPY(code, "NFA_MOPEN_INVISIBLE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1703 case NFA_NCLOSE: STRCPY(code, "NFA_MCLOSE_INVISIBLE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1704 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
1705 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
1706
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1707 case NFA_MULTIBYTE: STRCPY(code, "NFA_MULTIBYTE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1708 case NFA_END_MULTIBYTE: STRCPY(code, "NFA_END_MULTIBYTE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1709
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1710 case NFA_COMPOSING: STRCPY(code, "NFA_COMPOSING"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1711 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
1712
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1713 case NFA_MOPEN + 0:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1714 case NFA_MOPEN + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1715 case NFA_MOPEN + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1716 case NFA_MOPEN + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1717 case NFA_MOPEN + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1718 case NFA_MOPEN + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1719 case NFA_MOPEN + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1720 case NFA_MOPEN + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1721 case NFA_MOPEN + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1722 case NFA_MOPEN + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1723 STRCPY(code, "NFA_MOPEN(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1724 code[10] = c - NFA_MOPEN + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1725 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1726 case NFA_MCLOSE + 0:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1727 case NFA_MCLOSE + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1728 case NFA_MCLOSE + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1729 case NFA_MCLOSE + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1730 case NFA_MCLOSE + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1731 case NFA_MCLOSE + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1732 case NFA_MCLOSE + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1733 case NFA_MCLOSE + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1734 case NFA_MCLOSE + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1735 case NFA_MCLOSE + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1736 STRCPY(code, "NFA_MCLOSE(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1737 code[11] = c - NFA_MCLOSE + '0';
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1738 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1739 case NFA_EOL: STRCPY(code, "NFA_EOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1740 case NFA_BOL: STRCPY(code, "NFA_BOL "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1741 case NFA_EOW: STRCPY(code, "NFA_EOW "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1742 case NFA_BOW: STRCPY(code, "NFA_BOW "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1743 case NFA_STAR: STRCPY(code, "NFA_STAR "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1744 case NFA_PLUS: STRCPY(code, "NFA_PLUS "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1745 case NFA_NOT: STRCPY(code, "NFA_NOT "); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1746 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
1747 case NFA_OR: STRCPY(code, "NFA_OR"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1748 case NFA_QUEST: STRCPY(code, "NFA_QUEST"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1749 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
1750 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
1751 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
1752 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
1753 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
1754 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
1755 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
1756 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
1757 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
1758 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
1759 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
1760 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
1761 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
1762 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
1763 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
1764 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
1765 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
1766 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
1767
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1768 case NFA_ANY: STRCPY(code, "NFA_ANY"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1769 case NFA_IDENT: STRCPY(code, "NFA_IDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1770 case NFA_SIDENT:STRCPY(code, "NFA_SIDENT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1771 case NFA_KWORD: STRCPY(code, "NFA_KWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1772 case NFA_SKWORD:STRCPY(code, "NFA_SKWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1773 case NFA_FNAME: STRCPY(code, "NFA_FNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1774 case NFA_SFNAME:STRCPY(code, "NFA_SFNAME"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1775 case NFA_PRINT: STRCPY(code, "NFA_PRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1776 case NFA_SPRINT:STRCPY(code, "NFA_SPRINT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1777 case NFA_WHITE: STRCPY(code, "NFA_WHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1778 case NFA_NWHITE:STRCPY(code, "NFA_NWHITE"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1779 case NFA_DIGIT: STRCPY(code, "NFA_DIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1780 case NFA_NDIGIT:STRCPY(code, "NFA_NDIGIT"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1781 case NFA_HEX: STRCPY(code, "NFA_HEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1782 case NFA_NHEX: STRCPY(code, "NFA_NHEX"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1783 case NFA_OCTAL: STRCPY(code, "NFA_OCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1784 case NFA_NOCTAL:STRCPY(code, "NFA_NOCTAL"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1785 case NFA_WORD: STRCPY(code, "NFA_WORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1786 case NFA_NWORD: STRCPY(code, "NFA_NWORD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1787 case NFA_HEAD: STRCPY(code, "NFA_HEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1788 case NFA_NHEAD: STRCPY(code, "NFA_NHEAD"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1789 case NFA_ALPHA: STRCPY(code, "NFA_ALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1790 case NFA_NALPHA:STRCPY(code, "NFA_NALPHA"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1791 case NFA_LOWER: STRCPY(code, "NFA_LOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1792 case NFA_NLOWER:STRCPY(code, "NFA_NLOWER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1793 case NFA_UPPER: STRCPY(code, "NFA_UPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1794 case NFA_NUPPER:STRCPY(code, "NFA_NUPPER"); break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1795
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1796 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1797 STRCPY(code, "CHAR(x)");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1798 code[5] = c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1799 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1800
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1801 if (addnl == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1802 STRCAT(code, " + NEWLINE ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1803
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1804 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1805
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1806 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1807 static FILE *log_fd;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1808
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1809 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1810 * Print the postfix notation of the current regexp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1811 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1812 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1813 nfa_postfix_dump(expr, retval)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1814 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1815 int retval;
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 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1818 FILE *f;
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 f = fopen("LOG.log", "a");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1821 if (f != NULL)
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 fprintf(f, "\n-------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1824 if (retval == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1825 fprintf(f, ">>> NFA engine failed ... \n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1826 else if (retval == OK)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1827 fprintf(f, ">>> NFA engine succeeded !\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1828 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
1829 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
1830 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1831 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1832 fprintf(f, "%s, ", code);
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, "\"\nPostfix notation (int): ");
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
1835 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
1836 fprintf(f, "%d ", *p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1837 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1838 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1839 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1840 }
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1843 * Print the NFA starting with a root node "state".
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 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1846 nfa_print_state(debugf, state, ident)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1847 FILE *debugf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1848 nfa_state_T *state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1849 int ident;
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 int i;
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 if (state == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1854 return;
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 fprintf(debugf, "(%2d)", abs(state->id));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1857 for (i = 0; i < ident; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1858 fprintf(debugf, "%c", ' ');
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1859
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1860 nfa_set_code(state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1861 fprintf(debugf, "%s %s (%d) (id=%d)\n",
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1862 state->negated ? "NOT" : "", code, state->c, abs(state->id));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1863 if (state->id < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1864 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1865
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1866 state->id = abs(state->id) * -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1867 nfa_print_state(debugf, state->out, ident + 4);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1868 nfa_print_state(debugf, state->out1, ident + 4);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1869 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1870
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1871 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1872 * Print the NFA state machine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1873 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1874 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1875 nfa_dump(prog)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1876 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1877 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1878 FILE *debugf = fopen("LOG.log", "a");
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 if (debugf != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1881 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1882 nfa_print_state(debugf, prog->start, 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1883 fclose(debugf);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1884 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1885 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1886 #endif /* ENABLE_LOG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1887 #endif /* DEBUG */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1888
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1889 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1890 * 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
1891 * Return the postfix string on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1892 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1893 static int *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1894 re2post()
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1895 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1896 if (nfa_reg(REG_NOPAREN) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1897 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1898 EMIT(NFA_MOPEN);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1899 return post_start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1900 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1901
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1902 /* 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
1903
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1904 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1905 * 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
1906 * if c == MATCH, no arrows out; matching state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1907 * 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
1908 * 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
1909 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1910
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1911 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
1912
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1913 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1914 * Allocate and initialize nfa_state_T.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1915 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1916 static nfa_state_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1917 new_state(c, out, out1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1918 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1919 nfa_state_T *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1920 nfa_state_T *out1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1921 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1922 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1923
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1924 if (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1925 return NULL;
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 s = &state_ptr[istate++];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1928
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1929 s->c = c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1930 s->out = out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1931 s->out1 = out1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1932
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1933 s->id = istate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1934 s->lastlist = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1935 s->lastthread = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1936 s->visits = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1937 s->negated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1938
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1939 return s;
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1943 * 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
1944 * Frag_T.start points at the start state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1945 * 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
1946 * next state for this fragment.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1947 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1948 typedef union Ptrlist Ptrlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1949 struct Frag
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1950 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1951 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1952 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1953 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1954 typedef struct Frag Frag_T;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1955
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1956 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
1957 static Ptrlist *list1 __ARGS((nfa_state_T **outp));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1958 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
1959 static Ptrlist *append __ARGS((Ptrlist *l1, Ptrlist *l2));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1960 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
1961 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
1962
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1963 /*
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
1964 * Initialize a Frag_T struct and return it.
4444
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 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1967 frag(start, out)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1968 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1969 Ptrlist *out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1970 {
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
1971 Frag_T n;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
1972
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
1973 n.start = start;
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
1974 n.out = out;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1975 return n;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1976 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1977
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1978 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1979 * Since the out pointers in the list are always
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1980 * uninitialized, we use the pointers themselves
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1981 * as storage for the Ptrlists.
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 union Ptrlist
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 Ptrlist *next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1986 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1987 };
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1990 * Create singleton list containing just outp.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1991 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1992 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1993 list1(outp)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1994 nfa_state_T **outp;
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 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1997
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1998 l = (Ptrlist *)outp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1999 l->next = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2000 return l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2001 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2002
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2003 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2004 * 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
2005 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2006 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2007 patch(l, s)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2008 Ptrlist *l;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2009 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2010 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2011 Ptrlist *next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2012
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2013 for (; l; l = next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2014 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2015 next = l->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2016 l->s = s;
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 }
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2021 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2022 * 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
2023 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2024 static Ptrlist *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2025 append(l1, l2)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2026 Ptrlist *l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2027 Ptrlist *l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2028 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2029 Ptrlist *oldl1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2030
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2031 oldl1 = l1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2032 while (l1->next)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2033 l1 = l1->next;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2034 l1->next = l2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2035 return oldl1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2036 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2037
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2038 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2039 * Stack used for transforming postfix form into NFA.
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 static Frag_T empty;
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 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2044 st_error(postfix, end, p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2045 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2046 int *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2047 int *p;
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 FILE *df;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2050 int *p2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2051
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2052 df = fopen("stack.err", "a");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2053 if (df)
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 fprintf(df, "Error popping the stack!\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2056 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2057 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
2058 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2059 fprintf(df, "Postfix form is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2060 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2061 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2062 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2063 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2064 fprintf(df, "%s, ", code);
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 nfa_set_code(*p);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2067 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2068 for (p2 = postfix; p2 <= p; p2 ++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2069 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2070 nfa_set_code(*p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2071 fprintf(df, "%s, ", code);
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 #else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2074 for (p2 = postfix; p2 < end; p2++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2075 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2076 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2077 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2078 fprintf(df, "\nCurrent position is: ");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2079 for (p2 = postfix; p2 <= p; p2 ++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2080 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2081 fprintf(df, "%d, ", *p2);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2082 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2083 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2084 fprintf(df, "\n--------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2085 fclose(df);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2086 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2087 EMSG(_("E874: (NFA) Could not pop the stack !"));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2088 }
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 * Push an item onto the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2092 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2093 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2094 st_push(s, p, stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2095 Frag_T s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2096 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2097 Frag_T *stack_end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2098 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2099 Frag_T *stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2100
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2101 if (stackp >= stack_end)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2102 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2103 *stackp = s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2104 *p = *p + 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2105 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2106
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2107 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2108 * Pop an item from the stack.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2109 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2110 static Frag_T
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2111 st_pop(p, stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2112 Frag_T **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2113 Frag_T *stack;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2114 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2115 Frag_T *stackp;
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 *p = *p - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2118 stackp = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2119 if (stackp < stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2120 return empty;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2121 return **p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2122 }
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 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2125 * Convert a postfix form into its equivalent NFA.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2126 * Return the NFA start state on success, NULL otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2127 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2128 static nfa_state_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2129 post2nfa(postfix, end, nfa_calc_size)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2130 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2131 int *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2132 int nfa_calc_size;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2133 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2134 int *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2135 int mopen;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2136 int mclose;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2137 Frag_T *stack = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2138 Frag_T *stackp = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2139 Frag_T *stack_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2140 Frag_T e1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2141 Frag_T e2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2142 Frag_T e;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2143 nfa_state_T *s;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2144 nfa_state_T *s1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2145 nfa_state_T *matchstate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2146
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2147 if (postfix == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2148 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2149
4456
015a8fabf900 updated for version 7.3.976
Bram Moolenaar <bram@vim.org>
parents: 4454
diff changeset
2150 #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
2151 #define POP() st_pop(&stackp, stack); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2152 if (stackp < stack) \
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 st_error(postfix, end, p); \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2155 return NULL; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2156 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2157
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2158 if (nfa_calc_size == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2159 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2160 /* 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
2161 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
2162 stackp = stack;
4462
a63361b90979 updated for version 7.3.979
Bram Moolenaar <bram@vim.org>
parents: 4460
diff changeset
2163 stack_end = stack + (nstate + 1);
4444
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2166 for (p = postfix; p < end; ++p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2167 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2168 switch (*p)
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 case NFA_CONCAT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2171 /* Catenation.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2172 * Pay attention: this operator does not exist
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2173 * in the r.e. itself (it is implicit, really).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2174 * 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
2175 * form in re2post().
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2176 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2177 * No new state added here. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2178 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2179 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2180 /* nstate += 0; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2181 break;
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 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2184 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2185 patch(e1.out, e2.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2186 PUSH(frag(e1.start, e2.out));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2187 break;
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 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2190 /* Negation of a character */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2191 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2192 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2193 /* nstate += 0; */
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2194 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2195 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2196 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2197 e1.start->negated = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2198 if (e1.start->c == NFA_MULTIBYTE || e1.start->c == NFA_COMPOSING)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2199 e1.start->out1->negated = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2200 PUSH(e1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2201 break;
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 case NFA_OR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2204 /* Alternation */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2205 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2206 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2207 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2208 break;
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 e2 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2211 e1 = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2212 s = new_state(NFA_SPLIT, e1.start, e2.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2213 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2214 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2215 PUSH(frag(s, append(e1.out, e2.out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2216 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2217
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2218 case NFA_STAR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2219 /* Zero or more */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2220 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2221 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2222 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2223 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2224 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2225 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2226 s = new_state(NFA_SPLIT, e.start, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2227 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2228 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2229 patch(e.out, s);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2230 PUSH(frag(s, list1(&s->out1)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2231 break;
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 case NFA_QUEST:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2234 /* one or zero atoms=> greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2235 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2236 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2237 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2238 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2239 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2240 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2241 s = new_state(NFA_SPLIT, e.start, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2242 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2243 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2244 PUSH(frag(s, append(e.out, list1(&s->out1))));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2245 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2246
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2247 case NFA_QUEST_NONGREEDY:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2248 /* zero or one atoms => non-greedy match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2249 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2250 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2251 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2252 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2253 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2254 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2255 s = new_state(NFA_SPLIT, NULL, e.start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2256 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2257 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2258 PUSH(frag(s, append(e.out, list1(&s->out))));
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_PLUS:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2262 /* One or more */
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 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2269 s = new_state(NFA_SPLIT, e.start, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2270 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2271 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2272 patch(e.out, s);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2273 PUSH(frag(e.start, list1(&s->out1)));
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_SKIP_CHAR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2277 /* Symbol of 0-length, Used in a repetition
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2278 * with max/min count of 0 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2279 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2280 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2281 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2282 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2283 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2284 s = new_state(NFA_SKIP_CHAR, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2285 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2286 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2287 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2288 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2289
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2290 case NFA_PREV_ATOM_NO_WIDTH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2291 /* The \@= operator: match the preceding atom with 0 width.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2292 * Surrounds the preceding atom with START_INVISIBLE and
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2293 * END_INVISIBLE, similarly to MOPEN.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2294 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2295 /* TODO: Maybe this drops the speed? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2296 return NULL;
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 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2299 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2300 nstate += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2301 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2302 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2303 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2304 s1 = new_state(NFA_END_INVISIBLE, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2305 if (s1 == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2306 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2307 patch(e.out, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2308
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2309 s = new_state(NFA_START_INVISIBLE, e.start, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2310 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2311 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2312 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2313 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2314
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2315 case NFA_MOPEN + 0: /* Submatch */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2316 case NFA_MOPEN + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2317 case NFA_MOPEN + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2318 case NFA_MOPEN + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2319 case NFA_MOPEN + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2320 case NFA_MOPEN + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2321 case NFA_MOPEN + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2322 case NFA_MOPEN + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2323 case NFA_MOPEN + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2324 case NFA_MOPEN + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2325 case NFA_NOPEN: /* \%( "Invisible Submatch" */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2326 case NFA_MULTIBYTE: /* mbyte char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2327 case NFA_COMPOSING: /* composing char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2328 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2329 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2330 nstate += 2;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2331 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2332 }
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 mopen = *p;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2335 switch (*p)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2336 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2337 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2338 mclose = NFA_NCLOSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2339 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2340 case NFA_MULTIBYTE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2341 mclose = NFA_END_MULTIBYTE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2342 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2343 case NFA_COMPOSING:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2344 mclose = NFA_END_COMPOSING;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2345 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2346 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2347 /* NFA_MOPEN(0) ... NFA_MOPEN(9) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2348 mclose = *p + NSUBEXP;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2349 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2350 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2351
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2352 /* Allow "NFA_MOPEN" as a valid postfix representation for
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2353 * 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
2354 * NFA_MOPEN -> NFA_MCLOSE. Note that this also allows
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2355 * empty groups of parenthesis, and empty mbyte chars */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2356 if (stackp == stack)
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 s = new_state(mopen, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2359 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2360 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2361 s1 = new_state(mclose, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2362 if (s1 == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2363 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2364 patch(list1(&s->out), s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2365 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2366 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2367 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2368
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2369 /* 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
2370 * 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
2371 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2372 s = new_state(mopen, e.start, NULL); /* `(' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2373 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2374 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2375
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2376 s1 = new_state(mclose, NULL, NULL); /* `)' */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2377 if (s1 == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2378 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2379 patch(e.out, s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2380
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2381 if (mopen == NFA_MULTIBYTE || mopen == NFA_COMPOSING)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2382 /* MULTIBYTE->out1 = END_MULTIBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2383 * COMPOSING->out1 = END_COMPOSING */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2384 patch(list1(&s->out1), s1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2385
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2386 PUSH(frag(s, list1(&s1->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2387 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2388
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2389 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2390 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2391 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2392 /* Operands */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2393 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2394 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2395 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2396 break;
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 s = new_state(*p, NULL, NULL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2399 if (s == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2400 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2401 PUSH(frag(s, list1(&s->out)));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2402 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2403
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2404 } /* switch(*p) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2405
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2406 } /* for(p = postfix; *p; ++p) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2407
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2408 if (nfa_calc_size == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2409 {
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2410 nstate++;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2411 return NULL; /* Return value when counting size is ignored anyway */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2412 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2413
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2414 e = POP();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2415 if (stackp != stack)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2416 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
2417
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2418 if (istate >= nstate)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2419 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
2420
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2421 vim_free(stack);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2422
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2423 matchstate = &state_ptr[istate++]; /* the match state */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2424 matchstate->c = NFA_MATCH;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2425 matchstate->out = matchstate->out1 = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2426
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2427 patch(e.out, matchstate);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2428 return e.start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2429
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2430 #undef POP1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2431 #undef PUSH1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2432 #undef POP2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2433 #undef PUSH2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2434 #undef POP
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2435 #undef PUSH
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2436 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2437
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2438 /****************************************************************
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2439 * NFA execution code.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2440 ****************************************************************/
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2441
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2442 /* thread_T contains runtime information of a NFA state */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2443 struct thread
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2444 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2445 nfa_state_T *state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2446 regsub_T sub; /* submatch info */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2447 };
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2448
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2449 typedef struct
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2450 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2451 thread_T *t;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2452 int n;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2453 } List;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2454
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2455 static void addstate __ARGS((List *l, nfa_state_T *state, regsub_T *m, int off, int lid, int *match));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2456
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2457 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2458 addstate(l, state, m, off, lid, match)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2459 List *l; /* runtime state list */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2460 nfa_state_T *state; /* state to update */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2461 regsub_T *m; /* pointers to subexpressions */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2462 int off;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2463 int lid;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2464 int *match; /* found match? */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2465 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2466 regsub_T save;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2467 int subidx = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2468
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2469 if (l == NULL || state == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2470 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2471
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2472 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2473 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2474 case NFA_SPLIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2475 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2476 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2477 case NFA_NCLOSE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2478 case NFA_MCLOSE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2479 case NFA_MCLOSE + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2480 case NFA_MCLOSE + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2481 case NFA_MCLOSE + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2482 case NFA_MCLOSE + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2483 case NFA_MCLOSE + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2484 case NFA_MCLOSE + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2485 case NFA_MCLOSE + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2486 case NFA_MCLOSE + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2487 case NFA_MCLOSE + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2488 /* Do not remember these nodes in list "thislist" or "nextlist" */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2489 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2490
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2491 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2492 if (state->lastlist == lid)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2493 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2494 if (++state->visits > 2)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2495 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2496 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2497 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2498 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2499 /* add the state to the list */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2500 state->lastlist = lid;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2501 state->lastthread = &l->t[l->n++];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2502 state->lastthread->state = state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2503 state->lastthread->sub = *m;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2507 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2508 nfa_set_code(state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2509 fprintf(log_fd, "> Adding state %d to list. Character %s, code %d\n",
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2510 abs(state->id), code, state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2511 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2512 switch (state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2513 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2514 case NFA_MATCH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2515 *match = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2516 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2517
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2518 case NFA_SPLIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2519 addstate(l, state->out, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2520 addstate(l, state->out1, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2521 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2522
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2523 case NFA_SKIP_CHAR:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2524 addstate(l, state->out, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2525 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2526
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2527 #if 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2528 case NFA_END_NEG_RANGE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2529 /* 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
2530 break;
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 case NFA_NOT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2533 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
2534 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2535 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
2536 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2537 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2538
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2539 case NFA_COMPOSING:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2540 /* 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
2541 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2542
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2543 case NFA_MULTIBYTE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2544 /* nfa_regmatch() will match all the bytes of this multibyte char. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2545 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2546 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2547
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2548 case NFA_END_MULTIBYTE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2549 /* Successfully matched this mbyte char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2550 addstate(l, state->out, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2551 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2552
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2553 case NFA_NOPEN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2554 case NFA_NCLOSE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2555 addstate(l, state->out, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2556 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2557
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2558 /* 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
2559 * 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
2560 * first state after the "invisible" branch. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2561 #if 0
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2562 case NFA_END_INVISIBLE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2563 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2564 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2565
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2566 case NFA_MOPEN + 0:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2567 case NFA_MOPEN + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2568 case NFA_MOPEN + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2569 case NFA_MOPEN + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2570 case NFA_MOPEN + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2571 case NFA_MOPEN + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2572 case NFA_MOPEN + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2573 case NFA_MOPEN + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2574 case NFA_MOPEN + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2575 case NFA_MOPEN + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2576 case NFA_ZSTART:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2577 subidx = state->c - NFA_MOPEN;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2578 if (state->c == NFA_ZSTART)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2579 subidx = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2580
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2581 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2582 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2583 save.startpos[subidx] = m->startpos[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2584 save.endpos[subidx] = m->endpos[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2585 m->startpos[subidx].lnum = reglnum;
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2586 m->startpos[subidx].col = (colnr_T)(reginput - regline + off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2587 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2588 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2589 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2590 save.start[subidx] = m->start[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2591 save.end[subidx] = m->end[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2592 m->start[subidx] = reginput + off;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2593 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2594
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2595 addstate(l, state->out, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2596
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2597 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2598 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2599 m->startpos[subidx] = save.startpos[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2600 m->endpos[subidx] = save.endpos[subidx];
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 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2603 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2604 m->start[subidx] = save.start[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2605 m->end[subidx] = save.end[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2606 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2607 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2608
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2609 case NFA_MCLOSE + 0:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2610 if (nfa_has_zend == TRUE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2611 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2612 addstate(l, state->out, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2613 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2614 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2615 case NFA_MCLOSE + 1:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2616 case NFA_MCLOSE + 2:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2617 case NFA_MCLOSE + 3:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2618 case NFA_MCLOSE + 4:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2619 case NFA_MCLOSE + 5:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2620 case NFA_MCLOSE + 6:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2621 case NFA_MCLOSE + 7:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2622 case NFA_MCLOSE + 8:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2623 case NFA_MCLOSE + 9:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2624 case NFA_ZEND:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2625 subidx = state->c - NFA_MCLOSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2626 if (state->c == NFA_ZEND)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2627 subidx = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2628
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2629 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2630 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2631 save.startpos[subidx] = m->startpos[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2632 save.endpos[subidx] = m->endpos[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2633 m->endpos[subidx].lnum = reglnum;
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
2634 m->endpos[subidx].col = (colnr_T)(reginput - regline + off);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2635 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2636 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2637 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2638 save.start[subidx] = m->start[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2639 save.end[subidx] = m->end[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2640 m->end[subidx] = reginput + off;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2641 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2642
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2643 addstate(l, state->out, m, off, lid, match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2644
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2645 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2646 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2647 m->startpos[subidx] = save.startpos[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2648 m->endpos[subidx] = save.endpos[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2649 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2650 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2651 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2652 m->start[subidx] = save.start[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2653 m->end[subidx] = save.end[subidx];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2654 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2655 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2656 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2657 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2658
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2659 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2660 * Check character class "class" against current character c.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2661 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2662 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2663 check_char_class(class, c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2664 int class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2665 int c;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2666 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2667 switch (class)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2668 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2669 case NFA_CLASS_ALNUM:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2670 if (c >= 1 && c <= 255 && isalnum(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2671 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2672 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2673 case NFA_CLASS_ALPHA:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2674 if (c >= 1 && c <= 255 && isalpha(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2675 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2676 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2677 case NFA_CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2678 if (c == ' ' || c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2679 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2680 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2681 case NFA_CLASS_CNTRL:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2682 if (c >= 1 && c <= 255 && iscntrl(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2683 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2684 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2685 case NFA_CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2686 if (VIM_ISDIGIT(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2687 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2688 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2689 case NFA_CLASS_GRAPH:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2690 if (c >= 1 && c <= 255 && isgraph(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2691 return OK;
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 case NFA_CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2694 if (MB_ISLOWER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2695 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2696 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2697 case NFA_CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2698 if (vim_isprintc(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2699 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2700 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2701 case NFA_CLASS_PUNCT:
4464
c83656c9745a updated for version 7.3.980
Bram Moolenaar <bram@vim.org>
parents: 4462
diff changeset
2702 if (c >= 1 && c <= 255 && ispunct(c))
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2703 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2704 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2705 case NFA_CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2706 if ((c >=9 && c <= 13) || (c == ' '))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2707 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2708 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2709 case NFA_CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2710 if (MB_ISUPPER(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2711 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2712 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2713 case NFA_CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2714 if (vim_isxdigit(c))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2715 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2716 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2717 case NFA_CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2718 if (c == '\t')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2719 return OK;
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 case NFA_CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2722 if (c == '\r')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2723 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2724 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2725 case NFA_CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2726 if (c == '\b')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2727 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2728 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2729 case NFA_CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2730 if (c == '\033')
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2731 return OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2732 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2733
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2734 default:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2735 /* should not be here :P */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2736 EMSG_RET_FAIL(_("E877: (NFA regexp) Invalid character class "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2737 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2738 return FAIL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2739 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2740
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2741 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2742 * Set all NFA nodes' list ID equal to -1.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2743 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2744 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2745 nfa_set_neg_listids(start)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2746 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2747 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2748 if (start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2749 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2750 if (start->lastlist >= 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2751 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2752 start->lastlist = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2753 nfa_set_neg_listids(start->out);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2754 nfa_set_neg_listids(start->out1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2755 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2756 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2757
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2758 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2759 * Set all NFA nodes' list ID equal to 0.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2760 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2761 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2762 nfa_set_null_listids(start)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2763 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2764 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2765 if (start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2766 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2767 if (start->lastlist == -1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2768 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2769 start->lastlist = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2770 nfa_set_null_listids(start->out);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2771 nfa_set_null_listids(start->out1);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2772 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2773 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2774
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2775 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2776 * Save list IDs for all NFA states in "list".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2777 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2778 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2779 nfa_save_listids(start, list)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2780 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2781 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2782 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2783 if (start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2784 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2785 if (start->lastlist != -1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2786 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2787 list[abs(start->id)] = start->lastlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2788 start->lastlist = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2789 nfa_save_listids(start->out, list);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2790 nfa_save_listids(start->out1, list);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2791 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2792 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2793
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2794 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2795 * Restore list IDs from "list" to all NFA states.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2796 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2797 static void
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2798 nfa_restore_listids(start, list)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2799 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2800 int *list;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2801 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2802 if (start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2803 return;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2804 if (start->lastlist == -1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2805 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2806 start->lastlist = list[abs(start->id)];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2807 nfa_restore_listids(start->out, list);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2808 nfa_restore_listids(start->out1, list);
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 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2811
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2812 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2813 * Main matching routine.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2814 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2815 * Run NFA to determine whether it matches reginput.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2816 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2817 * Return TRUE if there is a match, FALSE otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2818 * Note: Caller must ensure that: start != NULL.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2819 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2820 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2821 nfa_regmatch(start, submatch, m)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2822 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2823 regsub_T *submatch;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2824 regsub_T *m;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2825 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2826 int c = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2827 int n;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2828 int i = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2829 int result;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2830 int size = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2831 int match = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2832 int flag = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2833 int old_reglnum = -1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2834 int reginput_updated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2835 thread_T *t;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2836 char_u *old_reginput = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2837 char_u *old_regline = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2838 nfa_state_T *sta;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2839 nfa_state_T *end;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2840 List list[3];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2841 List *listtbl[2][2];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2842 List *ll;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2843 int listid = 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2844 int endnode = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2845 List *thislist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2846 List *nextlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2847 List *neglist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2848 int *listids = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2849 int j = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2850 int len = 0;
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
2851 #ifdef NFA_REGEXP_DEBUG_LOG
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
2852 FILE *debug = fopen(NFA_REGEXP_DEBUG_LOG_NAME, "a");
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2853
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2854 if (debug == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2855 {
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
2856 EMSG2(_("(NFA) COULD NOT OPEN %s !"), NFA_REGEXP_DEBUG_LOG_NAME);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2857 return FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2858 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2859 #endif
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 /* Allocate memory for the lists of nodes */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2862 size = (nstate + 1) * sizeof(thread_T);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2863 list[0].t = (thread_T *)lalloc(size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2864 list[1].t = (thread_T *)lalloc(size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2865 list[2].t = (thread_T *)lalloc(size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2866 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
2867 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2868 vim_memset(list[0].t, 0, size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2869 vim_memset(list[1].t, 0, size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2870 vim_memset(list[2].t, 0, size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2871
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2872 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2873 log_fd = fopen(LOG_NAME, "a");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2874 if (log_fd != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2875 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2876 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2877 nfa_set_code(start->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2878 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
2879 abs(start->id), code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2880 fprintf(log_fd, "**********************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2881 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2882 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2883 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2884 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
2885 log_fd = stderr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2886 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2887 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2888
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2889 thislist = &list[0];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2890 thislist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2891 nextlist = &list[1];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2892 nextlist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2893 neglist = &list[2];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2894 neglist->n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2895 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2896 fprintf(log_fd, "(---) STARTSTATE\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2897 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2898 addstate(thislist, start, m, 0, listid, &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2899
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2900 /* 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
2901 * 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
2902 * 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
2903 * 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
2904 listtbl[0][0] = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2905 listtbl[0][1] = neglist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2906 listtbl[1][0] = nextlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2907 listtbl[1][1] = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2908 #define ADD_POS_NEG_STATE(node) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2909 ll = listtbl[result ? 1 : 0][node->negated]; \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2910 if (ll != NULL) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2911 addstate(ll, node->out , &t->sub, n, listid + 1, &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2912
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2913
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2914 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2915 * Run for each character.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2916 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2917 do {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2918 again:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2919 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2920 if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2921 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2922 c = (*mb_ptr2char)(reginput);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2923 n = (*mb_ptr2len)(reginput);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2924 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2925 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2926 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2927 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2928 c = *reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2929 n = 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2930 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2931 if (c == NUL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2932 n = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2933
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2934 /* swap lists */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2935 thislist = &list[flag];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2936 nextlist = &list[flag ^= 1];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2937 nextlist->n = 0; /* `clear' nextlist */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2938 listtbl[1][0] = nextlist;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2939 ++listid;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2940
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2941 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2942 fprintf(log_fd, "------------------------------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2943 fprintf(log_fd, ">>> Reginput is \"%s\"\n", reginput);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2944 fprintf(log_fd, ">>> Advanced one character ... Current char is %c (code %d) \n", c, (int)c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2945 fprintf(log_fd, ">>> Thislist has %d states available: ", thislist->n);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2946 for (i = 0; i< thislist->n; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2947 fprintf(log_fd, "%d ", abs(thislist->t[i].state->id));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2948 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2949 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2950
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
2951 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2952 fprintf(debug, "\n-------------------\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2953 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2954
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2955 /* compute nextlist */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2956 for (i = 0; i < thislist->n || neglist->n > 0; ++i)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2957 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2958 if (neglist->n > 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2959 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2960 t = &neglist->t[0];
4468
dde1cf311be6 updated for version 7.3.982
Bram Moolenaar <bram@vim.org>
parents: 4464
diff changeset
2961 neglist->n--;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2962 i--;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2963 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2964 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2965 t = &thislist->t[i];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2966
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
2967 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2968 nfa_set_code(t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2969 fprintf(debug, "%s, ", code);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2970 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2971 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2972 nfa_set_code(t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2973 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
2974 code, (int)t->state->c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2975 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2976
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2977 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2978 * Handle the possible codes of the current state.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2979 * The most important is NFA_MATCH.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2980 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2981 switch (t->state->c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2982 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2983 case NFA_MATCH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2984 match = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2985 *submatch = t->sub;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2986 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2987 for (j = 0; j < 4; j++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2988 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2989 fprintf(log_fd, "\n *** group %d, start: c=%d, l=%d, end: c=%d, l=%d",
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2990 j,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2991 t->sub.startpos[j].col,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2992 (int)t->sub.startpos[j].lnum,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2993 t->sub.endpos[j].col,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2994 (int)t->sub.endpos[j].lnum);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2995 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2996 fprintf(log_fd, "\n *** group %d, start: \"%s\", end: \"%s\"",
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2997 j,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2998 (char *)t->sub.start[j],
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2999 (char *)t->sub.end[j]);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3000 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3001 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3002 goto nextchar; /* found the left-most longest match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3003
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3004 case NFA_END_INVISIBLE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3005 /* 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
3006 * They surround a zero-width group, used with "\@=" and "\&".
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3007 * 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
3008 * finished successfully, so return control to the parent
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3009 * 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
3010 * the parent call. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3011 if (start->c == NFA_MOPEN + 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3012 addstate(thislist, t->state->out, &t->sub, 0, listid,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3013 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3014 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3015 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3016 *m = t->sub;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3017 match = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3018 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3019 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3020
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3021 case NFA_START_INVISIBLE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3022 /* 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
3023 * the current concat matches at this position. The concat
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3024 * ends with the node NFA_END_INVISIBLE */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3025 old_reginput = reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3026 old_regline = regline;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3027 old_reglnum = reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3028 if (listids == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3029 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3030 listids = (int *) lalloc(sizeof(int) * nstate, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3031 if (listids == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3032 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3033 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
3034 return 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3035 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3036 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3037 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3038 if (log_fd != stderr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3039 fclose(log_fd);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3040 log_fd = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3041 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3042 /* 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
3043 * nfa_regmatch() and addstate() can run properly after
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3044 * recursion. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3045 nfa_save_listids(start, listids);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3046 nfa_set_null_listids(start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3047 result = nfa_regmatch(t->state->out, submatch, m);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3048 nfa_set_neg_listids(start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3049 nfa_restore_listids(start, listids);
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 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3052 log_fd = fopen(LOG_NAME, "a");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3053 if (log_fd != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3054 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3055 fprintf(log_fd, "****************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3056 fprintf(log_fd, "FINISHED RUNNING nfa_regmatch() recursively\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3057 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
3058 fprintf(log_fd, "****************************\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3059 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3060 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3061 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3062 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
3063 log_fd = stderr;
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 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3066 if (result == TRUE)
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 /* Restore position in input text */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3069 reginput = old_reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3070 regline = old_regline;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3071 reglnum = old_reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3072 /* Copy submatch info from the recursive call */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3073 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3074 for (j = 1; j < NSUBEXP; j++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3075 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3076 t->sub.startpos[j] = m->startpos[j];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3077 t->sub.endpos[j] = m->endpos[j];
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 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3080 for (j = 1; j < NSUBEXP; j++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3081 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3082 t->sub.start[j] = m->start[j];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3083 t->sub.end[j] = m->end[j];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3084 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3085 /* t->state->out1 is the corresponding END_INVISIBLE node */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3086 addstate(thislist, t->state->out1->out, &t->sub, 0, listid,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3087 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3088 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3089 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3090 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3091 /* continue with next input char */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3092 reginput = old_reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3093 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3094 break;
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 case NFA_BOL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3097 if (reginput == regline)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3098 addstate(thislist, t->state->out, &t->sub, 0, listid,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3099 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3100 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3101
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3102 case NFA_EOL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3103 if (c == NUL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3104 addstate(thislist, t->state->out, &t->sub, 0, listid,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3105 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3106 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3107
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3108 case NFA_BOW:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3109 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3110 int bow = TRUE;
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 if (c == NUL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3113 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3114 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3115 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3116 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3117 int this_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3118
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3119 /* Get class of current and previous char (if it exists). */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3120 this_class = mb_get_class(reginput);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3121 if (this_class <= 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3122 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3123 else if (reg_prev_class() == this_class)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3124 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3125 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3126 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3127 else if (!vim_iswordc(c)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3128 || (reginput > regline && vim_iswordc(reginput[-1])))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3129 bow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3130 if (bow)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3131 addstate(thislist, t->state->out, &t->sub, 0, listid,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3132 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3133 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3134 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3135
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3136 case NFA_EOW:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3137 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3138 int eow = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3139
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3140 if (reginput == regline)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3141 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3142 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3143 else if (has_mbyte)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3144 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3145 int this_class, prev_class;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3146
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3147 /* Get class of current and previous char (if it exists). */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3148 this_class = mb_get_class(reginput);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3149 prev_class = reg_prev_class();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3150 if (this_class == prev_class
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3151 || prev_class == 0 || prev_class == 1)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3152 eow = 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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3155 else if (!vim_iswordc(reginput[-1])
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3156 || (reginput[0] != NUL && vim_iswordc(c)))
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3157 eow = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3158 if (eow)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3159 addstate(thislist, t->state->out, &t->sub, 0, listid,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3160 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3161 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3162 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3163
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3164 case NFA_MULTIBYTE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3165 case NFA_COMPOSING:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3166 switch (t->state->c)
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 case NFA_MULTIBYTE: endnode = NFA_END_MULTIBYTE; break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3169 case NFA_COMPOSING: endnode = NFA_END_COMPOSING; break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3170 default: endnode = 0;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3173 result = OK;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3174 sta = t->state->out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3175 len = 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3176 while (sta->c != endnode && len <= 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 if (reginput[len-1] != sta->c)
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 result = OK - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3181 break;
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 len++;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3184 sta = sta->out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3185 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3186
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3187 /* if input char length doesn't match regexp char length */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3188 if (len -1 < n || sta->c != endnode)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3189 result = OK - 1;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3190 end = t->state->out1; /* NFA_END_MULTIBYTE or
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3191 NFA_END_COMPOSING */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3192 /* If \Z was present, then ignore composing characters */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3193 if (regflags & RF_ICOMBINE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3194 result = 1 ^ sta->negated;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3195 ADD_POS_NEG_STATE(end);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3196 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3197
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3198 case NFA_NEWL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3199 if (!reg_line_lbr && REG_MULTI
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3200 && c == NUL && reglnum <= reg_maxline)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3201 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3202 if (reginput_updated == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3203 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3204 reg_nextline();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3205 reginput_updated = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3206 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3207 addstate(nextlist, t->state->out, &t->sub, n, listid + 1,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3208 &match);
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 break;
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 case NFA_CLASS_ALNUM:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3213 case NFA_CLASS_ALPHA:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3214 case NFA_CLASS_BLANK:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3215 case NFA_CLASS_CNTRL:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3216 case NFA_CLASS_DIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3217 case NFA_CLASS_GRAPH:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3218 case NFA_CLASS_LOWER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3219 case NFA_CLASS_PRINT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3220 case NFA_CLASS_PUNCT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3221 case NFA_CLASS_SPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3222 case NFA_CLASS_UPPER:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3223 case NFA_CLASS_XDIGIT:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3224 case NFA_CLASS_TAB:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3225 case NFA_CLASS_RETURN:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3226 case NFA_CLASS_BACKSPACE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3227 case NFA_CLASS_ESCAPE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3228 result = check_char_class(t->state->c, c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3229 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3230 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3231
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3232 case NFA_END_NEG_RANGE:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3233 /* This follows a series of negated nodes, like:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3234 * CHAR(x), NFA_NOT, CHAR(y), NFA_NOT etc. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3235 if (c > 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3236 addstate(nextlist, t->state->out, &t->sub, n, listid + 1,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3237 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3238 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3239
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3240 case NFA_ANY:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3241 /* Any printable char, not just any char. '\0' (end of input)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3242 * must not match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3243 if (c > 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3244 addstate(nextlist, t->state->out, &t->sub, n, listid + 1,
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3245 &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3246 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3247
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3248 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3249 * 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
3250 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3251 case NFA_IDENT: /* \i */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3252 result = vim_isIDc(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3253 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3254 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3255
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3256 case NFA_SIDENT: /* \I */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3257 result = !VIM_ISDIGIT(c) && vim_isIDc(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3258 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3259 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3260
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3261 case NFA_KWORD: /* \k */
4470
ab5154170c3d updated for version 7.3.983
Bram Moolenaar <bram@vim.org>
parents: 4468
diff changeset
3262 result = vim_iswordp(reginput);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3263 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3264 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3265
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3266 case NFA_SKWORD: /* \K */
4470
ab5154170c3d updated for version 7.3.983
Bram Moolenaar <bram@vim.org>
parents: 4468
diff changeset
3267 result = !VIM_ISDIGIT(c) && vim_iswordp(reginput);
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3268 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3269 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3270
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3271 case NFA_FNAME: /* \f */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3272 result = vim_isfilec(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3273 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3274 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3275
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3276 case NFA_SFNAME: /* \F */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3277 result = !VIM_ISDIGIT(c) && vim_isfilec(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3278 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3279 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3280
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3281 case NFA_PRINT: /* \p */
4470
ab5154170c3d updated for version 7.3.983
Bram Moolenaar <bram@vim.org>
parents: 4468
diff changeset
3282 result = ptr2cells(reginput) == 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3283 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3284 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3285
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3286 case NFA_SPRINT: /* \P */
4470
ab5154170c3d updated for version 7.3.983
Bram Moolenaar <bram@vim.org>
parents: 4468
diff changeset
3287 result = !VIM_ISDIGIT(c) && ptr2cells(reginput) == 1;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3288 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3289 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3290
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3291 case NFA_WHITE: /* \s */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3292 result = vim_iswhite(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3293 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3294 break;
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 case NFA_NWHITE: /* \S */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3297 result = c != NUL && !vim_iswhite(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3298 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3299 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3300
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3301 case NFA_DIGIT: /* \d */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3302 result = ri_digit(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3303 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3304 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3305
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3306 case NFA_NDIGIT: /* \D */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3307 result = c != NUL && !ri_digit(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3308 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3309 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3310
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3311 case NFA_HEX: /* \x */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3312 result = ri_hex(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3313 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3314 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3315
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3316 case NFA_NHEX: /* \X */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3317 result = c != NUL && !ri_hex(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3318 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3319 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3320
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3321 case NFA_OCTAL: /* \o */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3322 result = ri_octal(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3323 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3324 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3325
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3326 case NFA_NOCTAL: /* \O */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3327 result = c != NUL && !ri_octal(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3328 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3329 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3330
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3331 case NFA_WORD: /* \w */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3332 result = ri_word(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3333 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3334 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3335
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3336 case NFA_NWORD: /* \W */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3337 result = c != NUL && !ri_word(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3338 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3339 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3340
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3341 case NFA_HEAD: /* \h */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3342 result = ri_head(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3343 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3344 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3345
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3346 case NFA_NHEAD: /* \H */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3347 result = c != NUL && !ri_head(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3348 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3349 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3350
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3351 case NFA_ALPHA: /* \a */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3352 result = ri_alpha(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3353 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3354 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3355
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3356 case NFA_NALPHA: /* \A */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3357 result = c != NUL && !ri_alpha(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3358 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3359 break;
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 case NFA_LOWER: /* \l */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3362 result = ri_lower(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3363 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3364 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3365
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3366 case NFA_NLOWER: /* \L */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3367 result = c != NUL && !ri_lower(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3368 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3369 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3370
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3371 case NFA_UPPER: /* \u */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3372 result = ri_upper(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3373 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3374 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3375
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3376 case NFA_NUPPER: /* \U */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3377 result = c != NUL && !ri_upper(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3378 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3379 break;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3380
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3381 default: /* regular character */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3382 result = (no_Magic(t->state->c) == c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3383 if (!result)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3384 result = ireg_ic == TRUE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3385 && MB_TOLOWER(t->state->c) == MB_TOLOWER(c);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3386 ADD_POS_NEG_STATE(t->state);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3387 break;
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3390 } /* for (thislist = thislist; thislist->state; thislist++) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3391
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3392 /* The first found match is the leftmost one, but there may be a
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3393 * longer one. Keep running the NFA, but don't start from the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3394 * beginning. Also, do not add the start state in recursive calls of
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3395 * nfa_regmatch(), because recursive calls should only start in the
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3396 * first position. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3397 if (match == FALSE && start->c == NFA_MOPEN + 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3398 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3399 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3400 fprintf(log_fd, "(---) STARTSTATE\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3401 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3402 addstate(nextlist, start, m, n, listid + 1, &match);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3403 }
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 if (reginput_updated)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3406 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3407 reginput_updated = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3408 goto again;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3409 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3410
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3411 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3412 fprintf(log_fd, ">>> Thislist had %d states available: ", thislist->n);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3413 for (i = 0; i< thislist->n; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3414 fprintf(log_fd, "%d ", abs(thislist->t[i].state->id));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3415 fprintf(log_fd, "\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3416 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3417
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3418 nextchar:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3419 reginput += n;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3420 } while (c || reginput_updated);
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 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3423 if (log_fd != stderr)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3424 fclose(log_fd);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3425 log_fd = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3426 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3427
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3428 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3429 /* Free memory */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3430 vim_free(list[0].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3431 vim_free(list[1].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3432 vim_free(list[2].t);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3433 list[0].t = list[1].t = list[2].t = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3434 if (listids != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3435 vim_free(listids);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3436 #undef ADD_POS_NEG_STATE
4460
fe8a0a6a1c2a updated for version 7.3.978
Bram Moolenaar <bram@vim.org>
parents: 4458
diff changeset
3437 #ifdef NFA_REGEXP_DEBUG_LOG
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3438 fclose(debug);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3439 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3440
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3441 return match;
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
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 * Try match of "prog" with at regline["col"].
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3446 * 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
3447 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3448 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3449 nfa_regtry(start, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3450 nfa_state_T *start;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3451 colnr_T col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3452 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3453 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3454 regsub_T sub, m;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3455 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3456 FILE *f;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3457 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3458
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3459 reginput = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3460 need_clear_subexpr = TRUE;
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 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3463 f = fopen(LOG_NAME, "a");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3464 if (f != NULL)
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 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
3467 fprintf(f, " =======================================================\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3468 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3469 fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3470 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3471 fprintf(f, "\tInput text is \"%s\" \n", reginput);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3472 fprintf(f, " =======================================================\n\n\n\n\n\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3473 nfa_print_state(f, start, 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3474 fprintf(f, "\n\n");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3475 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3476 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3477 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3478 EMSG(_("Could not open temporary log file for writing "));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3479 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3480
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3481 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3482 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3483 /* Use 0xff to set lnum to -1 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3484 vim_memset(sub.startpos, 0xff, sizeof(lpos_T) * NSUBEXP);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3485 vim_memset(sub.endpos, 0xff, sizeof(lpos_T) * NSUBEXP);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3486 vim_memset(m.startpos, 0xff, sizeof(lpos_T) * NSUBEXP);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3487 vim_memset(m.endpos, 0xff, sizeof(lpos_T) * NSUBEXP);
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 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3490 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3491 vim_memset(sub.start, 0, sizeof(char_u *) * NSUBEXP);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3492 vim_memset(sub.end, 0, sizeof(char_u *) * NSUBEXP);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3493 vim_memset(m.start, 0, sizeof(char_u *) * NSUBEXP);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3494 vim_memset(m.end, 0, sizeof(char_u *) * NSUBEXP);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3495 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3496
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3497 if (nfa_regmatch(start, &sub, &m) == FALSE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3498 return 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3499
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3500 cleanup_subexpr();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3501 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3502 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3503 for (i = 0; i < NSUBEXP; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3504 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3505 reg_startpos[i] = sub.startpos[i];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3506 reg_endpos[i] = sub.endpos[i];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3507 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3508
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3509 if (reg_startpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3510 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3511 reg_startpos[0].lnum = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3512 reg_startpos[0].col = col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3513 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3514 if (reg_endpos[0].lnum < 0)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3515 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3516 reg_endpos[0].lnum = reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3517 reg_endpos[0].col = (int)(reginput - regline);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3518 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3519 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3520 /* Use line number of "\ze". */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3521 reglnum = reg_endpos[0].lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3522 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3523 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3524 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3525 for (i = 0; i < NSUBEXP; i++)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3526 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3527 reg_startp[i] = sub.start[i];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3528 reg_endp[i] = sub.end[i];
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3529 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3530
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3531 if (reg_startp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3532 reg_startp[0] = regline + col;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3533 if (reg_endp[0] == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3534 reg_endp[0] = reginput;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3535 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3536
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3537 return 1 + reglnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3538 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3539
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3540 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3541 * 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
3542 * lines ("line" is NULL, use reg_getline()).
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3543 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3544 * 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
3545 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3546 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3547 nfa_regexec_both(line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3548 char_u *line;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3549 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3550 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3551 nfa_regprog_T *prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3552 long retval = 0L;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3553 int i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3554
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3555 if (REG_MULTI)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3556 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3557 prog = (nfa_regprog_T *)reg_mmatch->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3558 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
3559 reg_startpos = reg_mmatch->startpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3560 reg_endpos = reg_mmatch->endpos;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3561 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3562 else
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3563 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3564 prog = (nfa_regprog_T *)reg_match->regprog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3565 reg_startp = reg_match->startp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3566 reg_endp = reg_match->endp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3567 }
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 /* Be paranoid... */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3570 if (prog == NULL || line == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3571 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3572 EMSG(_(e_null));
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3573 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3574 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3575
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3576 /* 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
3577 if (ireg_maxcol > 0 && col >= ireg_maxcol)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3578 goto theend;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3579
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3580 /* 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
3581 if (prog->regflags & RF_ICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3582 ireg_ic = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3583 else if (prog->regflags & RF_NOICASE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3584 ireg_ic = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3585
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3586 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3587 /* If pattern contains "\Z" overrule value of ireg_icombine */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3588 if (prog->regflags & RF_ICOMBINE)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3589 ireg_icombine = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3590 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3591
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3592 regline = line;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3593 reglnum = 0; /* relative to line */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3594
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3595 nstate = prog->nstate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3596
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3597 for (i = 0; i < nstate; ++i)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3598 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3599 prog->state[i].id = i;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3600 prog->state[i].lastlist = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3601 prog->state[i].visits = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3602 prog->state[i].lastthread = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3603 }
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 retval = nfa_regtry(prog->start, col);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3606
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3607 theend:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3608 return retval;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3609 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3610
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 * 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
3613 * 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
3614 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3615 static regprog_T *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3616 nfa_regcomp(expr, re_flags)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3617 char_u *expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3618 int re_flags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3619 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3620 nfa_regprog_T *prog;
4458
21e13403140a updated for version 7.3.977
Bram Moolenaar <bram@vim.org>
parents: 4456
diff changeset
3621 size_t prog_size;
4444
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3622 int *postfix;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3623
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3624 if (expr == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3625 return NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3626
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3627 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3628 nfa_regengine.expr = expr;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3629 #endif
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 init_class_tab();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3632
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3633 if (nfa_regcomp_start(expr, re_flags) == FAIL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3634 return NULL;
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 /* Space for compiled regexp */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3637 prog_size = sizeof(nfa_regprog_T) + sizeof(nfa_state_T) * nstate_max;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3638 prog = (nfa_regprog_T *)lalloc(prog_size, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3639 if (prog == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3640 goto fail;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3641 vim_memset(prog, 0, prog_size);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3642
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3643 /* Build postfix form of the regexp. Needed to build the NFA
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3644 * (and count its size) */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3645 postfix = re2post();
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3646 if (postfix == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3647 goto fail; /* Cascaded (syntax?) error */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3648
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3649 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3650 * 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
3651 * 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
3652 * 2. second to emit code
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3653 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3654 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3655 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3656 FILE *f = fopen(LOG_NAME, "a");
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3657
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3658 if (f != NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3659 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3660 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
3661 fclose(f);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3662 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3663 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3664 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3665
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3666 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3667 * PASS 1
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3668 * 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
3669 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3670 post2nfa(postfix, post_ptr, TRUE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3671 state_ptr = prog->state;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3672
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3673 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3674 * PASS 2
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3675 * Build the NFA
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 prog->start = post2nfa(postfix, post_ptr, FALSE);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3678 if (prog->start == NULL)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3679 goto fail;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3680
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3681 prog->regflags = regflags;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3682 prog->engine = &nfa_regengine;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3683 prog->nstate = nstate;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3684 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3685 nfa_postfix_dump(expr, OK);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3686 nfa_dump(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3687 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3688
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3689 out:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3690 vim_free(post_start);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3691 post_start = post_ptr = post_end = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3692 state_ptr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3693 return (regprog_T *)prog;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3694
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3695 fail:
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3696 vim_free(prog);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3697 prog = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3698 #ifdef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3699 nfa_postfix_dump(expr, FAIL);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3700 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3701 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3702 nfa_regengine.expr = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3703 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3704 goto out;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3705 }
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
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3708 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3709 * Match a regexp against a string.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3710 * "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
3711 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3712 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3713 * 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
3714 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3715 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3716 nfa_regexec(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3717 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3718 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3719 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3720 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3721 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3722 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3723 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3724 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3725 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3726 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3727 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3728 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3729 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3730 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3731 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3732 return (nfa_regexec_both(line, col) != 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3733 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3734
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3735 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3736 || defined(FIND_REPLACE_DIALOG) || defined(PROTO)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3737
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3738 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
3739
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3740 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3741 * 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
3742 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3743 static int
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3744 nfa_regexec_nl(rmp, line, col)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3745 regmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3746 char_u *line; /* string to match against */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3747 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3748 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3749 reg_match = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3750 reg_mmatch = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3751 reg_maxline = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3752 reg_line_lbr = TRUE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3753 reg_buf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3754 reg_win = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3755 ireg_ic = rmp->rm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3756 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3757 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3758 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3759 ireg_maxcol = 0;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3760 return (nfa_regexec_both(line, col) != 0);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3761 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3762 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3763
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3764
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3765 /*
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3766 * Match a regexp against multiple lines.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3767 * "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
3768 * Uses curbuf for line count and 'iskeyword'.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3769 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3770 * 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
3771 * match otherwise.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3772 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3773 * 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
3774 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3775 * ! 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
3776 * 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
3777 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3778 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3779 * |a |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3780 * |b |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3781 * |c |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3782 * | |
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3783 * +-------------------------+
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3784 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3785 * then nfa_regexec_multi() returns 3. while the original
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3786 * 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
3787 *
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3788 * FIXME if this behavior is not compatible.
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3789 */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3790 static long
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3791 nfa_regexec_multi(rmp, win, buf, lnum, col, tm)
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3792 regmmatch_T *rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3793 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
3794 buf_T *buf; /* buffer in which to search */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3795 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
3796 colnr_T col; /* column to start looking for match */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3797 proftime_T *tm UNUSED; /* timeout limit or NULL */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3798 {
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3799 long r;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3800 buf_T *save_curbuf = curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3801
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3802 reg_match = NULL;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3803 reg_mmatch = rmp;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3804 reg_buf = buf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3805 reg_win = win;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3806 reg_firstlnum = lnum;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3807 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
3808 reg_line_lbr = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3809 ireg_ic = rmp->rmm_ic;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3810 #ifdef FEAT_MBYTE
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3811 ireg_icombine = FALSE;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3812 #endif
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3813 ireg_maxcol = rmp->rmm_maxcol;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3814
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3815 /* Need to switch to buffer "buf" to make vim_iswordc() work. */
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3816 curbuf = buf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3817 r = nfa_regexec_both(NULL, col);
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3818 curbuf = save_curbuf;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3819
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3820 return r;
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3821 }
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3822
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3823 #ifdef DEBUG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3824 # undef ENABLE_LOG
ccecb03e5e8b updated for version 7.3.970
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3825 #endif