1#ifndef REDUCT_PARSE_IMPL_H
2#define REDUCT_PARSE_IMPL_H 1
13#define REDUCT_PARSE_STACK_MAX 256
121 while (*pos < list->length)
169 else if (*ctx->
ptr ==
'/' && ctx->
ptr + 1 < ctx->
input->
end && *(ctx->
ptr + 1) ==
'/')
176 else if (*ctx->
ptr ==
'/' && ctx->
ptr + 1 < ctx->
input->
end && *(ctx->
ptr + 1) ==
'*')
181 if (*ctx->
ptr ==
'*' && ctx->
ptr + 1 < ctx->
input->
end && *(ctx->
ptr + 1) ==
'/')
202 const char* start = ctx->
ptr;
209 else if (*ctx->
ptr ==
'"')
243 const char* start = ctx->
ptr;
245 *ctx->
ptr !=
')' && *ctx->
ptr !=
'{' && *ctx->
ptr !=
'}')
275 rootItem->
input = input;
399 fseek(file, 0, SEEK_END);
401 fseek(file, 0, SEEK_SET);
417 if (len > 0 &&
REDUCT_FREAD(buffer, 1, len, file) != len)
Atom representation and operations.
Core definitions and structures.
#define REDUCT_MALLOC(_size)
reduct_bool_t
Boolean type.
#define REDUCT_FCLOSE(_file)
#define REDUCT_CONTAINER_OF(_ptr, _type, _member)
Container of macro.
#define REDUCT_FOPEN(_path, _mode)
reduct_uint64_t reduct_handle_t
Handle type.
#define REDUCT_FREAD(_ptr, _size, _nmemb, _file)
#define REDUCT_ASSERT(_cond)
#define REDUCT_FREE(_ptr)
Error handling and reporting.
REDUCT_API reduct_atom_t * reduct_atom_lookup(struct reduct *reduct, const char *str, reduct_size_t len, reduct_atom_lookup_flags_t flags)
Lookup an atom in the Reduct structure.
static REDUCT_ALWAYS_INLINE reduct_bool_t reduct_atom_is_equal(reduct_atom_t *atom, const char *str, reduct_size_t len)
Check if an atom is equal to a string.
REDUCT_API void reduct_atom_normalize(struct reduct *reduct, reduct_atom_t *atom)
Normalize an atom, determining its shape and parsing escape sequences.
@ REDUCT_ATOM_LOOKUP_NONE
No flags.
@ REDUCT_ATOM_LOOKUP_QUOTED
Atom should be explicitly quoted.
#define REDUCT_CHAR_IS_WHITESPACE(_c)
Check if a character is whitespace.
REDUCT_API reduct_input_t * reduct_input_new(reduct_t *reduct, const char *buffer, reduct_size_t length, const char *path, reduct_input_flags_t flags)
Create a new input structure and push it onto the input stack.
@ REDUCT_INPUT_FLAG_OWNED
The input buffer is owned by the input structure and should be freed.
#define REDUCT_ERROR_SYNTAX(_error, _input, _ptr,...)
Throw a syntax error using the jump buffer in the error structure.
#define REDUCT_ERROR_INTERNAL(_reduct,...)
Throw an internal error using the jump buffer in the error structure.
#define REDUCT_GC_RETAIN(_reduct, _handle)
Retain an item, preventing it from being collected by the GC.
#define REDUCT_HANDLE_IS_ITEM(_handle)
Check if a handle is an item.
#define REDUCT_HANDLE_FROM_LIST(_list)
Create a handle from a list pointer.
#define REDUCT_HANDLE_TO_ITEM(_handle)
Get the item pointer of a handle.
REDUCT_API reduct_handle_t reduct_handle_nil(struct reduct *reduct)
Get the constant nil handle.
#define REDUCT_HANDLE_FROM_ITEM(_ptr)
Create a handle from an item pointer.
#define REDUCT_ITEM_TYPE_ATOM
An atom.
#define REDUCT_ITEM_FLAG_QUOTED
Item is a quoted atom.
REDUCT_API reduct_handle_t reduct_parse_file(reduct_t *reduct, const char *path)
Parse a Reduct file.
REDUCT_API reduct_handle_t reduct_parse(reduct_t *reduct, const char *str, reduct_size_t len, const char *path)
Parse a Reduct string.
REDUCT_API reduct_handle_t reduct_list_nth(struct reduct *reduct, reduct_list_t *list, reduct_size_t index)
Get the nth element of the list.
REDUCT_API void reduct_list_append(struct reduct *reduct, reduct_list_t *list, reduct_handle_t val)
Append an element to the list.
REDUCT_API reduct_list_t * reduct_list_new(struct reduct *reduct)
Create a new editable list.
static reduct_parse_precedence_t reduct_parse_get_precedence(reduct_handle_t handle, reduct_bool_t unary)
static void reduct_parse_quoted_atom(reduct_t *reduct, reduct_parse_ctx_t *ctx)
static void reduct_parse_unquoted_atom(reduct_t *reduct, reduct_parse_ctx_t *ctx)
#define REDUCT_PARSE_STACK_MAX
static reduct_handle_t reduct_parse_infix_transform(reduct_t *reduct, reduct_list_t *list)
static void reduct_parse_whitespace(reduct_parse_ctx_t *ctx)
static reduct_handle_t reduct_parse_infix_transform_recursive(reduct_t *reduct, reduct_list_t *list, reduct_size_t *pos, reduct_parse_precedence_t minPrecedence)
REDUCT_API reduct_handle_t reduct_parse_input(reduct_t *reduct, reduct_input_t *input)
reduct_parse_precedence_t
@ REDUCT_PARSE_PRECEDENCE_MAX
@ REDUCT_PARSE_PRECEDENCE_NONE
@ REDUCT_PARSE_PRECEDENCE_SHIFT
@ REDUCT_PARSE_PRECEDENCE_UNARY
@ REDUCT_PARSE_PRECEDENCE_BITWISE
@ REDUCT_PARSE_PRECEDENCE_ADD_SUB
@ REDUCT_PARSE_PRECEDENCE_COMPARISON
@ REDUCT_PARSE_PRECEDENCE_MUL_DIV
@ REDUCT_PARSE_PRECEDENCE_LOGICAL_OR
@ REDUCT_PARSE_PRECEDENCE_LOGICAL_AND
reduct_uint32_t position
The position in the input buffer where the item was parsed.
struct reduct_input * input
The parsed input that created this item.
reduct_item_flags_t flags
Flags for the item.
reduct_atom_t atom
An atom.
reduct_item_type_t type
The type of the item.
reduct_uint32_t length
Total number of elements.
reduct_list_t * stack[REDUCT_PARSE_STACK_MAX]
reduct_bool_t isInfix[REDUCT_PARSE_STACK_MAX]