forked from GitHub/gf-core
avoid using the wildcard constant
This commit is contained in:
@@ -460,7 +460,10 @@ void PgfExprParser::token()
|
|||||||
if (!getc())
|
if (!getc())
|
||||||
break;
|
break;
|
||||||
} while (pgf_is_ident_rest(ch));
|
} while (pgf_is_ident_rest(ch));
|
||||||
token_tag = PGF_TOKEN_IDENT;
|
if (token_value->size == 1 && strcmp(token_value->text,"_")==0)
|
||||||
|
token_tag = PGF_TOKEN_WILD;
|
||||||
|
else
|
||||||
|
token_tag = PGF_TOKEN_IDENT;
|
||||||
} else if (isdigit(ch)) {
|
} else if (isdigit(ch)) {
|
||||||
digit:
|
digit:
|
||||||
do {
|
do {
|
||||||
@@ -628,9 +631,6 @@ PgfExpr PgfExprParser::parse_arg()
|
|||||||
return arg;
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PGF_INTERNAL PgfText wildcard = {size: 1, text: {'_',0}};
|
|
||||||
PGF_INTERNAL PgfText wildcard = {size: 1, text: {}}; // TODO
|
|
||||||
|
|
||||||
PgfBind *PgfExprParser::parse_bind(PgfBind *next)
|
PgfBind *PgfExprParser::parse_bind(PgfBind *next)
|
||||||
{
|
{
|
||||||
PgfBind *last = next;
|
PgfBind *last = next;
|
||||||
@@ -643,10 +643,8 @@ PgfBind *PgfExprParser::parse_bind(PgfBind *next)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
PgfText *var;
|
PgfText *var;
|
||||||
if (token_tag == PGF_TOKEN_IDENT) {
|
if (token_tag == PGF_TOKEN_IDENT || token_tag == PGF_TOKEN_WILD) {
|
||||||
var = token_value;
|
var = token_value;
|
||||||
} else if (token_tag == PGF_TOKEN_WILD) {
|
|
||||||
var = &wildcard;
|
|
||||||
} else {
|
} else {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@@ -785,10 +783,8 @@ bool PgfExprParser::parse_hypos(size_t *n_hypos, PgfTypeHypo **hypos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PgfText *var;
|
PgfText *var;
|
||||||
if (token_tag == PGF_TOKEN_IDENT) {
|
if (token_tag == PGF_TOKEN_IDENT || token_tag == PGF_TOKEN_WILD) {
|
||||||
var = token_value;
|
var = token_value;
|
||||||
} else if (token_tag == PGF_TOKEN_WILD) {
|
|
||||||
var = &wildcard;
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -821,6 +817,18 @@ bool PgfExprParser::parse_hypos(size_t *n_hypos, PgfTypeHypo **hypos)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
PgfText *mk_wildcard()
|
||||||
|
{
|
||||||
|
PgfText *t = (PgfText *) malloc(sizeof(PgfText)+2);
|
||||||
|
if (t != NULL) {
|
||||||
|
t->size = 1;
|
||||||
|
t->text[0] = '_';
|
||||||
|
t->text[1] = 0;
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
PgfType PgfExprParser::parse_type()
|
PgfType PgfExprParser::parse_type()
|
||||||
{
|
{
|
||||||
PgfType type = 0;
|
PgfType type = 0;
|
||||||
@@ -856,7 +864,7 @@ PgfType PgfExprParser::parse_type()
|
|||||||
hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1));
|
hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1));
|
||||||
PgfTypeHypo *bt = &hypos[n_hypos];
|
PgfTypeHypo *bt = &hypos[n_hypos];
|
||||||
bt->bind_type = PGF_BIND_TYPE_EXPLICIT;
|
bt->bind_type = PGF_BIND_TYPE_EXPLICIT;
|
||||||
bt->cid = textdup(&wildcard);
|
bt->cid = mk_wildcard();
|
||||||
bt->type = 0;
|
bt->type = 0;
|
||||||
n_hypos++;
|
n_hypos++;
|
||||||
}
|
}
|
||||||
@@ -903,7 +911,7 @@ PgfType PgfExprParser::parse_type()
|
|||||||
hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1));
|
hypos = (PgfTypeHypo*) realloc(hypos, sizeof(PgfTypeHypo)*(n_hypos+1));
|
||||||
PgfTypeHypo *bt = &hypos[n_hypos];
|
PgfTypeHypo *bt = &hypos[n_hypos];
|
||||||
bt->bind_type = PGF_BIND_TYPE_EXPLICIT;
|
bt->bind_type = PGF_BIND_TYPE_EXPLICIT;
|
||||||
bt->cid = textdup(&wildcard);
|
bt->cid = mk_wildcard();
|
||||||
bt->type = u->dtyp(0,NULL,cat,n_args,args);
|
bt->type = u->dtyp(0,NULL,cat,n_args,args);
|
||||||
n_hypos++;
|
n_hypos++;
|
||||||
|
|
||||||
|
|||||||
@@ -267,8 +267,6 @@ public:
|
|||||||
prob_t get_prob() { return prob; };
|
prob_t get_prob() { return prob; };
|
||||||
};
|
};
|
||||||
|
|
||||||
PGF_INTERNAL_DECL extern PgfText wildcard;
|
|
||||||
|
|
||||||
/* The following functions release the memory in the database,
|
/* The following functions release the memory in the database,
|
||||||
* allocated for values of the corresponding types.
|
* allocated for values of the corresponding types.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ PgfLiteral PgfPrinter::lstr(PgfText *v)
|
|||||||
|
|
||||||
void PgfPrinter::hypo(PgfTypeHypo *hypo, int prio)
|
void PgfPrinter::hypo(PgfTypeHypo *hypo, int prio)
|
||||||
{
|
{
|
||||||
if (textcmp(hypo->cid, &wildcard) == 0) {
|
if (hypo->cid->size == 1 && strcmp(hypo->cid->text, "_") == 0) {
|
||||||
this->prio = prio;
|
this->prio = prio;
|
||||||
m->match_type(this, hypo->type);
|
m->match_type(this, hypo->type);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user