aboutsummaryrefslogtreecommitdiff
path: root/src/tokenizer.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-02-25 15:09:16 +0000
committergingerBill <bill@gingerbill.org>2018-02-25 15:09:16 +0000
commitd247ba4751d8189082849e114e3d4a6106b0d053 (patch)
tree56e023cb3006392918e2074b1d1489b06f59f4dd /src/tokenizer.cpp
parent27b7dc336ab7c108d711d6ce00686467f1f0319c (diff)
Hexadecimal floats for "perfect values" 0h42f60000 == 123; use `bit_cast` in compiler
Diffstat (limited to 'src/tokenizer.cpp')
-rw-r--r--src/tokenizer.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp
index 0caa748c3..70f52ab8f 100644
--- a/src/tokenizer.cpp
+++ b/src/tokenizer.cpp
@@ -254,7 +254,7 @@ void syntax_error_va(Token token, char *fmt, va_list va) {
LIT(token.pos.file), token.pos.line, token.pos.column,
gb_bprintf_va(fmt, va));
} else if (token.pos.line == 0) {
- gb_printf_err("Error: %s\n", gb_bprintf_va(fmt, va));
+ gb_printf_err("Syntax Error: %s\n", gb_bprintf_va(fmt, va));
}
gb_mutex_unlock(&global_error_collector.mutex);
@@ -401,15 +401,15 @@ void tokenizer_err(Tokenizer *t, char *msg, ...) {
if (column < 1) {
column = 1;
}
-
- gb_printf_err("%.*s(%td:%td) Syntax error: ", LIT(t->fullpath), t->line_count, column);
+ Token token = {};
+ token.pos.file = t->fullpath;
+ token.pos.line = t->line_count;
+ token.pos.column = column;
va_start(va, msg);
- gb_printf_err_va(msg, va);
+ syntax_error_va(token, msg, va);
va_end(va);
- gb_printf_err("\n");
-
t->error_count++;
}
@@ -577,14 +577,32 @@ Token scan_number_to_token(Tokenizer *t, bool seen_decimal_point) {
if (t->curr - prev <= 2) {
token.kind = Token_Invalid;
}
- } /* else if (t->curr_rune == 'h') { // Hexadecimal Float
+ } else if (t->curr_rune == 'h') { // Hexadecimal Float
token.kind = Token_Float;
advance_to_next_rune(t);
scan_mantissa(t, 16);
if (t->curr - prev <= 2) {
token.kind = Token_Invalid;
+ } else {
+ u8 *start = prev+2;
+ isize n = t->curr - start;
+ isize digit_count = 0;
+ for (isize i = 0; i < n; i++) {
+ if (start[i] != '_') {
+ digit_count += 1;
+ }
+ }
+ switch (digit_count) {
+ case 8:
+ case 16:
+ break;
+ default:
+ tokenizer_err(t, "Invalid hexadecimal float, expected 8 or 16 digits, got %td", digit_count);
+ break;
+ }
}
- } */ else {
+
+ } else {
seen_decimal_point = false;
scan_mantissa(t, 10);