| /* Distributed under the OSI-approved BSD 3-Clause License. | |
| See accompanying file LICENSE.rst for details. */ | |
| /* This code was generated by llpkgc, do not edit it by hand | |
| See: https://gitlab.kitware.com/utils/llpkgc */ | |
| #include <stdlib.h> | |
| #include <stdint.h> | |
| #include <string.h> | |
| #ifdef __SSE4_2__ | |
| #ifdef _MSC_VER | |
| #include <nmmintrin.h> | |
| #else /* !_MSC_VER */ | |
| #include <x86intrin.h> | |
| #endif /* _MSC_VER */ | |
| #endif /* __SSE4_2__ */ | |
| #if defined(__ARM_NEON__) || defined(__ARM_NEON) | |
| #include <arm_neon.h> | |
| #endif /* __ARM_NEON__ */ | |
| #ifdef __wasm__ | |
| #include <wasm_simd128.h> | |
| #endif /* __wasm__ */ | |
| #ifdef _MSC_VER | |
| #define ALIGN(n) _declspec(align(n)) | |
| #define UNREACHABLE __assume(0) | |
| #else /* !_MSC_VER */ | |
| #define ALIGN(n) __attribute__((aligned(n))) | |
| #define UNREACHABLE __builtin_unreachable() | |
| #endif /* _MSC_VER */ | |
| #include "llpkgc_whitespace__internal.h" | |
| typedef int (*llpkgc_whitespace__internal__span_cb)( | |
| llpkgc_whitespace__internal_t*, const char*, const char*); | |
| enum llparse_state_e { | |
| s_error, | |
| s_n_llpkgc_whitespace__internal__n_whitespace, | |
| s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span, | |
| s_n_llpkgc_whitespace__internal__n_lf, | |
| s_n_llpkgc_whitespace__internal__n_cr, | |
| s_n_llpkgc_whitespace__internal__n_escaped, | |
| s_n_llpkgc_whitespace__internal__n_start, | |
| }; | |
| typedef enum llparse_state_e llparse_state_t; | |
| int llpkgc_file__deferred_span( | |
| llpkgc_whitespace__internal_t* s, const unsigned char* p, | |
| const unsigned char* endp); | |
| int llpkgc_whitespace__internal_init(llpkgc_whitespace__internal_t* state) { | |
| memset(state, 0, sizeof(*state)); | |
| state->_current = (void*) (intptr_t) s_n_llpkgc_whitespace__internal__n_start; | |
| return 0; | |
| } | |
| static llparse_state_t llpkgc_whitespace__internal__run( | |
| llpkgc_whitespace__internal_t* state, | |
| const unsigned char* p, | |
| const unsigned char* endp) { | |
| int match; | |
| switch ((llparse_state_t) (intptr_t) state->_current) { | |
| case s_n_llpkgc_whitespace__internal__n_whitespace: | |
| s_n_llpkgc_whitespace__internal__n_whitespace: { | |
| if (p == endp) { | |
| return s_n_llpkgc_whitespace__internal__n_whitespace; | |
| } | |
| switch (*p) { | |
| case 9: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_whitespace; | |
| } | |
| case 11: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_whitespace; | |
| } | |
| case 12: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_whitespace; | |
| } | |
| case ' ': { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_whitespace; | |
| } | |
| default: { | |
| goto s_n_llpkgc_whitespace__internal__n_span_end_llpkgc_file__deferred_span; | |
| } | |
| } | |
| UNREACHABLE; | |
| } | |
| case s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span: | |
| s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span: { | |
| if (p == endp) { | |
| return s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; | |
| } | |
| state->_span_pos0 = (void*) p; | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_whitespace; | |
| UNREACHABLE; | |
| } | |
| case s_n_llpkgc_whitespace__internal__n_lf: | |
| s_n_llpkgc_whitespace__internal__n_lf: { | |
| if (p == endp) { | |
| return s_n_llpkgc_whitespace__internal__n_lf; | |
| } | |
| switch (*p) { | |
| case 13: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_start; | |
| } | |
| default: { | |
| goto s_n_llpkgc_whitespace__internal__n_start; | |
| } | |
| } | |
| UNREACHABLE; | |
| } | |
| case s_n_llpkgc_whitespace__internal__n_cr: | |
| s_n_llpkgc_whitespace__internal__n_cr: { | |
| if (p == endp) { | |
| return s_n_llpkgc_whitespace__internal__n_cr; | |
| } | |
| switch (*p) { | |
| case 10: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_start; | |
| } | |
| default: { | |
| goto s_n_llpkgc_whitespace__internal__n_start; | |
| } | |
| } | |
| UNREACHABLE; | |
| } | |
| case s_n_llpkgc_whitespace__internal__n_escaped: | |
| s_n_llpkgc_whitespace__internal__n_escaped: { | |
| if (p == endp) { | |
| return s_n_llpkgc_whitespace__internal__n_escaped; | |
| } | |
| switch (*p) { | |
| case 10: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_lf; | |
| } | |
| case 13: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_cr; | |
| } | |
| default: { | |
| goto s_n_llpkgc_whitespace__internal__n_error; | |
| } | |
| } | |
| UNREACHABLE; | |
| } | |
| case s_n_llpkgc_whitespace__internal__n_start: | |
| s_n_llpkgc_whitespace__internal__n_start: { | |
| if (p == endp) { | |
| return s_n_llpkgc_whitespace__internal__n_start; | |
| } | |
| switch (*p) { | |
| case 9: { | |
| goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; | |
| } | |
| case 11: { | |
| goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; | |
| } | |
| case 12: { | |
| goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; | |
| } | |
| case ' ': { | |
| goto s_n_llpkgc_whitespace__internal__n_span_start_llpkgc_file__deferred_span; | |
| } | |
| case 92: { | |
| p++; | |
| goto s_n_llpkgc_whitespace__internal__n_escaped; | |
| } | |
| default: { | |
| goto s_n_llpkgc_whitespace__internal__n_error; | |
| } | |
| } | |
| UNREACHABLE; | |
| } | |
| default: | |
| UNREACHABLE; | |
| } | |
| s_n_llpkgc_whitespace__internal__n_span_end_llpkgc_file__deferred_span: { | |
| const unsigned char* start; | |
| int err; | |
| start = state->_span_pos0; | |
| state->_span_pos0 = NULL; | |
| err = llpkgc_file__deferred_span(state, start, p); | |
| if (err != 0) { | |
| state->error = err; | |
| state->error_pos = (const char*) p; | |
| state->_current = (void*) (intptr_t) s_n_llpkgc_whitespace__internal__n_start; | |
| return s_error; | |
| } | |
| goto s_n_llpkgc_whitespace__internal__n_start; | |
| UNREACHABLE; | |
| } | |
| s_n_llpkgc_whitespace__internal__n_error: { | |
| state->error = 0x5; | |
| state->reason = "Invalid deferred whitespace range"; | |
| state->error_pos = (const char*) p; | |
| state->_current = (void*) (intptr_t) s_error; | |
| return s_error; | |
| UNREACHABLE; | |
| } | |
| } | |
| int llpkgc_whitespace__internal_execute(llpkgc_whitespace__internal_t* state, const char* p, const char* endp) { | |
| llparse_state_t next; | |
| /* check lingering errors */ | |
| if (state->error != 0) { | |
| return state->error; | |
| } | |
| /* restart spans */ | |
| if (state->_span_pos0 != NULL) { | |
| state->_span_pos0 = (void*) p; | |
| } | |
| next = llpkgc_whitespace__internal__run(state, (const unsigned char*) p, (const unsigned char*) endp); | |
| if (next == s_error) { | |
| return state->error; | |
| } | |
| state->_current = (void*) (intptr_t) next; | |
| /* execute spans */ | |
| if (state->_span_pos0 != NULL) { | |
| int error; | |
| error = llpkgc_file__deferred_span(state, state->_span_pos0, (const char*) endp); | |
| if (error != 0) { | |
| state->error = error; | |
| state->error_pos = endp; | |
| return error; | |
| } | |
| } | |
| return 0; | |
| } |