From: NeilBrown Date: Wed, 10 Mar 2021 04:26:59 +0000 (+1100) Subject: parsergen: don't bother with indent_depth X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=42d68f83351fb7cc2974e4ef126af258e63cea0f parsergen: don't bother with indent_depth 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 --- diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 0bef793..356edef 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -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; }