diff options
author | David Phillips <david@sighup.nz> | 2018-08-01 20:21:37 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-08-01 20:29:38 +1200 |
commit | 328e34077a2017d4017f907ac69c7ed5d6c160d4 (patch) | |
tree | 1795fd0d10293320dae0854b5b1d34a59e8fdbec /lexer.c | |
parent | 70c76b708308c72956e83163b2819be69f725a7e (diff) | |
download | hence-328e34077a2017d4017f907ac69c7ed5d6c160d4.tar.xz |
Trim leading whitespace from contextual error, detect EOF
Side-note that the token location tuple maintains the correct column
number to include the whitespace in the source file. Side-side note:
tabs are counted as one column but many editors will count them as
whatever the tabstop/tabwidth is.
Diffstat (limited to 'lexer.c')
-rw-r--r-- | lexer.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -53,6 +53,7 @@ static char buf[BUFFER_SIZE]; static FILE* fd; static size_t line_number = 0; static size_t column_number = 0; +static size_t leading_whitespace_len = 0; static struct token *tok_start = NULL; static struct token *tok_cursor = NULL; @@ -64,6 +65,7 @@ get_current_loc(void) { struct location l; l.line = line_number; l.column = column_number + 1; + l.leading_whitespace_len = leading_whitespace_len; return l; } @@ -187,6 +189,8 @@ lex_colon(void) { static int lex_line(void) { size_t length = strlen(buf); + leading_whitespace_len = 0; + while (column_number < length && column_number < strlen(buf)) { switch (buf[column_number]) { case ':': @@ -195,6 +199,9 @@ lex_line(void) { case ' ': case '\t': eat_whitespace(); + if (leading_whitespace_len == 0) { + leading_whitespace_len = column_number; + } break; case '\r': case '\n': |