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

S-expression analyser and reader for list literals. More...

#include "x-obj.h"

Go to the source code of this file.

Macros

#define X_SEXP_LIST_PRE_STR   "("
 
#define X_SEXP_LIST_DOT_STR   "."
 
#define X_SEXP_LIST_POST_STR   ")"
 
#define X_SEXP_LIST_CHARS_STR   X_SEXP_LIST_PRE_STR X_SEXP_LIST_POST_STR
 

Functions

x_obj_tx_sexp_list_analyse (x_obj_t *p_base, x_obj_t *args)
 
x_obj_tx_sexp_list_delimit (x_obj_t *p_base, x_obj_t *args)
 
x_obj_tx_sexp_list_read (x_obj_t *p_base, x_obj_t *args)
 

Variables

Analyser / reader primitives (satom).
x_satom_t x_sexp_list_analyse_prim
 
x_satom_t x_sexp_list_delimit_prim
 
x_satom_t x_sexp_list_read_prim
 

Detailed Description

S-expression analyser and reader for list literals.

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

Macro Definition Documentation

◆ X_SEXP_LIST_CHARS_STR

#define X_SEXP_LIST_CHARS_STR   X_SEXP_LIST_PRE_STR X_SEXP_LIST_POST_STR

< The characters the list type CLAIMS: the brackets, and nothing else.

The dot is deliberately absent. It used to be here, which made it a single-character token scored on sight – so every token BEGINNING with a dot became the pair separator, and ... reached the caller as the raw separator satom sitting in a list as a VALUE. Touching it segfaulted.

A dot is now an ordinary character: nothing claims it, the symbol analyser accumulates it like any other, and the list READER recognises the one-character symbol "." as the separator when it builds a pair. That is where the structural decision already lived.

◆ X_SEXP_LIST_DOT_STR

#define X_SEXP_LIST_DOT_STR   "."

Dotted-pair separator.

◆ X_SEXP_LIST_POST_STR

#define X_SEXP_LIST_POST_STR   ")"

List close delimiter.

◆ X_SEXP_LIST_PRE_STR

#define X_SEXP_LIST_PRE_STR   "("

List open delimiter.

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.

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: back up read pointer on list characters.

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.

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.

Variable Documentation

◆ x_sexp_list_analyse_prim

x_satom_t x_sexp_list_analyse_prim
extern

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

◆ x_sexp_list_delimit_prim

x_satom_t x_sexp_list_delimit_prim

◆ x_sexp_list_read_prim

x_satom_t x_sexp_list_read_prim