Skip to content

Commit 891ee3b

Browse files
committed
c2cat: improve output consistency
* output tokens with the original spelling * use Style enum and dispatch on token kind * add `--color` and `--nocolor` to force/disable color output * show syntax errors
1 parent 4eac1b2 commit 891ee3b

File tree

2 files changed

+219
-212
lines changed

2 files changed

+219
-212
lines changed

parser/c2_tokenizer.c2

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,7 @@ fn void Tokenizer.num_error(Tokenizer* t, Token* result, const char* p, const ch
694694
vsnprintf(t.error_msg, sizeof(t.error_msg), format, args);
695695
va_end(args);
696696

697-
// XXX: error position should be passed separately from token start
698-
result.loc = t.loc_start + (SrcLoc)(p - t.input_start);
697+
SrcLoc err_loc = t.loc_start + (SrcLoc)(p - t.input_start);
699698
// read the rest of the pp-number token
700699
for (;;) {
701700
if ((*p == 'e' || *p == 'E' || *p == 'p' || *p == 'P') && (p[1] == '+' || p[1] == '-')) {
@@ -712,7 +711,7 @@ fn void Tokenizer.num_error(Tokenizer* t, Token* result, const char* p, const ch
712711
}
713712
t.cur = p;
714713
result.len = (u16)((p - t.input_start) - (result.loc - t.loc_start));
715-
if (t.on_warning) t.on_warning(t.fn_arg, result.loc);
714+
if (t.on_warning) t.on_warning(t.fn_arg, err_loc);
716715
}
717716

718717
fn void Tokenizer.lex_identifier(Tokenizer* t, Token* result) {

0 commit comments

Comments
 (0)