]> ocean-lang.org Git - ocean/commitdiff
parsegen: fix up look-ahead for $$NEWLINE items.
authorNeilBrown <neil@brown.name>
Sun, 16 Jun 2019 01:31:54 +0000 (11:31 +1000)
committerNeilBrown <neil@brown.name>
Sun, 16 Jun 2019 02:06:01 +0000 (12:06 +1000)
I was discarding all non-newlines from the lookahead
in the wrong place.
I need to do it based on the productions added, not
the item the are generated by.

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

index 478186ae19d81f0eadea542c19166c4a1794aacf..af7768dd1d763638d5142987c895d108d2a9f0a1 100644 (file)
@@ -3557,7 +3557,7 @@ defined.
        case Xcond_statement: free_cond_statement(cast(cond_statement, e)); break;
 
 ###### ComplexStatement Grammar
-       | CondStatement $$NEWLINE ${ $0 = $<1; }$
+       | CondStatement ${ $0 = $<1; }$
 
 ###### Grammar
 
@@ -3585,9 +3585,11 @@ defined.
                        $0->condpart = $1.condpart; $1.condpart = NULL;
                        $0->dopart = $1.dopart; $1.dopart = NULL;
                        }$
-               | SwitchPart CondSuffix ${
-                       $0 = $<2;
+               | SwitchPart CasePart CondSuffix ${
+                       $0 = $<3;
                        $0->condpart = $<1;
+                       $2->next = $0->casepart;
+                       $0->casepart = $<2;
                        }$
                | IfPart IfSuffix ${
                        $0 = $<2;
index 04974c3c6a7d749908ba3e672179e253082fca4e..1981c901ac013afe1a2ab932dbc2d8742666b964 100644 (file)
@@ -1309,6 +1309,8 @@ into the go to set, so the item is ineffective.
                struct symbol *s;
                struct symset LA = INIT_SYMSET;
                unsigned short sn = 0;
+               struct symset LAnl = INIT_SYMSET;
+               unsigned short snnl = 0;
 
                if (is->min_prefix == 0 ||
                    (bs > 0 && bs < is->min_prefix))
@@ -1341,15 +1343,14 @@ into the go to set, so the item is ineffective.
                        int to_end;
                        add_first(pr, bs+1, &LA, g, &to_end);
                        if (to_end) {
-                               if (pr->line_like)
-                                       symset_add(&LA, TK_newline, 0);
-                               else {
-                                       struct symset ss = set_find(g, is->items.data[i]);
-                                       symset_union(&LA, &ss);
-                               }
+                               struct symset ss = set_find(g, is->items.data[i]);
+                               symset_union(&LA, &ss);
                        }
                        sn = save_set(g, LA);
                        LA = set_find(g, sn);
+                       symset_add(&LAnl, TK_newline, 0);
+                       snnl = save_set(g, LAnl);
+                       LAnl = set_find(g, snnl);
                }
 
                /* Add productions for this symbol */
@@ -1360,19 +1361,25 @@ into the go to set, so the item is ineffective.
                        int itm = item_num(p2, 0);
                        int pos = symset_find(&is->items, itm);
                        if (pos < 0) {
-                               symset_add(&is->items, itm, sn);
+                               if (g->productions[p2]->line_like)
+                                       symset_add(&is->items, itm, snnl);
+                               else
+                                       symset_add(&is->items, itm, sn);
                                /* Will have re-ordered, so start
                                 * from beginning again */
                                i = -1;
                        } else if (type >= LALR) {
                                struct symset ss = set_find(g, is->items.data[pos]);
                                struct symset tmp = INIT_SYMSET;
+                               struct symset *la = &LA;
 
+                               if (g->productions[p2]->line_like)
+                                       la = &LAnl;
                                symset_union(&tmp, &ss);
-                               if (symset_union(&tmp, &LA)) {
+                               if (symset_union(&tmp, la)) {
                                        is->items.data[pos] = save_set(g, tmp);
                                        i = -1;
-                               }else
+                               } else
                                        symset_free(tmp);
                        }
                }