core: lexer: Add operational tokens

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-05-23 09:01:18 -04:00
parent 2ec8122a91
commit 5f72602471
3 changed files with 31 additions and 4 deletions
+21 -4
View File
@@ -304,6 +304,18 @@ lexer_nom(struct cescal_state *state, struct token *res)
res->type = TT_COLON; res->type = TT_COLON;
res->c = c; res->c = c;
return 0; return 0;
case '+':
res->type = TT_PLUS;
res->c = c;
return 0;
case '*':
res->type = TT_STAR;
res->c = c;
return 0;
case '=':
res->type = TT_EQUALS;
res->c = c;
return 0;
case '#': case '#':
if ((c = lexer_consume_single(state, true)) == '\0') { if ((c = lexer_consume_single(state, true)) == '\0') {
return -1; return -1;
@@ -318,21 +330,26 @@ lexer_nom(struct cescal_state *state, struct token *res)
return 0; return 0;
case '/': case '/':
if (lexer_consume_single(state, true) == '/') { if ((c = lexer_consume_single(state, true)) == '/') {
res->type = TT_COMMENT; res->type = TT_COMMENT;
res->c = c; res->c = c;
lexer_skip_comment(state); lexer_skip_comment(state);
return 0; return 0;
} }
return -1; lexer_putback(state, c);
res->type = TT_SLASH;
return 0;
case '-': case '-':
res->c = c; res->c = c;
if (lexer_consume_single(state, true) == '>') { if ((c = lexer_consume_single(state, true)) == '>') {
res->type = TT_ARROW; res->type = TT_ARROW;
return 0; return 0;
} }
return -1;
lexer_putback(state, c);
res->type = TT_MINUS;
return 0;
default: default:
if (lexer_scan_ident(state, c, res) == 0) { if (lexer_scan_ident(state, c, res) == 0) {
lexer_check_kw(state, res); lexer_check_kw(state, res);
+5
View File
@@ -39,6 +39,11 @@ static const char *toktab[] = {
[TT_COMMA] = qtok(","), [TT_COMMA] = qtok(","),
[TT_COLON] = qtok(":"), [TT_COLON] = qtok(":"),
[TT_ARROW] = qtok("->"), [TT_ARROW] = qtok("->"),
[TT_PLUS] = qtok("+"),
[TT_MINUS] = qtok("-"),
[TT_SLASH] = qtok("/"),
[TT_STAR] = qtok("*"),
[TT_EQUALS] = qtok("="),
[TT_DEFINE] = qtok("#define"), [TT_DEFINE] = qtok("#define"),
[TT_IFNDEF] = qtok("#ifndef"), [TT_IFNDEF] = qtok("#ifndef"),
[TT_IFDEF] = qtok("#ifdef"), [TT_IFDEF] = qtok("#ifdef"),
+5
View File
@@ -19,6 +19,11 @@ typedef enum {
TT_COMMA, /* ',' */ TT_COMMA, /* ',' */
TT_COLON, /* ':' */ TT_COLON, /* ':' */
TT_ARROW, /* '->' */ TT_ARROW, /* '->' */
TT_PLUS, /* '+' */
TT_MINUS, /* '-' */
TT_SLASH, /* '/' */
TT_STAR, /* '*' */
TT_EQUALS, /* '=' */
TT_DEFINE, /* '#define' */ TT_DEFINE, /* '#define' */
TT_IFNDEF, /* '#ifndef' */ TT_IFNDEF, /* '#ifndef' */
TT_IFDEF, /* '#ifdef' */ TT_IFDEF, /* '#ifdef' */