]> ocean-lang.org Git - ocean/blobdiff - csrc/parsergen.mdc
parsergen: allow $$OUT to be satisfied are start-of-line.
[ocean] / csrc / parsergen.mdc
index 2546d7632722a0673d4c78c83f6d924310390379..df73f513ceec725931af6c78832d234a0913e45a 100644 (file)
@@ -499,6 +499,8 @@ Now we have all the bits we need to parse a full production.
                        vs = sym_find(g, tk.txt);
                        if (vs->num == TK_newline)
                                p.line_like = 1;
+                       else if (vs->num == TK_out)
+                               p.line_like = 2;
                        else if (vs->precedence == 0) {
                                err = "symbol after $$ must have precedence";
                                goto abort;
@@ -1348,7 +1350,8 @@ into the go to set, so the item is ineffective.
                        }
                        sn = save_set(g, LA);
                        LA = set_find(g, sn);
-                       symset_add(&LAnl, TK_newline, 0);
+                       if (symset_find(&LA, TK_newline))
+                               symset_add(&LAnl, TK_newline, 0);
                        snnl = save_set(g, LAnl);
                        LAnl = set_find(g, snnl);
                }
@@ -1650,8 +1653,10 @@ it up a bit.  First the items, with production number and associativity.
                        printf(" [%d%s]", s->precedence,
                               assoc_names[s->assoc]);
                }
-               if (pr->line_like)
+               if (pr->line_like == 1)
                        printf(" $$NEWLINE");
+               else if (pr->line_like)
+                       printf(" $$OUT");
                printf("\n");
        }
 
@@ -2866,9 +2871,13 @@ checks if a given token is in any of these look-ahead sets.
                force_reduce:
                        if (states[tos->state].reduce_prod >= 0 &&
                            states[tos->state].newline_only &&
-                           tk->num != TK_newline && tk->num != TK_eof && tk->num != TK_out) {
-                               /* Anything other than newline in an error as this
-                                * production must end at EOL
+                           !(tk->num == TK_newline ||
+                             tk->num == TK_eof ||
+                             tk->num == TK_out ||
+                             (tos->indents == 0 && tos->since_newline == 0))) {
+                               /* Anything other than newline or out or eof
+                                * in an error unless we are already at start
+                                * of line, as this production must end at EOL.
                                 */
                        } else if (states[tos->state].reduce_prod >= 0) {
                                void **body;