1
0
forked from GitHub/gf-core

fix in the parser for callbacks in the middle of a word

This commit is contained in:
krasimir
2015-02-18 16:14:29 +00:00
parent 24232004f0
commit e3a87c657b

View File

@@ -1607,7 +1607,7 @@ pgf_parsing_symbol(PgfParsing* ps, PgfItem* item, PgfSymbol sym)
} }
else { else {
PgfItemConts* conts = PgfItemConts* conts =
pgf_parsing_get_conts(ps->before, pgf_parsing_get_conts(ps->before,
parg->ccat, slit->r, parg->ccat, slit->r,
ps->pool); ps->pool);
gu_buf_push(conts->items, PgfItem*, item); gu_buf_push(conts->items, PgfItem*, item);
@@ -1616,39 +1616,45 @@ pgf_parsing_symbol(PgfParsing* ps, PgfItem* item, PgfSymbol sym)
/* This is the first time when we encounter this /* This is the first time when we encounter this
* literal category so we must call the callback */ * literal category so we must call the callback */
PgfLiteralCallback* callback = bool match = false;
gu_map_get(ps->callbacks, if (!ps->before->needs_bind) {
parg->ccat->cnccat, PgfLiteralCallback* callback =
PgfLiteralCallback*); gu_map_get(ps->callbacks,
parg->ccat->cnccat,
PgfLiteralCallback*);
if (callback != NULL) { if (callback != NULL) {
size_t start = ps->before->end_offset; size_t start = ps->before->end_offset;
size_t offset = start; size_t offset = start;
PgfExprProb *ep = PgfExprProb *ep =
callback->match(callback, callback->match(callback,
slit->r, slit->r,
ps->sentence, &offset, ps->sentence, &offset,
ps->out_pool); ps->out_pool);
if (ep != NULL) { if (ep != NULL) {
PgfProduction prod; PgfProduction prod;
PgfProductionExtern* pext = PgfProductionExtern* pext =
gu_new_variant(PGF_PRODUCTION_EXTERN, gu_new_variant(PGF_PRODUCTION_EXTERN,
PgfProductionExtern, PgfProductionExtern,
&prod, ps->pool); &prod, ps->pool);
pext->ep = ep; pext->ep = ep;
pext->lins = NULL; pext->lins = NULL;
PgfItem* item = PgfItem* item =
pgf_new_item(ps, conts, prod); pgf_new_item(ps, conts, prod);
item->curr_sym = pgf_collect_extern_tok(ps,start,offset); item->curr_sym = pgf_collect_extern_tok(ps,start,offset);
item->sym_idx = pgf_item_symbols_length(item); item->sym_idx = pgf_item_symbols_length(item);
PgfParseState* state = PgfParseState* state =
pgf_new_parse_state(ps, offset, BIND_NONE, pgf_new_parse_state(ps, offset, BIND_NONE,
item->inside_prob+item->conts->outside_prob); item->inside_prob+item->conts->outside_prob);
gu_buf_heap_push(state->agenda, pgf_item_prob_order, &item); gu_buf_heap_push(state->agenda, pgf_item_prob_order, &item);
match = true;
}
} }
} else { }
if (!match) {
pgf_item_free(ps, item); pgf_item_free(ps, item);
} }
} else { } else {