summaryrefslogtreecommitdiff
path: root/src/lexer.c
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-02-13 17:32:00 -0500
committerLLLL Colonq <llll@colonq>2026-02-13 17:32:00 -0500
commit2b47c650a161fe2c2c4c7f4d74a19c2c6fe6021e (patch)
tree357e6484f707faaafae41aa4a35bbb418c791bf1 /src/lexer.c
parente6329f2ce1df83fd729e79f7e92e55fe96a2e826 (diff)
Update
Diffstat (limited to 'src/lexer.c')
-rw-r--r--src/lexer.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/lexer.c b/src/lexer.c
index 019dcc5..623dd39 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -11,6 +11,8 @@ const char *PIT_LEX_TOKEN_NAMES[PIT_LEX_TOKEN__SENTINEL] = {
/* [PIT_LEX_TOKEN_EOF] = */ "eof",
/* [PIT_LEX_TOKEN_LPAREN] = */ "lparen",
/* [PIT_LEX_TOKEN_RPAREN] = */ "rparen",
+ /* [PIT_LEX_TOKEN_LSQUARE] = */ "lsquare",
+ /* [PIT_LEX_TOKEN_RSQUARE] = */ "rsquare",
/* [PIT_LEX_TOKEN_DOT] = */ "dot",
/* [PIT_LEX_TOKEN_QUOTE] = */ "quote",
/* [PIT_LEX_TOKEN_INTEGER_LITERAL] = */ "integer_literal",
@@ -30,6 +32,11 @@ static int is_symchar(int c) {
return c != '(' && c != ')' && c != '.' && c != '\'' && c != '"' && isprint(c) && !isspace(c);
}
+static int is_hexdigit(int c) {
+ return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
+}
+
+
static char peek(pit_lexer *st) {
if (is_more_input(st)) return st->input[st->end];
else return 0;
@@ -104,6 +111,8 @@ restart:
case ';': while (is_more_input(st) && advance(st) != '\n'); goto restart;
case '(': return PIT_LEX_TOKEN_LPAREN;
case ')': return PIT_LEX_TOKEN_RPAREN;
+ case '[': return PIT_LEX_TOKEN_LSQUARE;
+ case ']': return PIT_LEX_TOKEN_RSQUARE;
case '.': return PIT_LEX_TOKEN_DOT;
case '\'': return PIT_LEX_TOKEN_QUOTE;
case '"':
@@ -119,10 +128,14 @@ restart:
default:
if (isspace(c)) goto restart;
if (isdigit(c)) {
- while (match(st, isdigit)) {}
+ if (c == '0') {
+ int next = peek(st);
+ if (next != 'x' && next != 'o' && next != 'b') return PIT_LEX_TOKEN_INTEGER_LITERAL;
+ advance(st); /* skip base specifier */
+ }
+ while (match(st, is_hexdigit)) {}
return PIT_LEX_TOKEN_INTEGER_LITERAL;
- }
- else {
+ } else {
while (match(st, is_symchar)) {}
return PIT_LEX_TOKEN_SYMBOL;
}