/src/CMake/Utilities/cmllpkgc/llpkgc_frag__internal.c
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. |
2 | | See accompanying file LICENSE.rst for details. */ |
3 | | /* This code was generated by llpkgc, do not edit it by hand |
4 | | See: https://gitlab.kitware.com/utils/llpkgc */ |
5 | | |
6 | | |
7 | | #include <stdlib.h> |
8 | | #include <stdint.h> |
9 | | #include <string.h> |
10 | | |
11 | | #ifdef __SSE4_2__ |
12 | | #ifdef _MSC_VER |
13 | | #include <nmmintrin.h> |
14 | | #else /* !_MSC_VER */ |
15 | | #include <x86intrin.h> |
16 | | #endif /* _MSC_VER */ |
17 | | #endif /* __SSE4_2__ */ |
18 | | |
19 | | #if defined(__ARM_NEON__) || defined(__ARM_NEON) |
20 | | #include <arm_neon.h> |
21 | | #endif /* __ARM_NEON__ */ |
22 | | |
23 | | #ifdef __wasm__ |
24 | | #include <wasm_simd128.h> |
25 | | #endif /* __wasm__ */ |
26 | | |
27 | | #ifdef _MSC_VER |
28 | | #define ALIGN(n) _declspec(align(n)) |
29 | | #define UNREACHABLE __assume(0) |
30 | | #else /* !_MSC_VER */ |
31 | | #define ALIGN(n) __attribute__((aligned(n))) |
32 | 0 | #define UNREACHABLE __builtin_unreachable() |
33 | | #endif /* _MSC_VER */ |
34 | | |
35 | | #include "llpkgc_frag__internal.h" |
36 | | |
37 | | typedef int (*llpkgc_frag__internal__span_cb)( |
38 | | llpkgc_frag__internal_t*, const char*, const char*); |
39 | | |
40 | | enum llparse_state_e { |
41 | | s_error, |
42 | | s_n_llpkgc_frag__internal__n_double_quote_end, |
43 | | s_n_llpkgc_frag__internal__n_double_escaped_character, |
44 | | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1, |
45 | | s_n_llpkgc_frag__internal__n_double_escape, |
46 | | s_n_llpkgc_frag__internal__n_double_escape_start, |
47 | | s_n_llpkgc_frag__internal__n_double_quote, |
48 | | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text, |
49 | | s_n_llpkgc_frag__internal__n_single_quote_end, |
50 | | s_n_llpkgc_frag__internal__n_single_quote, |
51 | | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_2, |
52 | | s_n_llpkgc_frag__internal__n_text, |
53 | | s_n_llpkgc_frag__internal__n_escaped_character, |
54 | | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_3, |
55 | | s_n_llpkgc_frag__internal__n_escape_start, |
56 | | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_4, |
57 | | s_n_llpkgc_frag__internal__n_token, |
58 | | s_n_llpkgc_frag__internal__n_invoke_update_finish, |
59 | | s_n_llpkgc_frag__internal__n_start, |
60 | | }; |
61 | | typedef enum llparse_state_e llparse_state_t; |
62 | | |
63 | | int llpkgc_frag__on_fragment_text( |
64 | | llpkgc_frag__internal_t* s, const unsigned char* p, |
65 | | const unsigned char* endp); |
66 | | |
67 | | int llpkgc_frag__internal__c_update_finish( |
68 | | llpkgc_frag__internal_t* state, |
69 | | const unsigned char* p, |
70 | 93.8M | const unsigned char* endp) { |
71 | 93.8M | state->finish = 1; |
72 | 93.8M | return 0; |
73 | 93.8M | } |
74 | | |
75 | | int llpkgc_frag__on_frag_complete( |
76 | | llpkgc_frag__internal_t* s, const unsigned char* p, |
77 | | const unsigned char* endp); |
78 | | |
79 | | int llpkgc_frag__internal__c_update_finish_1( |
80 | | llpkgc_frag__internal_t* state, |
81 | | const unsigned char* p, |
82 | 44.9M | const unsigned char* endp) { |
83 | 44.9M | state->finish = 0; |
84 | 44.9M | return 0; |
85 | 44.9M | } |
86 | | |
87 | | int llpkgc_frag__internal__c_update_finish_2( |
88 | | llpkgc_frag__internal_t* state, |
89 | | const unsigned char* p, |
90 | 3.83M | const unsigned char* endp) { |
91 | 3.83M | state->finish = 2; |
92 | 3.83M | return 0; |
93 | 3.83M | } |
94 | | |
95 | | int llpkgc_frag__emit_mark( |
96 | | llpkgc_frag__internal_t* s, const unsigned char* p, |
97 | | const unsigned char* endp); |
98 | | |
99 | | int llpkgc_frag__internal__c_update_finish_5( |
100 | | llpkgc_frag__internal_t* state, |
101 | | const unsigned char* p, |
102 | 678k | const unsigned char* endp) { |
103 | 678k | state->finish = 3; |
104 | 678k | return 0; |
105 | 678k | } |
106 | | |
107 | 3.89k | int llpkgc_frag__internal_init(llpkgc_frag__internal_t* state) { |
108 | 3.89k | memset(state, 0, sizeof(*state)); |
109 | 3.89k | state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_start; |
110 | 3.89k | return 0; |
111 | 3.89k | } |
112 | | |
113 | | static llparse_state_t llpkgc_frag__internal__run( |
114 | | llpkgc_frag__internal_t* state, |
115 | | const unsigned char* p, |
116 | 3.71k | const unsigned char* endp) { |
117 | 3.71k | int match; |
118 | 3.71k | switch ((llparse_state_t) (intptr_t) state->_current) { |
119 | 0 | case s_n_llpkgc_frag__internal__n_double_quote_end: |
120 | 2.96M | s_n_llpkgc_frag__internal__n_double_quote_end: { |
121 | 2.96M | if (p == endp) { |
122 | 0 | return s_n_llpkgc_frag__internal__n_double_quote_end; |
123 | 0 | } |
124 | 2.96M | p++; |
125 | 2.96M | goto s_n_llpkgc_frag__internal__n_invoke_update_finish; |
126 | 2.96M | UNREACHABLE; |
127 | 2.96M | } |
128 | 0 | case s_n_llpkgc_frag__internal__n_double_escaped_character: |
129 | 161k | s_n_llpkgc_frag__internal__n_double_escaped_character: { |
130 | 161k | if (p == endp) { |
131 | 0 | return s_n_llpkgc_frag__internal__n_double_escaped_character; |
132 | 0 | } |
133 | 161k | p++; |
134 | 161k | goto s_n_llpkgc_frag__internal__n_invoke_update_finish_3; |
135 | 161k | UNREACHABLE; |
136 | 161k | } |
137 | 0 | case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1: |
138 | 161k | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1: { |
139 | 161k | if (p == endp) { |
140 | 0 | return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1; |
141 | 0 | } |
142 | 161k | state->_span_pos0 = (void*) p; |
143 | 161k | goto s_n_llpkgc_frag__internal__n_double_escaped_character; |
144 | 161k | UNREACHABLE; |
145 | 161k | } |
146 | 0 | case s_n_llpkgc_frag__internal__n_double_escape: |
147 | 161k | s_n_llpkgc_frag__internal__n_double_escape: { |
148 | 161k | if (p == endp) { |
149 | 45 | return s_n_llpkgc_frag__internal__n_double_escape; |
150 | 45 | } |
151 | 161k | switch (*p) { |
152 | 905 | case '"': { |
153 | 905 | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1; |
154 | 0 | } |
155 | 18.5k | case '$': { |
156 | 18.5k | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1; |
157 | 0 | } |
158 | 67.6k | case 92: { |
159 | 67.6k | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1; |
160 | 0 | } |
161 | 682 | case '`': { |
162 | 682 | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1; |
163 | 0 | } |
164 | 73.2k | default: { |
165 | 73.2k | goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__emit_mark; |
166 | 0 | } |
167 | 161k | } |
168 | 161k | UNREACHABLE; |
169 | 161k | } |
170 | 0 | case s_n_llpkgc_frag__internal__n_double_escape_start: |
171 | 161k | s_n_llpkgc_frag__internal__n_double_escape_start: { |
172 | 161k | if (p == endp) { |
173 | 0 | return s_n_llpkgc_frag__internal__n_double_escape_start; |
174 | 0 | } |
175 | 161k | p++; |
176 | 161k | goto s_n_llpkgc_frag__internal__n_double_escape; |
177 | 161k | UNREACHABLE; |
178 | 161k | } |
179 | 0 | case s_n_llpkgc_frag__internal__n_double_quote: |
180 | 35.2M | s_n_llpkgc_frag__internal__n_double_quote: { |
181 | 35.2M | if (p == endp) { |
182 | 267 | return s_n_llpkgc_frag__internal__n_double_quote; |
183 | 267 | } |
184 | 35.2M | switch (*p) { |
185 | 2.96M | case '"': { |
186 | 2.96M | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text; |
187 | 0 | } |
188 | 161k | case 92: { |
189 | 161k | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_1; |
190 | 0 | } |
191 | 32.1M | default: { |
192 | 32.1M | p++; |
193 | 32.1M | goto s_n_llpkgc_frag__internal__n_double_quote; |
194 | 0 | } |
195 | 35.2M | } |
196 | 35.2M | UNREACHABLE; |
197 | 35.2M | } |
198 | 0 | case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text: |
199 | 2.96M | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text: { |
200 | 2.96M | if (p == endp) { |
201 | 54 | return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text; |
202 | 54 | } |
203 | 2.96M | state->_span_pos0 = (void*) p; |
204 | 2.96M | goto s_n_llpkgc_frag__internal__n_invoke_update_finish_2; |
205 | 2.96M | UNREACHABLE; |
206 | 2.96M | } |
207 | 0 | case s_n_llpkgc_frag__internal__n_single_quote_end: |
208 | 716k | s_n_llpkgc_frag__internal__n_single_quote_end: { |
209 | 716k | if (p == endp) { |
210 | 0 | return s_n_llpkgc_frag__internal__n_single_quote_end; |
211 | 0 | } |
212 | 716k | p++; |
213 | 716k | goto s_n_llpkgc_frag__internal__n_invoke_update_finish; |
214 | 716k | UNREACHABLE; |
215 | 716k | } |
216 | 0 | case s_n_llpkgc_frag__internal__n_single_quote: |
217 | 239M | s_n_llpkgc_frag__internal__n_single_quote: { |
218 | 239M | if (p == endp) { |
219 | 195 | return s_n_llpkgc_frag__internal__n_single_quote; |
220 | 195 | } |
221 | 239M | switch (*p) { |
222 | 716k | case 39: { |
223 | 716k | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_2; |
224 | 0 | } |
225 | 238M | default: { |
226 | 238M | p++; |
227 | 238M | goto s_n_llpkgc_frag__internal__n_single_quote; |
228 | 0 | } |
229 | 239M | } |
230 | 239M | UNREACHABLE; |
231 | 239M | } |
232 | 0 | case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_2: |
233 | 716k | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_2: { |
234 | 716k | if (p == endp) { |
235 | 82 | return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_2; |
236 | 82 | } |
237 | 716k | state->_span_pos0 = (void*) p; |
238 | 716k | goto s_n_llpkgc_frag__internal__n_invoke_update_finish_4; |
239 | 716k | UNREACHABLE; |
240 | 716k | } |
241 | 0 | case s_n_llpkgc_frag__internal__n_text: |
242 | 355M | s_n_llpkgc_frag__internal__n_text: { |
243 | 355M | if (p == endp) { |
244 | 2.89k | return s_n_llpkgc_frag__internal__n_text; |
245 | 2.89k | } |
246 | 355M | switch (*p) { |
247 | 3.48M | case 9: { |
248 | 3.48M | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
249 | 0 | } |
250 | 0 | case 10: { |
251 | 0 | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
252 | 0 | } |
253 | 87.5k | case 11: { |
254 | 87.5k | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
255 | 0 | } |
256 | 46.5k | case 12: { |
257 | 46.5k | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
258 | 0 | } |
259 | 0 | case 13: { |
260 | 0 | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
261 | 0 | } |
262 | 39.9M | case ' ': { |
263 | 39.9M | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
264 | 0 | } |
265 | 91.7k | case '"': { |
266 | 91.7k | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
267 | 0 | } |
268 | 413k | case 39: { |
269 | 413k | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
270 | 0 | } |
271 | 404k | case 92: { |
272 | 404k | goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3; |
273 | 0 | } |
274 | 310M | default: { |
275 | 310M | p++; |
276 | 310M | goto s_n_llpkgc_frag__internal__n_text; |
277 | 0 | } |
278 | 355M | } |
279 | 355M | UNREACHABLE; |
280 | 355M | } |
281 | 0 | case s_n_llpkgc_frag__internal__n_escaped_character: |
282 | 678k | s_n_llpkgc_frag__internal__n_escaped_character: { |
283 | 678k | if (p == endp) { |
284 | 0 | return s_n_llpkgc_frag__internal__n_escaped_character; |
285 | 0 | } |
286 | 678k | p++; |
287 | 678k | goto s_n_llpkgc_frag__internal__n_invoke_update_finish_6; |
288 | 678k | UNREACHABLE; |
289 | 678k | } |
290 | 0 | case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_3: |
291 | 678k | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_3: { |
292 | 678k | if (p == endp) { |
293 | 53 | return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_3; |
294 | 53 | } |
295 | 678k | state->_span_pos0 = (void*) p; |
296 | 678k | goto s_n_llpkgc_frag__internal__n_escaped_character; |
297 | 678k | UNREACHABLE; |
298 | 678k | } |
299 | 0 | case s_n_llpkgc_frag__internal__n_escape_start: |
300 | 678k | s_n_llpkgc_frag__internal__n_escape_start: { |
301 | 678k | if (p == endp) { |
302 | 0 | return s_n_llpkgc_frag__internal__n_escape_start; |
303 | 0 | } |
304 | 678k | p++; |
305 | 678k | goto s_n_llpkgc_frag__internal__n_invoke_update_finish_5; |
306 | 678k | UNREACHABLE; |
307 | 678k | } |
308 | 0 | case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_4: |
309 | 43.7M | s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_4: { |
310 | 43.7M | if (p == endp) { |
311 | 0 | return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_4; |
312 | 0 | } |
313 | 43.7M | state->_span_pos0 = (void*) p; |
314 | 43.7M | p++; |
315 | 43.7M | goto s_n_llpkgc_frag__internal__n_text; |
316 | 43.7M | UNREACHABLE; |
317 | 43.7M | } |
318 | 0 | case s_n_llpkgc_frag__internal__n_token: |
319 | 93.1M | s_n_llpkgc_frag__internal__n_token: { |
320 | 93.1M | if (p == endp) { |
321 | 73 | return s_n_llpkgc_frag__internal__n_token; |
322 | 73 | } |
323 | 93.1M | switch (*p) { |
324 | 4.86M | case 9: { |
325 | 4.86M | p++; |
326 | 4.86M | goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__on_frag_complete; |
327 | 0 | } |
328 | 0 | case 10: { |
329 | 0 | p++; |
330 | 0 | goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__on_frag_complete; |
331 | 0 | } |
332 | 87.5k | case 11: { |
333 | 87.5k | p++; |
334 | 87.5k | goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__on_frag_complete; |
335 | 0 | } |
336 | 46.5k | case 12: { |
337 | 46.5k | p++; |
338 | 46.5k | goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__on_frag_complete; |
339 | 0 | } |
340 | 0 | case 13: { |
341 | 0 | p++; |
342 | 0 | goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__on_frag_complete; |
343 | 0 | } |
344 | 39.9M | case ' ': { |
345 | 39.9M | p++; |
346 | 39.9M | goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__on_frag_complete; |
347 | 0 | } |
348 | 2.96M | case '"': { |
349 | 2.96M | p++; |
350 | 2.96M | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text; |
351 | 0 | } |
352 | 716k | case 39: { |
353 | 716k | p++; |
354 | 716k | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_2; |
355 | 0 | } |
356 | 678k | case 92: { |
357 | 678k | goto s_n_llpkgc_frag__internal__n_escape_start; |
358 | 0 | } |
359 | 43.7M | default: { |
360 | 43.7M | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_4; |
361 | 0 | } |
362 | 93.1M | } |
363 | 93.1M | UNREACHABLE; |
364 | 93.1M | } |
365 | 0 | case s_n_llpkgc_frag__internal__n_invoke_update_finish: |
366 | 93.1M | s_n_llpkgc_frag__internal__n_invoke_update_finish: { |
367 | 93.1M | switch (llpkgc_frag__internal__c_update_finish(state, p, endp)) { |
368 | 93.1M | default: |
369 | 93.1M | goto s_n_llpkgc_frag__internal__n_token; |
370 | 93.1M | } |
371 | 93.1M | UNREACHABLE; |
372 | 93.1M | } |
373 | 3.71k | case s_n_llpkgc_frag__internal__n_start: |
374 | 51.5M | s_n_llpkgc_frag__internal__n_start: { |
375 | 51.5M | if (p == endp) { |
376 | 53 | return s_n_llpkgc_frag__internal__n_start; |
377 | 53 | } |
378 | 51.5M | switch (*p) { |
379 | 952k | case 9: { |
380 | 952k | p++; |
381 | 952k | goto s_n_llpkgc_frag__internal__n_start; |
382 | 0 | } |
383 | 0 | case 10: { |
384 | 0 | p++; |
385 | 0 | goto s_n_llpkgc_frag__internal__n_start; |
386 | 0 | } |
387 | 20.1k | case 11: { |
388 | 20.1k | p++; |
389 | 20.1k | goto s_n_llpkgc_frag__internal__n_start; |
390 | 0 | } |
391 | 134k | case 12: { |
392 | 134k | p++; |
393 | 134k | goto s_n_llpkgc_frag__internal__n_start; |
394 | 0 | } |
395 | 0 | case 13: { |
396 | 0 | p++; |
397 | 0 | goto s_n_llpkgc_frag__internal__n_start; |
398 | 0 | } |
399 | 5.48M | case ' ': { |
400 | 5.48M | p++; |
401 | 5.48M | goto s_n_llpkgc_frag__internal__n_start; |
402 | 0 | } |
403 | 44.9M | default: { |
404 | 44.9M | goto s_n_llpkgc_frag__internal__n_invoke_update_finish; |
405 | 0 | } |
406 | 51.5M | } |
407 | 51.5M | UNREACHABLE; |
408 | 51.5M | } |
409 | 0 | default: |
410 | 0 | UNREACHABLE; |
411 | 3.71k | } |
412 | 44.9M | s_n_llpkgc_frag__internal__n_invoke_update_finish_1: { |
413 | 44.9M | switch (llpkgc_frag__internal__c_update_finish_1(state, p, endp)) { |
414 | 44.9M | default: |
415 | 44.9M | goto s_n_llpkgc_frag__internal__n_start; |
416 | 44.9M | } |
417 | 44.9M | UNREACHABLE; |
418 | 44.9M | } |
419 | 0 | s_n_llpkgc_frag__internal__n_error_1: { |
420 | 0 | state->error = 0x5; |
421 | 0 | state->reason = "Internal parser error"; |
422 | 0 | state->error_pos = (const char*) p; |
423 | 0 | state->_current = (void*) (intptr_t) s_error; |
424 | 0 | return s_error; |
425 | 44.9M | UNREACHABLE; |
426 | 44.9M | } |
427 | 0 | s_n_llpkgc_frag__internal__n_error: { |
428 | 0 | state->error = 0x2; |
429 | 0 | state->reason = "Callback error"; |
430 | 0 | state->error_pos = (const char*) p; |
431 | 0 | state->_current = (void*) (intptr_t) s_error; |
432 | 0 | return s_error; |
433 | 44.9M | UNREACHABLE; |
434 | 44.9M | } |
435 | 44.9M | s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__on_frag_complete: { |
436 | 44.9M | switch (llpkgc_frag__on_frag_complete(state, p, endp)) { |
437 | 44.9M | case 0: |
438 | 44.9M | goto s_n_llpkgc_frag__internal__n_invoke_update_finish_1; |
439 | 0 | case 5: |
440 | 0 | goto s_n_llpkgc_frag__internal__n_error_1; |
441 | 0 | default: |
442 | 0 | goto s_n_llpkgc_frag__internal__n_error; |
443 | 44.9M | } |
444 | 44.9M | UNREACHABLE; |
445 | 44.9M | } |
446 | 2.96M | s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text: { |
447 | 2.96M | const unsigned char* start; |
448 | 2.96M | int err; |
449 | | |
450 | 2.96M | start = state->_span_pos0; |
451 | 2.96M | state->_span_pos0 = NULL; |
452 | 2.96M | err = llpkgc_frag__on_fragment_text(state, start, p); |
453 | 2.96M | if (err != 0) { |
454 | 0 | state->error = err; |
455 | 0 | state->error_pos = (const char*) p; |
456 | 0 | state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_double_quote_end; |
457 | 0 | return s_error; |
458 | 0 | } |
459 | 2.96M | goto s_n_llpkgc_frag__internal__n_double_quote_end; |
460 | 2.96M | UNREACHABLE; |
461 | 2.96M | } |
462 | 161k | s_n_llpkgc_frag__internal__n_invoke_update_finish_3: { |
463 | 161k | switch (llpkgc_frag__internal__c_update_finish_2(state, p, endp)) { |
464 | 161k | default: |
465 | 161k | goto s_n_llpkgc_frag__internal__n_double_quote; |
466 | 161k | } |
467 | 161k | UNREACHABLE; |
468 | 161k | } |
469 | 0 | s_n_llpkgc_frag__internal__n_error_3: { |
470 | 0 | state->error = 0x5; |
471 | 0 | state->reason = "Internal parser error"; |
472 | 0 | state->error_pos = (const char*) p; |
473 | 0 | state->_current = (void*) (intptr_t) s_error; |
474 | 0 | return s_error; |
475 | 161k | UNREACHABLE; |
476 | 161k | } |
477 | 0 | s_n_llpkgc_frag__internal__n_error_2: { |
478 | 0 | state->error = 0x2; |
479 | 0 | state->reason = "Callback error"; |
480 | 0 | state->error_pos = (const char*) p; |
481 | 0 | state->_current = (void*) (intptr_t) s_error; |
482 | 0 | return s_error; |
483 | 161k | UNREACHABLE; |
484 | 161k | } |
485 | 73.2k | s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__emit_mark: { |
486 | 73.2k | switch (llpkgc_frag__emit_mark(state, p, endp)) { |
487 | 73.2k | case 0: |
488 | 73.2k | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_1; |
489 | 0 | case 5: |
490 | 0 | goto s_n_llpkgc_frag__internal__n_error_3; |
491 | 0 | default: |
492 | 0 | goto s_n_llpkgc_frag__internal__n_error_2; |
493 | 73.2k | } |
494 | 73.2k | UNREACHABLE; |
495 | 73.2k | } |
496 | 161k | s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_1: { |
497 | 161k | const unsigned char* start; |
498 | 161k | int err; |
499 | | |
500 | 161k | start = state->_span_pos0; |
501 | 161k | state->_span_pos0 = NULL; |
502 | 161k | err = llpkgc_frag__on_fragment_text(state, start, p); |
503 | 161k | if (err != 0) { |
504 | 0 | state->error = err; |
505 | 0 | state->error_pos = (const char*) p; |
506 | 0 | state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_double_escape_start; |
507 | 0 | return s_error; |
508 | 0 | } |
509 | 161k | goto s_n_llpkgc_frag__internal__n_double_escape_start; |
510 | 161k | UNREACHABLE; |
511 | 161k | } |
512 | 2.96M | s_n_llpkgc_frag__internal__n_invoke_update_finish_2: { |
513 | 2.96M | switch (llpkgc_frag__internal__c_update_finish_2(state, p, endp)) { |
514 | 2.96M | default: |
515 | 2.96M | goto s_n_llpkgc_frag__internal__n_double_quote; |
516 | 2.96M | } |
517 | 2.96M | UNREACHABLE; |
518 | 2.96M | } |
519 | 716k | s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_2: { |
520 | 716k | const unsigned char* start; |
521 | 716k | int err; |
522 | | |
523 | 716k | start = state->_span_pos0; |
524 | 716k | state->_span_pos0 = NULL; |
525 | 716k | err = llpkgc_frag__on_fragment_text(state, start, p); |
526 | 716k | if (err != 0) { |
527 | 0 | state->error = err; |
528 | 0 | state->error_pos = (const char*) p; |
529 | 0 | state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_single_quote_end; |
530 | 0 | return s_error; |
531 | 0 | } |
532 | 716k | goto s_n_llpkgc_frag__internal__n_single_quote_end; |
533 | 716k | UNREACHABLE; |
534 | 716k | } |
535 | 716k | s_n_llpkgc_frag__internal__n_invoke_update_finish_4: { |
536 | 716k | switch (llpkgc_frag__internal__c_update_finish_2(state, p, endp)) { |
537 | 716k | default: |
538 | 716k | goto s_n_llpkgc_frag__internal__n_single_quote; |
539 | 716k | } |
540 | 716k | UNREACHABLE; |
541 | 716k | } |
542 | 44.4M | s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__on_fragment_text_3: { |
543 | 44.4M | const unsigned char* start; |
544 | 44.4M | int err; |
545 | | |
546 | 44.4M | start = state->_span_pos0; |
547 | 44.4M | state->_span_pos0 = NULL; |
548 | 44.4M | err = llpkgc_frag__on_fragment_text(state, start, p); |
549 | 44.4M | if (err != 0) { |
550 | 0 | state->error = err; |
551 | 0 | state->error_pos = (const char*) p; |
552 | 0 | state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_invoke_update_finish; |
553 | 0 | return s_error; |
554 | 0 | } |
555 | 44.4M | goto s_n_llpkgc_frag__internal__n_invoke_update_finish; |
556 | 44.4M | UNREACHABLE; |
557 | 44.4M | } |
558 | 678k | s_n_llpkgc_frag__internal__n_invoke_update_finish_6: { |
559 | 678k | switch (llpkgc_frag__internal__c_update_finish(state, p, endp)) { |
560 | 678k | default: |
561 | 678k | goto s_n_llpkgc_frag__internal__n_text; |
562 | 678k | } |
563 | 678k | UNREACHABLE; |
564 | 678k | } |
565 | 678k | s_n_llpkgc_frag__internal__n_invoke_update_finish_5: { |
566 | 678k | switch (llpkgc_frag__internal__c_update_finish_5(state, p, endp)) { |
567 | 678k | default: |
568 | 678k | goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__on_fragment_text_3; |
569 | 678k | } |
570 | 678k | UNREACHABLE; |
571 | 678k | } |
572 | 678k | } |
573 | | |
574 | 3.71k | int llpkgc_frag__internal_execute(llpkgc_frag__internal_t* state, const char* p, const char* endp) { |
575 | 3.71k | llparse_state_t next; |
576 | | |
577 | | /* check lingering errors */ |
578 | 3.71k | if (state->error != 0) { |
579 | 0 | return state->error; |
580 | 0 | } |
581 | | |
582 | | /* restart spans */ |
583 | 3.71k | if (state->_span_pos0 != NULL) { |
584 | 0 | state->_span_pos0 = (void*) p; |
585 | 0 | } |
586 | | |
587 | 3.71k | next = llpkgc_frag__internal__run(state, (const unsigned char*) p, (const unsigned char*) endp); |
588 | 3.71k | if (next == s_error) { |
589 | 0 | return state->error; |
590 | 0 | } |
591 | 3.71k | state->_current = (void*) (intptr_t) next; |
592 | | |
593 | | /* execute spans */ |
594 | 3.71k | if (state->_span_pos0 != NULL) { |
595 | 3.35k | int error; |
596 | | |
597 | 3.35k | error = llpkgc_frag__on_fragment_text(state, state->_span_pos0, (const char*) endp); |
598 | 3.35k | if (error != 0) { |
599 | 0 | state->error = error; |
600 | 0 | state->error_pos = endp; |
601 | 0 | return error; |
602 | 0 | } |
603 | 3.35k | } |
604 | | |
605 | 3.71k | return 0; |
606 | 3.71k | } |
607 | | #include <string.h> |
608 | | #include "llpkgc_frag.h" |
609 | | int llpkgc_frag__on_frag_complete(llpkgc_frag_t*, const unsigned char*, const unsigned char*); |
610 | | |
611 | 3.33k | int llpkgc_frag__on_fraglist_complete(llpkgc_frag_t* s, const unsigned char* p, const unsigned char* endp) { |
612 | 3.33k | const llpkgc_frag_settings_t* settings = s->settings; |
613 | 3.33k | int err; |
614 | 3.33k | if (settings == NULL || settings->on_fraglist_complete == NULL) return 0; |
615 | 0 | err = settings->on_fraglist_complete(s); |
616 | 0 | if (err != 0) { |
617 | 0 | if (s->reason == NULL) s->reason = "User callback error in on_fraglist_complete"; |
618 | 0 | s->callback_reason = (void*) s->reason; |
619 | 0 | return PFFE_USER; |
620 | 0 | } |
621 | 0 | return 0; |
622 | 0 | } |
623 | | |
624 | 48.3M | int llpkgc_frag__on_fragment_text(llpkgc_frag_t* s, const unsigned char* p, const unsigned char* endp) { |
625 | 48.3M | const llpkgc_frag_settings_t* settings = s->settings; |
626 | 48.3M | int err; |
627 | 48.3M | if (settings == NULL || settings->on_fragment_text == NULL) return 0; |
628 | 48.3M | err = settings->on_fragment_text(s, (const char*) p, (size_t) (endp - p)); |
629 | 48.3M | if (err != 0) { |
630 | 0 | if (s->reason == NULL) s->reason = "User callback error in on_fragment_text"; |
631 | 0 | s->callback_reason = (void*) s->reason; |
632 | 0 | return PFFE_USER; |
633 | 0 | } |
634 | 48.3M | return 0; |
635 | 48.3M | } |
636 | | |
637 | 44.9M | int llpkgc_frag__on_frag_complete(llpkgc_frag_t* s, const unsigned char* p, const unsigned char* endp) { |
638 | 44.9M | const llpkgc_frag_settings_t* settings = s->settings; |
639 | 44.9M | int err; |
640 | 44.9M | if (settings == NULL || settings->on_frag_complete == NULL) return 0; |
641 | 44.9M | err = settings->on_frag_complete(s); |
642 | 44.9M | if (err != 0) { |
643 | 0 | if (s->reason == NULL) s->reason = "User callback error in on_frag_complete"; |
644 | 0 | s->callback_reason = (void*) s->reason; |
645 | 0 | return PFFE_USER; |
646 | 0 | } |
647 | 44.9M | return 0; |
648 | 44.9M | } |
649 | | |
650 | 3.89k | void llpkgc_frag_init(llpkgc_frag_t* s, const llpkgc_frag_settings_t* settings) { |
651 | 3.89k | llpkgc_frag__internal_init(s); |
652 | 3.89k | s->settings = (void*) settings; |
653 | 3.89k | } |
654 | 0 | void llpkgc_frag_reset(llpkgc_frag_t* s) { |
655 | 0 | const llpkgc_frag_settings_t* settings = s->settings; |
656 | 0 | void* data = s->data; |
657 | 0 | llpkgc_frag_init(s, settings); |
658 | 0 | s->data = data; |
659 | 0 | } |
660 | 0 | void llpkgc_frag_settings_init(llpkgc_frag_settings_t* settings) { |
661 | 0 | memset(settings, 0, sizeof(*settings)); |
662 | 0 | } |
663 | 3.89k | llpkgc_frag_errno_t llpkgc_frag_execute(llpkgc_frag_t* s, const char* data, size_t len) { |
664 | 3.89k | if (s->error != 0) return s->error; |
665 | 3.89k | if (s->done) { |
666 | 0 | s->reason = "Input after finish"; |
667 | 0 | s->error_pos = data; |
668 | 0 | return s->error = PFFE_INVALID; |
669 | 0 | } |
670 | | |
671 | 3.89k | if (len == 0) return PFFE_OK; |
672 | 3.71k | s->end = (void*) (data + len); |
673 | 3.71k | { |
674 | 3.71k | int err = llpkgc_frag__internal_execute(s, data, data + len); |
675 | 3.71k | if (err == PFFE_USER && s->callback_reason != NULL) |
676 | 0 | s->reason = s->callback_reason; |
677 | | |
678 | 3.71k | return err; |
679 | 3.89k | } |
680 | 3.89k | } |
681 | 3.89k | llpkgc_frag_errno_t llpkgc_frag_finish(llpkgc_frag_t* s) { |
682 | 3.89k | int err; |
683 | 3.89k | if (s->error != 0) return s->error; |
684 | 3.89k | if (s->done) return PFFE_OK; |
685 | 3.89k | switch (s->finish) { |
686 | 236 | case 0: |
687 | 236 | err = llpkgc_frag__on_fraglist_complete(s, s->end, s->end); |
688 | 236 | if (err != 0) { |
689 | 0 | s->error = err; |
690 | 0 | s->error_pos = s->end; |
691 | 0 | return s->error; |
692 | 0 | } |
693 | 236 | break; |
694 | 3.10k | case 1: |
695 | 3.10k | err = llpkgc_frag__on_frag_complete(s, s->end, s->end); |
696 | 3.10k | if (err != 0) { |
697 | 0 | s->error = err; |
698 | 0 | s->error_pos = s->end; |
699 | 0 | return s->error; |
700 | 0 | } |
701 | | |
702 | 3.10k | err = llpkgc_frag__on_fraglist_complete(s, s->end, s->end); |
703 | 3.10k | if (err != 0) { |
704 | 0 | s->error = err; |
705 | 0 | s->error_pos = s->end; |
706 | 0 | return s->error; |
707 | 0 | } |
708 | 3.10k | break; |
709 | 3.10k | case 2: s->reason = "Unterminated quote at end of input"; |
710 | 507 | s->error = PFFE_UNFINISHED; s->error_pos = s->end; return s->error; |
711 | 53 | case 3: s->reason = "Unfinished escape at end of input"; |
712 | 53 | s->error = PFFE_UNFINISHED; s->error_pos = s->end; return s->error; |
713 | 0 | default: s->reason = "Invalid finish action"; return s->error = PFFE_INTERNAL; |
714 | 3.89k | } |
715 | 3.33k | s->done = 1; |
716 | 3.33k | return PFFE_OK; |
717 | 3.89k | } |
718 | 0 | llpkgc_frag_errno_t llpkgc_frag_get_errno(const llpkgc_frag_t* s) { return s->error; } |
719 | 0 | const char* llpkgc_frag_get_error_reason(const llpkgc_frag_t* s) { return s->reason; } |
720 | 0 | void llpkgc_frag_set_error_reason(llpkgc_frag_t* s, const char* reason) { s->reason = reason; } |
721 | 0 | const char* llpkgc_frag_get_error_pos(const llpkgc_frag_t* s) { return s->error_pos; } |
722 | 0 | const char* llpkgc_frag_errno_name(llpkgc_frag_errno_t err) { |
723 | 0 | switch (err) { |
724 | 0 | case PFFE_OK: return "PFFE_OK"; |
725 | 0 | case PFFE_USER: return "PFFE_USER"; |
726 | 0 | case PFFE_UNFINISHED: return "PFFE_UNFINISHED"; |
727 | 0 | case PFFE_INVALID: return "PFFE_INVALID"; |
728 | | |
729 | 0 | default: return "PFFE_INTERNAL"; |
730 | 0 | } |
731 | 0 | } |
732 | | |