mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-10 17:14:10 +00:00
llpkgc 2026-07-07 (12b80381)
Code extracted from:
https://gitlab.kitware.com/utils/llpkgc.git
at commit 12b80381152d003186ee3bddb200743b4ce91ffa (12b80381152d003186ee3bddb200743b4ce91ffa).
This commit is contained in:
committed by
Vito Gamberini
parent
e2db237fb6
commit
bec4510a0f
28
LICENSE.rst
Normal file
28
LICENSE.rst
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright 2024-2026 Kitware, Inc. and Contributors
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of Kitware, Inc. nor the names of Contributors
|
||||
may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
205
llpkgc.c
205
llpkgc.c
@@ -1,205 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "llpkgc.h"
|
||||
|
||||
#define CALLBACK_MAYBE(PARSER, NAME) \
|
||||
do { \
|
||||
const llpkgc_settings_t* settings; \
|
||||
settings = (const llpkgc_settings_t*) (PARSER)->settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER)); \
|
||||
} while(0)
|
||||
|
||||
#define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN) \
|
||||
do { \
|
||||
const llpkgc_settings_t* settings; \
|
||||
settings = (const llpkgc_settings_t*) (PARSER)->settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER), (START), (LEN)); \
|
||||
if(err == -1) { \
|
||||
err = PCE_USER; \
|
||||
llpkgc_set_error_reason((PARSER), "Span callback error in " #NAME); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
void llpkgc_init(llpkgc_t* parser, const llpkgc_settings_t* settings) {
|
||||
llpkgc__internal_init(parser);
|
||||
|
||||
parser->settings = (void*) settings;
|
||||
}
|
||||
|
||||
void llpkgc_reset(llpkgc_t* parser) {
|
||||
llpkgc_settings_t* settings = parser->settings;
|
||||
void* data = parser->data;
|
||||
|
||||
llpkgc__internal_init(parser);
|
||||
|
||||
parser->settings = settings;
|
||||
parser->data = data;
|
||||
}
|
||||
|
||||
void llpkgc_settings_init(llpkgc_settings_t* settings) {
|
||||
memset(settings, 0, sizeof(*settings));
|
||||
}
|
||||
|
||||
llpkgc_errno_t llpkgc_execute(llpkgc_t* parser, const char* data, size_t len) {
|
||||
return llpkgc__internal_execute(parser, data, data + len);
|
||||
}
|
||||
|
||||
llpkgc_errno_t llpkgc_finish(llpkgc_t* parser) {
|
||||
if(parser->error != 0)
|
||||
return parser->error;
|
||||
|
||||
int err;
|
||||
// ToDo: Better handling of user callback errors here
|
||||
if(parser->unfinished_ == 1) {
|
||||
parser->reason = "Invalid EOF state";
|
||||
parser->error = PCE_UNFINISHED;
|
||||
return PCE_UNFINISHED;
|
||||
} else if(parser->unfinished_ == 2) {
|
||||
CALLBACK_MAYBE(parser, on_value_literal_complete);
|
||||
if(err != PCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
CALLBACK_MAYBE(parser, on_value_complete);
|
||||
if(err != PCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
} else if(parser->unfinished_ == 3) {
|
||||
CALLBACK_MAYBE(parser, on_value_complete);
|
||||
if(err != PCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
CALLBACK_MAYBE(parser, on_pkgc_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
void llpkgc_pause(llpkgc_t* parser) {
|
||||
if(parser->error != PCE_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
parser->error = PCE_PAUSED;
|
||||
parser->reason = "Paused";
|
||||
}
|
||||
|
||||
void llpkgc_resume(llpkgc_t* parser) {
|
||||
if(parser->error != PCE_PAUSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
parser->error = 0;
|
||||
}
|
||||
|
||||
llpkgc_errno_t llpkgc_get_errno(const llpkgc_t* parser) {
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
const char* llpkgc_get_error_reason(const llpkgc_t* parser) {
|
||||
return parser->reason;
|
||||
}
|
||||
|
||||
void llpkgc_set_error_reason(llpkgc_t* parser, const char* reason) {
|
||||
parser->reason = reason;
|
||||
}
|
||||
|
||||
const char* llpkgc_get_error_pos(const llpkgc_t* parser) {
|
||||
return parser->error_pos;
|
||||
}
|
||||
|
||||
const char* llpkgc_errno_name(llpkgc_errno_t err) {
|
||||
switch(err) {
|
||||
case PCE_OK:
|
||||
return "PCE_OK";
|
||||
case PCE_INTERNAL:
|
||||
return "PCE_INTERNAL";
|
||||
case PCE_PAUSED:
|
||||
return "PCE_PAUSED";
|
||||
case PCE_USER:
|
||||
return "PCE_USER";
|
||||
case PCE_UNFINISHED:
|
||||
return "PCE_UNFINISHED";
|
||||
}
|
||||
return "INVALID_ERRNO";
|
||||
}
|
||||
|
||||
int llpkgc__line_begin(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
s->unfinished_ = 1;
|
||||
CALLBACK_MAYBE(s, on_line_begin);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__key_span(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_key, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__keyword_complete(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
s->unfinished_ = 3;
|
||||
CALLBACK_MAYBE(s, on_keyword_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__variable_complete(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
s->unfinished_ = 3;
|
||||
CALLBACK_MAYBE(s, on_variable_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__vallit_span(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
if(s->escaped_) {
|
||||
--endp;
|
||||
s->escaped_ = 0;
|
||||
}
|
||||
s->unfinished_ = 2;
|
||||
SPAN_CALLBACK_MAYBE(s, on_value_literal, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__vallit_complete(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
s->unfinished_ = 3;
|
||||
CALLBACK_MAYBE(s, on_value_literal_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__valvar_span(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
s->unfinished_ = 1;
|
||||
SPAN_CALLBACK_MAYBE(s, on_value_variable, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__valvar_complete(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
s->unfinished_ = 3;
|
||||
CALLBACK_MAYBE(s, on_value_variable_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc__value_complete(llpkgc_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
s->unfinished_ = 0;
|
||||
CALLBACK_MAYBE(s, on_value_complete);
|
||||
return err;
|
||||
}
|
||||
147
llpkgc.h
147
llpkgc.h
@@ -1,143 +1,6 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License.
|
||||
See accompanying file LICENSE.rst for details. */
|
||||
|
||||
#ifndef INCLUDE_LLPKGC_API_H_
|
||||
#define INCLUDE_LLPKGC_API_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
#include "llpkgc__internal.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define LLPKGC_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define LLPKGC_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
typedef llpkgc__internal_t llpkgc_t;
|
||||
typedef struct llpkgc_settings_s llpkgc_settings_t;
|
||||
|
||||
typedef int (*llpkgc_data_cb)(llpkgc_t*, const char* at, size_t length);
|
||||
typedef int (*llpkgc_cb)(llpkgc_t*);
|
||||
|
||||
struct llpkgc_settings_s {
|
||||
/* Possible return values 0, -1, PCE_USER */
|
||||
llpkgc_data_cb on_key;
|
||||
llpkgc_data_cb on_value_literal;
|
||||
llpkgc_data_cb on_value_variable;
|
||||
|
||||
/* Possible return values 0, -1, `PCE_PAUSED` */
|
||||
llpkgc_cb on_line_begin;
|
||||
llpkgc_cb on_keyword_complete;
|
||||
llpkgc_cb on_variable_complete;
|
||||
llpkgc_cb on_value_literal_complete;
|
||||
llpkgc_cb on_value_variable_complete;
|
||||
llpkgc_cb on_value_complete;
|
||||
llpkgc_cb on_pkgc_complete;
|
||||
};
|
||||
|
||||
enum llpkgc_errno {
|
||||
PCE_OK = 0,
|
||||
PCE_INTERNAL = 1,
|
||||
PCE_PAUSED = 2,
|
||||
PCE_USER = 3,
|
||||
PCE_UNFINISHED = 4,
|
||||
};
|
||||
typedef enum llpkgc_errno llpkgc_errno_t;
|
||||
|
||||
/* Initialize the parser with user settings.
|
||||
*
|
||||
* NOTE: lifetime of `settings` has to be at least the same as the lifetime of
|
||||
* the `parser` here. In practice, `settings` has to be either a static
|
||||
* variable or be allocated with `malloc`, `new`, etc.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
void llpkgc_init(llpkgc_t* parser, const llpkgc_settings_t* settings);
|
||||
|
||||
/* Reset an already initialized parser back to the start state, preserving the
|
||||
* existing callback settings and user data.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
void llpkgc_reset(llpkgc_t* parser);
|
||||
|
||||
/* Initialize the settings object */
|
||||
LLPKGC_EXPORT
|
||||
void llpkgc_settings_init(llpkgc_settings_t* settings);
|
||||
|
||||
/* Parse full or partial pc data, invoking user callbacks along the way.
|
||||
*
|
||||
* If any of `llpkgc_data_cb` returns errno not equal to `PCE_OK` - the parsing
|
||||
* interrupts, and such errno is returned from `llpkgc_execute()`. If
|
||||
* `PCE_PAUSED` was used as an errno, the execution can be resumed with
|
||||
* `llpkgc_resume()` call.
|
||||
*
|
||||
* NOTE: if this function ever returns a non-pause type error, it will continue
|
||||
* to return the same error upon each successive call up until `llpkgc_init()`
|
||||
* or `llpkgc_reset()` are called.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
llpkgc_errno_t llpkgc_execute(llpkgc_t* parser, const char* data, size_t len);
|
||||
|
||||
/* This method should be called when the input has reached EOF
|
||||
*
|
||||
* This method will invoke `on_pkgc_complete()` callback if the file was
|
||||
* terminated safely. Otherwise an error code will be returned.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
llpkgc_errno_t llpkgc_finish(llpkgc_t* parser);
|
||||
|
||||
/* Make further calls of `llpkgc_execute()` return `PCE_PAUSED` and set
|
||||
* appropriate error reason.
|
||||
*
|
||||
* Important: do not call this from user callbacks! User callbacks must return
|
||||
* `PCE_PAUSED` if pausing is required.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
void llpkgc_pause(llpkgc_t* parser);
|
||||
|
||||
/* Might be called to resume the execution after the pause in user's callback.
|
||||
* See `llpkgc_execute()` above for details.
|
||||
*
|
||||
* Call this only if `llpkgc_execute()` returns `PCE_PAUSED`.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
void llpkgc_resume(llpkgc_t* parser);
|
||||
|
||||
/* Returns the latest return error */
|
||||
LLPKGC_EXPORT
|
||||
llpkgc_errno_t llpkgc_get_errno(const llpkgc_t* parser);
|
||||
|
||||
/* Returns the verbal explanation of the latest returned error.
|
||||
*
|
||||
* Note: User callback should set error reason when returning the error. See
|
||||
* `llpkgc_set_error_reason()` for details.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
const char* llpkgc_get_error_reason(const llpkgc_t* parser);
|
||||
|
||||
/* Assign verbal description to the returned error. Must be called in user
|
||||
* callbacks right before returning the errno.
|
||||
*
|
||||
* Note: `PCE_USER` error code might be useful in user callbacks.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
void llpkgc_set_error_reason(llpkgc_t* parser, const char* reason);
|
||||
|
||||
/* Returns the pointer to the last parsed byte before the returned error. The
|
||||
* pointer is relative to the `data` argument of `llpkgc_execute()`.
|
||||
*
|
||||
* Note: this method might be useful for counting the number of parsed bytes.
|
||||
*/
|
||||
LLPKGC_EXPORT
|
||||
const char* llpkgc_get_error_pos(const llpkgc_t* parser);
|
||||
|
||||
/* Returns textual name of error code */
|
||||
LLPKGC_EXPORT
|
||||
const char* llpkgc_errno_name(llpkgc_errno_t err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC_API_H_ */
|
||||
#include "llpkgc_dep.h"
|
||||
#include "llpkgc_file.h"
|
||||
#include "llpkgc_frag.h"
|
||||
|
||||
1069
llpkgc__internal.c
1069
llpkgc__internal.c
File diff suppressed because it is too large
Load Diff
@@ -1,37 +0,0 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
file Copyright.txt or https://cmake.org/licensing for details. */
|
||||
|
||||
/* This code was generated by llpkgc, do not edit it by hand
|
||||
See: https://gitlab.kitware.com/utils/llpkgc */
|
||||
|
||||
|
||||
#ifndef INCLUDE_LLPKGC__INTERNAL_H_
|
||||
#define INCLUDE_LLPKGC__INTERNAL_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct llpkgc__internal_s llpkgc__internal_t;
|
||||
struct llpkgc__internal_s {
|
||||
int32_t _index;
|
||||
void* _span_pos0;
|
||||
void* _span_cb0;
|
||||
int32_t error;
|
||||
const char* reason;
|
||||
const char* error_pos;
|
||||
void* data;
|
||||
void* _current;
|
||||
void* settings;
|
||||
uint8_t unfinished_;
|
||||
uint8_t escaped_;
|
||||
};
|
||||
|
||||
int llpkgc__internal_init(llpkgc__internal_t* s);
|
||||
int llpkgc__internal_execute(llpkgc__internal_t* s, const char* p, const char* endp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC__INTERNAL_H_ */
|
||||
181
llpkgc_dep.c
Normal file
181
llpkgc_dep.c
Normal file
@@ -0,0 +1,181 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License.
|
||||
See accompanying file LICENSE.rst for details. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "llpkgc_dep.h"
|
||||
|
||||
#define CALLBACK_MAYBE(PARSER, NAME) \
|
||||
do { \
|
||||
const llpkgc_dep_settings_t* settings; \
|
||||
settings = \
|
||||
(const llpkgc_dep_settings_t*) (PARSER)->llpkgc_dep__settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER)); \
|
||||
} while(0)
|
||||
|
||||
#define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN) \
|
||||
do { \
|
||||
const llpkgc_dep_settings_t* settings; \
|
||||
settings = \
|
||||
(const llpkgc_dep_settings_t*) (PARSER)->llpkgc_dep__settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER), (START), (LEN)); \
|
||||
if(err == -1) { \
|
||||
err = PDEP_USER; \
|
||||
llpkgc_dep_set_error_reason((PARSER), "Span callback error in " #NAME); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
enum llpkgc_dep_state {
|
||||
PDEP_START = 0,
|
||||
PDEP_DEP_NAME = 1,
|
||||
PDEP_DEP_OP = 2,
|
||||
PDEP_AFTER_OP = 3,
|
||||
PDEP_DEP_VERSION = 4,
|
||||
};
|
||||
|
||||
void llpkgc_dep_init(llpkgc_dep_t* parser,
|
||||
const llpkgc_dep_settings_t* settings) {
|
||||
llpkgc_dep__internal_init(parser);
|
||||
parser->llpkgc_dep__settings = (void*) settings;
|
||||
}
|
||||
|
||||
void llpkgc_dep_reset(llpkgc_dep_t* parser) {
|
||||
llpkgc_dep_settings_t* settings = parser->llpkgc_dep__settings;
|
||||
void* data = parser->data;
|
||||
llpkgc_dep__internal_init(parser);
|
||||
parser->llpkgc_dep__settings = settings;
|
||||
parser->data = data;
|
||||
}
|
||||
|
||||
void llpkgc_dep_settings_init(llpkgc_dep_settings_t* settings) {
|
||||
memset(settings, 0, sizeof(*settings));
|
||||
}
|
||||
|
||||
llpkgc_dep_errno_t llpkgc_dep_execute(llpkgc_dep_t* parser, const char* data,
|
||||
size_t len) {
|
||||
return llpkgc_dep__internal_execute(parser, data, data + len);
|
||||
}
|
||||
|
||||
llpkgc_dep_errno_t llpkgc_dep_finish(llpkgc_dep_t* parser) {
|
||||
int err = PDEP_OK;
|
||||
|
||||
if(parser->error != 0) {
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
switch(parser->llpkgc_dep__state) {
|
||||
case PDEP_DEP_NAME:
|
||||
CALLBACK_MAYBE(parser, on_dep_complete);
|
||||
if(err != PDEP_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
|
||||
case PDEP_DEP_OP:
|
||||
case PDEP_AFTER_OP:
|
||||
case PDEP_DEP_VERSION:
|
||||
CALLBACK_MAYBE(parser, on_dep_complete);
|
||||
if(err != PDEP_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
|
||||
case PDEP_START:
|
||||
break;
|
||||
}
|
||||
|
||||
CALLBACK_MAYBE(parser, on_dep_list_complete);
|
||||
if(err != PDEP_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
|
||||
return PDEP_OK;
|
||||
}
|
||||
|
||||
void llpkgc_dep_pause(llpkgc_dep_t* parser) {
|
||||
if(parser->error != PDEP_OK) {
|
||||
return;
|
||||
}
|
||||
parser->error = PDEP_PAUSED;
|
||||
parser->reason = "Paused";
|
||||
}
|
||||
|
||||
void llpkgc_dep_resume(llpkgc_dep_t* parser) {
|
||||
if(parser->error != PDEP_PAUSED) {
|
||||
return;
|
||||
}
|
||||
parser->error = 0;
|
||||
}
|
||||
|
||||
llpkgc_dep_errno_t llpkgc_dep_get_errno(const llpkgc_dep_t* parser) {
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
const char* llpkgc_dep_get_error_reason(const llpkgc_dep_t* parser) {
|
||||
return parser->reason;
|
||||
}
|
||||
|
||||
void llpkgc_dep_set_error_reason(llpkgc_dep_t* parser, const char* reason) {
|
||||
parser->reason = reason;
|
||||
}
|
||||
|
||||
const char* llpkgc_dep_get_error_pos(const llpkgc_dep_t* parser) {
|
||||
return parser->error_pos;
|
||||
}
|
||||
|
||||
const char* llpkgc_dep_errno_name(llpkgc_dep_errno_t err) {
|
||||
switch(err) {
|
||||
case PDEP_OK:
|
||||
return "PDEP_OK";
|
||||
case PDEP_INTERNAL:
|
||||
return "PDEP_INTERNAL";
|
||||
case PDEP_PAUSED:
|
||||
return "PDEP_PAUSED";
|
||||
case PDEP_USER:
|
||||
return "PDEP_USER";
|
||||
case PDEP_UNFINISHED:
|
||||
return "PDEP_UNFINISHED";
|
||||
}
|
||||
return "INVALID_ERRNO";
|
||||
}
|
||||
|
||||
int llpkgc_dep__dep_name(llpkgc_dep_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_dep_name, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_dep__dep_op(llpkgc_dep_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_dep_op, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_dep__dep_version(llpkgc_dep_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_dep_version, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_dep__dep_complete(llpkgc_dep_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_dep_complete);
|
||||
return err;
|
||||
}
|
||||
85
llpkgc_dep.h
Normal file
85
llpkgc_dep.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License.
|
||||
See accompanying file LICENSE.rst for details. */
|
||||
|
||||
#ifndef INCLUDE_LLPKGC_DEP_API_H_
|
||||
#define INCLUDE_LLPKGC_DEP_API_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
#include "llpkgc_dep__internal.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define LLPKGC_DEP_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define LLPKGC_DEP_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
typedef llpkgc_dep__internal_t llpkgc_dep_t;
|
||||
typedef struct llpkgc_dep_settings_s llpkgc_dep_settings_t;
|
||||
|
||||
typedef int (
|
||||
*llpkgc_dep_data_cb)(llpkgc_dep_t*, const char* at, size_t length);
|
||||
typedef int (*llpkgc_dep_cb)(llpkgc_dep_t*);
|
||||
|
||||
struct llpkgc_dep_settings_s {
|
||||
llpkgc_dep_data_cb on_dep_name;
|
||||
llpkgc_dep_data_cb on_dep_op;
|
||||
llpkgc_dep_data_cb on_dep_version;
|
||||
|
||||
llpkgc_dep_cb on_dep_complete;
|
||||
llpkgc_dep_cb on_dep_list_complete;
|
||||
};
|
||||
|
||||
enum llpkgc_dep_errno {
|
||||
PDEP_INTERNAL = -1,
|
||||
PDEP_OK = 0,
|
||||
PDEP_PAUSED = 1,
|
||||
PDEP_USER = 2,
|
||||
PDEP_UNFINISHED = 3,
|
||||
};
|
||||
typedef enum llpkgc_dep_errno llpkgc_dep_errno_t;
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
void llpkgc_dep_init(llpkgc_dep_t* parser,
|
||||
const llpkgc_dep_settings_t* settings);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
void llpkgc_dep_reset(llpkgc_dep_t* parser);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
void llpkgc_dep_settings_init(llpkgc_dep_settings_t* settings);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
llpkgc_dep_errno_t llpkgc_dep_execute(llpkgc_dep_t* parser, const char* data,
|
||||
size_t len);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
llpkgc_dep_errno_t llpkgc_dep_finish(llpkgc_dep_t* parser);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
void llpkgc_dep_pause(llpkgc_dep_t* parser);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
void llpkgc_dep_resume(llpkgc_dep_t* parser);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
llpkgc_dep_errno_t llpkgc_dep_get_errno(const llpkgc_dep_t* parser);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
const char* llpkgc_dep_get_error_reason(const llpkgc_dep_t* parser);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
void llpkgc_dep_set_error_reason(llpkgc_dep_t* parser, const char* reason);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
const char* llpkgc_dep_get_error_pos(const llpkgc_dep_t* parser);
|
||||
|
||||
LLPKGC_DEP_EXPORT
|
||||
const char* llpkgc_dep_errno_name(llpkgc_dep_errno_t err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC_DEP_API_H_ */
|
||||
565
llpkgc_dep__internal.c
Normal file
565
llpkgc_dep__internal.c
Normal file
@@ -0,0 +1,565 @@
|
||||
/* 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_dep__internal.h"
|
||||
|
||||
typedef int (*llpkgc_dep__internal__span_cb)(
|
||||
llpkgc_dep__internal_t*, const char*, const char*);
|
||||
|
||||
enum llparse_state_e {
|
||||
s_error,
|
||||
s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete,
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_dep_version,
|
||||
s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_version,
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_after_op,
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op,
|
||||
s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_op,
|
||||
s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1,
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws,
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_dep_name,
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name,
|
||||
s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_name,
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_start,
|
||||
};
|
||||
typedef enum llparse_state_e llparse_state_t;
|
||||
|
||||
int llpkgc_dep__dep_name(
|
||||
llpkgc_dep__internal_t* s, const unsigned char* p,
|
||||
const unsigned char* endp);
|
||||
|
||||
int llpkgc_dep__dep_op(
|
||||
llpkgc_dep__internal_t* s, const unsigned char* p,
|
||||
const unsigned char* endp);
|
||||
|
||||
int llpkgc_dep__dep_version(
|
||||
llpkgc_dep__internal_t* s, const unsigned char* p,
|
||||
const unsigned char* endp);
|
||||
|
||||
int llpkgc_dep__internal__c_update_llpkgc_dep__state(
|
||||
llpkgc_dep__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_dep__state = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_dep__internal__c_update_llpkgc_dep__state_1(
|
||||
llpkgc_dep__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_dep__state = 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_dep__internal__c_update_llpkgc_dep__state_2(
|
||||
llpkgc_dep__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_dep__state = 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_dep__dep_complete(
|
||||
llpkgc_dep__internal_t* s, const unsigned char* p,
|
||||
const unsigned char* endp);
|
||||
|
||||
int llpkgc_dep__internal__c_update_llpkgc_dep__state_3(
|
||||
llpkgc_dep__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_dep__state = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_dep__internal__c_update_llpkgc_dep__state_4(
|
||||
llpkgc_dep__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_dep__state = 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_dep__internal_init(llpkgc_dep__internal_t* state) {
|
||||
memset(state, 0, sizeof(*state));
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_pkgc_dep_start;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static llparse_state_t llpkgc_dep__internal__run(
|
||||
llpkgc_dep__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_dep__internal__n_invoke_llpkgc_dep__dep_complete:
|
||||
s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete: {
|
||||
switch (llpkgc_dep__dep_complete(state, p, endp)) {
|
||||
case 0:
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_3;
|
||||
default:
|
||||
goto s_n_llpkgc_dep__internal__n_error;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_pkgc_dep_dep_version:
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_dep_version: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_pkgc_dep_dep_version;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_version;
|
||||
}
|
||||
case ' ': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_version;
|
||||
}
|
||||
case ',': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_version;
|
||||
}
|
||||
default: {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_version;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_version:
|
||||
s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_version: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_version;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
state->_span_cb0 = llpkgc_dep__dep_version;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_version;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_pkgc_dep_after_op:
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_after_op: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_pkgc_dep_after_op;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_after_op;
|
||||
}
|
||||
case ' ': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_after_op;
|
||||
}
|
||||
case ',': {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_4;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op:
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op;
|
||||
}
|
||||
switch (*p) {
|
||||
case '!': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op;
|
||||
}
|
||||
case '<': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op;
|
||||
}
|
||||
case '=': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op;
|
||||
}
|
||||
case '>': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_2;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_op:
|
||||
s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_op: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_op;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
state->_span_cb0 = llpkgc_dep__dep_op;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_op;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1:
|
||||
s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1: {
|
||||
switch (llpkgc_dep__internal__c_update_llpkgc_dep__state_1(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_op;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws:
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws;
|
||||
}
|
||||
case ' ': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws;
|
||||
}
|
||||
case '!': {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1;
|
||||
}
|
||||
case '<': {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1;
|
||||
}
|
||||
case '=': {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1;
|
||||
}
|
||||
case '>': {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_pkgc_dep_dep_name:
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_dep_name: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_pkgc_dep_dep_name;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_2;
|
||||
}
|
||||
case ' ': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_2;
|
||||
}
|
||||
case '!': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_3;
|
||||
}
|
||||
case ',': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_4;
|
||||
}
|
||||
case '<': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_3;
|
||||
}
|
||||
case '=': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_3;
|
||||
}
|
||||
case '>': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_3;
|
||||
}
|
||||
default: {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_name;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name:
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name;
|
||||
}
|
||||
case ' ': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name;
|
||||
}
|
||||
case '!': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name;
|
||||
}
|
||||
case ',': {
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_1;
|
||||
}
|
||||
case '<': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name;
|
||||
}
|
||||
case '=': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name;
|
||||
}
|
||||
case '>': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_5;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_name:
|
||||
s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_name: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_name;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
state->_span_cb0 = llpkgc_dep__dep_name;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_first_dep_name;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_dep__internal__n_pkgc_dep_start:
|
||||
s_n_llpkgc_dep__internal__n_pkgc_dep_start: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_dep__internal__n_pkgc_dep_start;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_start;
|
||||
}
|
||||
case ' ': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_start;
|
||||
}
|
||||
case ',': {
|
||||
p++;
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_start;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_3: {
|
||||
switch (llpkgc_dep__internal__c_update_llpkgc_dep__state_3(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_start;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_error: {
|
||||
state->error = 0x1;
|
||||
state->reason = "Dep complete error";
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_error;
|
||||
return s_error;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_version: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_dep__dep_version(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_4: {
|
||||
switch (llpkgc_dep__internal__c_update_llpkgc_dep__state_4(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_version;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_op: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_dep__dep_op(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_pkgc_dep_after_op;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_after_op;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_2: {
|
||||
switch (llpkgc_dep__internal__c_update_llpkgc_dep__state_2(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_op;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_dep__dep_name(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_1: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_dep__dep_name(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_2: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_dep__dep_name(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_name_ws;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_3: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_dep__dep_name(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_1;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_span_end_llpkgc_dep__dep_name_4: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_dep__dep_name(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_dep__internal__n_invoke_llpkgc_dep__dep_complete;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state_5: {
|
||||
switch (llpkgc_dep__internal__c_update_llpkgc_dep__state(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_dep__internal__n_pkgc_dep_dep_name;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_dep__internal__n_invoke_update_llpkgc_dep__state: {
|
||||
switch (llpkgc_dep__internal__c_update_llpkgc_dep__state(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_dep__internal__n_span_start_llpkgc_dep__dep_name;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
int llpkgc_dep__internal_execute(llpkgc_dep__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_dep__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_dep__internal__span_cb) state->_span_cb0)(state, state->_span_pos0, (const char*) endp);
|
||||
if (error != 0) {
|
||||
state->error = error;
|
||||
state->error_pos = endp;
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
35
llpkgc_dep__internal.h
Normal file
35
llpkgc_dep__internal.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* 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 */
|
||||
|
||||
|
||||
#ifndef INCLUDE_LLPKGC_DEP__INTERNAL_H_
|
||||
#define INCLUDE_LLPKGC_DEP__INTERNAL_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct llpkgc_dep__internal_s llpkgc_dep__internal_t;
|
||||
struct llpkgc_dep__internal_s {
|
||||
int32_t _index;
|
||||
void* _span_pos0;
|
||||
void* _span_cb0;
|
||||
int32_t error;
|
||||
const char* reason;
|
||||
const char* error_pos;
|
||||
void* data;
|
||||
void* _current;
|
||||
void* llpkgc_dep__settings;
|
||||
uint8_t llpkgc_dep__state;
|
||||
};
|
||||
|
||||
int llpkgc_dep__internal_init(llpkgc_dep__internal_t* s);
|
||||
int llpkgc_dep__internal_execute(llpkgc_dep__internal_t* s, const char* p, const char* endp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC_DEP__INTERNAL_H_ */
|
||||
338
llpkgc_file.c
Normal file
338
llpkgc_file.c
Normal file
@@ -0,0 +1,338 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License.
|
||||
See accompanying file LICENSE.rst for details. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "llpkgc_file.h"
|
||||
|
||||
#define CALLBACK_MAYBE(PARSER, NAME) \
|
||||
do { \
|
||||
const llpkgc_file_settings_t* settings; \
|
||||
settings = \
|
||||
(const llpkgc_file_settings_t*) (PARSER)->llpkgc_file__settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER)); \
|
||||
} while(0)
|
||||
|
||||
#define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN) \
|
||||
do { \
|
||||
const llpkgc_file_settings_t* settings; \
|
||||
settings = \
|
||||
(const llpkgc_file_settings_t*) (PARSER)->llpkgc_file__settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER), (START), (LEN)); \
|
||||
if(err == -1) { \
|
||||
err = PFCE_USER; \
|
||||
llpkgc_file_set_error_reason((PARSER), "Span callback error in " #NAME); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
enum llpkgc_file_unfinished_state {
|
||||
PFUS_NONE = 0,
|
||||
PFUS_IDENT = 1,
|
||||
PFUS_BAREWORDS = 2,
|
||||
PFUS_EXPECT_VALUE = 3,
|
||||
PFUS_VALUE = 4,
|
||||
PFUS_VALUE_LITERAL = 5,
|
||||
PFUS_VALUE_SUBSTITUTION = 6,
|
||||
};
|
||||
|
||||
void llpkgc_file_init(llpkgc_file_t* parser,
|
||||
const llpkgc_file_settings_t* settings) {
|
||||
llpkgc_file__internal_init(parser);
|
||||
|
||||
parser->llpkgc_file__settings = (void*) settings;
|
||||
}
|
||||
|
||||
void llpkgc_file_reset(llpkgc_file_t* parser) {
|
||||
llpkgc_file_settings_t* settings = parser->llpkgc_file__settings;
|
||||
void* data = parser->data;
|
||||
|
||||
llpkgc_file__internal_init(parser);
|
||||
|
||||
parser->llpkgc_file__settings = settings;
|
||||
parser->data = data;
|
||||
}
|
||||
|
||||
void llpkgc_file_settings_init(llpkgc_file_settings_t* settings) {
|
||||
memset(settings, 0, sizeof(*settings));
|
||||
}
|
||||
|
||||
llpkgc_file_errno_t llpkgc_file_execute(llpkgc_file_t* parser, const char* data,
|
||||
size_t len) {
|
||||
return llpkgc_file__internal_execute(parser, data, data + len);
|
||||
}
|
||||
|
||||
int llpkgc_file__line_begin(llpkgc_file_t* s, const char* p, const char* endp);
|
||||
int llpkgc_file__ident_span(llpkgc_file_t* s, const char* p, const char* endp);
|
||||
|
||||
llpkgc_file_errno_t llpkgc_file_finish(llpkgc_file_t* parser) {
|
||||
int err = PFCE_OK;
|
||||
|
||||
if(parser->error == PFCE_LOOKAHEAD) {
|
||||
if(parser->error_pos == NULL) {
|
||||
parser->error = PFCE_INTERNAL;
|
||||
parser->reason = "Missing lookahead error position";
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
parser->llpkgc_file__eof = 1;
|
||||
llpkgc_file_resume(parser);
|
||||
err = llpkgc_file_execute(parser, parser->error_pos, 1);
|
||||
parser->llpkgc_file__eof = 0;
|
||||
|
||||
if(err != PFCE_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
parser->llpkgc_file__lookahead = 0;
|
||||
} else if(parser->error != 0) {
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
switch(parser->llpkgc_file__unfinished) {
|
||||
case PFUS_IDENT:
|
||||
case PFUS_BAREWORDS:
|
||||
CALLBACK_MAYBE(parser, on_barewords_complete);
|
||||
if(err != PFCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
|
||||
CALLBACK_MAYBE(parser, on_value_complete);
|
||||
if(err != PFCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
|
||||
case PFUS_EXPECT_VALUE:
|
||||
case PFUS_VALUE:
|
||||
CALLBACK_MAYBE(parser, on_value_complete);
|
||||
if(err != PFCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
|
||||
case PFUS_VALUE_LITERAL:
|
||||
CALLBACK_MAYBE(parser, on_value_literal_complete);
|
||||
if(err != PFCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
|
||||
CALLBACK_MAYBE(parser, on_value_complete);
|
||||
if(err != PFCE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
|
||||
case PFUS_VALUE_SUBSTITUTION:
|
||||
parser->reason = "Invalid EOF state";
|
||||
parser->error = PFCE_UNFINISHED;
|
||||
return PFCE_UNFINISHED;
|
||||
|
||||
case PFUS_NONE:
|
||||
break;
|
||||
}
|
||||
|
||||
CALLBACK_MAYBE(parser, on_pkgc_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
void llpkgc_file_pause(llpkgc_file_t* parser) {
|
||||
if(parser->error != PFCE_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
parser->error = PFCE_PAUSED;
|
||||
parser->reason = "Paused";
|
||||
}
|
||||
|
||||
void llpkgc_file_resume(llpkgc_file_t* parser) {
|
||||
if(parser->error != PFCE_PAUSED && parser->error != PFCE_LOOKAHEAD) {
|
||||
return;
|
||||
}
|
||||
|
||||
parser->error = 0;
|
||||
}
|
||||
|
||||
llpkgc_file_errno_t llpkgc_file_get_errno(const llpkgc_file_t* parser) {
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
const char* llpkgc_file_get_error_reason(const llpkgc_file_t* parser) {
|
||||
return parser->reason;
|
||||
}
|
||||
|
||||
void llpkgc_file_set_error_reason(llpkgc_file_t* parser, const char* reason) {
|
||||
parser->reason = reason;
|
||||
}
|
||||
|
||||
const char* llpkgc_file_get_error_pos(const llpkgc_file_t* parser) {
|
||||
return parser->error_pos;
|
||||
}
|
||||
|
||||
const char* llpkgc_file_errno_name(llpkgc_file_errno_t err) {
|
||||
switch(err) {
|
||||
case PFCE_OK:
|
||||
return "PFCE_OK";
|
||||
case PFCE_INTERNAL:
|
||||
return "PFCE_INTERNAL";
|
||||
case PFCE_PAUSED:
|
||||
return "PFCE_PAUSED";
|
||||
case PFCE_USER:
|
||||
return "PFCE_USER";
|
||||
case PFCE_UNFINISHED:
|
||||
return "PFCE_UNFINISHED";
|
||||
case PFCE_LOOKAHEAD:
|
||||
return "PFCE_LOOKAHEAD";
|
||||
}
|
||||
return "INVALID_ERRNO";
|
||||
}
|
||||
|
||||
int llpkgc_file__lookahead(llpkgc_file_t* s, const char* p, const char* endp) {
|
||||
if(p == endp) {
|
||||
llpkgc_file_set_error_reason(s, "Invalid lookahead state");
|
||||
return PFCE_INTERNAL;
|
||||
}
|
||||
|
||||
if(p + 1 == endp) {
|
||||
if(s->llpkgc_file__eof != 0) {
|
||||
s->llpkgc_file__lookahead = 0;
|
||||
return 3;
|
||||
}
|
||||
|
||||
s->llpkgc_file__lookahead = (uint8_t) *p;
|
||||
return PFCE_LOOKAHEAD;
|
||||
}
|
||||
|
||||
s->llpkgc_file__lookahead = 0;
|
||||
|
||||
if(*p != '$') {
|
||||
llpkgc_file_set_error_reason(s, "Invalid lookahead state");
|
||||
return PFCE_INTERNAL;
|
||||
}
|
||||
|
||||
switch(p[1]) {
|
||||
case '{':
|
||||
return 1;
|
||||
case '$':
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int llpkgc_file__lookahead_backslash(llpkgc_file_t* s, const char* p,
|
||||
const char* endp) {
|
||||
if(p == endp) {
|
||||
llpkgc_file_set_error_reason(s, "Invalid lookahead state");
|
||||
return PFCE_INTERNAL;
|
||||
}
|
||||
|
||||
if(p + 1 == endp) {
|
||||
if(s->llpkgc_file__eof != 0) {
|
||||
s->llpkgc_file__lookahead = 0;
|
||||
return 4;
|
||||
}
|
||||
|
||||
s->llpkgc_file__lookahead = (uint8_t) *p;
|
||||
return 5;
|
||||
}
|
||||
|
||||
s->llpkgc_file__lookahead = 0;
|
||||
|
||||
if(*p != '\\') {
|
||||
llpkgc_file_set_error_reason(s, "Invalid lookahead state");
|
||||
return PFCE_INTERNAL;
|
||||
}
|
||||
|
||||
switch(p[1]) {
|
||||
case '\r':
|
||||
case '\n':
|
||||
return 1;
|
||||
case '#':
|
||||
return 2;
|
||||
case '\\':
|
||||
return 3;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int llpkgc_file__line_begin(llpkgc_file_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_line_begin);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__ident_span(llpkgc_file_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_ident, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__prop_decl_complete(llpkgc_file_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_property_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__var_decl_complete(llpkgc_file_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_variable_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__barewords_decl_complete(llpkgc_file_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_barewords_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__lit_span(llpkgc_file_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_value_literal, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__lit_complete(llpkgc_file_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_value_literal_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__sub_span(llpkgc_file_t* s, const char* p, const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_value_substitution, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__sub_complete(llpkgc_file_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_value_substitution_complete);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_file__val_complete(llpkgc_file_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_value_complete);
|
||||
return err;
|
||||
}
|
||||
92
llpkgc_file.h
Normal file
92
llpkgc_file.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License.
|
||||
See accompanying file LICENSE.rst for details. */
|
||||
|
||||
#ifndef INCLUDE_LLPKGC_FILE_API_H_
|
||||
#define INCLUDE_LLPKGC_FILE_API_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
#include "llpkgc_file__internal.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define LLPKGC_FILE_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define LLPKGC_FILE_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
typedef llpkgc_file__internal_t llpkgc_file_t;
|
||||
typedef struct llpkgc_file_settings_s llpkgc_file_settings_t;
|
||||
|
||||
typedef int (
|
||||
*llpkgc_file_data_cb)(llpkgc_file_t*, const char* at, size_t length);
|
||||
typedef int (*llpkgc_file_cb)(llpkgc_file_t*);
|
||||
|
||||
struct llpkgc_file_settings_s {
|
||||
llpkgc_file_data_cb on_ident;
|
||||
llpkgc_file_data_cb on_value_literal;
|
||||
llpkgc_file_data_cb on_value_substitution;
|
||||
|
||||
llpkgc_file_cb on_line_begin;
|
||||
llpkgc_file_cb on_property_complete;
|
||||
llpkgc_file_cb on_variable_complete;
|
||||
llpkgc_file_cb on_barewords_complete;
|
||||
llpkgc_file_cb on_value_literal_complete;
|
||||
llpkgc_file_cb on_value_substitution_complete;
|
||||
llpkgc_file_cb on_value_complete;
|
||||
llpkgc_file_cb on_pkgc_complete;
|
||||
};
|
||||
|
||||
enum llpkgc_file_errno {
|
||||
PFCE_INTERNAL = -1,
|
||||
PFCE_OK = 0,
|
||||
PFCE_PAUSED = 1,
|
||||
PFCE_USER = 2,
|
||||
PFCE_UNFINISHED = 3,
|
||||
PFCE_LOOKAHEAD = 4,
|
||||
};
|
||||
typedef enum llpkgc_file_errno llpkgc_file_errno_t;
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
void llpkgc_file_init(llpkgc_file_t* parser,
|
||||
const llpkgc_file_settings_t* settings);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
void llpkgc_file_reset(llpkgc_file_t* parser);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
void llpkgc_file_settings_init(llpkgc_file_settings_t* settings);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
llpkgc_file_errno_t llpkgc_file_execute(llpkgc_file_t* parser, const char* data,
|
||||
size_t len);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
llpkgc_file_errno_t llpkgc_file_finish(llpkgc_file_t* parser);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
void llpkgc_file_pause(llpkgc_file_t* parser);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
void llpkgc_file_resume(llpkgc_file_t* parser);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
llpkgc_file_errno_t llpkgc_file_get_errno(const llpkgc_file_t* parser);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
const char* llpkgc_file_get_error_reason(const llpkgc_file_t* parser);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
void llpkgc_file_set_error_reason(llpkgc_file_t* parser, const char* reason);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
const char* llpkgc_file_get_error_pos(const llpkgc_file_t* parser);
|
||||
|
||||
LLPKGC_FILE_EXPORT
|
||||
const char* llpkgc_file_errno_name(llpkgc_file_errno_t err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC_FILE_API_H_ */
|
||||
2489
llpkgc_file__internal.c
Normal file
2489
llpkgc_file__internal.c
Normal file
File diff suppressed because it is too large
Load Diff
41
llpkgc_file__internal.h
Normal file
41
llpkgc_file__internal.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* 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 */
|
||||
|
||||
|
||||
#ifndef INCLUDE_LLPKGC_FILE__INTERNAL_H_
|
||||
#define INCLUDE_LLPKGC_FILE__INTERNAL_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct llpkgc_file__internal_s llpkgc_file__internal_t;
|
||||
struct llpkgc_file__internal_s {
|
||||
int32_t _index;
|
||||
void* _span_pos0;
|
||||
void* _span_cb0;
|
||||
void* _span_pos1;
|
||||
int32_t error;
|
||||
const char* reason;
|
||||
const char* error_pos;
|
||||
void* data;
|
||||
void* _current;
|
||||
void* llpkgc_file__settings;
|
||||
uint8_t llpkgc_file__unfinished;
|
||||
uint8_t llpkgc_file__lookahead;
|
||||
uint8_t llpkgc_file__eof;
|
||||
uint8_t llpkgc_file__value_resume;
|
||||
uint8_t llpkgc_file__line_resume;
|
||||
uint8_t llpkgc_file__text_resume;
|
||||
};
|
||||
|
||||
int llpkgc_file__internal_init(llpkgc_file__internal_t* s);
|
||||
int llpkgc_file__internal_execute(llpkgc_file__internal_t* s, const char* p, const char* endp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC_FILE__INTERNAL_H_ */
|
||||
215
llpkgc_frag.c
Normal file
215
llpkgc_frag.c
Normal file
@@ -0,0 +1,215 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License.
|
||||
See accompanying file LICENSE.rst for details. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "llpkgc_frag.h"
|
||||
|
||||
#define CALLBACK_MAYBE(PARSER, NAME) \
|
||||
do { \
|
||||
const llpkgc_frag_settings_t* settings; \
|
||||
settings = \
|
||||
(const llpkgc_frag_settings_t*) (PARSER)->llpkgc_frag__settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER)); \
|
||||
} while(0)
|
||||
|
||||
#define SPAN_CALLBACK_MAYBE(PARSER, NAME, START, LEN) \
|
||||
do { \
|
||||
const llpkgc_frag_settings_t* settings; \
|
||||
settings = \
|
||||
(const llpkgc_frag_settings_t*) (PARSER)->llpkgc_frag__settings; \
|
||||
if(settings == NULL || settings->NAME == NULL) { \
|
||||
err = 0; \
|
||||
break; \
|
||||
} \
|
||||
err = settings->NAME((PARSER), (START), (LEN)); \
|
||||
if(err == -1) { \
|
||||
err = PFFE_USER; \
|
||||
llpkgc_frag_set_error_reason((PARSER), "Span callback error in " #NAME); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
enum llpkgc_frag_state {
|
||||
PFFS_START = 0,
|
||||
PFFS_UNQUOTED = 1,
|
||||
PFFS_DOUBLE_QUOTED = 2,
|
||||
PFFS_SINGLE_QUOTED = 3,
|
||||
};
|
||||
|
||||
void llpkgc_frag_init(llpkgc_frag_t* parser,
|
||||
const llpkgc_frag_settings_t* settings) {
|
||||
llpkgc_frag__internal_init(parser);
|
||||
parser->llpkgc_frag__settings = (void*) settings;
|
||||
}
|
||||
|
||||
void llpkgc_frag_reset(llpkgc_frag_t* parser) {
|
||||
llpkgc_frag_settings_t* settings = parser->llpkgc_frag__settings;
|
||||
void* data = parser->data;
|
||||
llpkgc_frag__internal_init(parser);
|
||||
parser->llpkgc_frag__settings = settings;
|
||||
parser->data = data;
|
||||
}
|
||||
|
||||
void llpkgc_frag_settings_init(llpkgc_frag_settings_t* settings) {
|
||||
memset(settings, 0, sizeof(*settings));
|
||||
}
|
||||
|
||||
llpkgc_frag_errno_t llpkgc_frag_execute(llpkgc_frag_t* parser, const char* data,
|
||||
size_t len) {
|
||||
return llpkgc_frag__internal_execute(parser, data, data + len);
|
||||
}
|
||||
|
||||
llpkgc_frag_errno_t llpkgc_frag_finish(llpkgc_frag_t* parser) {
|
||||
int err = PFFE_OK;
|
||||
|
||||
if(parser->error == PFFE_LOOKAHEAD) {
|
||||
if(parser->error_pos == NULL) {
|
||||
parser->error = PFFE_INTERNAL;
|
||||
parser->reason = "Missing lookahead error position";
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
parser->llpkgc_frag__eof = 1;
|
||||
llpkgc_frag_resume(parser);
|
||||
err = llpkgc_frag_execute(parser, parser->error_pos, 1);
|
||||
parser->llpkgc_frag__eof = 0;
|
||||
|
||||
if(err != PFFE_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
parser->llpkgc_frag__lookahead = 0;
|
||||
} else if(parser->error != 0) {
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
switch(parser->llpkgc_frag__state) {
|
||||
case PFFS_UNQUOTED:
|
||||
CALLBACK_MAYBE(parser, on_frag_complete);
|
||||
if(err != PFFE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
|
||||
case PFFS_DOUBLE_QUOTED:
|
||||
case PFFS_SINGLE_QUOTED:
|
||||
parser->reason = "Unterminated quote at end of input";
|
||||
parser->error = PFFE_UNFINISHED;
|
||||
return PFFE_UNFINISHED;
|
||||
|
||||
case PFFS_START:
|
||||
break;
|
||||
}
|
||||
|
||||
CALLBACK_MAYBE(parser, on_fraglist_complete);
|
||||
if(err != PFFE_OK) {
|
||||
parser->error = err;
|
||||
return err;
|
||||
}
|
||||
|
||||
return PFFE_OK;
|
||||
}
|
||||
|
||||
void llpkgc_frag_pause(llpkgc_frag_t* parser) {
|
||||
if(parser->error != PFFE_OK) {
|
||||
return;
|
||||
}
|
||||
parser->error = PFFE_PAUSED;
|
||||
parser->reason = "Paused";
|
||||
}
|
||||
|
||||
void llpkgc_frag_resume(llpkgc_frag_t* parser) {
|
||||
if(parser->error != PFFE_PAUSED && parser->error != PFFE_LOOKAHEAD) {
|
||||
return;
|
||||
}
|
||||
parser->error = 0;
|
||||
}
|
||||
|
||||
llpkgc_frag_errno_t llpkgc_frag_get_errno(const llpkgc_frag_t* parser) {
|
||||
return parser->error;
|
||||
}
|
||||
|
||||
const char* llpkgc_frag_get_error_reason(const llpkgc_frag_t* parser) {
|
||||
return parser->reason;
|
||||
}
|
||||
|
||||
void llpkgc_frag_set_error_reason(llpkgc_frag_t* parser, const char* reason) {
|
||||
parser->reason = reason;
|
||||
}
|
||||
|
||||
const char* llpkgc_frag_get_error_pos(const llpkgc_frag_t* parser) {
|
||||
return parser->error_pos;
|
||||
}
|
||||
|
||||
const char* llpkgc_frag_errno_name(llpkgc_frag_errno_t err) {
|
||||
switch(err) {
|
||||
case PFFE_OK:
|
||||
return "PFFE_OK";
|
||||
case PFFE_INTERNAL:
|
||||
return "PFFE_INTERNAL";
|
||||
case PFFE_PAUSED:
|
||||
return "PFFE_PAUSED";
|
||||
case PFFE_USER:
|
||||
return "PFFE_USER";
|
||||
case PFFE_UNFINISHED:
|
||||
return "PFFE_UNFINISHED";
|
||||
case PFFE_LOOKAHEAD:
|
||||
return "PFFE_LOOKAHEAD";
|
||||
}
|
||||
return "INVALID_ERRNO";
|
||||
}
|
||||
|
||||
int llpkgc_frag__lookahead_dq_backslash(llpkgc_frag_t* s, const char* p,
|
||||
const char* endp) {
|
||||
if(p == endp) {
|
||||
llpkgc_frag_set_error_reason(s, "Invalid lookahead state");
|
||||
return PFFE_INTERNAL;
|
||||
}
|
||||
|
||||
if(p + 1 == endp) {
|
||||
if(s->llpkgc_frag__eof != 0) {
|
||||
s->llpkgc_frag__lookahead = 0;
|
||||
return 1;
|
||||
}
|
||||
s->llpkgc_frag__lookahead = (uint8_t) *p;
|
||||
return PFFE_LOOKAHEAD;
|
||||
}
|
||||
|
||||
s->llpkgc_frag__lookahead = 0;
|
||||
|
||||
if(*p != '\\') {
|
||||
llpkgc_frag_set_error_reason(s, "Invalid lookahead state");
|
||||
return PFFE_INTERNAL;
|
||||
}
|
||||
|
||||
switch(p[1]) {
|
||||
case '$':
|
||||
case '`':
|
||||
case '"':
|
||||
case '\\':
|
||||
return 0;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int llpkgc_frag__fragment_text(llpkgc_frag_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
SPAN_CALLBACK_MAYBE(s, on_fragment_text, p, endp - p);
|
||||
return err;
|
||||
}
|
||||
|
||||
int llpkgc_frag__frag_complete(llpkgc_frag_t* s, const char* p,
|
||||
const char* endp) {
|
||||
int err;
|
||||
CALLBACK_MAYBE(s, on_frag_complete);
|
||||
return err;
|
||||
}
|
||||
83
llpkgc_frag.h
Normal file
83
llpkgc_frag.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* Distributed under the OSI-approved BSD 3-Clause License.
|
||||
See accompanying file LICENSE.rst for details. */
|
||||
|
||||
#ifndef INCLUDE_LLPKGC_FRAG_API_H_
|
||||
#define INCLUDE_LLPKGC_FRAG_API_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <stddef.h>
|
||||
|
||||
#include "llpkgc_frag__internal.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define LLPKGC_FRAG_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define LLPKGC_FRAG_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
typedef llpkgc_frag__internal_t llpkgc_frag_t;
|
||||
typedef struct llpkgc_frag_settings_s llpkgc_frag_settings_t;
|
||||
|
||||
typedef int (
|
||||
*llpkgc_frag_data_cb)(llpkgc_frag_t*, const char* at, size_t length);
|
||||
typedef int (*llpkgc_frag_cb)(llpkgc_frag_t*);
|
||||
|
||||
struct llpkgc_frag_settings_s {
|
||||
llpkgc_frag_data_cb on_fragment_text;
|
||||
llpkgc_frag_cb on_frag_complete;
|
||||
llpkgc_frag_cb on_fraglist_complete;
|
||||
};
|
||||
|
||||
enum llpkgc_frag_errno {
|
||||
PFFE_INTERNAL = -1,
|
||||
PFFE_OK = 0,
|
||||
PFFE_PAUSED = 1,
|
||||
PFFE_USER = 2,
|
||||
PFFE_UNFINISHED = 3,
|
||||
PFFE_LOOKAHEAD = 4,
|
||||
};
|
||||
typedef enum llpkgc_frag_errno llpkgc_frag_errno_t;
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
void llpkgc_frag_init(llpkgc_frag_t* parser,
|
||||
const llpkgc_frag_settings_t* settings);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
void llpkgc_frag_reset(llpkgc_frag_t* parser);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
void llpkgc_frag_settings_init(llpkgc_frag_settings_t* settings);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
llpkgc_frag_errno_t llpkgc_frag_execute(llpkgc_frag_t* parser, const char* data,
|
||||
size_t len);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
llpkgc_frag_errno_t llpkgc_frag_finish(llpkgc_frag_t* parser);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
void llpkgc_frag_pause(llpkgc_frag_t* parser);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
void llpkgc_frag_resume(llpkgc_frag_t* parser);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
llpkgc_frag_errno_t llpkgc_frag_get_errno(const llpkgc_frag_t* parser);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
const char* llpkgc_frag_get_error_reason(const llpkgc_frag_t* parser);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
void llpkgc_frag_set_error_reason(llpkgc_frag_t* parser, const char* reason);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
const char* llpkgc_frag_get_error_pos(const llpkgc_frag_t* parser);
|
||||
|
||||
LLPKGC_FRAG_EXPORT
|
||||
const char* llpkgc_frag_errno_name(llpkgc_frag_errno_t err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC_FRAG_API_H_ */
|
||||
674
llpkgc_frag__internal.c
Normal file
674
llpkgc_frag__internal.c
Normal file
@@ -0,0 +1,674 @@
|
||||
/* 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_frag__internal.h"
|
||||
|
||||
typedef int (*llpkgc_frag__internal__span_cb)(
|
||||
llpkgc_frag__internal_t*, const char*, const char*);
|
||||
|
||||
enum llparse_state_e {
|
||||
s_error,
|
||||
s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__frag_complete,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_dq,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_sq,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_sq,
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_1,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_sq,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_escaped_char,
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_3,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_skip_backslash,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted,
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_2,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_after_quote,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_dq,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special_skip,
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_4,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq_keep_backslash,
|
||||
s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__lookahead_dq_backslash,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq,
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text,
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_start,
|
||||
};
|
||||
typedef enum llparse_state_e llparse_state_t;
|
||||
|
||||
int llpkgc_frag__fragment_text(
|
||||
llpkgc_frag__internal_t* s, const unsigned char* p,
|
||||
const unsigned char* endp);
|
||||
|
||||
int llpkgc_frag__internal__c_update_llpkgc_frag__state(
|
||||
llpkgc_frag__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_frag__state = 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_frag__internal__c_update_llpkgc_frag__state_1(
|
||||
llpkgc_frag__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_frag__state = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_frag__frag_complete(
|
||||
llpkgc_frag__internal_t* s, const unsigned char* p,
|
||||
const unsigned char* endp);
|
||||
|
||||
int llpkgc_frag__internal__c_update_llpkgc_frag__state_2(
|
||||
llpkgc_frag__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_frag__state = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_frag__internal__c_update_llpkgc_frag__state_3(
|
||||
llpkgc_frag__internal_t* state,
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp) {
|
||||
state->llpkgc_frag__state = 3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int llpkgc_frag__lookahead_dq_backslash(
|
||||
llpkgc_frag__internal_t* s, const unsigned char* p,
|
||||
const unsigned char* endp);
|
||||
|
||||
int llpkgc_frag__internal_init(llpkgc_frag__internal_t* state) {
|
||||
memset(state, 0, sizeof(*state));
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_pkgc_frag_start;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static llparse_state_t llpkgc_frag__internal__run(
|
||||
llpkgc_frag__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_frag__internal__n_invoke_llpkgc_frag__frag_complete:
|
||||
s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__frag_complete: {
|
||||
switch (llpkgc_frag__frag_complete(state, p, endp)) {
|
||||
case 0:
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_2;
|
||||
default:
|
||||
goto s_n_llpkgc_frag__internal__n_error;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_consume_dq:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_dq: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_consume_dq;
|
||||
}
|
||||
switch (*p) {
|
||||
case '"': {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_1;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_sq:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_sq: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_sq;
|
||||
}
|
||||
switch (*p) {
|
||||
case 39: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_1;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_1;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_sq:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_sq: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_sq;
|
||||
}
|
||||
switch (*p) {
|
||||
case 39: {
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_1;
|
||||
}
|
||||
default: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_sq;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_1:
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_1: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_1;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_sq;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_consume_sq:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_sq: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_consume_sq;
|
||||
}
|
||||
switch (*p) {
|
||||
case 39: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_3;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_1;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_escaped_char:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_escaped_char: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_escaped_char;
|
||||
}
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_3:
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_3: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_3;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_escaped_char;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_skip_backslash:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_skip_backslash: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_skip_backslash;
|
||||
}
|
||||
switch (*p) {
|
||||
case 92: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_3;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_2;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_2;
|
||||
}
|
||||
case ' ': {
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_2;
|
||||
}
|
||||
case '"': {
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_3;
|
||||
}
|
||||
case 39: {
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_4;
|
||||
}
|
||||
case 92: {
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_5;
|
||||
}
|
||||
default: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_2:
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_2: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_2;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_after_quote:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_after_quote: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_after_quote;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__frag_complete;
|
||||
}
|
||||
case ' ': {
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__frag_complete;
|
||||
}
|
||||
case '"': {
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_consume_dq;
|
||||
}
|
||||
case 39: {
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_consume_sq;
|
||||
}
|
||||
case 92: {
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_4;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_4;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_dq:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_dq: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_dq;
|
||||
}
|
||||
switch (*p) {
|
||||
case '"': {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_1;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_1;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special_skip:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special_skip: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special_skip;
|
||||
}
|
||||
switch (*p) {
|
||||
case '"': {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
}
|
||||
case '$': {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
}
|
||||
case 92: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
}
|
||||
case '`': {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_2;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_4:
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_4: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_4;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special_skip;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special;
|
||||
}
|
||||
switch (*p) {
|
||||
case 92: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_4;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_2;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_dq_keep_backslash:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq_keep_backslash: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_dq_keep_backslash;
|
||||
}
|
||||
switch (*p) {
|
||||
case 92: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_error_2;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__lookahead_dq_backslash:
|
||||
s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__lookahead_dq_backslash: {
|
||||
switch (llpkgc_frag__lookahead_dq_backslash(state, p, endp)) {
|
||||
case 0:
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_6;
|
||||
case 1:
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq_keep_backslash;
|
||||
case 4:
|
||||
goto s_n_llpkgc_frag__internal__n_pause;
|
||||
default:
|
||||
goto s_n_llpkgc_frag__internal__n_error_2;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_dq:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_dq: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
}
|
||||
switch (*p) {
|
||||
case '"': {
|
||||
goto s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text;
|
||||
}
|
||||
case 92: {
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__lookahead_dq_backslash;
|
||||
}
|
||||
default: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text:
|
||||
s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text;
|
||||
}
|
||||
state->_span_pos0 = (void*) p;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq;
|
||||
UNREACHABLE;
|
||||
}
|
||||
case s_n_llpkgc_frag__internal__n_pkgc_frag_start:
|
||||
s_n_llpkgc_frag__internal__n_pkgc_frag_start: {
|
||||
if (p == endp) {
|
||||
return s_n_llpkgc_frag__internal__n_pkgc_frag_start;
|
||||
}
|
||||
switch (*p) {
|
||||
case 9: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_start;
|
||||
}
|
||||
case ' ': {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_start;
|
||||
}
|
||||
case '"': {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state;
|
||||
}
|
||||
case 39: {
|
||||
p++;
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_3;
|
||||
}
|
||||
default: {
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_4;
|
||||
}
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_2: {
|
||||
switch (llpkgc_frag__internal__c_update_llpkgc_frag__state_2(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_start;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_error: {
|
||||
state->error = 0x1;
|
||||
state->reason = "Fragment complete error";
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_error;
|
||||
return s_error;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_error_1: {
|
||||
state->error = 0x1;
|
||||
state->reason = "Fragment parse error";
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_error;
|
||||
return s_error;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_1: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_frag__fragment_text(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_sq;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_sq;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_3: {
|
||||
switch (llpkgc_frag__internal__c_update_llpkgc_frag__state_3(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_1;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_2: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_frag__fragment_text(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__frag_complete;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__frag_complete;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_3: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_frag__fragment_text(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_pkgc_frag_consume_dq;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_consume_dq;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_4: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_frag__fragment_text(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_pkgc_frag_consume_sq;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_consume_sq;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_error_2: {
|
||||
state->error = 0x3;
|
||||
state->reason = "Lookahead error";
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_error;
|
||||
return s_error;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_5: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_frag__fragment_text(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_skip_backslash;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_unquoted_skip_backslash;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_4: {
|
||||
switch (llpkgc_frag__internal__c_update_llpkgc_frag__state_1(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text_2;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state_1: {
|
||||
switch (llpkgc_frag__internal__c_update_llpkgc_frag__state_1(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_after_quote;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_frag__fragment_text(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_dq;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_consume_closing_dq;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_span_end_llpkgc_frag__fragment_text_6: {
|
||||
const unsigned char* start;
|
||||
int err;
|
||||
|
||||
start = state->_span_pos0;
|
||||
state->_span_pos0 = NULL;
|
||||
err = llpkgc_frag__fragment_text(state, start, p);
|
||||
if (err != 0) {
|
||||
state->error = err;
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special;
|
||||
return s_error;
|
||||
}
|
||||
goto s_n_llpkgc_frag__internal__n_pkgc_frag_dq_special;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_pause: {
|
||||
state->error = 0x4;
|
||||
state->reason = "Lookahead required";
|
||||
state->error_pos = (const char*) p;
|
||||
state->_current = (void*) (intptr_t) s_n_llpkgc_frag__internal__n_invoke_llpkgc_frag__lookahead_dq_backslash;
|
||||
return s_error;
|
||||
UNREACHABLE;
|
||||
}
|
||||
s_n_llpkgc_frag__internal__n_invoke_update_llpkgc_frag__state: {
|
||||
switch (llpkgc_frag__internal__c_update_llpkgc_frag__state(state, p, endp)) {
|
||||
default:
|
||||
goto s_n_llpkgc_frag__internal__n_span_start_llpkgc_frag__fragment_text;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
}
|
||||
|
||||
int llpkgc_frag__internal_execute(llpkgc_frag__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_frag__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_frag__fragment_text(state, state->_span_pos0, (const char*) endp);
|
||||
if (error != 0) {
|
||||
state->error = error;
|
||||
state->error_pos = endp;
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
36
llpkgc_frag__internal.h
Normal file
36
llpkgc_frag__internal.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* 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 */
|
||||
|
||||
|
||||
#ifndef INCLUDE_LLPKGC_FRAG__INTERNAL_H_
|
||||
#define INCLUDE_LLPKGC_FRAG__INTERNAL_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct llpkgc_frag__internal_s llpkgc_frag__internal_t;
|
||||
struct llpkgc_frag__internal_s {
|
||||
int32_t _index;
|
||||
void* _span_pos0;
|
||||
int32_t error;
|
||||
const char* reason;
|
||||
const char* error_pos;
|
||||
void* data;
|
||||
void* _current;
|
||||
void* llpkgc_frag__settings;
|
||||
uint8_t llpkgc_frag__state;
|
||||
uint8_t llpkgc_frag__eof;
|
||||
uint8_t llpkgc_frag__lookahead;
|
||||
};
|
||||
|
||||
int llpkgc_frag__internal_init(llpkgc_frag__internal_t* s);
|
||||
int llpkgc_frag__internal_execute(llpkgc_frag__internal_t* s, const char* p, const char* endp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
#endif /* INCLUDE_LLPKGC_FRAG__INTERNAL_H_ */
|
||||
Reference in New Issue
Block a user