diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-10-27 20:39:29 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-10-27 20:39:29 -0400 |
commit | 33c3e2121e185e619cd993280b23038b4490f4f5 (patch) | |
tree | 5201b24d31efd92d9985ab667f90a7cc1cf37d54 | |
parent | f6ce73bd76ee9b07bb13a6df9a5663a38ccf4013 (diff) | |
download | dimension-33c3e2121e185e619cd993280b23038b4490f4f5.tar.xz |
Add line and column numbers to tokens.
-rw-r--r-- | dimension/tokenize.c | 8 | ||||
-rw-r--r-- | dimension/tokenize.h | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/dimension/tokenize.c b/dimension/tokenize.c index c34cfc6..1d53f2f 100644 --- a/dimension/tokenize.c +++ b/dimension/tokenize.c @@ -56,8 +56,10 @@ dmnsn_tokenize(FILE *file) unsigned int i; while (next - map < size) { - /* Saves us some code repetition in the vast majority of cases */ + /* Saves us some code repetition */ token.value = NULL; + token.line = line; + token.col = col; switch (*next) { case ' ': @@ -121,12 +123,16 @@ dmnsn_tokenize(FILE *file) token.value = malloc(endf - next + 1); strncpy(token.value, next, endf - next); token.value[endf - next] = '\0'; + + col += endf - next; next = endf; } else if (endi > next) { token.type = DMNSN_INT; token.value = malloc(endi - next + 1); strncpy(token.value, next, endi - next); token.value[endi - next] = '\0'; + + col += endi - next; next = endi; } else { fprintf(stderr, "Invalid numeric value on line %u, column %u.\n", diff --git a/dimension/tokenize.h b/dimension/tokenize.h index 91d59f6..938eb5f 100644 --- a/dimension/tokenize.h +++ b/dimension/tokenize.h @@ -45,6 +45,9 @@ typedef struct dmnsn_token dmnsn_token; struct dmnsn_token { dmnsn_token_type type; char *value; + + /* Line and column numbers from source code */ + unsigned int line, col; }; dmnsn_array *dmnsn_tokenize(FILE *file); |