forked from GitHub/gf-core
added commands create cat & drop cat
This commit is contained in:
@@ -1025,6 +1025,72 @@ exit:
|
||||
return type;
|
||||
}
|
||||
|
||||
PgfTypeHypo *PgfExprParser::parse_context(size_t *p_n_hypos)
|
||||
{
|
||||
size_t n_hypos = 0;
|
||||
PgfTypeHypo *hypos = NULL;
|
||||
|
||||
for (;;) {
|
||||
if (token_tag == PGF_TOKEN_LPAR) {
|
||||
token();
|
||||
|
||||
size_t n_start = n_hypos;
|
||||
|
||||
if ((token_tag == PGF_TOKEN_IDENT &&
|
||||
(lookahead(',') ||
|
||||
lookahead(':'))) ||
|
||||
(token_tag == PGF_TOKEN_LCURLY) ||
|
||||
(token_tag == PGF_TOKEN_WILD)) {
|
||||
|
||||
if (!parse_hypos(&n_hypos, &hypos))
|
||||
goto exit;
|
||||
|
||||
if (token_tag != PGF_TOKEN_COLON)
|
||||
goto exit;
|
||||
|
||||
token();
|
||||
} else {
|
||||
hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1));
|
||||
PgfTypeHypo *bt = &hypos[n_hypos];
|
||||
bt->bind_type = PGF_BIND_TYPE_EXPLICIT;
|
||||
bt->cid = mk_wildcard();
|
||||
bt->type = 0;
|
||||
n_hypos++;
|
||||
}
|
||||
|
||||
size_t n_end = n_hypos;
|
||||
|
||||
PgfType type = parse_type();
|
||||
if (type == 0)
|
||||
goto exit;
|
||||
|
||||
if (token_tag != PGF_TOKEN_RPAR)
|
||||
goto exit;
|
||||
|
||||
token();
|
||||
|
||||
for (size_t i = n_start; i < n_end; i++) {
|
||||
hypos[i].type = type;
|
||||
}
|
||||
} else if (token_tag == PGF_TOKEN_IDENT) {
|
||||
hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1));
|
||||
PgfTypeHypo *bt = &hypos[n_hypos];
|
||||
bt->bind_type = PGF_BIND_TYPE_EXPLICIT;
|
||||
bt->cid = mk_wildcard();
|
||||
bt->type = u->dtyp(0,NULL,token_value,0,NULL);
|
||||
n_hypos++;
|
||||
|
||||
token();
|
||||
} else {
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
*p_n_hypos = n_hypos;
|
||||
return hypos;
|
||||
}
|
||||
|
||||
PgfExpr PgfExprProbEstimator::eabs(PgfBindType bind_type, PgfText *name, PgfExpr body)
|
||||
{
|
||||
m->match_expr(this, body);
|
||||
|
||||
@@ -185,6 +185,7 @@ public:
|
||||
|
||||
bool parse_hypos(size_t *n_hypos, PgfTypeHypo **hypos);
|
||||
PgfType parse_type();
|
||||
PgfTypeHypo *parse_context(size_t *p_n_hypos);
|
||||
|
||||
bool eof();
|
||||
|
||||
|
||||
@@ -718,6 +718,22 @@ PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u)
|
||||
return res;
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfTypeHypo *pgf_read_context(PgfText *input, PgfUnmarshaller *u, size_t *n_hypos)
|
||||
{
|
||||
PgfExprParser parser(input, u);
|
||||
PgfTypeHypo *res = parser.parse_context(n_hypos);
|
||||
if (!parser.eof()) {
|
||||
for (size_t i = 0; i < *n_hypos; i++) {
|
||||
free(res[i].cid);
|
||||
u->free_ref(res[i].type);
|
||||
}
|
||||
*n_hypos = (size_t) -1;
|
||||
return NULL;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
PGF_API
|
||||
PgfText *pgf_print_category_internal(object o)
|
||||
{
|
||||
|
||||
@@ -376,7 +376,10 @@ PgfText *pgf_print_context(size_t n_hypos, PgfTypeHypo *hypos,
|
||||
PGF_API_DECL
|
||||
PgfType pgf_read_type(PgfText *input, PgfUnmarshaller *u);
|
||||
|
||||
PGF_API
|
||||
PGF_API_DECL
|
||||
PgfTypeHypo *pgf_read_context(PgfText *input, PgfUnmarshaller *u, size_t *n_hypos);
|
||||
|
||||
PGF_API_DECL
|
||||
PgfText *pgf_print_start_cat_internal(PgfDB *db, PgfRevision revision, PgfExn *err);
|
||||
|
||||
PGF_API_DECL
|
||||
|
||||
Reference in New Issue
Block a user