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

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

#include "x-eval.h"
#include "x-token.h"
#include "x-type/buffer.h"
#include "x-type/char.h"
#include "x-type/int.h"
#include "x-type/prim.h"
#include "x-token/sexp/char.h"

Macros

#define x_next_state(self, dflt)
 

Functions

static x_obj_tx_sexp_char_analyse4 (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_sexp_char_analyse_utf8 (x_obj_t *p_base, x_obj_t *p_args)
 
static int is_lower (x_char_t c)
 
x_obj_tx_sexp_char_analyse1 (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_char_analyse2 (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_char_analyse3 (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_char_read (x_obj_t *p_base, x_obj_t *p_args)
 

Variables

x_spair_t x_sexp_char_analyse1_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_analyse1 }, { NULL })
 
x_spair_t x_sexp_char_analyse2_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_analyse2 }, { NULL })
 
x_spair_t x_sexp_char_analyse3_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_analyse3 }, { NULL })
 
x_satom_t x_sexp_char_read_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_read })
 
static x_spair_t x_sexp_char_analyse4_prim
 
static x_spair_t x_sexp_char_analyse_utf8_prim
 

Detailed Description

S-expression analyser, reader, and writer for character literals.

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

Macro Definition Documentation

◆ x_next_state

#define x_next_state (   self,
  dflt 
)
Value:
(x_obj_isnil(p_base, x_callable_state(self)) \
? (x_obj_t *)(dflt) : x_callable_state(self))
Definition x-obj.h:212
int x_obj_isnil(x_obj_t *p_base, x_obj_t *p_obj)
Definition x-obj.c:54
#define x_callable_state(X)
Definition prim.h:40

Read next-state from callable state slot, with default fallback.

Function Documentation

◆ is_lower()

static int is_lower ( x_char_t  c)
static

◆ x_sexp_char_analyse1()

x_obj_t * x_sexp_char_analyse1 ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse state 1: match first character of the #\ prefix.

Parameters
p_baseBase (execution context).
p_argsPair of (self, read-args).
Returns
Next analyser state, or NULL on mismatch.

◆ x_sexp_char_analyse2()

x_obj_t * x_sexp_char_analyse2 ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse state 2: match second character of the #\ prefix.

Parameters
p_baseBase (execution context).
p_argsPair of (self, read-args).
Returns
Next analyser state, or NULL on mismatch.

◆ x_sexp_char_analyse3()

x_obj_t * x_sexp_char_analyse3 ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse state 3: classify character after prefix.

A lowercase letter transitions to the named-character state (analyse4). Any other character scores immediately as a single-char literal.

Parameters
p_baseBase (execution context).
p_argsPair of (self, read-args).
Returns
Score object on match, next state for named chars, or NULL.

◆ x_sexp_char_analyse4()

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

Analyse state 4 (static): named-character continuation.

Keeps consuming lowercase letters. On a non-letter delimiter the read pointer is backed up and the accumulated length is scored.

Parameters
p_baseBase (execution context).
p_argsPair of (self, read-args).
Returns
Self to keep reading, or score on delimiter.

◆ x_sexp_char_analyse_utf8()

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

Analyse UTF-8 continuation: consume 10xxxxxx bytes.

Reached after a multi-byte lead byte. Keeps consuming continuation bytes (0x80-0xBF). On the first non-continuation byte the read pointer is backed up and the accumulated length is scored.

Parameters
p_baseBase (execution context).
p_argsPair of (self, read-args).
Returns
Self to keep reading, or score at the end of the sequence.

◆ x_sexp_char_read()

x_obj_t * x_sexp_char_read ( x_obj_t p_base,
x_obj_t p_args 
)

Read a character literal from the token buffer.

Handles single-character literals (#\c, length 3) and named characters (e.g. #\newline) by looking up the name in the character type's data alist.

Parameters
p_baseBase (execution context).
p_argsRead-args containing the token buffer.
Returns
A newly created character object, or NULL on error.
Note
Signals an error for unknown character names.

Variable Documentation

◆ x_sexp_char_analyse1_prim

x_spair_t x_sexp_char_analyse1_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_analyse1 }, { NULL })

◆ x_sexp_char_analyse2_prim

x_spair_t x_sexp_char_analyse2_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_analyse2 }, { NULL })

◆ x_sexp_char_analyse3_prim

x_spair_t x_sexp_char_analyse3_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_analyse3 }, { NULL })

◆ x_sexp_char_analyse4_prim

x_spair_t x_sexp_char_analyse4_prim
static
Initial value:
=
x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_analyse4 }, { NULL })
@ X_OBJ_FLAG_NONE
Definition x-obj.h:129
#define x_obj_set(T, F,...)
Definition x-obj.h:342
static x_obj_t * x_sexp_char_analyse4(x_obj_t *p_base, x_obj_t *p_args)
Definition char.c:130

◆ x_sexp_char_analyse_utf8_prim

x_spair_t x_sexp_char_analyse_utf8_prim
static
Initial value:
=
static x_obj_t * x_sexp_char_analyse_utf8(x_obj_t *p_base, x_obj_t *p_args)
Definition char.c:158

◆ x_sexp_char_read_prim

x_satom_t x_sexp_char_read_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_char_read })