X-Git-Url: https://ocean-lang.org/code/?a=blobdiff_plain;f=csrc%2Fparsergen.mdc;h=c167e0967cddac00f2fe937027ff3165b45f37bd;hb=23eff3db9345ded5920fba114c0b411466c7cbf9;hp=679fab6996de66a9fe267d914c654812f74771f3;hpb=f24b54a97b9955aa5761b22aa64d5418e23e80f2;p=ocean diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 679fab6..c167e09 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -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; @@ -1332,11 +1334,11 @@ into the go to set, so the item is ineffective. continue; if (symset_find(&done, s->num) < 0) { symset_add(&done, s->num, 0); - if (s->line_like) - is->starts_line = 1; } if (s->type != Nonterminal) continue; + if (s->line_like) + is->starts_line = 1; again = 1; if (type >= LALR) { // Need the LA set. @@ -1651,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"); } @@ -2867,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; @@ -3021,7 +3029,7 @@ end inside square brackets. fputs(reserved_words[tk->num], trace); else text_dump(trace, tk->txt, 20); - fputs("]", trace); + fprintf(trace, ":%d:%d]", tk->line, tk->col); } void parser_trace_action(FILE *trace, char *action)