]> ocean-lang.org Git - ocean/commitdiff
parsergen: don't bother with indent_depth
authorNeilBrown <neil@brown.name>
Wed, 10 Mar 2021 04:26:59 +0000 (15:26 +1100)
committerNeilBrown <neil@brown.name>
Wed, 10 Mar 2021 04:31:49 +0000 (15:31 +1100)
We don't need to store the indent_depth if we just shift the bit-stack
up and down.  <<1 pushes a zero, >>1 pops, |=1 changes the zero to one.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/parsergen.mdc

index 0bef7934d3ec112b77eff4ecd4a007240ff92f34..356edef02ef96a4fcc1f1704a8740005dd7acc25 100644 (file)
@@ -2643,10 +2643,9 @@ to mark the beginning of the file as well as the end.
 
 Indents (IN) are sometimes shifted and sometimes only accounted.
 Whatever decision is made must apply equally to the matching OUT.  To
-ensure this we keep a stack of bits in `ignored_indents` and
-`indent_depth`.  When we process an IN, we record if it was ignored.
-When we see an out, we pop of the relavant bit and use it to decide how
-to handle the OUT.
+ensure this we keep a stack of bits in `ignored_indents`.  When we
+process an IN, we record if it was ignored.  When we see an out, we pop
+of the relavant bit and use it to decide how to handle the OUT.
 
 ###### parser functions
 
@@ -2801,7 +2800,6 @@ need a small stack of flags, which is easily stored as bits in an
 
 ###### parser state
        unsigned long ignored_indents;
-       int indent_depth;
 
 NEWLINE/EOL is ignored when in an indented section of text which was not
 explicitly expected by the grammar.  So if the most recent indent is
@@ -2813,10 +2811,10 @@ we try to reduce a production.
 ###### try shift or ignore
 
        if ((tk->num == TK_newline || tk->num == TK_out) &&
-           (p.ignored_indents & (1 << p.indent_depth))) {
+           (p.ignored_indents & 1)) {
                /* indented, so ignore OUT and NEWLINE */
                if (tk->num == TK_out)
-                       p.indent_depth -= 1;
+                       p.ignored_indents >>= 1;
                free(tk);
                tk = NULL;
                parser_trace_action(trace, "Ignore");
@@ -2826,11 +2824,10 @@ we try to reduce a production.
        switch (shift(&p, tk->num, tk, states)) {
        case 1:
                if (tk->num == TK_out)
-                       p.indent_depth -= 1;
-               if (tk->num == TK_in) {
-                       p.indent_depth += 1;
-                       p.ignored_indents &= ~(1 << p.indent_depth);
-               }
+                       p.ignored_indents >>= 1;
+               if (tk->num == TK_in)
+                       p.ignored_indents <<= 1;
+
                tk = NULL;
                /* fallthrough */
        case 2:
@@ -2843,8 +2840,8 @@ we try to reduce a production.
                /* No indent expected here, so ignore IN */
                free(tk);
                tk = NULL;
-               p.indent_depth += 1;
-               p.ignored_indents |= (1 << p.indent_depth);
+               p.ignored_indents <<= 1;
+               p.ignored_indents |= 1;
                parser_trace_action(trace, "Ignore");
                continue;
        }