]> ocean-lang.org Git - ocean/commitdiff
scanner: fix at_son()
authorNeilBrown <neil@brown.name>
Sat, 8 Jun 2019 04:26:15 +0000 (14:26 +1000)
committerNeilBrown <neil@brown.name>
Sat, 8 Jun 2019 04:26:15 +0000 (14:26 +1000)
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 <neil@brown.name>
csrc/scanner.mdc

index 84eaf4af60f427d7f7f90adc7753833b786894b1..fa27a89524a85d4eeb9a16019558e61a993afb5f 100644 (file)
@@ -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;
        }