From ec7354ca1c217ce6d9532bc49edd9d1d625e2321 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Mon, 27 Jul 2026 16:00:33 +0200 Subject: [PATCH] bugfixe in td_epsilon and better pretty printing --- src/runtime/c/pgf/parser.cxx | 46 ++++++++++++++++++------------------ src/runtime/c/pgf/parser.h | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/runtime/c/pgf/parser.cxx b/src/runtime/c/pgf/parser.cxx index 05533ad69..1a5586e6f 100644 --- a/src/runtime/c/pgf/parser.cxx +++ b/src/runtime/c/pgf/parser.cxx @@ -2,8 +2,8 @@ #include "printer.h" #include "parser.h" -#define DEBUG_PARSER -#define DEBUG_EXPRS +//#define DEBUG_PARSER +//#define DEBUG_EXPRS PgfAbstractParser::PgfAbstractParser(ref concr) { @@ -535,20 +535,16 @@ void PgfAbstractParser::td_epsilon(State *state, Cont *cont, ref pitem, arg_ccat->covered = true; } item->args[i] = arg_ccat; + } -/* if (!item->instantiate(item->rule->args[i], pitem->args[i]->value)) { - delete item; - goto next; - }*/ - } else { - /*if (!item->instantiate(item->rule->args[i], pitem->args[i]->value)) { - delete item; - continue; - }*/ + if (!item->instantiate(item->rule->args[i], pitem->rule, &pitem->vars[0], pitem->rule->args[i])) { + delete item; + goto next; } } process(item, state->start, false); +next:; } } default:; @@ -652,12 +648,12 @@ void PgfAbstractParser::print_item(Item *item, const PgfTextSpot &spot) if (item->cont) { if (item->cont->ccat == NULL) { printer.efun(&item->cont->lincat->name); - printer.puts("("); - printer.lparam(item->rule->res); - printer.puts(")"); } else { printer.emeta(item->cont->ccat->fid); } + printer.puts("("); + printer.lparam(item->rule->res); + printer.puts(")"); } printer.puts(" -> "); @@ -674,12 +670,12 @@ void PgfAbstractParser::print_item(Item *item, const PgfTextSpot &spot) CCat *ccat = item->args[i]; if (ccat == NULL) { printer.efun(&lin->absfun->type->hypos[i].type->name); - printer.puts("("); - printer.lparam(item->rule->args[i]); - printer.puts(")"); } else { printer.emeta(ccat->fid); } + printer.puts("("); + printer.lparam(item->rule->args[i]); + printer.puts(")"); } printer.puts("]; "); break; @@ -724,6 +720,10 @@ void PgfAbstractParser::print_prod(CCat *ccat, Production *prod) } printer.emeta(ccat->fid); + printer.puts("("); + printer.lparam(prod->rule->res); + printer.puts(")"); + printer.puts(" -> "); switch (ref::get_tag(prod->rule->container)) { @@ -739,12 +739,12 @@ void PgfAbstractParser::print_prod(CCat *ccat, Production *prod) CCat *ccat = prod->args[i]; if (ccat == NULL) { printer.efun(&lin->absfun->type->hypos[i].type->name); - printer.puts("("); - printer.lparam(prod->rule->args[i]); - printer.puts(")"); } else { printer.emeta(ccat->fid); } + printer.puts("("); + printer.lparam(prod->rule->args[i]); + printer.puts(")"); } printer.puts("]"); break; @@ -1368,7 +1368,7 @@ void PgfParser::print_expr_state_left(PgfPrinter *printer, PgfMarshaller *m, Exp printer->puts("::"); } -void PgfParser::print_expr_state_right(PgfPrinter *printer, PgfMarshaller *m, ExprState *estate) +void PgfParser::print_expr_state_right(PgfPrinter *printer, ExprState *estate) { for (size_t i = estate->index+1; i < estate->n_args; i++) { printer->puts(" "); @@ -1381,7 +1381,7 @@ void PgfParser::print_expr_state_right(PgfPrinter *printer, PgfMarshaller *m, Ex if (estate->res && estate->res->pending.size() > 0) { printer->puts(")"); ExprState *parent = estate->res->pending[0]; - print_expr_state_right(printer, m, parent); + print_expr_state_right(printer, parent); } } @@ -1391,7 +1391,7 @@ void PgfParser::print_expr_state(PgfMarshaller *m, ExprState *estate) printer.nprintf(64,"[%f] ",estate->prob); print_expr_state_left(&printer, m, estate); printer.puts(" ."); - print_expr_state_right(&printer, m, estate); + print_expr_state_right(&printer, estate); PgfText *text = printer.get_text(); fprintf(stderr, "%s\n", text->text); diff --git a/src/runtime/c/pgf/parser.h b/src/runtime/c/pgf/parser.h index 5033a5298..35a799682 100644 --- a/src/runtime/c/pgf/parser.h +++ b/src/runtime/c/pgf/parser.h @@ -261,7 +261,7 @@ class PGF_INTERNAL_DECL PgfParser : private PgfAbstractParser, public PgfExprEnu static void print_expr_state_left(PgfPrinter *printer, PgfMarshaller *m, ExprState *estate); static - void print_expr_state_right(PgfPrinter *printer, PgfMarshaller *m, ExprState *estate); + void print_expr_state_right(PgfPrinter *printer, ExprState *estate); static void print_expr_state(PgfMarshaller *m, ExprState *estate);