43#include "snobol/version.h"
49#define SNOBOL_ABI_VERSION 1
60#if defined(__GNUC__) || defined(__clang__)
61#define SNOBOL_DEPRECATED __attribute__((deprecated))
62#elif defined(_MSC_VER)
63#define SNOBOL_DEPRECATED __declspec(deprecated)
65#define SNOBOL_DEPRECATED
134#define SNOBOL_API_MAX_VARS 64
202 const char *subject,
size_t len,
292#define SNOBOL_FLAG_CASE_INSENSITIVE 0x0001u
309 const char *source,
size_t len,
325 const char *source,
size_t len,
326 uint32_t flags,
char **error);
352 uint32_t flags,
char **error);
451 const char **names,
size_t n);
465 const char *subject,
size_t len);
515 const char *subject,
size_t len);
541 const uint8_t *bc,
size_t bc_len);
584 bool (*eval_fn)(
int fn_id,
const char *s,
size_t start,
size_t end,
646 size_t start_offset);
690 const char *subject,
size_t subject_len,
691 size_t start_offset,
size_t *out_pos,
717 const char *subject,
size_t len,
873 const char *subject,
size_t sub_len,
921 const char *text,
size_t len);
925 const char *set,
size_t len);
929 const char *set,
size_t len);
933 const char *set,
size_t len);
937 const char *set,
size_t len);
1000 const char *set,
size_t len);
1004 uint32_t open_cp, uint32_t close_cp);
Runtime-owned sparse array objects for SNOBOL4.
struct snobol_array snobol_array_t
Sparse array state.
Abstract Syntax Tree representation for SNOBOL patterns.
struct ast_node ast_node_t
Compiler for SNOBOL pattern AST to bytecode.
Dynamic pattern objects and canonical cache keys.
struct snobol_table snobol_table_t
Associative table (opaque handle).
Lexer for SNOBOL pattern syntax.
Recursive descent parser for SNOBOL pattern syntax.
Core search runtime API for libsnobol4.
struct snobol_auto_trie_t snobol_auto_trie_t
Opaque pre-allocated trie used by the Tier-5 alternation matcher.
ast_node_t * snobol_pattern_build_concat(snobol_pattern_build_t *build, ast_node_t **parts, size_t count)
Create a CONCAT AST node (sequence of parts). Takes ownership of parts array and all child nodes.
ast_node_t * snobol_pattern_build_abort(snobol_pattern_build_t *build)
Create an ABORT AST node.
uint32_t snobol_get_api_version(void)
ast_node_t * snobol_pattern_build_label(snobol_pattern_build_t *build, const char *name, ast_node_t *target)
Create a LABEL AST node.
ast_node_t * snobol_pattern_build_fail(snobol_pattern_build_t *build)
Create a FAIL AST node.
int snobol_pattern_search_state_set_tables(snobol_pattern_search_state_t *state, snobol_table_t *const *tables, size_t n)
Set the tables registered into a search state's persistent VM.
void snobol_pattern_build_destroy(snobol_pattern_build_t *build)
Destroy a builder. Does NOT free emitted AST nodes.
ast_node_t * snobol_pattern_build_notany(snobol_pattern_build_t *build, const char *set, size_t len)
Create a NOTANY AST node (match single char NOT in set).
ast_node_t * snobol_pattern_build_rpos(snobol_pattern_build_t *build, int32_t n)
Create a RPOS AST node.
snobol_match_t * snobol_pattern_match(snobol_pattern_t *pattern, const char *subject, size_t len)
Execute a compiled pattern against a subject string.
bool snobol_pattern_search_reuse(snobol_pattern_t *pattern, const char *subject, size_t len, snobol_match_t *match_out)
Search using a caller-allocated, reusable match object.
snobol_pattern_t * snobol_pattern_compile_ex(snobol_context_t *ctx, const char *source, size_t len, uint32_t flags, char **error)
void snobol_match_free(snobol_match_t *match)
Free a match result.
bool snobol_pattern_search_batch_ex(snobol_pattern_search_state_t *state, const char *subject, size_t len, snobol_batch_result_t *out)
Stateful batch search that reuses VM, range_meta, and (for automaton-eligible patterns) the DFA/trie/...
snobol_pattern_build_t * snobol_pattern_build_create(void)
Create a new builder.
ast_node_t * snobol_pattern_build_tab(snobol_pattern_build_t *build, int32_t n)
Create a TAB AST node.
ast_node_t * snobol_pattern_build_assign(snobol_pattern_build_t *build, int var, int reg)
Create an ASSIGN AST node (assign register to variable).
const char * snobol_match_get_variable(snobol_match_t *match, const char *name, size_t *len)
Retrieve the value of a named capture variable from a match result.
ast_node_t * snobol_pattern_build_span(snobol_pattern_build_t *build, const char *set, size_t len)
Create a SPAN AST node (match 1+ chars in set).
int snobol_pattern_bind_tables(snobol_pattern_t *pattern, const char **names, snobol_table_t *const *tables, size_t n)
Bind host tables to a compiled pattern by name.
ast_node_t * snobol_pattern_build_arbno(snobol_pattern_build_t *build, ast_node_t *sub)
Create an ARBNO AST node (zero or more repetitions).
void snobol_match_reset(snobol_match_t *match)
Reset a match result for reuse without freeing.
snobol_match_t * snobol_pattern_search_ex_anchored(snobol_pattern_search_state_t *state, const char *subject, size_t subject_len)
Stateful anchored search that reuses VM, DFA, and range_meta.
ast_node_t * snobol_pattern_build_fence(snobol_pattern_build_t *build)
Create a FENCE AST node.
#define SNOBOL_API_MAX_VARS
Maximum named variables returned from a match.
void snobol_batch_result_free(snobol_batch_result_t *out)
Free all arrays owned by a batch result struct. NULL-safe.
struct snobol_match snobol_match_t
Match result object.
ast_node_t * snobol_pattern_build_rtab(snobol_pattern_build_t *build, int32_t n)
Create a RTAB AST node.
ast_node_t * snobol_pattern_build_alt(snobol_pattern_build_t *build, ast_node_t *left, ast_node_t *right)
Create an ALT AST node (alternation).
struct snobol_pattern_build snobol_pattern_build_t
Opaque builder state.
bool snobol_pattern_search_next(snobol_pattern_search_state_t *state, const char *subject, size_t subject_len, size_t start_offset, size_t *out_pos, size_t *out_len)
Lightweight unanchored search for single-literal patterns.
void snobol_context_destroy(snobol_context_t *ctx)
Destroy a pattern matching context and free all associated resources.
void snobol_pattern_free(snobol_pattern_t *pattern)
Free a compiled pattern.
void snobol_pattern_search_state_set_pattern(snobol_pattern_search_state_t *state, snobol_pattern_t *pattern)
Associate an owning pattern with a search state.
void snobol_version(int *major, int *minor, int *patch)
struct snobol_context snobol_context_t
Pattern matching context (opaque handle).
ast_node_t * snobol_pattern_build_bal(snobol_pattern_build_t *build, uint32_t open_cp, uint32_t close_cp)
Create a BAL AST node.
ast_node_t * snobol_pattern_build_lit(snobol_pattern_build_t *build, const char *text, size_t len)
Create a LITERAL AST node.
ast_node_t * snobol_pattern_build_rem(snobol_pattern_build_t *build)
Create a REM AST node.
struct snobol_pattern_search_state snobol_pattern_search_state_t
Opaque state for snobol_pattern_search_ex().
ast_node_t * snobol_pattern_build_breakx(snobol_pattern_build_t *build, const char *set, size_t len)
Create a BREAKX AST node.
ast_node_t * snobol_pattern_build_emit(snobol_pattern_build_t *build, ast_node_t *root)
Finalize and emit an AST tree built with the builder.
const char * snobol_match_get_output(snobol_match_t *match, size_t *len)
Retrieve the output buffer produced by a successful match.
snobol_match_t * snobol_match_create(void)
Create a new match result object.
struct snobol_literal_match snobol_literal_match_t
Lightweight result from snobol_pattern_match_literal().
void snobol_pattern_search_state_destroy(snobol_pattern_search_state_t *state)
Destroy a search state object. NULL-safe.
struct snobol_pattern snobol_pattern_t
Compiled pattern (opaque handle).
snobol_match_t * snobol_pattern_search(snobol_pattern_t *pattern, const char *subject, size_t len)
Execute a compiled pattern in search (un-anchored) mode.
const uint8_t * snobol_pattern_get_bc(const snobol_pattern_t *pattern)
Get the bytecode pointer from a compiled pattern.
struct snobol_batch_result snobol_batch_result_t
Result from snobol_pattern_search_batch().
ast_node_t * snobol_pattern_build_succeed(snobol_pattern_build_t *build)
Create a SUCCEED AST node.
snobol_pattern_t * snobol_pattern_compile(snobol_context_t *ctx, const char *source, size_t len, char **error)
Compile a SNOBOL4 pattern string to a compiled pattern object.
uint32_t snobol_get_abi_version(void)
const snobol_search_meta_t * snobol_pattern_get_meta(const snobol_pattern_t *pattern)
Get the pre-derived search metadata for a compiled pattern.
snobol_pattern_t * snobol_pattern_build_compile(snobol_context_t *ctx, ast_node_t *root, uint32_t flags, char **error)
Compile a built AST root into a compiled pattern object.
size_t snobol_match_get_length(const snobol_match_t *match)
Get the length of the match in bytes.
snobol_literal_match_t snobol_pattern_match_literal(snobol_pattern_t *pattern, const char *subject, size_t len)
Lightweight anchored literal match for literal-only patterns.
int snobol_pattern_bind_bytecode_tables(uint8_t *bc, size_t bc_len, const char **names, size_t n)
Bind table ids in a compiled pattern bytecode buffer by name.
ast_node_t * snobol_pattern_build_goto(snobol_pattern_build_t *build, const char *label)
Create a GOTO AST node.
ast_node_t * snobol_pattern_build_cap(snobol_pattern_build_t *build, int reg, ast_node_t *sub)
Create a CAP AST node (capture sub-pattern into register).
struct snobol_match_result snobol_match_result_t
Result from the one-shot snobol_match() convenience API.
snobol_pattern_search_state_t * snobol_pattern_search_state_create(const uint8_t *bc, size_t bc_len)
Create a state object for snobol_pattern_search_ex().
snobol_match_t * snobol_pattern_search_ex(snobol_pattern_search_state_t *state, const char *subject, size_t subject_len, size_t start_offset)
Stateful search that reuses VM, output buffer, and match result across calls.
snobol_match_result_t * snobol_match(const char *pattern, size_t pat_len, const char *subject, size_t sub_len, uint32_t flags)
One-shot convenience match: compile and run a pattern in one call.
snobol_pattern_t * snobol_pattern_from_bytecode(uint8_t *bc, size_t bc_len, uint32_t flags, char **error)
Build a pattern from an existing bytecode buffer.
ast_node_t * snobol_pattern_build_pos(snobol_pattern_build_t *build, int32_t n)
Create a POS AST node.
ast_node_t * snobol_pattern_build_brk(snobol_pattern_build_t *build, const char *set, size_t len)
Create a BREAK AST node (consume until char in set).
const snobol_range_meta_t * snobol_pattern_get_range_meta(const snobol_pattern_t *pattern, size_t *count)
Retrieve cached charclass range metadata from a compiled pattern.
void snobol_pattern_search_state_set_trie_cache(snobol_pattern_search_state_t *state, snobol_auto_trie_t *trie)
bool snobol_pattern_search_batch(const uint8_t *bc, size_t bc_len, const char *subject, size_t len, const snobol_search_meta_t *meta, snobol_batch_result_t *out)
Find all non-overlapping matches in a single pass.
ast_node_t * snobol_pattern_build_any(snobol_pattern_build_t *build, const char *set, size_t len)
Create an ANY AST node (match single char in optional set).
ast_node_t * snobol_pattern_build_name(snobol_pattern_build_t *build, int reg, ast_node_t *sub)
Create a match-naming node: bind sub-pattern's match to register.
snobol_context_t * snobol_context_create(void)
Create a new pattern matching context.
size_t snobol_match_get_position(const snobol_match_t *match)
Get the absolute offset where the match started within the subject.
void snobol_match_result_free(snobol_match_result_t *result)
Free a snobol_match_result_t and all its owned resources.
bool snobol_match_success(snobol_match_t *match)
Return whether a match result represents a successful match.
ast_node_t * snobol_pattern_build_len(snobol_pattern_build_t *build, int32_t n)
Create a LEN AST node (match exactly N codepoints).
size_t snobol_pattern_get_bc_len(const snobol_pattern_t *pattern)
Get the bytecode length from a compiled pattern.
void snobol_pattern_search_state_set_eval_fn(snobol_pattern_search_state_t *state, bool(*eval_fn)(int fn_id, const char *s, size_t start, size_t end, void *userdata), void *eval_udata)
Set the EVAL callback function on a search state's persistent VM.
SNOBOL4 built-in string transformation functions.
Result from snobol_pattern_search_batch().
Lightweight result from snobol_pattern_match_literal().
Result from the one-shot snobol_match() convenience API.
size_t var_lens[SNOBOL_API_MAX_VARS]
size_t var_off[SNOBOL_API_MAX_VARS]
char * var_values[SNOBOL_API_MAX_VARS]
size_t var_len[SNOBOL_API_MAX_VARS]
Runtime-owned associative table objects for SNOBOL4.
SNOBOL4 built-in comparison and type-checking functions.
Virtual machine types, opcodes, and execution API for libsnobol4.