|
libsnobol4 1.0.2
High-performance SNOBOL4-style pattern matching library
|
Abstract Syntax Tree representation for SNOBOL patterns. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include "snobol/arena.h"

Go to the source code of this file.
Classes | |
| struct | snobol_ast_version_t |
| struct | ast_node |
Macros | |
| #define | SNOBOL_AST_VERSION_MAJOR 1 |
| #define | SNOBOL_AST_VERSION_MINOR 0 |
| #define | SNOBOL_AST_VERSION_PATCH 0 |
| #define | SNOBOL_AST_VERSION_STRING "1.0.0" |
| #define | SNOBOL_AST_VERSION_CHECK(major, minor) |
Typedefs | |
| typedef struct ast_node | ast_node_t |
Enumerations | |
| enum | ast_type_t { AST_LITERAL , AST_CONCAT , AST_ALT , AST_REPETITION , AST_SPAN , AST_BREAK , AST_ANY , AST_NOTANY , AST_ARBNO , AST_CAP , AST_ASSIGN , AST_LEN , AST_EVAL , AST_DYNAMIC_EVAL , AST_ANCHOR , AST_EMIT , AST_LABEL , AST_GOTO , AST_TABLE_ACCESS , AST_TABLE_UPDATE , AST_BREAKX , AST_BAL , AST_FENCE , AST_REM , AST_RPOS , AST_RTAB , AST_POS , AST_TAB , AST_ABORT , AST_FAIL , AST_SUCCEED , AST_REG_REF } |
| enum | anchor_type_t { ANCHOR_START , ANCHOR_END } |
Abstract Syntax Tree representation for SNOBOL patterns.
Uses tagged union structs for type-safe AST nodes. Memory ownership: parent nodes own child nodes recursively. Caller is responsible for calling snobol_ast_free() to free entire tree.
Version: 1.0.0
Definition in file ast.h.
| #define SNOBOL_AST_VERSION_CHECK | ( | major, | |
| minor ) |
Check if AST version is compatible Returns true if major version matches and minor version >= required
| #define SNOBOL_AST_VERSION_MAJOR 1 |
AST version information Use snobol_ast_get_version() to retrieve at runtime
| typedef struct ast_node ast_node_t |
| enum anchor_type_t |
| enum ast_type_t |
AST node type tags
| snobol_arena_t * snobol_ast_clear_arena | ( | void | ) |
Clear the thread-local AST arena binding and return the previously bound arena (or NULL if none). Convenient for reclaiming node storage after the tree has been freed.
| ast_node_t * snobol_ast_clone | ( | const ast_node_t * | node | ) |
Deep-clone an AST node and all children recursively
| node | Node to clone (NULL returns NULL) |
| ast_node_t * snobol_ast_create_abort | ( | void | ) |
Create AST_ABORT node (no args)
| ast_node_t * snobol_ast_create_alt | ( | ast_node_t * | left, |
| ast_node_t * | right ) |
Create an alternation AST node
| left | Left alternative (ownership transferred) |
| right | Right alternative (ownership transferred) |
| ast_node_t * snobol_ast_create_anchor | ( | anchor_type_t | atype | ) |
Create AST_ANCHOR node
| ast_node_t * snobol_ast_create_any | ( | const char * | set, |
| size_t | len ) |
Create an any AST node
| set | Character set string (copied, or NULL for any char) |
| len | Length of set (0 if NULL) |
| ast_node_t * snobol_ast_create_arbno | ( | ast_node_t * | sub | ) |
Create an arbno (zero-or-more) AST node
| sub | Sub-pattern (ownership transferred) |
| ast_node_t * snobol_ast_create_assign | ( | int | var, |
| int | reg ) |
Create AST_ASSIGN node
| ast_node_t * snobol_ast_create_bal | ( | uint32_t | open_cp, |
| uint32_t | close_cp ) |
Create AST_BAL node
| ast_node_t * snobol_ast_create_break | ( | const char * | set, |
| size_t | len ) |
Create AST_BREAK node
| ast_node_t * snobol_ast_create_breakx | ( | const char * | set, |
| size_t | len ) |
Create AST_BREAKX node
| ast_node_t * snobol_ast_create_cap | ( | int | reg, |
| ast_node_t * | sub ) |
Create a capture AST node
| reg | Register number |
| sub | Sub-pattern to capture (ownership transferred) |
| ast_node_t * snobol_ast_create_concat | ( | ast_node_t ** | parts, |
| size_t | count ) |
Create a concatenation AST node
| parts | Array of child nodes (ownership transferred) |
| count | Number of parts |
| ast_node_t * snobol_ast_create_dynamic_eval | ( | ast_node_t * | expr | ) |
Create AST_DYNAMIC_EVAL node
| ast_node_t * snobol_ast_create_emit | ( | const char * | text, |
| size_t | len, | ||
| int | reg ) |
Create AST_EMIT node
| ast_node_t * snobol_ast_create_eval | ( | int | fn, |
| int | reg ) |
Create AST_EVAL node
| ast_node_t * snobol_ast_create_fail | ( | void | ) |
Create AST_FAIL node (no args)
| ast_node_t * snobol_ast_create_fence | ( | void | ) |
Create AST_FENCE node (no args)
| ast_node_t * snobol_ast_create_goto | ( | const char * | label | ) |
Create a goto AST node
| label | Target label name (copied) |
| ast_node_t * snobol_ast_create_label | ( | char * | name, |
| ast_node_t * | target ) |
Create a label AST node
| name | Label name (copied, ownership transferred) |
| target | Target pattern (ownership transferred) |
| ast_node_t * snobol_ast_create_len | ( | int32_t | n | ) |
Create AST_LEN node
| ast_node_t * snobol_ast_create_lit | ( | const char * | text, |
| size_t | len ) |
Create a literal AST node
| text | Literal text (copied, must be freed by caller if not using create_lit) |
| len | Length of text |
| ast_node_t * snobol_ast_create_literal | ( | const char * | text, |
| size_t | len ) |
Alias for snobol_ast_create_lit
| ast_node_t * snobol_ast_create_notany | ( | const char * | set, |
| size_t | len ) |
Create AST_NOTANY node
| ast_node_t * snobol_ast_create_pos | ( | int32_t | n | ) |
Create AST_POS node
| ast_node_t * snobol_ast_create_regref | ( | int | reg | ) |
Create AST_REG_REF node (value of register vN as a table key).
| ast_node_t * snobol_ast_create_rem | ( | void | ) |
Create AST_REM node (no args)
| ast_node_t * snobol_ast_create_repeat | ( | ast_node_t * | sub, |
| int32_t | min, | ||
| int32_t | max ) |
Create a repetition AST node
| sub | Sub-pattern (ownership transferred) |
| min | Minimum repetitions |
| max | Maximum repetitions (-1 for unbounded) |
| ast_node_t * snobol_ast_create_rpos | ( | int32_t | n | ) |
Create AST_RPOS node
| ast_node_t * snobol_ast_create_rtab | ( | int32_t | n | ) |
Create AST_RTAB node
| ast_node_t * snobol_ast_create_span | ( | const char * | set, |
| size_t | len ) |
Create a span AST node
| set | Character set string (copied) |
| len | Length of set |
| ast_node_t * snobol_ast_create_succeed | ( | void | ) |
Create AST_SUCCEED node (no args)
| ast_node_t * snobol_ast_create_tab | ( | int32_t | n | ) |
Create AST_TAB node
| ast_node_t * snobol_ast_create_table_access | ( | const char * | table, |
| ast_node_t * | key ) |
Create AST_TABLE_ACCESS node
| ast_node_t * snobol_ast_create_table_update | ( | const char * | table, |
| ast_node_t * | key, | ||
| ast_node_t * | value ) |
Create AST_TABLE_UPDATE node
| uint32_t snobol_ast_depth | ( | const ast_node_t * | node | ) |
Subtree height of an AST node.
The value is maintained by the node factories, so this is O(1): a leaf is 1 and NULL is 0.
| node | AST node, or NULL |
| void snobol_ast_dump | ( | const ast_node_t * | node, |
| FILE * | out, | ||
| int | indent ) |
Dump AST to file for debugging
| node | Root node |
| out | File to write to (e.g., stdout) |
| indent | Current indentation level (0 for root) |
| void snobol_ast_free | ( | ast_node_t * | node | ) |
Free an AST node and all children recursively
| node | Node to free (NULL is safe) |
| snobol_ast_version_t snobol_ast_get_version | ( | void | ) |
Get AST version information
| void snobol_ast_set_arena | ( | snobol_arena_t * | arena | ) |
Bind a bump arena that subsequent AST node allocations draw from. Pass NULL to revert to the default heap (calloc) allocator. The binding is thread-local so concurrent compiles on different threads use independent arenas. When the arena is exhausted, allocations transparently fall back to calloc. Owned sub-allocations (strings, concat part arrays) always use the heap. The caller is responsible for resetting/freeing the arena after the tree has been consumed (e.g. via snobol_ast_free followed by snobol_arena_reset).
| arena | Arena to use, or NULL for the default allocator. |
| const char * snobol_ast_type_name | ( | ast_type_t | type | ) |
Get a string representation of AST node type for debugging
| type | Node type |
| bool snobol_ast_version_check | ( | uint16_t | required_major, |
| uint16_t | required_minor ) |
Check if AST library version is compatible with required version
| required_major | Required major version |
| required_minor | Required minor version |
| const char * snobol_ast_version_string | ( | void | ) |
Get AST version as a string (e.g., "1.0.0")