summaryrefslogtreecommitdiff
path: root/pit/src/lexer.c
diff options
context:
space:
mode:
Diffstat (limited to 'pit/src/lexer.c')
-rw-r--r--pit/src/lexer.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/pit/src/lexer.c b/pit/src/lexer.c
index def4084..ba4c3d6 100644
--- a/pit/src/lexer.c
+++ b/pit/src/lexer.c
@@ -11,6 +11,7 @@ const char *PIT_LEX_TOKEN_NAMES[PIT_LEX_TOKEN__SENTINEL] = {
/* [PIT_LEX_TOKEN_DOT] = */ "dot",
/* [PIT_LEX_TOKEN_QUOTE] = */ "quote",
/* [PIT_LEX_TOKEN_INTEGER_LITERAL] = */ "integer_literal",
+ /* [PIT_LEX_TOKEN_DOUBLE_LITERAL] = */ "double_literal",
/* [PIT_LEX_TOKEN_STRING_LITERAL] = */ "string_literal",
/* [PIT_LEX_TOKEN_SYMBOL] = */ "symbol",
};
@@ -24,7 +25,7 @@ static bool is_more_input(pit_lexer *st) {
}
static int is_symchar(int c) {
- return c != '(' && c != ')' && c != '[' && c != ']' && c != '.' && c != '\'' && c != '"'
+ return c != '(' && c != ')' && c != '[' && c != ']' && c != '\'' && c != '"'
&& pit_libc_ctype_isprint(c)
&& !pit_libc_ctype_isspace(c);
}
@@ -69,6 +70,8 @@ void pit_lex_bytes(pit_lexer *ret, char *buf, i64 len) {
ret->error = NULL;
}
+#include <stdio.h>
+
pit_lex_token pit_lex_next(pit_lexer *st) {
restart:
st->start = st->end;
@@ -99,6 +102,7 @@ restart:
pit_lex_token ret = PIT_LEX_TOKEN_INTEGER_LITERAL;
int num_idx = 0;
bool hex = false;
+ bool binary_or_octal = false;
bool leading_dash = false;
bool zero_prefix = false;
if (!is_symchar(c)) {
@@ -115,11 +119,14 @@ restart:
case 1:
if (zero_prefix) {
if (c == 'x') { hex = true; continue; }
- else if (c == 'o' || c == 'b') continue;
+ else if (c == 'o' || c == 'b') { binary_or_octal = true; continue; }
}
break;
}
- if (!(pit_libc_ctype_isdigit(c) || (hex && is_hexdigit(c)))) ret = PIT_LEX_TOKEN_SYMBOL;
+ if (!hex && !binary_or_octal && c == '.' && ret != PIT_LEX_TOKEN_DOUBLE_LITERAL)
+ ret = PIT_LEX_TOKEN_DOUBLE_LITERAL;
+ else if (!(pit_libc_ctype_isdigit(c) || (hex && is_hexdigit(c))))
+ ret = PIT_LEX_TOKEN_SYMBOL;
++num_idx;
} while (c = peek(st), match(st, is_symchar));
}