9#include "../../src/common.h"
64static inline uint16_t _exblex_priv_tokenid(
const struct exblex *l,
char tk)
86 rdesc_assert(tokens[0] ==
'\0',
"first element of tokens (tokens[0]) "
92 .token_count = strlen(
tokens + 1),
93 .cur = 0, .current_seminfo = NULL,
94 .pushback_char =
'\0',
109 return l->current_seminfo;
127 char c = l->
buf[l->
cur++];
128 char *seminfo = NULL;
129 size_t seminfo_len = 0;
132 while (isalnum(c) || c ==
'_') {
133 if (seminfo == NULL) {
134 rdesc_assert(seminfo = malloc(
sizeof(
char) * 2),
138 rdesc_assert(seminfo = realloc(seminfo,
sizeof(
char) * (++seminfo_len + 1)),
145 seminfo[seminfo_len - 1] = c;
151 seminfo[seminfo_len] =
'\0';
157 id = _exblex_priv_tokenid(l,
'd');
158 else if (!isdigit(seminfo[0]))
159 id = _exblex_priv_tokenid(l,
'w');
162 l->current_seminfo = seminfo;
175 return _exblex_priv_tokenid(l, c);
static char * exblex_current_seminfo(struct exblex *l)
Retrieves the semantic information for the last token.
Definition exblex.h:107
static uint16_t exblex_next(struct exblex *l)
Fetches the next token.
Definition exblex.h:122
static void exblex_init(struct exblex *l, const char *buf, const char *tokens)
Initializes the basic lexer with a null-terminated list of chars.
Definition exblex.h:82
EXtremely Basic LEXer.
Definition exblex.h:37
const char * tokens
Array of token characters.
Definition exblex.h:42
const char * buf
Underlying null-terminated input buffer.
Definition exblex.h:39
size_t cur
(current) Position in the buffer.
Definition exblex.h:50
size_t token_count
Number of tokens in provided array.
Definition exblex.h:45