diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-10 10:14:00 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2019-12-10 10:14:11 -0500 |
commit | e73b5a6cb8930d8fc46edd0112d1e292746b7ada (patch) | |
tree | c35cb9eeca665f409899d8e461d1b3e61f2b7a64 /tokenizer.c | |
parent | ef38e72c7c2ff1134f83772a8aaed98ef995ba01 (diff) |
changed Location to be smaller
Diffstat (limited to 'tokenizer.c')
-rw-r--r-- | tokenizer.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tokenizer.c b/tokenizer.c index 2841961..a4037ad 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -143,7 +143,10 @@ static char tokr_esc_seq(Tokenizer *t) { /* to be used during tokenization */ static void tokenization_err(Tokenizer *t, const char *fmt, ...) { va_list args; - Location where = {t->line, t->s, t->err_ctx}; + Location where; + where.line = t->line; + where.ctx = t->err_ctx; + where.pos = (CodePos)(t->s - where.ctx->str); va_start(args, fmt); err_vprint(where, fmt, args); va_end(args); @@ -181,13 +184,13 @@ static void tokr_err_( static void tokr_put_location(Tokenizer *tokr, Token *t) { t->where.line = tokr->line; - t->where.code = tokr->s; t->where.ctx = tokr->err_ctx; + t->where.pos = (CodePos)(tokr->s - t->where.ctx->str); } static void tokr_get_location(Tokenizer *tokr, Token *t) { tokr->line = t->where.line; - tokr->s = t->where.code; + tokr->s = t->where.pos + t->where.ctx->str; } /* @@ -270,7 +273,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { /* it's a directive */ Token *token = tokr_add(t); tokr_put_location(t, token); - token->where.code = start_s; + token->where.pos = (CodePos)(start_s - token->where.ctx->str); token->kind = TOKEN_DIRECT; token->direct = direct; continue; @@ -287,7 +290,7 @@ static bool tokenize_string(Tokenizer *t, char *str) { /* it's a keyword */ Token *token = tokr_add(t); tokr_put_location(t, token); - token->where.code = start_s; + token->where.pos = (CodePos)(start_s - token->where.ctx->str); token->kind = TOKEN_KW; token->kw = kw; continue; |