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

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

#include <ctype.h>
#include "x-token/sexp/int.h"
#include "x-token.h"
#include "x-type/char.h"
#include "x-type/buffer.h"
#include "x-type/int.h"
#include "x-type/prim.h"

Macros

#define x_next_state(self, dflt)
 

Functions

x_obj_tx_sexp_int_analyse_digits (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_int_analyse_xdigits (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_int_analyse_base (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_int_analyse_prefix (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_int_analyse_sign (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_sexp_int_read (x_obj_t *p_base, x_obj_t *p_args)
 

Variables

x_spair_t x_sexp_int_analyse_sign_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_sign }, { NULL })
 
x_spair_t x_sexp_int_analyse_prefix_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_prefix }, { NULL })
 
x_spair_t x_sexp_int_analyse_base_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_base }, { NULL })
 
x_spair_t x_sexp_int_analyse_digits_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_digits }, { NULL })
 
x_spair_t x_sexp_int_analyse_xdigits_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_xdigits }, { NULL })
 
x_satom_t x_sexp_int_read_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_read })
 

Detailed Description

S-expression analyser, reader, and writer for integer 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

◆ x_sexp_int_analyse_base()

x_obj_t * x_sexp_int_analyse_base ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse: detect 0x/0X hex prefix or fall through to decimal.

If the current character is x or X, transitions to the xdigits state. Otherwise delegates to the digits analyser.

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

◆ x_sexp_int_analyse_digits()

x_obj_t * x_sexp_int_analyse_digits ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse: consume decimal digits and score.

Returns self while digits are being read. On a non-digit, backs up the read pointer and scores the buffer length (or returns NULL if no digits were consumed).

Parameters
p_baseBase (execution context).
p_argsPair of (self, read-args).
Returns
Self, score, or NULL.

◆ x_sexp_int_analyse_prefix()

x_obj_t * x_sexp_int_analyse_prefix ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse: handle leading 0 (possible hex prefix) or first digit.

A leading 0 transitions to the base state; other digits delegate to the digits analyser; non-digits cause rejection.

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

◆ x_sexp_int_analyse_sign()

x_obj_t * x_sexp_int_analyse_sign ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse: handle optional leading + or - sign.

If a sign character is found, transitions to the prefix state. Otherwise delegates directly to the prefix analyser.

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

◆ x_sexp_int_analyse_xdigits()

x_obj_t * x_sexp_int_analyse_xdigits ( x_obj_t p_base,
x_obj_t p_args 
)

Analyse: consume hexadecimal digits and score.

Identical logic to analyse_digits but accepts 0-9, a-f, A-F.

Parameters
p_baseBase (execution context).
p_argsPair of (self, read-args).
Returns
Self, score, or NULL.

◆ x_sexp_int_read()

x_obj_t * x_sexp_int_read ( x_obj_t p_base,
x_obj_t p_args 
)

Read an integer literal from the token buffer.

Parses the buffer contents with x_lib_strtoint using base 0 (auto-detecting decimal, octal, or hexadecimal).

Parameters
p_baseBase (execution context).
p_argsRead-args whose first element is the token buffer.
Returns
A newly created integer object, or NULL on empty buffer.

Variable Documentation

◆ x_sexp_int_analyse_base_prim

x_spair_t x_sexp_int_analyse_base_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_base }, { NULL })

◆ x_sexp_int_analyse_digits_prim

x_spair_t x_sexp_int_analyse_digits_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_digits }, { NULL })

◆ x_sexp_int_analyse_prefix_prim

x_spair_t x_sexp_int_analyse_prefix_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_prefix }, { NULL })

◆ x_sexp_int_analyse_sign_prim

x_spair_t x_sexp_int_analyse_sign_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_sign }, { NULL })

◆ x_sexp_int_analyse_xdigits_prim

x_spair_t x_sexp_int_analyse_xdigits_prim = x_obj_set(NULL, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_analyse_xdigits }, { NULL })

◆ x_sexp_int_read_prim

x_satom_t x_sexp_int_read_prim = x_obj_set(x_type_atom_obj, X_OBJ_FLAG_NONE, { .fn = x_sexp_int_read })