x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
list.c File Reference

S-expression analyser, reader, writer, and display for list literals. More...

#include "x-type/list.h"
#include "x-type/buffer.h"
#include "x-type/symbol.h"
#include "x-eval.h"
#include "x-heap.h"
#include "x-token.h"
#include "x-token/sexp/list.h"
#include "x-token/sexp/whitespace.h"

Functions

x_obj_tx_sexp_list_analyse (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_list_delimit (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_sexp_list_read_next (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_list_read (x_obj_t *p_base, x_obj_t *p_args)
 

Variables

x_satom_t x_sexp_list_analyse_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_list_analyse })
 
x_satom_t x_sexp_list_delimit_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_list_delimit })
 
x_satom_t x_sexp_list_read_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_list_read })
 

Detailed Description

S-expression analyser, reader, writer, and display for list literals.

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Function Documentation

◆ x_sexp_list_analyse()

x_obj_t * x_sexp_list_analyse ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse: score on any list delimiter character.

Matches ( and ) only. Scores the buffer length immediately, which is sound because the brackets really are always single-character tokens.

The dot is NOT matched, and that sentence used to be false of it: a dot scored here on sight, so a token merely BEGINNING with one was taken whole as the pair separator. It is an ordinary character now – the symbol analyser accumulates it, and the list reader recognises the symbol "." when it builds a pair.

Parameters
p_baseBase (execution context).
p_argsRead-args containing the token buffer and score.
Returns
Score on match, or NULL.

◆ x_sexp_list_delimit()

x_obj_t * x_sexp_list_delimit ( x_obj_t p_base,
x_obj_t p_args 
)

Delimiter callback for list characters.

Backs up the read pointer when a list delimiter is encountered so the current token is terminated before the delimiter.

Parameters
p_baseBase (execution context).
p_argsRead-args containing the token buffer.
Returns
The buffer on delimiter match, or NULL.

◆ x_sexp_list_read()

x_obj_t * x_sexp_list_read ( x_obj_t p_base,
x_obj_t p_args 
)

Read a list (or dotted pair) from the token stream.

Two cases, on the bracket character:

  • ) – returns the read_prim sentinel (end of list).
  • ( – recursively reads elements via x_token_read until the close-paren sentinel, treating the one-character symbol . as the pair separator when it meets one.

The separator has no sentinel of its own. It used to: the dot was a single-character token and this returned delimit_prim for it, which meant every token beginning with a dot became the separator and ... reached the caller as that raw satom, inside a list, as a value.

Parameters
p_baseBase (execution context).
p_argsRead-args containing the token buffer.
Returns
The constructed list, or a sentinel primitive.

◆ x_sexp_list_read_next()

static x_obj_t * x_sexp_list_read_next ( x_obj_t p_base,
x_obj_t p_args 
)
static

x_token_read, but end-of-input inside an OPEN list is truncation: raise instead of returning the EOF sentinel. Control never returns, so a partial list can never reach evaluation, and the callers that used to spin appending the ambiguous NULL (#156) terminate loudly. No root-pop before the raise: guard restores the root chain (x-syntax/control.c) and the no-handler path exits – the same protocol as every mid-eval raise.

Parameters
p_baseBase (execution context).
p_argsRead-args containing the token buffer.
Returns
The token object; never the EOF sentinel.

Variable Documentation

◆ x_sexp_list_analyse_prim

x_satom_t x_sexp_list_analyse_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_list_analyse })

Analyser / delimiter / reader primitive satoms for the list type.

◆ x_sexp_list_delimit_prim

x_satom_t x_sexp_list_delimit_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_list_delimit })

◆ x_sexp_list_read_prim

x_satom_t x_sexp_list_read_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_list_read })