From c040191336b755321af667a0251b97782d8eed71 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 8 Jun 2019 14:26:15 +1000 Subject: [PATCH] scanner: fix at_son() Current test for "at start of node" is broken for 2 reasons. 1/ it doesn't account for the node-indent chars that are stripped off by do_strip() 2/ it check the ->offset *after* a character has been extracted, it needs to check the offset from before, which is in ->prev_offset Signed-off-by: NeilBrown --- csrc/scanner.mdc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/csrc/scanner.mdc b/csrc/scanner.mdc index 84eaf4a..fa27a89 100644 --- a/csrc/scanner.mdc +++ b/csrc/scanner.mdc @@ -934,6 +934,7 @@ a flag that tells us whether or not we need to strip. int offset; int line; int col; + int strip_offset; ###### internal functions @@ -973,6 +974,7 @@ a flag that tells us whether or not we need to strip. return WEOF; state->line = state->node->line_no; state->col = do_strip(state); + state->strip_offset = state->offset; } ## before get_char @@ -1126,7 +1128,7 @@ differently there. static int at_son(struct token_state *state) { - return state->offset == 0; + return state->prev_offset <= state->strip_offset; } static int at_eon(struct token_state *state) @@ -1210,6 +1212,7 @@ As well as getting tokens, we need to be able to create the state->node = code; state->line = code->line_no; state->col = do_strip(state); + state->strip_offset = state->offset; state->conf = conf; return state; } -- 2.43.0