]> ocean-lang.org Git - ocean/blobdiff - csrc/scanner.mdc
scanner: fix calculation of column.
[ocean] / csrc / scanner.mdc
index 4d922415018e67a2f9aa87dba9a0f28b60fb6485..a5eeb1f128b5163b1715b263a033a3a64265c73a 100644 (file)
@@ -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)