diff options
author | Himbeer <himbeer@disroot.org> | 2024-09-12 12:44:41 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-09-12 12:45:13 +0200 |
commit | 2b8b9bd1250bcde34e43bc2f3c2e583cdae84780 (patch) | |
tree | f4bff90d3d3d11a40de7b8a84593dd1f1789da5d /src | |
parent | 3642954f1715e43fa33f404315d18a8061c29050 (diff) |
Make identifiers / paths sequences of names delimited by ::
This is much easier to lex than separate token kinds.
Diffstat (limited to 'src')
-rw-r--r-- | src/lex.c | 16 | ||||
-rw-r--r-- | src/main.c | 3 |
2 files changed, 5 insertions, 14 deletions
@@ -146,27 +146,19 @@ search(const char *buf, int bound) } static enum lexical_token -lex_ident(struct lexer *lexer, struct token *out) +lex_name(struct lexer *lexer, struct token *out) { - bool isident = false; - uint32_t c; while ((c = next(lexer)) != C_EOF) { - if (c >= 0x7F || (!isalnum(c) && c != '/')) { + if (c >= 0x7F || !isalnum(c)) { unget(lexer); break; } - if (c == '/') { - isident = true; - } push(lexer, c); } void *token = search(lexer->buf, T_LAST_BUILTIN_TYPE); - if (!token && isident) { - out->token = T_IDENT; - out->info.str = strdup(lexer->buf); - } else if (!token) { + if (!token) { out->token = T_NAME; out->info.str = strdup(lexer->buf); } else { @@ -240,7 +232,7 @@ lex(struct lexer *lexer, struct token *out) if (c <= 0x7F && isalpha(c)) { push(lexer, c); - return lex_ident(lexer, out); + return lex_name(lexer, out); } if (c <= 0x7F && isdigit(c)) { @@ -43,8 +43,7 @@ main(int argc, char *argv[]) struct token token; while (lex(&lexer, &token) != T_EOF) { printf("%d", token.token); - if (token.token == T_IDENT || token.token == T_NAME - || token.token == T_STRING) { + if (token.token == T_NAME || token.token == T_STRING) { printf(" %s", token.info.str); } else if (token.token == T_NUMBER && token.info.num.isfloat) { |