From: NeilBrown Date: Sun, 18 Feb 2018 05:10:59 +0000 (+1100) Subject: scanner: fix calculation of column. X-Git-Tag: StoneyCreek~11 X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=69b32e1af53f61ab687421cc8316f4b90d40dc38 scanner: fix calculation of column. When we stripe the expected indent from the start of each line, we need to update 'col' to correctly account for tabs. Previous code effectively assumed tabs were 4 spaces. Signed-off-by: NeilBrown --- diff --git a/csrc/scanner.mdc b/csrc/scanner.mdc index 4d92241..a5eeb1f 100644 --- a/csrc/scanner.mdc +++ b/csrc/scanner.mdc @@ -901,19 +901,23 @@ a flag that tells us whether or not we need to strip. ###### internal functions - static void do_strip(struct token_state *state) + static int do_strip(struct token_state *state) { + int indent = 0; if (state->node->needs_strip) { int n = 4; while (n && state->node->code.txt[state->offset] == ' ') { + indent += 1; state->offset += 1; n -= 1; } while (n == 4 && state->node->code.txt[state->offset] == '\t') { + indent = indent_tab(indent); state->offset += 1; n -= 4; } } + return indent; } static wint_t get_char(struct token_state *state) @@ -931,9 +935,8 @@ a flag that tells us whether or not we need to strip. state->offset = 0; if (state->node == NULL) return WEOF; - do_strip(state); state->line = state->node->line_no; - state->col = state->node->indent; + state->col = do_strip(state); } ## before get_char @@ -958,8 +961,7 @@ a flag that tells us whether or not we need to strip. state->col += 1; } else if (is_newline(next)) { state->line += 1; - state->col = state->node->indent; - do_strip(state); + state->col = do_strip(state); } else if (next == '\t') { state->col = indent_tab(state->col); } @@ -1169,9 +1171,8 @@ As well as getting tokens, we need to be able to create the memset(state, 0, sizeof(*state)); state->node = code; state->line = code->line_no; - state->col = code->indent; + state->col = do_strip(state); state->conf = conf; - do_strip(state); return state; } void token_close(struct token_state *state)