lexer: Handle differentation between zero and prefix

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-02-16 14:20:23 -05:00
parent 68e7f41181
commit 0a8a7cddd0

View File

@@ -26,6 +26,22 @@ lexer_is_ws(char c)
return false;
}
/*
* Returns true if the given character is apart of a numbering
* system prefix (e.g., '0x' or 'o0')
*/
static inline bool
lexer_is_num_prefix(char c)
{
switch (c) {
case 'o':
case 'x':
return true;
}
return false;
}
/*
* Place a given character into the putback buffer
*
@@ -355,8 +371,8 @@ lexer_scan_num(struct rifle_state *state, int lc, struct token *tok)
if (lc == '0') {
if ((prefix = lexer_nom(state, false)) == '\0')
return -1;
if ((lc = lexer_nom(state, false)) == '\0')
return -1;
if (!lexer_is_num_prefix(prefix))
lexer_putback(state, prefix);
}
/*
@@ -367,9 +383,15 @@ lexer_scan_num(struct rifle_state *state, int lc, struct token *tok)
*/
switch (prefix) {
case 'x':
if ((lc = lexer_nom(state, false)) == '\0')
return -1;
radix = 16;
break;
case 'o':
if ((lc = lexer_nom(state, false)) == '\0')
return -1;
radix = 8;
break;
default: