mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
fix a rather intricate bug where coercions in the PMCFG grammar didn't interact properly with the lazy parser
This commit is contained in:
@@ -429,7 +429,10 @@ pgf_print_expr_state(PgfExprState* st,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gu_puts(" (", out, err);
|
gu_puts(" (", out, err);
|
||||||
pgf_print_expr(st->ep.expr, NULL, 0, out, err);
|
if (gu_variant_is_null(st->ep.expr))
|
||||||
|
gu_puts("_", out, err);
|
||||||
|
else
|
||||||
|
pgf_print_expr(st->ep.expr, NULL, 0, out, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -458,7 +461,11 @@ pgf_print_expr_state0(PgfExprState* st,
|
|||||||
gu_puts(" (", out, err);
|
gu_puts(" (", out, err);
|
||||||
else
|
else
|
||||||
gu_puts(" ", out, err);
|
gu_puts(" ", out, err);
|
||||||
pgf_print_expr(st->ep.expr, NULL, 0, out, err);
|
|
||||||
|
if (gu_variant_is_null(st->ep.expr))
|
||||||
|
gu_puts("_", out, err);
|
||||||
|
else
|
||||||
|
pgf_print_expr(st->ep.expr, NULL, 0, out, err);
|
||||||
|
|
||||||
size_t n_counts = gu_buf_length(stack);
|
size_t n_counts = gu_buf_length(stack);
|
||||||
for (size_t i = 0; i < n_counts; i++) {
|
for (size_t i = 0; i < n_counts; i++) {
|
||||||
@@ -1712,7 +1719,7 @@ static GuOrder
|
|||||||
pgf_expr_state_order = { cmp_expr_state };
|
pgf_expr_state_order = { cmp_expr_state };
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgf_result_production(PgfParsing* ps,
|
pgf_result_production(PgfParsing* ps,
|
||||||
PgfAnswers* answers, PgfProduction prod)
|
PgfAnswers* answers, PgfProduction prod)
|
||||||
{
|
{
|
||||||
GuVariantInfo pi = gu_variant_open(prod);
|
GuVariantInfo pi = gu_variant_open(prod);
|
||||||
@@ -1739,11 +1746,15 @@ pgf_result_production(PgfParsing* ps,
|
|||||||
PgfProductionCoerce* pcoerce = pi.data;
|
PgfProductionCoerce* pcoerce = pi.data;
|
||||||
|
|
||||||
PgfCCat* ccat = pcoerce->coerce;
|
PgfCCat* ccat = pcoerce->coerce;
|
||||||
for (size_t i = 0; i < ccat->n_synprods; i++) {
|
|
||||||
PgfProduction prod =
|
PgfExprState *st = gu_new(PgfExprState, ps->pool);
|
||||||
gu_seq_get(ccat->prods, PgfProduction, i);
|
st->answers = answers;
|
||||||
pgf_result_production(ps, answers, prod);
|
st->ep.expr = gu_null_variant;
|
||||||
}
|
st->ep.prob = ccat->viterbi_prob;
|
||||||
|
st->args = gu_empty_seq();
|
||||||
|
st->arg_idx = 0;
|
||||||
|
|
||||||
|
pgf_result_predict(ps, st, ccat);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PGF_PRODUCTION_EXTERN: {
|
case PGF_PRODUCTION_EXTERN: {
|
||||||
@@ -1804,10 +1815,12 @@ pgf_result_predict(PgfParsing* ps,
|
|||||||
PgfExprState* st = gu_new(PgfExprState, ps->pool);
|
PgfExprState* st = gu_new(PgfExprState, ps->pool);
|
||||||
st->answers = cont->answers;
|
st->answers = cont->answers;
|
||||||
st->ep.expr =
|
st->ep.expr =
|
||||||
gu_new_variant_i(ps->out_pool,
|
gu_variant_is_null(cont->ep.expr) ?
|
||||||
PGF_EXPR_APP, PgfExprApp,
|
ep->expr :
|
||||||
.fun = cont->ep.expr,
|
gu_new_variant_i(ps->out_pool,
|
||||||
.arg = ep->expr);
|
PGF_EXPR_APP, PgfExprApp,
|
||||||
|
.fun = cont->ep.expr,
|
||||||
|
.arg = ep->expr);
|
||||||
st->ep.prob = cont->ep.prob+ep->prob;
|
st->ep.prob = cont->ep.prob+ep->prob;
|
||||||
st->args = cont->args;
|
st->args = cont->args;
|
||||||
st->arg_idx = cont->arg_idx+1;
|
st->arg_idx = cont->arg_idx+1;
|
||||||
@@ -1979,13 +1992,17 @@ pgf_parse_result_next(PgfParsing* ps)
|
|||||||
gu_seq_index(st->args, PgfPArg, st->arg_idx)->ccat;
|
gu_seq_index(st->args, PgfPArg, st->arg_idx)->ccat;
|
||||||
|
|
||||||
if (ccat->fid < ps->concr->total_cats) {
|
if (ccat->fid < ps->concr->total_cats) {
|
||||||
|
PgfExpr meta = gu_new_variant_i(ps->out_pool,
|
||||||
|
PGF_EXPR_META, PgfExprMeta,
|
||||||
|
.id = 0);
|
||||||
|
|
||||||
st->ep.expr =
|
st->ep.expr =
|
||||||
gu_new_variant_i(ps->out_pool,
|
gu_variant_is_null(st->ep.expr) ?
|
||||||
PGF_EXPR_APP, PgfExprApp,
|
meta :
|
||||||
.fun = st->ep.expr,
|
gu_new_variant_i(ps->out_pool,
|
||||||
.arg = gu_new_variant_i(ps->out_pool,
|
PGF_EXPR_APP, PgfExprApp,
|
||||||
PGF_EXPR_META, PgfExprMeta,
|
.fun = st->ep.expr,
|
||||||
.id = 0));
|
.arg = meta);
|
||||||
st->arg_idx++;
|
st->arg_idx++;
|
||||||
gu_buf_heap_push(ps->expr_queue, &pgf_expr_state_order, &st);
|
gu_buf_heap_push(ps->expr_queue, &pgf_expr_state_order, &st);
|
||||||
} else {
|
} else {
|
||||||
@@ -2005,10 +2022,12 @@ pgf_parse_result_next(PgfParsing* ps)
|
|||||||
PgfExprState* st3 = gu_new(PgfExprState, ps->pool);
|
PgfExprState* st3 = gu_new(PgfExprState, ps->pool);
|
||||||
st3->answers = st2->answers;
|
st3->answers = st2->answers;
|
||||||
st3->ep.expr =
|
st3->ep.expr =
|
||||||
gu_new_variant_i(ps->out_pool,
|
gu_variant_is_null(st2->ep.expr) ?
|
||||||
PGF_EXPR_APP, PgfExprApp,
|
st->ep.expr :
|
||||||
.fun = st2->ep.expr,
|
gu_new_variant_i(ps->out_pool,
|
||||||
.arg = st->ep.expr);
|
PGF_EXPR_APP, PgfExprApp,
|
||||||
|
.fun = st2->ep.expr,
|
||||||
|
.arg = st->ep.expr);
|
||||||
st3->ep.prob = st2->ep.prob + st->ep.prob;
|
st3->ep.prob = st2->ep.prob + st->ep.prob;
|
||||||
st3->args = st2->args;
|
st3->args = st2->args;
|
||||||
st3->arg_idx = st2->arg_idx+1;
|
st3->arg_idx = st2->arg_idx+1;
|
||||||
|
|||||||
Reference in New Issue
Block a user