|
x-engine-c v0.2.13
The C engine for x-lang
|
Tokenization interface. More...
#include "x-obj.h"Go to the source code of this file.
Macros | |
Reader Argument Access Macros | |
Decompose the argument list passed to token reader callbacks. Layout: | |
| #define | x_token_read_arg_prim(X) x_0((X)) |
| #define | x_token_read_arg_buffer(X) x_0((X)) |
| #define | x_token_read_arg_score(X) x_01((X)) |
| #define | x_token_read_arg_char(X) x_0(x_11((X))) |
| #define | x_token_read_arg_variant(X) x_01((X)) |
Tokenization Pipeline | |
| x_satom_t | x_token_eof_prim |
| x_obj_t * | x_token_delimit (x_obj_t *p_base, x_obj_t *p_obj) |
| x_obj_t * | x_token_analyse (x_obj_t *p_base, x_obj_t *p_obj, x_int_t *p_variant) |
| x_obj_t * | x_token_read (x_obj_t *p_base, x_obj_t *p_obj) |
Tokenization interface.
Declares the type-dispatched tokenization pipeline: delimiting, analysing, reading, writing, and displaying. Each stage iterates the registered type alist and delegates to per-type handlers.
THE VARIANT CHANNEL. An analyser knows things about the token it accepts that the text alone does not say – which of its states ran, whether a numeric literal passed through a fraction or an exponent – and used to throw them away, leaving the reader to rescan the text. The score cell an analyser is handed now carries a VARIANT cell on its rest: the state writes an integer there as it accepts (x-lang's score-variant!, a plain set-cell-int! on the cell; compiled states call jit_score_variant), the analyse loop records the winning handler's variant, and x_token_read hands it to the type's reader as the reader's SECOND argument – a raw ATOM CELL whose value word is the integer (x_atomint in C, cell-int in x-lang; nil when no state declared one, which is every type that never heard of the channel). A cell rather than an int because an int object only exists relative to a base that registered the int type, and a tokenizer base has none by design. Readers already received (buffer ()) so nothing about their arity changes.
| #define x_token_read_arg_buffer | ( | X | ) | x_0((X)) |
Alias – buffer object for the reader.
| #define x_token_read_arg_prim | ( | X | ) | x_0((X)) |
Reader primitive / buffer object.
| #define x_token_read_arg_score | ( | X | ) | x_01((X)) |
Current best score (integer).
| #define x_token_read_arg_variant | ( | X | ) | x_01((X)) |
In a READER's argument list, (buffer variant): the variant the accepting analyser declared, a raw atom cell (read it with x_atomint), or NULL when none did.
Run per-type analysis on a completed token buffer. Writes the winning handler's declared variant (0 when none) through p_variant.
Determine which type best matches the next token in the buffer.
Iterates all registered types, calling each type's analyse hook character by character. Tracks the winning type by score (number of buffer characters consumed). Uses first-char hint strings on x-lang closures to skip non-matching types early. The >= comparison means later types (C built-ins) win ties against earlier (custom) types.
After finding the winner, advances the buffer read pointer by the winning score.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (buffer . base) pair |
| p_variant | x_int_t* – Out: the variant the winning handler declared through the variant cell (0 when none) |
Check whether p_obj delimits the current token for any type.
Check whether any type's delimiter matches at the current buffer position.
Iterates all registered types (except the given type itself) and calls each type's delimit hook. Returns the buffer if a delimiter matched, NULL otherwise.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – Read-args whose first element is the buffer |
Read a single token from the input stream.
Read the next token from the buffer and return its parsed object.
Calls x_token_analyse to identify the token type, counts newlines in the consumed region for line tracking, then invokes the winning type's read hook. Types with no read hook (e.g. whitespace) are discarded and the loop retries. Stamps source line numbers on created objects when meta tracking is enabled.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (buffer . base) pair |
()) or every reader declined; x_token_eof_prim at clean end of input (zero consumption).
|
extern |
Clean end-of-input sentinel, returned by x_token_read when analysis finds no token with zero consumption. Distinguishes true EOF from a read NIL VALUE (() reads as NULL by design). Compared by ADDRESS in C; bound as token-eof for x-lang, where identity is (obj same?) – never eq?, which compares value words.
Clean-EOF sentinel (see x-token.h). The value word is its own address so eq?'s value-word compare cannot conflate it with a small integer; identity tests use the ADDRESS (C ==, x-lang (obj same?)).