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 <neil@brown.name>
###### internal functions
###### internal functions
- static void do_strip(struct token_state *state)
+ static int do_strip(struct token_state *state)
if (state->node->needs_strip) {
int n = 4;
while (n && state->node->code.txt[state->offset] == ' ') {
if (state->node->needs_strip) {
int n = 4;
while (n && state->node->code.txt[state->offset] == ' ') {
state->offset += 1;
n -= 1;
}
while (n == 4 && state->node->code.txt[state->offset] == '\t') {
state->offset += 1;
n -= 1;
}
while (n == 4 && state->node->code.txt[state->offset] == '\t') {
+ indent = indent_tab(indent);
state->offset += 1;
n -= 4;
}
}
state->offset += 1;
n -= 4;
}
}
}
static wint_t get_char(struct token_state *state)
}
static wint_t get_char(struct token_state *state)
state->offset = 0;
if (state->node == NULL)
return WEOF;
state->offset = 0;
if (state->node == NULL)
return WEOF;
state->line = state->node->line_no;
state->line = state->node->line_no;
- state->col = state->node->indent;
+ state->col = do_strip(state);
state->col += 1;
} else if (is_newline(next)) {
state->line += 1;
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);
}
} else if (next == '\t') {
state->col = indent_tab(state->col);
}
memset(state, 0, sizeof(*state));
state->node = code;
state->line = code->line_no;
memset(state, 0, sizeof(*state));
state->node = code;
state->line = code->line_no;
- state->col = code->indent;
+ state->col = do_strip(state);
return state;
}
void token_close(struct token_state *state)
return state;
}
void token_close(struct token_state *state)