yeptris 0.6.59.1-arm-linux-eabihf → 0.6.60.1-arm-linux-eabihf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/yeptris_native/version.h +2 -2
- data/lib/yeptris/3.4/native.so +0 -0
- data/lib/yeptris/ffi.rb +19 -0
- data/lib/yeptris/yaml.rb +61 -0
- data/lib/yeptris.rb +1 -1
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/CMakeLists.txt +7 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +30 -2
- data/vendor/libyeptris/src/include/yeptris/parse.h +52 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +8 -0
- data/vendor/libyeptris/src/include/yeptris/validate.h +222 -21
- data/vendor/libyeptris/src/include/yeptris/values.h +8 -2
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +10 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +5 -7
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +9 -9
- data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +1 -1
- data/vendor/libyeptris/src/yeptris/common/error.h +2 -0
- data/vendor/libyeptris/src/yeptris/doc.h +20 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +85 -13
- data/vendor/libyeptris/src/yeptris/emit/writer.c +158 -642
- data/vendor/libyeptris/src/yeptris/emit/writer.h +15 -1
- data/vendor/libyeptris/src/yeptris/events/push.c +28 -3
- data/vendor/libyeptris/src/yeptris/events/values.c +24 -0
- data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +121 -40
- data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +326 -0
- data/vendor/libyeptris/src/yeptris/parse.c +173 -43
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +1 -1
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +11 -3
- data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
- data/vendor/libyeptris/src/yeptris/resolve/json12.c +12 -6
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +20 -0
- data/vendor/libyeptris/src/yeptris/validate/compile.c +39 -3
- data/vendor/libyeptris/src/yeptris/validate/internal.h +223 -7
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +645 -115
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +623 -157
- data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
- data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
- data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
- data/vendor/libyeptris/src/yeptris/validate/validate.c +288 -145
- metadata +8 -1
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
/* regexp.c — the bounded ECMA-regex subset behind JSON Schema's
|
|
2
|
-
* `pattern` keyword (#882 slice 2; #885 item 2
|
|
2
|
+
* `pattern` keyword (#882 slice 2; #885 item 2; the 2020-12 sota
|
|
3
|
+
* sweep's code-point classes).
|
|
3
4
|
*
|
|
4
5
|
* Supported: literals, '.', [...] classes (ranges, negation, \d\w\s
|
|
5
|
-
* and their negations, \n\t\r\f\v\0, \xHH
|
|
6
|
+
* and their negations, \n\t\r\f\v\0, \xHH, \cX control codes,
|
|
7
|
+
* \p{Letter}/\p{digit} property escapes), groups (capturing ignored,
|
|
6
8
|
* (?:...) fine), alternation, the quantifiers * + ? {n} {n,} {n,m}
|
|
7
9
|
* (lazy markers parse and are ignored — match/no-match has no
|
|
8
10
|
* preference), the ^ $ \b \B assertions. Unsupported constructs
|
|
9
11
|
* (backreferences, lookaround) are SyntaxErrors, and unknown LETTER
|
|
10
|
-
* escapes are identity escapes (non-unicode ECMA-262 Annex B:
|
|
11
|
-
*
|
|
12
|
-
* pattern as an absent keyword (2020-12's ignore posture),
|
|
13
|
-
* guess.
|
|
12
|
+
* escapes are identity escapes (non-unicode ECMA-262 Annex B: an
|
|
13
|
+
* unsupported \p{...} name is the literal 'p'): the caller treats an
|
|
14
|
+
* invalid pattern as an absent keyword (2020-12's ignore posture),
|
|
15
|
+
* never a guess.
|
|
14
16
|
*
|
|
15
|
-
* Shape:
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* Shape: code-point classes over byte literals — a class (bracket,
|
|
18
|
+
* named, or property) matches and consumes a WHOLE UTF-8 code point
|
|
19
|
+
* (a byte bitmap holds the point when every byte of it is in the
|
|
20
|
+
* bitmap: exactly the ECMA verdict for positive and negated classes
|
|
21
|
+
* alike); the named classes carry range tables (\d and \w are the
|
|
22
|
+
* ASCII classes ECMA-262 defines, \s is ECMA WhiteSpace plus
|
|
23
|
+
* LineTerminator, \D/\W/\S their code-point complements,
|
|
24
|
+
* \p{Letter}/\p{digit} the generated Unicode tables above). Thread
|
|
25
|
+
* positions are per-thread in a five-slot ring — a consumer advances
|
|
26
|
+
* by its code point's length, so the window is bounded and every
|
|
27
|
+
* array stays fixed-size. Parse -> AST -> Thompson NFA -> Pike-style
|
|
28
|
+
* simulation: O(subject * program), NO backtracking blowup, no
|
|
29
|
+
* recursion over the subject. Every array is a fixed budget; overflow
|
|
30
|
+
* is a SyntaxError (-1), never a crash. Truth lives here once (MECE:
|
|
31
|
+
* a second consumer moves this to its own module).
|
|
22
32
|
*
|
|
23
33
|
* Two consumption shapes over one compiler (#885 item 3):
|
|
24
34
|
* `yep_re_search` compiles into a stack ctx and drops it (the one-shot
|
|
@@ -29,6 +39,7 @@
|
|
|
29
39
|
* the cache itself is immutable once populated.
|
|
30
40
|
*/
|
|
31
41
|
|
|
42
|
+
#include <stdio.h>
|
|
32
43
|
#include <string.h>
|
|
33
44
|
|
|
34
45
|
#include "internal.h"
|
|
@@ -40,6 +51,198 @@
|
|
|
40
51
|
#define RE_AST_DEPTH 64
|
|
41
52
|
#define RE_REP_INF 0xFFFFu
|
|
42
53
|
|
|
54
|
+
/* The Unicode range tables behind the kernel's code-point classes
|
|
55
|
+
* (the 2020-12 sota sweep): sorted inclusive (lo, hi) pairs over
|
|
56
|
+
* scalar values, generated from Unicode 13.0.0 (python unicodedata).
|
|
57
|
+
* The kernel carries exactly two named properties -- Letter (general
|
|
58
|
+
* category L) and digit (Nd), the suite's exercised set; every other
|
|
59
|
+
* \p{...} name stays the Annex B identity escape. \d and \w are the
|
|
60
|
+
* ASCII classes ECMA-262 defines them to be; \s is ECMA WhiteSpace
|
|
61
|
+
* plus LineTerminator (Unicode-aware); \D \W \S are their code-point
|
|
62
|
+
* complements. */
|
|
63
|
+
static const uint32_t RE_PROP_L[] = {
|
|
64
|
+
0x0041, 0x005A, 0x0061, 0x007A, 0x00AA, 0x00AA, 0x00B5, 0x00B5, 0x00BA, 0x00BA,
|
|
65
|
+
0x00C0, 0x00D6, 0x00D8, 0x00F6, 0x00F8, 0x02C1, 0x02C6, 0x02D1, 0x02E0, 0x02E4,
|
|
66
|
+
0x02EC, 0x02EC, 0x02EE, 0x02EE, 0x0370, 0x0374, 0x0376, 0x0377, 0x037A, 0x037D,
|
|
67
|
+
0x037F, 0x037F, 0x0386, 0x0386, 0x0388, 0x038A, 0x038C, 0x038C, 0x038E, 0x03A1,
|
|
68
|
+
0x03A3, 0x03F5, 0x03F7, 0x0481, 0x048A, 0x052F, 0x0531, 0x0556, 0x0559, 0x0559,
|
|
69
|
+
0x0560, 0x0588, 0x05D0, 0x05EA, 0x05EF, 0x05F2, 0x0620, 0x064A, 0x066E, 0x066F,
|
|
70
|
+
0x0671, 0x06D3, 0x06D5, 0x06D5, 0x06E5, 0x06E6, 0x06EE, 0x06EF, 0x06FA, 0x06FC,
|
|
71
|
+
0x06FF, 0x06FF, 0x0710, 0x0710, 0x0712, 0x072F, 0x074D, 0x07A5, 0x07B1, 0x07B1,
|
|
72
|
+
0x07CA, 0x07EA, 0x07F4, 0x07F5, 0x07FA, 0x07FA, 0x0800, 0x0815, 0x081A, 0x081A,
|
|
73
|
+
0x0824, 0x0824, 0x0828, 0x0828, 0x0840, 0x0858, 0x0860, 0x086A, 0x08A0, 0x08B4,
|
|
74
|
+
0x08B6, 0x08C7, 0x0904, 0x0939, 0x093D, 0x093D, 0x0950, 0x0950, 0x0958, 0x0961,
|
|
75
|
+
0x0971, 0x0980, 0x0985, 0x098C, 0x098F, 0x0990, 0x0993, 0x09A8, 0x09AA, 0x09B0,
|
|
76
|
+
0x09B2, 0x09B2, 0x09B6, 0x09B9, 0x09BD, 0x09BD, 0x09CE, 0x09CE, 0x09DC, 0x09DD,
|
|
77
|
+
0x09DF, 0x09E1, 0x09F0, 0x09F1, 0x09FC, 0x09FC, 0x0A05, 0x0A0A, 0x0A0F, 0x0A10,
|
|
78
|
+
0x0A13, 0x0A28, 0x0A2A, 0x0A30, 0x0A32, 0x0A33, 0x0A35, 0x0A36, 0x0A38, 0x0A39,
|
|
79
|
+
0x0A59, 0x0A5C, 0x0A5E, 0x0A5E, 0x0A72, 0x0A74, 0x0A85, 0x0A8D, 0x0A8F, 0x0A91,
|
|
80
|
+
0x0A93, 0x0AA8, 0x0AAA, 0x0AB0, 0x0AB2, 0x0AB3, 0x0AB5, 0x0AB9, 0x0ABD, 0x0ABD,
|
|
81
|
+
0x0AD0, 0x0AD0, 0x0AE0, 0x0AE1, 0x0AF9, 0x0AF9, 0x0B05, 0x0B0C, 0x0B0F, 0x0B10,
|
|
82
|
+
0x0B13, 0x0B28, 0x0B2A, 0x0B30, 0x0B32, 0x0B33, 0x0B35, 0x0B39, 0x0B3D, 0x0B3D,
|
|
83
|
+
0x0B5C, 0x0B5D, 0x0B5F, 0x0B61, 0x0B71, 0x0B71, 0x0B83, 0x0B83, 0x0B85, 0x0B8A,
|
|
84
|
+
0x0B8E, 0x0B90, 0x0B92, 0x0B95, 0x0B99, 0x0B9A, 0x0B9C, 0x0B9C, 0x0B9E, 0x0B9F,
|
|
85
|
+
0x0BA3, 0x0BA4, 0x0BA8, 0x0BAA, 0x0BAE, 0x0BB9, 0x0BD0, 0x0BD0, 0x0C05, 0x0C0C,
|
|
86
|
+
0x0C0E, 0x0C10, 0x0C12, 0x0C28, 0x0C2A, 0x0C39, 0x0C3D, 0x0C3D, 0x0C58, 0x0C5A,
|
|
87
|
+
0x0C60, 0x0C61, 0x0C80, 0x0C80, 0x0C85, 0x0C8C, 0x0C8E, 0x0C90, 0x0C92, 0x0CA8,
|
|
88
|
+
0x0CAA, 0x0CB3, 0x0CB5, 0x0CB9, 0x0CBD, 0x0CBD, 0x0CDE, 0x0CDE, 0x0CE0, 0x0CE1,
|
|
89
|
+
0x0CF1, 0x0CF2, 0x0D04, 0x0D0C, 0x0D0E, 0x0D10, 0x0D12, 0x0D3A, 0x0D3D, 0x0D3D,
|
|
90
|
+
0x0D4E, 0x0D4E, 0x0D54, 0x0D56, 0x0D5F, 0x0D61, 0x0D7A, 0x0D7F, 0x0D85, 0x0D96,
|
|
91
|
+
0x0D9A, 0x0DB1, 0x0DB3, 0x0DBB, 0x0DBD, 0x0DBD, 0x0DC0, 0x0DC6, 0x0E01, 0x0E30,
|
|
92
|
+
0x0E32, 0x0E33, 0x0E40, 0x0E46, 0x0E81, 0x0E82, 0x0E84, 0x0E84, 0x0E86, 0x0E8A,
|
|
93
|
+
0x0E8C, 0x0EA3, 0x0EA5, 0x0EA5, 0x0EA7, 0x0EB0, 0x0EB2, 0x0EB3, 0x0EBD, 0x0EBD,
|
|
94
|
+
0x0EC0, 0x0EC4, 0x0EC6, 0x0EC6, 0x0EDC, 0x0EDF, 0x0F00, 0x0F00, 0x0F40, 0x0F47,
|
|
95
|
+
0x0F49, 0x0F6C, 0x0F88, 0x0F8C, 0x1000, 0x102A, 0x103F, 0x103F, 0x1050, 0x1055,
|
|
96
|
+
0x105A, 0x105D, 0x1061, 0x1061, 0x1065, 0x1066, 0x106E, 0x1070, 0x1075, 0x1081,
|
|
97
|
+
0x108E, 0x108E, 0x10A0, 0x10C5, 0x10C7, 0x10C7, 0x10CD, 0x10CD, 0x10D0, 0x10FA,
|
|
98
|
+
0x10FC, 0x1248, 0x124A, 0x124D, 0x1250, 0x1256, 0x1258, 0x1258, 0x125A, 0x125D,
|
|
99
|
+
0x1260, 0x1288, 0x128A, 0x128D, 0x1290, 0x12B0, 0x12B2, 0x12B5, 0x12B8, 0x12BE,
|
|
100
|
+
0x12C0, 0x12C0, 0x12C2, 0x12C5, 0x12C8, 0x12D6, 0x12D8, 0x1310, 0x1312, 0x1315,
|
|
101
|
+
0x1318, 0x135A, 0x1380, 0x138F, 0x13A0, 0x13F5, 0x13F8, 0x13FD, 0x1401, 0x166C,
|
|
102
|
+
0x166F, 0x167F, 0x1681, 0x169A, 0x16A0, 0x16EA, 0x16F1, 0x16F8, 0x1700, 0x170C,
|
|
103
|
+
0x170E, 0x1711, 0x1720, 0x1731, 0x1740, 0x1751, 0x1760, 0x176C, 0x176E, 0x1770,
|
|
104
|
+
0x1780, 0x17B3, 0x17D7, 0x17D7, 0x17DC, 0x17DC, 0x1820, 0x1878, 0x1880, 0x1884,
|
|
105
|
+
0x1887, 0x18A8, 0x18AA, 0x18AA, 0x18B0, 0x18F5, 0x1900, 0x191E, 0x1950, 0x196D,
|
|
106
|
+
0x1970, 0x1974, 0x1980, 0x19AB, 0x19B0, 0x19C9, 0x1A00, 0x1A16, 0x1A20, 0x1A54,
|
|
107
|
+
0x1AA7, 0x1AA7, 0x1B05, 0x1B33, 0x1B45, 0x1B4B, 0x1B83, 0x1BA0, 0x1BAE, 0x1BAF,
|
|
108
|
+
0x1BBA, 0x1BE5, 0x1C00, 0x1C23, 0x1C4D, 0x1C4F, 0x1C5A, 0x1C7D, 0x1C80, 0x1C88,
|
|
109
|
+
0x1C90, 0x1CBA, 0x1CBD, 0x1CBF, 0x1CE9, 0x1CEC, 0x1CEE, 0x1CF3, 0x1CF5, 0x1CF6,
|
|
110
|
+
0x1CFA, 0x1CFA, 0x1D00, 0x1DBF, 0x1E00, 0x1F15, 0x1F18, 0x1F1D, 0x1F20, 0x1F45,
|
|
111
|
+
0x1F48, 0x1F4D, 0x1F50, 0x1F57, 0x1F59, 0x1F59, 0x1F5B, 0x1F5B, 0x1F5D, 0x1F5D,
|
|
112
|
+
0x1F5F, 0x1F7D, 0x1F80, 0x1FB4, 0x1FB6, 0x1FBC, 0x1FBE, 0x1FBE, 0x1FC2, 0x1FC4,
|
|
113
|
+
0x1FC6, 0x1FCC, 0x1FD0, 0x1FD3, 0x1FD6, 0x1FDB, 0x1FE0, 0x1FEC, 0x1FF2, 0x1FF4,
|
|
114
|
+
0x1FF6, 0x1FFC, 0x2071, 0x2071, 0x207F, 0x207F, 0x2090, 0x209C, 0x2102, 0x2102,
|
|
115
|
+
0x2107, 0x2107, 0x210A, 0x2113, 0x2115, 0x2115, 0x2119, 0x211D, 0x2124, 0x2124,
|
|
116
|
+
0x2126, 0x2126, 0x2128, 0x2128, 0x212A, 0x212D, 0x212F, 0x2139, 0x213C, 0x213F,
|
|
117
|
+
0x2145, 0x2149, 0x214E, 0x214E, 0x2183, 0x2184, 0x2C00, 0x2C2E, 0x2C30, 0x2C5E,
|
|
118
|
+
0x2C60, 0x2CE4, 0x2CEB, 0x2CEE, 0x2CF2, 0x2CF3, 0x2D00, 0x2D25, 0x2D27, 0x2D27,
|
|
119
|
+
0x2D2D, 0x2D2D, 0x2D30, 0x2D67, 0x2D6F, 0x2D6F, 0x2D80, 0x2D96, 0x2DA0, 0x2DA6,
|
|
120
|
+
0x2DA8, 0x2DAE, 0x2DB0, 0x2DB6, 0x2DB8, 0x2DBE, 0x2DC0, 0x2DC6, 0x2DC8, 0x2DCE,
|
|
121
|
+
0x2DD0, 0x2DD6, 0x2DD8, 0x2DDE, 0x2E2F, 0x2E2F, 0x3005, 0x3006, 0x3031, 0x3035,
|
|
122
|
+
0x303B, 0x303C, 0x3041, 0x3096, 0x309D, 0x309F, 0x30A1, 0x30FA, 0x30FC, 0x30FF,
|
|
123
|
+
0x3105, 0x312F, 0x3131, 0x318E, 0x31A0, 0x31BF, 0x31F0, 0x31FF, 0x3400, 0x4DBF,
|
|
124
|
+
0x4E00, 0x9FFC, 0xA000, 0xA48C, 0xA4D0, 0xA4FD, 0xA500, 0xA60C, 0xA610, 0xA61F,
|
|
125
|
+
0xA62A, 0xA62B, 0xA640, 0xA66E, 0xA67F, 0xA69D, 0xA6A0, 0xA6E5, 0xA717, 0xA71F,
|
|
126
|
+
0xA722, 0xA788, 0xA78B, 0xA7BF, 0xA7C2, 0xA7CA, 0xA7F5, 0xA801, 0xA803, 0xA805,
|
|
127
|
+
0xA807, 0xA80A, 0xA80C, 0xA822, 0xA840, 0xA873, 0xA882, 0xA8B3, 0xA8F2, 0xA8F7,
|
|
128
|
+
0xA8FB, 0xA8FB, 0xA8FD, 0xA8FE, 0xA90A, 0xA925, 0xA930, 0xA946, 0xA960, 0xA97C,
|
|
129
|
+
0xA984, 0xA9B2, 0xA9CF, 0xA9CF, 0xA9E0, 0xA9E4, 0xA9E6, 0xA9EF, 0xA9FA, 0xA9FE,
|
|
130
|
+
0xAA00, 0xAA28, 0xAA40, 0xAA42, 0xAA44, 0xAA4B, 0xAA60, 0xAA76, 0xAA7A, 0xAA7A,
|
|
131
|
+
0xAA7E, 0xAAAF, 0xAAB1, 0xAAB1, 0xAAB5, 0xAAB6, 0xAAB9, 0xAABD, 0xAAC0, 0xAAC0,
|
|
132
|
+
0xAAC2, 0xAAC2, 0xAADB, 0xAADD, 0xAAE0, 0xAAEA, 0xAAF2, 0xAAF4, 0xAB01, 0xAB06,
|
|
133
|
+
0xAB09, 0xAB0E, 0xAB11, 0xAB16, 0xAB20, 0xAB26, 0xAB28, 0xAB2E, 0xAB30, 0xAB5A,
|
|
134
|
+
0xAB5C, 0xAB69, 0xAB70, 0xABE2, 0xAC00, 0xD7A3, 0xD7B0, 0xD7C6, 0xD7CB, 0xD7FB,
|
|
135
|
+
0xF900, 0xFA6D, 0xFA70, 0xFAD9, 0xFB00, 0xFB06, 0xFB13, 0xFB17, 0xFB1D, 0xFB1D,
|
|
136
|
+
0xFB1F, 0xFB28, 0xFB2A, 0xFB36, 0xFB38, 0xFB3C, 0xFB3E, 0xFB3E, 0xFB40, 0xFB41,
|
|
137
|
+
0xFB43, 0xFB44, 0xFB46, 0xFBB1, 0xFBD3, 0xFD3D, 0xFD50, 0xFD8F, 0xFD92, 0xFDC7,
|
|
138
|
+
0xFDF0, 0xFDFB, 0xFE70, 0xFE74, 0xFE76, 0xFEFC, 0xFF21, 0xFF3A, 0xFF41, 0xFF5A,
|
|
139
|
+
0xFF66, 0xFFBE, 0xFFC2, 0xFFC7, 0xFFCA, 0xFFCF, 0xFFD2, 0xFFD7, 0xFFDA, 0xFFDC,
|
|
140
|
+
0x10000, 0x1000B, 0x1000D, 0x10026, 0x10028, 0x1003A, 0x1003C, 0x1003D, 0x1003F, 0x1004D,
|
|
141
|
+
0x10050, 0x1005D, 0x10080, 0x100FA, 0x10280, 0x1029C, 0x102A0, 0x102D0, 0x10300, 0x1031F,
|
|
142
|
+
0x1032D, 0x10340, 0x10342, 0x10349, 0x10350, 0x10375, 0x10380, 0x1039D, 0x103A0, 0x103C3,
|
|
143
|
+
0x103C8, 0x103CF, 0x10400, 0x1049D, 0x104B0, 0x104D3, 0x104D8, 0x104FB, 0x10500, 0x10527,
|
|
144
|
+
0x10530, 0x10563, 0x10600, 0x10736, 0x10740, 0x10755, 0x10760, 0x10767, 0x10800, 0x10805,
|
|
145
|
+
0x10808, 0x10808, 0x1080A, 0x10835, 0x10837, 0x10838, 0x1083C, 0x1083C, 0x1083F, 0x10855,
|
|
146
|
+
0x10860, 0x10876, 0x10880, 0x1089E, 0x108E0, 0x108F2, 0x108F4, 0x108F5, 0x10900, 0x10915,
|
|
147
|
+
0x10920, 0x10939, 0x10980, 0x109B7, 0x109BE, 0x109BF, 0x10A00, 0x10A00, 0x10A10, 0x10A13,
|
|
148
|
+
0x10A15, 0x10A17, 0x10A19, 0x10A35, 0x10A60, 0x10A7C, 0x10A80, 0x10A9C, 0x10AC0, 0x10AC7,
|
|
149
|
+
0x10AC9, 0x10AE4, 0x10B00, 0x10B35, 0x10B40, 0x10B55, 0x10B60, 0x10B72, 0x10B80, 0x10B91,
|
|
150
|
+
0x10C00, 0x10C48, 0x10C80, 0x10CB2, 0x10CC0, 0x10CF2, 0x10D00, 0x10D23, 0x10E80, 0x10EA9,
|
|
151
|
+
0x10EB0, 0x10EB1, 0x10F00, 0x10F1C, 0x10F27, 0x10F27, 0x10F30, 0x10F45, 0x10FB0, 0x10FC4,
|
|
152
|
+
0x10FE0, 0x10FF6, 0x11003, 0x11037, 0x11083, 0x110AF, 0x110D0, 0x110E8, 0x11103, 0x11126,
|
|
153
|
+
0x11144, 0x11144, 0x11147, 0x11147, 0x11150, 0x11172, 0x11176, 0x11176, 0x11183, 0x111B2,
|
|
154
|
+
0x111C1, 0x111C4, 0x111DA, 0x111DA, 0x111DC, 0x111DC, 0x11200, 0x11211, 0x11213, 0x1122B,
|
|
155
|
+
0x11280, 0x11286, 0x11288, 0x11288, 0x1128A, 0x1128D, 0x1128F, 0x1129D, 0x1129F, 0x112A8,
|
|
156
|
+
0x112B0, 0x112DE, 0x11305, 0x1130C, 0x1130F, 0x11310, 0x11313, 0x11328, 0x1132A, 0x11330,
|
|
157
|
+
0x11332, 0x11333, 0x11335, 0x11339, 0x1133D, 0x1133D, 0x11350, 0x11350, 0x1135D, 0x11361,
|
|
158
|
+
0x11400, 0x11434, 0x11447, 0x1144A, 0x1145F, 0x11461, 0x11480, 0x114AF, 0x114C4, 0x114C5,
|
|
159
|
+
0x114C7, 0x114C7, 0x11580, 0x115AE, 0x115D8, 0x115DB, 0x11600, 0x1162F, 0x11644, 0x11644,
|
|
160
|
+
0x11680, 0x116AA, 0x116B8, 0x116B8, 0x11700, 0x1171A, 0x11800, 0x1182B, 0x118A0, 0x118DF,
|
|
161
|
+
0x118FF, 0x11906, 0x11909, 0x11909, 0x1190C, 0x11913, 0x11915, 0x11916, 0x11918, 0x1192F,
|
|
162
|
+
0x1193F, 0x1193F, 0x11941, 0x11941, 0x119A0, 0x119A7, 0x119AA, 0x119D0, 0x119E1, 0x119E1,
|
|
163
|
+
0x119E3, 0x119E3, 0x11A00, 0x11A00, 0x11A0B, 0x11A32, 0x11A3A, 0x11A3A, 0x11A50, 0x11A50,
|
|
164
|
+
0x11A5C, 0x11A89, 0x11A9D, 0x11A9D, 0x11AC0, 0x11AF8, 0x11C00, 0x11C08, 0x11C0A, 0x11C2E,
|
|
165
|
+
0x11C40, 0x11C40, 0x11C72, 0x11C8F, 0x11D00, 0x11D06, 0x11D08, 0x11D09, 0x11D0B, 0x11D30,
|
|
166
|
+
0x11D46, 0x11D46, 0x11D60, 0x11D65, 0x11D67, 0x11D68, 0x11D6A, 0x11D89, 0x11D98, 0x11D98,
|
|
167
|
+
0x11EE0, 0x11EF2, 0x11FB0, 0x11FB0, 0x12000, 0x12399, 0x12480, 0x12543, 0x13000, 0x1342E,
|
|
168
|
+
0x14400, 0x14646, 0x16800, 0x16A38, 0x16A40, 0x16A5E, 0x16AD0, 0x16AED, 0x16B00, 0x16B2F,
|
|
169
|
+
0x16B40, 0x16B43, 0x16B63, 0x16B77, 0x16B7D, 0x16B8F, 0x16E40, 0x16E7F, 0x16F00, 0x16F4A,
|
|
170
|
+
0x16F50, 0x16F50, 0x16F93, 0x16F9F, 0x16FE0, 0x16FE1, 0x16FE3, 0x16FE3, 0x17000, 0x187F7,
|
|
171
|
+
0x18800, 0x18CD5, 0x18D00, 0x18D08, 0x1B000, 0x1B11E, 0x1B150, 0x1B152, 0x1B164, 0x1B167,
|
|
172
|
+
0x1B170, 0x1B2FB, 0x1BC00, 0x1BC6A, 0x1BC70, 0x1BC7C, 0x1BC80, 0x1BC88, 0x1BC90, 0x1BC99,
|
|
173
|
+
0x1D400, 0x1D454, 0x1D456, 0x1D49C, 0x1D49E, 0x1D49F, 0x1D4A2, 0x1D4A2, 0x1D4A5, 0x1D4A6,
|
|
174
|
+
0x1D4A9, 0x1D4AC, 0x1D4AE, 0x1D4B9, 0x1D4BB, 0x1D4BB, 0x1D4BD, 0x1D4C3, 0x1D4C5, 0x1D505,
|
|
175
|
+
0x1D507, 0x1D50A, 0x1D50D, 0x1D514, 0x1D516, 0x1D51C, 0x1D51E, 0x1D539, 0x1D53B, 0x1D53E,
|
|
176
|
+
0x1D540, 0x1D544, 0x1D546, 0x1D546, 0x1D54A, 0x1D550, 0x1D552, 0x1D6A5, 0x1D6A8, 0x1D6C0,
|
|
177
|
+
0x1D6C2, 0x1D6DA, 0x1D6DC, 0x1D6FA, 0x1D6FC, 0x1D714, 0x1D716, 0x1D734, 0x1D736, 0x1D74E,
|
|
178
|
+
0x1D750, 0x1D76E, 0x1D770, 0x1D788, 0x1D78A, 0x1D7A8, 0x1D7AA, 0x1D7C2, 0x1D7C4, 0x1D7CB,
|
|
179
|
+
0x1E100, 0x1E12C, 0x1E137, 0x1E13D, 0x1E14E, 0x1E14E, 0x1E2C0, 0x1E2EB, 0x1E800, 0x1E8C4,
|
|
180
|
+
0x1E900, 0x1E943, 0x1E94B, 0x1E94B, 0x1EE00, 0x1EE03, 0x1EE05, 0x1EE1F, 0x1EE21, 0x1EE22,
|
|
181
|
+
0x1EE24, 0x1EE24, 0x1EE27, 0x1EE27, 0x1EE29, 0x1EE32, 0x1EE34, 0x1EE37, 0x1EE39, 0x1EE39,
|
|
182
|
+
0x1EE3B, 0x1EE3B, 0x1EE42, 0x1EE42, 0x1EE47, 0x1EE47, 0x1EE49, 0x1EE49, 0x1EE4B, 0x1EE4B,
|
|
183
|
+
0x1EE4D, 0x1EE4F, 0x1EE51, 0x1EE52, 0x1EE54, 0x1EE54, 0x1EE57, 0x1EE57, 0x1EE59, 0x1EE59,
|
|
184
|
+
0x1EE5B, 0x1EE5B, 0x1EE5D, 0x1EE5D, 0x1EE5F, 0x1EE5F, 0x1EE61, 0x1EE62, 0x1EE64, 0x1EE64,
|
|
185
|
+
0x1EE67, 0x1EE6A, 0x1EE6C, 0x1EE72, 0x1EE74, 0x1EE77, 0x1EE79, 0x1EE7C, 0x1EE7E, 0x1EE7E,
|
|
186
|
+
0x1EE80, 0x1EE89, 0x1EE8B, 0x1EE9B, 0x1EEA1, 0x1EEA3, 0x1EEA5, 0x1EEA9, 0x1EEAB, 0x1EEBB,
|
|
187
|
+
0x20000, 0x2A6DD, 0x2A700, 0x2B734, 0x2B740, 0x2B81D, 0x2B820, 0x2CEA1, 0x2CEB0, 0x2EBE0,
|
|
188
|
+
0x2F800, 0x2FA1D, 0x30000, 0x3134A,
|
|
189
|
+
};
|
|
190
|
+
#define RE_PROP_L_N 622u
|
|
191
|
+
|
|
192
|
+
static const uint32_t RE_PROP_ND[] = {
|
|
193
|
+
0x0030, 0x0039, 0x0660, 0x0669, 0x06F0, 0x06F9, 0x07C0, 0x07C9, 0x0966, 0x096F,
|
|
194
|
+
0x09E6, 0x09EF, 0x0A66, 0x0A6F, 0x0AE6, 0x0AEF, 0x0B66, 0x0B6F, 0x0BE6, 0x0BEF,
|
|
195
|
+
0x0C66, 0x0C6F, 0x0CE6, 0x0CEF, 0x0D66, 0x0D6F, 0x0DE6, 0x0DEF, 0x0E50, 0x0E59,
|
|
196
|
+
0x0ED0, 0x0ED9, 0x0F20, 0x0F29, 0x1040, 0x1049, 0x1090, 0x1099, 0x17E0, 0x17E9,
|
|
197
|
+
0x1810, 0x1819, 0x1946, 0x194F, 0x19D0, 0x19D9, 0x1A80, 0x1A89, 0x1A90, 0x1A99,
|
|
198
|
+
0x1B50, 0x1B59, 0x1BB0, 0x1BB9, 0x1C40, 0x1C49, 0x1C50, 0x1C59, 0xA620, 0xA629,
|
|
199
|
+
0xA8D0, 0xA8D9, 0xA900, 0xA909, 0xA9D0, 0xA9D9, 0xA9F0, 0xA9F9, 0xAA50, 0xAA59,
|
|
200
|
+
0xABF0, 0xABF9, 0xFF10, 0xFF19, 0x104A0, 0x104A9, 0x10D30, 0x10D39, 0x11066, 0x1106F,
|
|
201
|
+
0x110F0, 0x110F9, 0x11136, 0x1113F, 0x111D0, 0x111D9, 0x112F0, 0x112F9, 0x11450, 0x11459,
|
|
202
|
+
0x114D0, 0x114D9, 0x11650, 0x11659, 0x116C0, 0x116C9, 0x11730, 0x11739, 0x118E0, 0x118E9,
|
|
203
|
+
0x11950, 0x11959, 0x11C50, 0x11C59, 0x11D50, 0x11D59, 0x11DA0, 0x11DA9, 0x16A60, 0x16A69,
|
|
204
|
+
0x16B50, 0x16B59, 0x1D7CE, 0x1D7FF, 0x1E140, 0x1E149, 0x1E2F0, 0x1E2F9, 0x1E950, 0x1E959,
|
|
205
|
+
0x1FBF0, 0x1FBF9,
|
|
206
|
+
};
|
|
207
|
+
#define RE_PROP_ND_N 61u
|
|
208
|
+
|
|
209
|
+
static const uint32_t RE_RANGES_D[] = {
|
|
210
|
+
0x0030,
|
|
211
|
+
0x0039,
|
|
212
|
+
};
|
|
213
|
+
#define RE_RANGES_D_N 1u
|
|
214
|
+
|
|
215
|
+
static const uint32_t RE_RANGES_WHITE[] = {
|
|
216
|
+
0x0009, 0x000D, 0x0020, 0x0020, 0x00A0, 0x00A0, 0x1680, 0x1680, 0x2000, 0x200A,
|
|
217
|
+
0x2028, 0x2029, 0x202F, 0x202F, 0x205F, 0x205F, 0x3000, 0x3000, 0xFEFF, 0xFEFF,
|
|
218
|
+
};
|
|
219
|
+
#define RE_RANGES_WHITE_N 10u
|
|
220
|
+
|
|
221
|
+
static const uint32_t RE_RANGES_WORD[] = {
|
|
222
|
+
0x0030, 0x0039, 0x0041, 0x005A, 0x005F, 0x005F, 0x0061, 0x007A,
|
|
223
|
+
|
|
224
|
+
};
|
|
225
|
+
#define RE_RANGES_WORD_N 4u
|
|
226
|
+
|
|
227
|
+
static const uint32_t RE_RANGES_NOTD[] = {
|
|
228
|
+
0x0000,
|
|
229
|
+
0x002F,
|
|
230
|
+
0x003A,
|
|
231
|
+
0x10FFFF,
|
|
232
|
+
};
|
|
233
|
+
#define RE_RANGES_NOTD_N 2u
|
|
234
|
+
|
|
235
|
+
static const uint32_t RE_RANGES_NOTW[] = {
|
|
236
|
+
0x0000, 0x002F, 0x003A, 0x0040, 0x005B, 0x005E, 0x0060, 0x0060, 0x007B, 0x10FFFF,
|
|
237
|
+
};
|
|
238
|
+
#define RE_RANGES_NOTW_N 5u
|
|
239
|
+
|
|
240
|
+
static const uint32_t RE_RANGES_NOTS[] = {
|
|
241
|
+
0x0000, 0x0008, 0x000E, 0x001F, 0x0021, 0x009F, 0x00A1, 0x167F, 0x1681, 0x1FFF, 0x200B,
|
|
242
|
+
0x2027, 0x202A, 0x202E, 0x2030, 0x205E, 0x2060, 0x2FFF, 0x3001, 0xFEFE, 0xFF00, 0x10FFFF,
|
|
243
|
+
};
|
|
244
|
+
#define RE_RANGES_NOTS_N 11u
|
|
245
|
+
|
|
43
246
|
enum {
|
|
44
247
|
A_BYTE = 1, /* a: the literal byte */
|
|
45
248
|
A_CLASS, /* cls */
|
|
@@ -87,6 +290,11 @@ typedef struct {
|
|
|
87
290
|
int ast_n;
|
|
88
291
|
uint8_t cls[RE_MAX_CLS][32];
|
|
89
292
|
int cls_n;
|
|
293
|
+
/* the code-point classes: a class whose entry is non-NULL matches
|
|
294
|
+
* whole UTF-8 code points by range table (the named and property
|
|
295
|
+
* classes); NULL entries match bytes through the bitmap */
|
|
296
|
+
const uint32_t* ucls[RE_MAX_CLS];
|
|
297
|
+
uint16_t ucls_n[RE_MAX_CLS];
|
|
90
298
|
/* compile */
|
|
91
299
|
re_inst inst[RE_MAX_INST];
|
|
92
300
|
int inst_n;
|
|
@@ -125,24 +333,31 @@ static void cls_set(re_ctx* c, int id, unsigned b) {
|
|
|
125
333
|
c->cls[id][(b >> 3) & 31] |= (uint8_t)(1u << (b & 7));
|
|
126
334
|
}
|
|
127
335
|
|
|
336
|
+
/* Registers a class as a code-point range table (the named and
|
|
337
|
+
* property classes). The ranges are process-immutable statics, so a
|
|
338
|
+
* retained program can hold the reference for its lifetime. */
|
|
339
|
+
static void cls_add_ranges(re_ctx* c, int id, const uint32_t* ranges, uint16_t n) {
|
|
340
|
+
c->ucls[id] = ranges;
|
|
341
|
+
c->ucls_n[id] = n;
|
|
342
|
+
}
|
|
343
|
+
|
|
128
344
|
static void cls_add_named(re_ctx* c, int id, int neg, int kind) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
345
|
+
/* \d and \w are the ASCII classes ECMA-262 defines; \s is ECMA
|
|
346
|
+
* WhiteSpace plus LineTerminator; the D/W/S forms are their
|
|
347
|
+
* code-point complements */
|
|
348
|
+
const uint32_t* r = NULL;
|
|
349
|
+
uint16_t n = 0;
|
|
350
|
+
if (kind == 0) {
|
|
351
|
+
r = neg ? RE_RANGES_NOTD : RE_RANGES_D;
|
|
352
|
+
n = neg ? RE_RANGES_NOTD_N : RE_RANGES_D_N;
|
|
353
|
+
} else if (kind == 1) {
|
|
354
|
+
r = neg ? RE_RANGES_NOTW : RE_RANGES_WORD;
|
|
355
|
+
n = neg ? RE_RANGES_NOTW_N : RE_RANGES_WORD_N;
|
|
356
|
+
} else {
|
|
357
|
+
r = neg ? RE_RANGES_NOTS : RE_RANGES_WHITE;
|
|
358
|
+
n = neg ? RE_RANGES_NOTS_N : RE_RANGES_WHITE_N;
|
|
359
|
+
}
|
|
360
|
+
cls_add_ranges(c, id, r, n);
|
|
146
361
|
}
|
|
147
362
|
|
|
148
363
|
static int p_hex(re_ctx* c, int nibbles) {
|
|
@@ -223,6 +438,21 @@ static int p_escape(re_ctx* c, int* out) {
|
|
|
223
438
|
case '0':
|
|
224
439
|
*out = 0;
|
|
225
440
|
return 0;
|
|
441
|
+
case 'c': {
|
|
442
|
+
/* ECMA-262 \cX: the control code of a letter (X & 0x1F). A
|
|
443
|
+
* non-letter after \c is the Annex B identity escape (the
|
|
444
|
+
* literal 'c' — the next byte parses on its own). */
|
|
445
|
+
if (c->pi < c->pn) {
|
|
446
|
+
char l = c->pat[c->pi];
|
|
447
|
+
if ((l >= 'A' && l <= 'Z') || (l >= 'a' && l <= 'z')) {
|
|
448
|
+
c->pi++;
|
|
449
|
+
*out = (unsigned char)(l & 0x1F);
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
*out = (unsigned char)'c';
|
|
454
|
+
return 0;
|
|
455
|
+
}
|
|
226
456
|
case 'x': {
|
|
227
457
|
int v = p_hex(c, 2);
|
|
228
458
|
if (v < 0) {
|
|
@@ -232,12 +462,51 @@ static int p_escape(re_ctx* c, int* out) {
|
|
|
232
462
|
*out = v;
|
|
233
463
|
return 0;
|
|
234
464
|
}
|
|
465
|
+
case 'p': {
|
|
466
|
+
/* \p{Name}: the suite's two exercised properties (Letter,
|
|
467
|
+
* digit — case-insensitive) ride the generated range tables;
|
|
468
|
+
* every other name is the Annex B identity escape (the literal
|
|
469
|
+
* 'p'; the braced name re-parses as literals). */
|
|
470
|
+
if (c->pi < c->pn && c->pat[c->pi] == '{') {
|
|
471
|
+
size_t close = c->pi;
|
|
472
|
+
while (close < c->pn && c->pat[close] != '}') {
|
|
473
|
+
close++;
|
|
474
|
+
}
|
|
475
|
+
size_t nl = close - (size_t)(c->pi + 1);
|
|
476
|
+
if (close < c->pn && nl >= 4 && nl <= 8) {
|
|
477
|
+
char name[8];
|
|
478
|
+
for (size_t i = 0; i < nl; i++) {
|
|
479
|
+
name[i] = c->pat[c->pi + 1 + i];
|
|
480
|
+
}
|
|
481
|
+
name[nl] = '\0';
|
|
482
|
+
/* the exact canonical spellings only: any other name
|
|
483
|
+
* (and any other casing) stays the Annex B identity
|
|
484
|
+
* escape — the bounded kernel carries the suite's two
|
|
485
|
+
* exercised properties, never a guess */
|
|
486
|
+
int prop = (nl == 6 && memcmp(name, "Letter", 6) == 0)
|
|
487
|
+
? 1
|
|
488
|
+
: ((nl == 5 && memcmp(name, "digit", 5) == 0) ? 2 : 0);
|
|
489
|
+
if (prop != 0) {
|
|
490
|
+
c->pi = (uint32_t)close + 1;
|
|
491
|
+
int id = cls_new(c);
|
|
492
|
+
if (id < 0) {
|
|
493
|
+
return -1;
|
|
494
|
+
}
|
|
495
|
+
cls_add_ranges(c, id, prop == 1 ? RE_PROP_L : RE_PROP_ND,
|
|
496
|
+
prop == 1 ? (uint16_t)RE_PROP_L_N : (uint16_t)RE_PROP_ND_N);
|
|
497
|
+
*out = id;
|
|
498
|
+
return 1;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
*out = (unsigned char)'p';
|
|
503
|
+
return 0;
|
|
504
|
+
}
|
|
235
505
|
default:
|
|
236
506
|
/* non-unicode ECMA-262 (Annex B): unknown LETTER escapes are
|
|
237
|
-
* identity escapes — \p
|
|
238
|
-
* 'p'
|
|
239
|
-
*
|
|
240
|
-
* out of the subset — an ignored pattern beats a misread one.
|
|
507
|
+
* identity escapes — an unsupported \p{...} name is the literal
|
|
508
|
+
* 'p'. Digits stay SyntaxError: 1-9 are backreferences, out of
|
|
509
|
+
* the subset — an ignored pattern beats a misread one.
|
|
241
510
|
* Punctuation is identity too. */
|
|
242
511
|
if (e >= '0' && e <= '9') {
|
|
243
512
|
c->err = 1;
|
|
@@ -299,9 +568,26 @@ static int p_class(re_ctx* c) {
|
|
|
299
568
|
return -1;
|
|
300
569
|
}
|
|
301
570
|
if (rc == 1) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
571
|
+
if (c->ucls[v] != NULL) {
|
|
572
|
+
/* a code-point class contributes the bytes of its
|
|
573
|
+
* sub-0x100 ranges (the bracket stays byte-wise:
|
|
574
|
+
* the multi-byte whites and \p{...} letters beyond
|
|
575
|
+
* latin-1 are the documented bracket divergence) */
|
|
576
|
+
for (uint16_t rr = 0; rr < c->ucls_n[v]; rr++) {
|
|
577
|
+
uint32_t blo = c->ucls[v][rr * 2];
|
|
578
|
+
uint32_t bhi = c->ucls[v][rr * 2 + 1];
|
|
579
|
+
if (bhi > 0xFF) {
|
|
580
|
+
bhi = 0xFF;
|
|
581
|
+
}
|
|
582
|
+
for (uint32_t b = blo; b <= bhi; b++) {
|
|
583
|
+
cls_set(c, id, (unsigned)b);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
} else {
|
|
587
|
+
for (int b = 0; b < 256; b++) {
|
|
588
|
+
if (c->cls[v][(b >> 3) & 31] & (1u << (b & 7))) {
|
|
589
|
+
cls_set(c, id, (unsigned)b);
|
|
590
|
+
}
|
|
305
591
|
}
|
|
306
592
|
}
|
|
307
593
|
continue;
|
|
@@ -853,150 +1139,320 @@ static int re_build(re_ctx* c, const char* pat, uint32_t pat_len, int* entry_out
|
|
|
853
1139
|
|
|
854
1140
|
/* ---- the Pike VM (shared by the one-shot and the retained programs) ----- */
|
|
855
1141
|
|
|
1142
|
+
/* Decodes one UTF-8 code point at `at`: the scalar value, and its byte
|
|
1143
|
+
* length in *len (1 for a malformed or lone byte, which reads as
|
|
1144
|
+
* latin-1). Never reads past s_len. */
|
|
1145
|
+
static uint32_t re_cp_at(const char* s, uint32_t s_len, uint32_t at, uint32_t* len) {
|
|
1146
|
+
unsigned char b = (unsigned char)s[at];
|
|
1147
|
+
if (b < 0x80) {
|
|
1148
|
+
*len = 1;
|
|
1149
|
+
return b;
|
|
1150
|
+
}
|
|
1151
|
+
int n;
|
|
1152
|
+
uint32_t cp;
|
|
1153
|
+
if ((b & 0xE0) == 0xC0 && b >= 0xC2) {
|
|
1154
|
+
n = 2;
|
|
1155
|
+
cp = b & 0x1Fu;
|
|
1156
|
+
} else if ((b & 0xF0) == 0xE0) {
|
|
1157
|
+
n = 3;
|
|
1158
|
+
cp = b & 0x0Fu;
|
|
1159
|
+
} else if ((b & 0xF8) == 0xF0 && b <= 0xF4) {
|
|
1160
|
+
n = 4;
|
|
1161
|
+
cp = b & 0x07u;
|
|
1162
|
+
} else {
|
|
1163
|
+
*len = 1;
|
|
1164
|
+
return b;
|
|
1165
|
+
}
|
|
1166
|
+
if (at + (uint32_t)n > s_len) {
|
|
1167
|
+
*len = 1;
|
|
1168
|
+
return b;
|
|
1169
|
+
}
|
|
1170
|
+
for (int i = 1; i < n; i++) {
|
|
1171
|
+
unsigned char cb = (unsigned char)s[at + i];
|
|
1172
|
+
if ((cb & 0xC0) != 0x80) {
|
|
1173
|
+
*len = 1;
|
|
1174
|
+
return b;
|
|
1175
|
+
}
|
|
1176
|
+
cp = (cp << 6) | (cb & 0x3Fu);
|
|
1177
|
+
}
|
|
1178
|
+
*len = (uint32_t)n;
|
|
1179
|
+
return cp;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/* Range membership (sorted inclusive lo,hi pairs; binary search). */
|
|
1183
|
+
static int re_ranges_has(const uint32_t* r, uint16_t n, uint32_t cp) {
|
|
1184
|
+
uint16_t lo = 0, hi = n;
|
|
1185
|
+
while (lo < hi) {
|
|
1186
|
+
uint16_t mid = (uint16_t)(lo + (hi - lo) / 2);
|
|
1187
|
+
if (cp < r[mid * 2]) {
|
|
1188
|
+
hi = mid;
|
|
1189
|
+
} else if (cp > r[mid * 2 + 1]) {
|
|
1190
|
+
lo = (uint16_t)(mid + 1);
|
|
1191
|
+
} else {
|
|
1192
|
+
return 1;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return 0;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
/* The \b machinery: a code point is a word character iff it is ASCII
|
|
1199
|
+
* [0-9A-Z_a-z]; every non-ASCII code point is non-word, and UTF-8's
|
|
1200
|
+
* self-synchronization keeps a boundary from forming inside one. */
|
|
1201
|
+
static int re_word_before(const char* s, uint32_t at) {
|
|
1202
|
+
if (at == 0) {
|
|
1203
|
+
return 0;
|
|
1204
|
+
}
|
|
1205
|
+
uint32_t q = at;
|
|
1206
|
+
while (q > 0 && ((unsigned char)s[q - 1] & 0xC0) == 0x80) {
|
|
1207
|
+
q--;
|
|
1208
|
+
}
|
|
1209
|
+
if (q < at) {
|
|
1210
|
+
uint32_t len = 0;
|
|
1211
|
+
(void)re_cp_at(s, at, q, &len);
|
|
1212
|
+
if (q + len != at) {
|
|
1213
|
+
q = at - 1; /* a malformed tail: the last byte reads as itself */
|
|
1214
|
+
}
|
|
1215
|
+
} else {
|
|
1216
|
+
q = at - 1;
|
|
1217
|
+
}
|
|
1218
|
+
return re_word((unsigned char)s[q]);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
static int re_word_at(const char* s, uint32_t s_len, uint32_t at) {
|
|
1222
|
+
if (at >= s_len) {
|
|
1223
|
+
return 0;
|
|
1224
|
+
}
|
|
1225
|
+
uint32_t len = 0;
|
|
1226
|
+
uint32_t cp = re_cp_at(s, s_len, at, &len);
|
|
1227
|
+
return cp < 0x80 && re_word((unsigned char)cp);
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/* The step machine. Positions are PER-THREAD in a bounded window: a
|
|
1231
|
+
* byte-literal consumes 1 byte, a class consumes its whole code point
|
|
1232
|
+
* (up to 4), so successor positions trail the frontier by at most
|
|
1233
|
+
* 3 bytes — the pending ring holds them, one slot per frontier
|
|
1234
|
+
* offset. Dedup is (pc, position) per generation: tag 1 marks a ring
|
|
1235
|
+
* enqueue, tag 2 a closure visit. */
|
|
1236
|
+
typedef struct {
|
|
1237
|
+
const re_inst* inst;
|
|
1238
|
+
const uint8_t (*cls)[32];
|
|
1239
|
+
const uint32_t* const* ucls;
|
|
1240
|
+
const uint16_t* ucls_n;
|
|
1241
|
+
const char* s;
|
|
1242
|
+
uint32_t s_len;
|
|
1243
|
+
uint8_t* mark_gen; /* the closure's dedup: (gen, pos, tag=2) per pc */
|
|
1244
|
+
uint8_t* mark_pos;
|
|
1245
|
+
uint8_t* mark_tag;
|
|
1246
|
+
uint8_t* ring_gen; /* the ring-enqueue dedup: (gen, pos, tag=1); a pc
|
|
1247
|
+
* can be a live consumer AND a future successor,
|
|
1248
|
+
* so the two marks never share storage */
|
|
1249
|
+
uint8_t* ring_pos;
|
|
1250
|
+
uint8_t* ring_tag;
|
|
1251
|
+
uint32_t gen;
|
|
1252
|
+
uint32_t gen_at; /* the frontier position the current step started at */
|
|
1253
|
+
uint16_t* stack; /* RE_MAX_INST * 2 + 2 */
|
|
1254
|
+
uint16_t (*ring)[RE_MAX_INST * 2];
|
|
1255
|
+
int* ring_n;
|
|
1256
|
+
int matched;
|
|
1257
|
+
} re_mach;
|
|
1258
|
+
|
|
1259
|
+
static void re_closure(re_mach* v, uint16_t seed, uint32_t pos) {
|
|
1260
|
+
int st_n = 0;
|
|
1261
|
+
v->stack[st_n++] = seed;
|
|
1262
|
+
while (st_n > 0) {
|
|
1263
|
+
uint16_t pc = v->stack[--st_n];
|
|
1264
|
+
/* the TAG field is the gate: it is memset at entry and written
|
|
1265
|
+
* together with gen/pos, so testing it first keeps the other
|
|
1266
|
+
* two reads defined (valgrind: they are uninitialized until
|
|
1267
|
+
* the pc's first real marking) */
|
|
1268
|
+
if (v->mark_tag[pc] == 2 && v->mark_gen[pc] == (uint8_t)v->gen &&
|
|
1269
|
+
v->mark_pos[pc] == (uint8_t)pos) {
|
|
1270
|
+
continue;
|
|
1271
|
+
}
|
|
1272
|
+
v->mark_gen[pc] = (uint8_t)v->gen;
|
|
1273
|
+
v->mark_pos[pc] = (uint8_t)pos;
|
|
1274
|
+
v->mark_tag[pc] = 2;
|
|
1275
|
+
const re_inst* in = &v->inst[pc];
|
|
1276
|
+
if (in->op == RE_OP_JMP) {
|
|
1277
|
+
v->stack[st_n++] = in->x;
|
|
1278
|
+
} else if (in->op == RE_OP_SPLIT) {
|
|
1279
|
+
v->stack[st_n++] = in->x;
|
|
1280
|
+
v->stack[st_n++] = in->y;
|
|
1281
|
+
} else if (in->op == RE_OP_MATCH) {
|
|
1282
|
+
v->matched = 1;
|
|
1283
|
+
} else if (in->op == RE_OP_ASSERT) {
|
|
1284
|
+
int ok = 0;
|
|
1285
|
+
switch (in->cls) {
|
|
1286
|
+
case RE_AS_BOL:
|
|
1287
|
+
ok = pos == 0;
|
|
1288
|
+
break;
|
|
1289
|
+
case RE_AS_EOL:
|
|
1290
|
+
ok = pos == v->s_len;
|
|
1291
|
+
break;
|
|
1292
|
+
default: {
|
|
1293
|
+
int wp = re_word_before(v->s, pos);
|
|
1294
|
+
int wn = re_word_at(v->s, v->s_len, pos);
|
|
1295
|
+
ok = in->cls == RE_AS_WBOUND ? (wp != wn) : (wp == wn);
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
if (ok) {
|
|
1300
|
+
v->stack[st_n++] = in->x;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
/* CHAR/BYTE: consumers — the step at `pos` evaluates them */
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
/* Enqueues a successor state for `pos` (tag 1; the ring slot is the
|
|
1308
|
+
* position's offset from the frontier). */
|
|
1309
|
+
static void re_ring_push(re_mach* v, uint16_t pc, uint32_t pos) {
|
|
1310
|
+
int slot = (int)(pos - (v->gen_at)); /* the frontier this step started at */
|
|
1311
|
+
if (slot < 1 || slot > 4) {
|
|
1312
|
+
return; /* unreachable (adv <= 4); a guard, not a guess */
|
|
1313
|
+
}
|
|
1314
|
+
if (v->ring_tag[pc] == 1 && v->ring_gen[pc] == (uint8_t)v->gen &&
|
|
1315
|
+
v->ring_pos[pc] == (uint8_t)pos) {
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
v->ring_gen[pc] = (uint8_t)v->gen;
|
|
1319
|
+
v->ring_pos[pc] = (uint8_t)pos;
|
|
1320
|
+
v->ring_tag[pc] = 1;
|
|
1321
|
+
if (v->ring_n[slot] >= RE_MAX_INST * 2) {
|
|
1322
|
+
return; /* the slot cap: a duplicate arrival, already bounded */
|
|
1323
|
+
}
|
|
1324
|
+
v->ring[slot][v->ring_n[slot]++] = pc;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
856
1327
|
/* Runs one compiled program over the subject: 1 match, 0 no match.
|
|
857
1328
|
* `entry` is the fragment entry pc (MATCH is emitted last, so the graph
|
|
858
1329
|
* is self-contained). Never fails: a program exists only when its
|
|
859
1330
|
* pattern compiled. */
|
|
860
|
-
static int re_vm(const re_inst* inst, const uint8_t (*cls)[32],
|
|
861
|
-
uint32_t s_len) {
|
|
862
|
-
uint8_t
|
|
863
|
-
|
|
864
|
-
/*
|
|
865
|
-
*
|
|
866
|
-
|
|
867
|
-
|
|
1331
|
+
static int re_vm(const re_inst* inst, const uint8_t (*cls)[32], const uint32_t* const* ucls,
|
|
1332
|
+
const uint16_t* ucls_n, int entry, const char* s, uint32_t s_len) {
|
|
1333
|
+
uint8_t mark_gen[RE_MAX_INST], mark_pos[RE_MAX_INST], mark_tag[RE_MAX_INST];
|
|
1334
|
+
uint8_t ring_gen[RE_MAX_INST], ring_pos[RE_MAX_INST], ring_tag[RE_MAX_INST];
|
|
1335
|
+
/* slot d holds the states positioned at the frontier sp+d; a code
|
|
1336
|
+
* point consumes at most 4 bytes, so five slots cover the window */
|
|
1337
|
+
uint16_t ring[5][RE_MAX_INST * 2];
|
|
1338
|
+
int ring_n[5] = {0, 0, 0, 0, 0};
|
|
868
1339
|
uint16_t stack[RE_MAX_INST * 2 + 2];
|
|
869
1340
|
uint32_t gen = 1;
|
|
870
|
-
memset(
|
|
1341
|
+
memset(mark_tag, 0, sizeof(mark_tag)); /* gen 0 never matches: marks start at 1 */
|
|
1342
|
+
memset(ring_tag, 0, sizeof(ring_tag));
|
|
871
1343
|
|
|
872
1344
|
if (entry < 0) {
|
|
873
1345
|
return 1; /* an empty pattern matches everywhere */
|
|
874
1346
|
}
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1347
|
+
re_mach v;
|
|
1348
|
+
memset(&v, 0, sizeof(v));
|
|
1349
|
+
v.inst = inst;
|
|
1350
|
+
v.cls = cls;
|
|
1351
|
+
v.ucls = ucls;
|
|
1352
|
+
v.ucls_n = ucls_n;
|
|
1353
|
+
v.s = s;
|
|
1354
|
+
v.s_len = s_len;
|
|
1355
|
+
v.mark_gen = mark_gen;
|
|
1356
|
+
v.mark_pos = mark_pos;
|
|
1357
|
+
v.mark_tag = mark_tag;
|
|
1358
|
+
v.ring_gen = ring_gen;
|
|
1359
|
+
v.ring_pos = ring_pos;
|
|
1360
|
+
v.ring_tag = ring_tag;
|
|
1361
|
+
v.gen = gen;
|
|
1362
|
+
v.stack = stack;
|
|
1363
|
+
v.ring = ring;
|
|
1364
|
+
v.ring_n = ring_n;
|
|
1365
|
+
|
|
1366
|
+
/* the initial closure at position 0 (MATCH reachable here is the
|
|
1367
|
+
* empty match) */
|
|
1368
|
+
re_closure(&v, (uint16_t)entry, 0);
|
|
1369
|
+
if (v.matched) {
|
|
1370
|
+
return 1;
|
|
1371
|
+
}
|
|
1372
|
+
for (uint32_t sp = 0; sp < s_len; sp++) {
|
|
1373
|
+
v.gen_at = sp;
|
|
1374
|
+
/* the states that reached THIS position */
|
|
1375
|
+
int n0 = ring_n[0];
|
|
1376
|
+
for (int i = 0; i < n0; i++) {
|
|
1377
|
+
mark_tag[ring[0][i]] = 0; /* the closure re-marks */
|
|
1378
|
+
re_closure(&v, ring[0][i], sp);
|
|
1379
|
+
if (v.matched) {
|
|
1380
|
+
return 1;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
/* the unanchored restart: the entry at every byte offset */
|
|
1384
|
+
re_closure(&v, (uint16_t)entry, sp);
|
|
1385
|
+
if (v.matched) {
|
|
1386
|
+
return 1;
|
|
1387
|
+
}
|
|
1388
|
+
/* the consumers live at sp: everything the closures marked
|
|
1389
|
+
* tag 2 at (gen, sp) */
|
|
1390
|
+
uint32_t len = 1;
|
|
1391
|
+
uint32_t cp = re_cp_at(s, s_len, sp, &len);
|
|
1392
|
+
for (int pc = 0; pc < RE_MAX_INST; pc++) {
|
|
1393
|
+
if (mark_tag[pc] != 2 || mark_gen[pc] != (uint8_t)gen || mark_pos[pc] != (uint8_t)sp) {
|
|
884
1394
|
continue;
|
|
885
1395
|
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
int wn = s_len > 0 && re_word((unsigned char)s[0]);
|
|
909
|
-
ok = inst[pc].cls == RE_AS_WBOUND ? (int)wn : !(int)wn;
|
|
910
|
-
break;
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
if (ok) {
|
|
914
|
-
stack[st_n++] = inst[pc].x; /* the connected exit */
|
|
1396
|
+
const re_inst* in = &inst[pc];
|
|
1397
|
+
int hit = 0;
|
|
1398
|
+
uint32_t adv = 1;
|
|
1399
|
+
if (in->op == RE_OP_BYTE) {
|
|
1400
|
+
hit = in->cls == (unsigned char)s[sp];
|
|
1401
|
+
} else if (in->op == RE_OP_CHAR) {
|
|
1402
|
+
if (ucls != NULL && ucls[in->cls] != NULL) {
|
|
1403
|
+
hit = re_ranges_has(ucls[in->cls], ucls_n[in->cls], cp);
|
|
1404
|
+
adv = len;
|
|
1405
|
+
} else {
|
|
1406
|
+
/* the byte bitmap covers the whole code point: the
|
|
1407
|
+
* point matches when EVERY byte of it is in the
|
|
1408
|
+
* class (for ASCII code points the old behavior) */
|
|
1409
|
+
hit = 1;
|
|
1410
|
+
for (uint32_t k = 0; k < len; k++) {
|
|
1411
|
+
unsigned char b = (unsigned char)s[sp + k];
|
|
1412
|
+
if (!(cls[in->cls][(b >> 3) & 31] & (1u << (b & 7)))) {
|
|
1413
|
+
hit = 0;
|
|
1414
|
+
break;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
adv = len;
|
|
915
1418
|
}
|
|
916
1419
|
} else {
|
|
917
|
-
|
|
1420
|
+
continue;
|
|
918
1421
|
}
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
for (uint32_t sp = 0; sp < s_len; sp++) {
|
|
922
|
-
gen++;
|
|
923
|
-
if ((gen & 0xFF) == 0) { /* the mark generation wrapped */
|
|
924
|
-
memset(mark, 0, sizeof(mark));
|
|
925
|
-
gen++;
|
|
926
|
-
}
|
|
927
|
-
uint8_t byte = (unsigned char)s[sp];
|
|
928
|
-
int nxt_n = 0;
|
|
929
|
-
for (int i = 0; i < cur_n; i++) {
|
|
930
|
-
uint16_t pc = cur[i];
|
|
931
|
-
int hit = inst[pc].op == RE_OP_BYTE
|
|
932
|
-
? (inst[pc].cls == byte)
|
|
933
|
-
: (cls[inst[pc].cls][(byte >> 3) & 31] & (1u << (byte & 7))) != 0;
|
|
934
1422
|
if (hit) {
|
|
935
|
-
|
|
936
|
-
* a fall-through: fragments link arbitrary pcs */
|
|
937
|
-
nxt[nxt_n++] = inst[pc].x;
|
|
1423
|
+
re_ring_push(&v, in->x, sp + adv);
|
|
938
1424
|
}
|
|
939
1425
|
}
|
|
940
|
-
|
|
941
|
-
|
|
1426
|
+
/* the ring shifts: slot d holds sp+d; the next frontier is sp+1 */
|
|
1427
|
+
for (int d = 0; d < 4; d++) {
|
|
1428
|
+
memcpy(ring[d], ring[d + 1], (size_t)ring_n[d + 1] * sizeof(uint16_t));
|
|
1429
|
+
ring_n[d] = ring_n[d + 1];
|
|
1430
|
+
}
|
|
1431
|
+
ring_n[4] = 0;
|
|
942
1432
|
gen++;
|
|
943
|
-
if ((gen & 0xFF) == 0) {
|
|
944
|
-
memset(
|
|
1433
|
+
if ((gen & 0xFF) == 0) { /* the mark generation wrapped */
|
|
1434
|
+
memset(mark_tag, 0, sizeof(mark_tag));
|
|
1435
|
+
memset(ring_tag, 0, sizeof(ring_tag));
|
|
945
1436
|
gen++;
|
|
946
1437
|
}
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
if (op == RE_OP_JMP) {
|
|
960
|
-
stack[st_n++] = inst[pc].x;
|
|
961
|
-
} else if (op == RE_OP_SPLIT) {
|
|
962
|
-
stack[st_n++] = inst[pc].x;
|
|
963
|
-
stack[st_n++] = inst[pc].y;
|
|
964
|
-
} else if (op == RE_OP_MATCH) {
|
|
965
|
-
matched = 1;
|
|
966
|
-
} else if (op == RE_OP_ASSERT) {
|
|
967
|
-
int ok = 0;
|
|
968
|
-
switch (inst[pc].cls) {
|
|
969
|
-
case RE_AS_BOL:
|
|
970
|
-
ok = (sp + 1) == 0;
|
|
971
|
-
break;
|
|
972
|
-
case RE_AS_EOL:
|
|
973
|
-
ok = (int)(sp + 1) == (int)s_len;
|
|
974
|
-
break;
|
|
975
|
-
default: {
|
|
976
|
-
int wp = re_word((unsigned char)s[sp]);
|
|
977
|
-
int wn = (sp + 1) < (uint32_t)s_len && re_word((unsigned char)s[sp + 1]);
|
|
978
|
-
ok = inst[pc].cls == RE_AS_WBOUND ? (wp != wn) : (wp == wn);
|
|
979
|
-
break;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
if (ok) {
|
|
983
|
-
stack[st_n++] = inst[pc].x; /* the connected exit */
|
|
984
|
-
}
|
|
985
|
-
} else {
|
|
986
|
-
nxt[live_n++] = pc; /* a live thread for the next byte */
|
|
1438
|
+
v.gen = gen;
|
|
1439
|
+
/* the tail: states that reached s_len run their closure there
|
|
1440
|
+
* (EOL and MATCH live at the end) */
|
|
1441
|
+
}
|
|
1442
|
+
{
|
|
1443
|
+
int n0 = ring_n[0];
|
|
1444
|
+
v.gen_at = s_len;
|
|
1445
|
+
for (int i = 0; i < n0; i++) {
|
|
1446
|
+
mark_tag[ring[0][i]] = 0;
|
|
1447
|
+
re_closure(&v, ring[0][i], s_len);
|
|
1448
|
+
if (v.matched) {
|
|
1449
|
+
return 1;
|
|
987
1450
|
}
|
|
988
1451
|
}
|
|
989
|
-
if (matched) {
|
|
990
|
-
return 1;
|
|
991
|
-
}
|
|
992
|
-
memcpy(cur, nxt, (size_t)live_n * sizeof(uint16_t));
|
|
993
|
-
cur_n = live_n;
|
|
994
1452
|
}
|
|
995
1453
|
return 0;
|
|
996
1454
|
}
|
|
997
1455
|
|
|
998
|
-
/* ---- the one-shot search (compile fresh, run, drop) --------------------- */
|
|
999
|
-
|
|
1000
1456
|
int yep_re_search(const char* pat, uint32_t pat_len, const char* s, uint32_t s_len) {
|
|
1001
1457
|
if (pat == NULL || pat_len == 0 || pat_len > RE_MAX_PAT) {
|
|
1002
1458
|
return -1;
|
|
@@ -1006,7 +1462,7 @@ int yep_re_search(const char* pat, uint32_t pat_len, const char* s, uint32_t s_l
|
|
|
1006
1462
|
if (re_build(&c, pat, pat_len, &entry) != 0) {
|
|
1007
1463
|
return -1;
|
|
1008
1464
|
}
|
|
1009
|
-
return re_vm(c.inst, c.cls, entry, s, s_len);
|
|
1465
|
+
return re_vm(c.inst, c.cls, (const uint32_t* const*)c.ucls, c.ucls_n, entry, s, s_len);
|
|
1010
1466
|
}
|
|
1011
1467
|
|
|
1012
1468
|
/* ---- the retained programs (the compiled schema's pattern cache) -------- */
|
|
@@ -1018,6 +1474,10 @@ typedef struct {
|
|
|
1018
1474
|
re_inst* inst;
|
|
1019
1475
|
uint8_t (*cls)[32];
|
|
1020
1476
|
int inst_n, cls_n;
|
|
1477
|
+
/* the code-point class refs: process-immutable static tables, so
|
|
1478
|
+
* the reference rides the program (never freed per-program) */
|
|
1479
|
+
const uint32_t* ucls[RE_MAX_CLS];
|
|
1480
|
+
uint16_t ucls_n[RE_MAX_CLS];
|
|
1021
1481
|
int entry;
|
|
1022
1482
|
} re_prog;
|
|
1023
1483
|
|
|
@@ -1055,6 +1515,11 @@ static int re_compile(const char* pat, uint32_t pat_len, re_prog* out) {
|
|
|
1055
1515
|
}
|
|
1056
1516
|
memcpy(p.inst, c.inst, (size_t)c.inst_n * sizeof(re_inst));
|
|
1057
1517
|
memcpy(p.cls, c.cls, (size_t)c.cls_n * 32);
|
|
1518
|
+
memcpy((void*)p.ucls, (const void*)c.ucls, sizeof(p.ucls)); /* MSVC C4090: the
|
|
1519
|
+
* const-pointee array decays
|
|
1520
|
+
* at the wrong level for
|
|
1521
|
+
* void* */
|
|
1522
|
+
memcpy(p.ucls_n, c.ucls_n, sizeof(p.ucls_n));
|
|
1058
1523
|
*out = p;
|
|
1059
1524
|
return 0;
|
|
1060
1525
|
}
|
|
@@ -1123,8 +1588,9 @@ int yep_re_cache_search(const yep_re_cache* t, const char* pat, uint32_t plen, c
|
|
|
1123
1588
|
if (t != NULL && pat != NULL) {
|
|
1124
1589
|
for (int i = 0; i < t->n; i++) {
|
|
1125
1590
|
if (t->slot[i].plen == plen && memcmp(t->slot[i].pat, pat, plen) == 0) {
|
|
1126
|
-
return re_vm(t->slot[i].prog.inst, t->slot[i].prog.cls,
|
|
1127
|
-
|
|
1591
|
+
return re_vm(t->slot[i].prog.inst, t->slot[i].prog.cls,
|
|
1592
|
+
(const uint32_t* const*)t->slot[i].prog.ucls, t->slot[i].prog.ucls_n,
|
|
1593
|
+
t->slot[i].prog.entry, s, s_len);
|
|
1128
1594
|
}
|
|
1129
1595
|
}
|
|
1130
1596
|
}
|