mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 16:42:51 -06:00
libpgf: few fixes to make the loading of grammars with def rules possible
This commit is contained in:
@@ -160,10 +160,7 @@ GU_DEFINE_TYPE(
|
|||||||
PGF_PATT_APP, PgfPattApp,
|
PGF_PATT_APP, PgfPattApp,
|
||||||
GU_MEMBER(PgfPattApp, ctor, PgfCId),
|
GU_MEMBER(PgfPattApp, ctor, PgfCId),
|
||||||
GU_MEMBER(PgfPattApp, n_args, GuLength),
|
GU_MEMBER(PgfPattApp, n_args, GuLength),
|
||||||
GU_MEMBER(PgfPattApp, args, PgfPatt)),
|
GU_FLEX_MEMBER(PgfPattApp, args, PgfPatt)),
|
||||||
GU_CONSTRUCTOR_S(
|
|
||||||
PGF_PATT_LIT, PgfPattLit,
|
|
||||||
GU_MEMBER(PgfPattLit, lit, PgfLiteral)),
|
|
||||||
GU_CONSTRUCTOR_S(
|
GU_CONSTRUCTOR_S(
|
||||||
PGF_PATT_VAR, PgfPattVar,
|
PGF_PATT_VAR, PgfPattVar,
|
||||||
GU_MEMBER(PgfPattVar, var, PgfCId)),
|
GU_MEMBER(PgfPattVar, var, PgfCId)),
|
||||||
@@ -173,6 +170,9 @@ GU_DEFINE_TYPE(
|
|||||||
GU_MEMBER(PgfPattAs, patt, PgfPatt)),
|
GU_MEMBER(PgfPattAs, patt, PgfPatt)),
|
||||||
GU_CONSTRUCTOR(
|
GU_CONSTRUCTOR(
|
||||||
PGF_PATT_WILD, void),
|
PGF_PATT_WILD, void),
|
||||||
|
GU_CONSTRUCTOR_S(
|
||||||
|
PGF_PATT_LIT, PgfPattLit,
|
||||||
|
GU_MEMBER(PgfPattLit, lit, PgfLiteral)),
|
||||||
GU_CONSTRUCTOR_S(
|
GU_CONSTRUCTOR_S(
|
||||||
PGF_PATT_IMPL_ARG, PgfPattImplArg,
|
PGF_PATT_IMPL_ARG, PgfPattImplArg,
|
||||||
GU_MEMBER(PgfPattImplArg, patt, PgfPatt)),
|
GU_MEMBER(PgfPattImplArg, patt, PgfPatt)),
|
||||||
@@ -184,7 +184,7 @@ GU_DEFINE_TYPE(
|
|||||||
PgfEquation, struct,
|
PgfEquation, struct,
|
||||||
GU_MEMBER(PgfEquation, body, PgfExpr),
|
GU_MEMBER(PgfEquation, body, PgfExpr),
|
||||||
GU_MEMBER(PgfEquation, n_patts, GuLength),
|
GU_MEMBER(PgfEquation, n_patts, GuLength),
|
||||||
GU_MEMBER(PgfEquation, patts, PgfPatt));
|
GU_FLEX_MEMBER(PgfEquation, patts, PgfPatt));
|
||||||
|
|
||||||
// Distinct type so we can give it special treatment in the reader
|
// Distinct type so we can give it special treatment in the reader
|
||||||
GU_DEFINE_TYPE(PgfEquationsM, GuSeq, gu_type(PgfEquation));
|
GU_DEFINE_TYPE(PgfEquationsM, GuSeq, gu_type(PgfEquation));
|
||||||
|
|||||||
@@ -274,6 +274,8 @@ typedef struct {
|
|||||||
} PgfProductionConst;
|
} PgfProductionConst;
|
||||||
|
|
||||||
|
|
||||||
|
extern GU_DECLARE_TYPE(PgfPatt, GuVariant);
|
||||||
|
|
||||||
extern GU_DECLARE_TYPE(PgfProduction, GuVariant);
|
extern GU_DECLARE_TYPE(PgfProduction, GuVariant);
|
||||||
extern GU_DECLARE_TYPE(PgfBindType, enum);
|
extern GU_DECLARE_TYPE(PgfBindType, enum);
|
||||||
extern GU_DECLARE_TYPE(PgfLiteral, GuVariant);
|
extern GU_DECLARE_TYPE(PgfLiteral, GuVariant);
|
||||||
@@ -286,10 +288,10 @@ pgf_literal_cat(PgfLiteral lit);
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PGF_PATT_APP,
|
PGF_PATT_APP,
|
||||||
PGF_PATT_LIT,
|
|
||||||
PGF_PATT_VAR,
|
PGF_PATT_VAR,
|
||||||
PGF_PATT_AS,
|
PGF_PATT_AS,
|
||||||
PGF_PATT_WILD,
|
PGF_PATT_WILD,
|
||||||
|
PGF_PATT_LIT,
|
||||||
PGF_PATT_IMPL_ARG,
|
PGF_PATT_IMPL_ARG,
|
||||||
PGF_PATT_TILDE,
|
PGF_PATT_TILDE,
|
||||||
PGF_PATT_NUM_TAGS
|
PGF_PATT_NUM_TAGS
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ GU_DEFINE_TYPE(
|
|||||||
GU_MEMBER(PgfExprMeta, id, int)),
|
GU_MEMBER(PgfExprMeta, id, int)),
|
||||||
GU_CONSTRUCTOR_S(
|
GU_CONSTRUCTOR_S(
|
||||||
PGF_EXPR_FUN, PgfExprFun,
|
PGF_EXPR_FUN, PgfExprFun,
|
||||||
GU_MEMBER(PgfExprFun, fun, GuStr)),
|
GU_MEMBER(PgfExprFun, fun, GuString)),
|
||||||
GU_CONSTRUCTOR_S(
|
GU_CONSTRUCTOR_S(
|
||||||
PGF_EXPR_VAR, PgfExprVar,
|
PGF_EXPR_VAR, PgfExprVar,
|
||||||
GU_MEMBER(PgfExprVar, var, int)),
|
GU_MEMBER(PgfExprVar, var, int)),
|
||||||
|
|||||||
@@ -516,7 +516,7 @@ pgf_read_to_GuSeq(GuType* type, PgfReader* rdr, void* to)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgf_read_to_maybe_seq(GuType* type, PgfReader* rdr, void* to)
|
pgf_read_to_PgfEquationsM(GuType* type, PgfReader* rdr, void* to)
|
||||||
{
|
{
|
||||||
GuSeq* sto = to;
|
GuSeq* sto = to;
|
||||||
uint8_t tag = pgf_read_u8(rdr);
|
uint8_t tag = pgf_read_u8(rdr);
|
||||||
@@ -525,9 +525,32 @@ pgf_read_to_maybe_seq(GuType* type, PgfReader* rdr, void* to)
|
|||||||
case 0:
|
case 0:
|
||||||
*sto = gu_null_seq;
|
*sto = gu_null_seq;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1: {
|
||||||
pgf_read_to_GuSeq(type, rdr, to);
|
GuLength length = pgf_read_len(rdr);
|
||||||
|
gu_return_on_exn(rdr->err, );
|
||||||
|
|
||||||
|
GuSeq seq = gu_new_seq(PgfEquation*, length, rdr->opool);
|
||||||
|
PgfEquation** data = gu_seq_data(seq);
|
||||||
|
for (size_t i = 0; i < length; i++) {
|
||||||
|
GuLength n_patts = pgf_read_len(rdr);
|
||||||
|
gu_return_on_exn(rdr->err, );
|
||||||
|
|
||||||
|
PgfEquation *equ =
|
||||||
|
gu_malloc(rdr->opool,
|
||||||
|
sizeof(PgfEquation)+sizeof(PgfPatt)*n_patts);
|
||||||
|
equ->n_patts = n_patts;
|
||||||
|
for (int j = 0; j < n_patts; j++) {
|
||||||
|
pgf_read_to(rdr, gu_type(PgfPatt), &equ->patts[j]);
|
||||||
|
gu_return_on_exn(rdr->err, );
|
||||||
|
}
|
||||||
|
pgf_read_to(rdr, gu_type(PgfExpr), &equ->body);
|
||||||
|
gu_return_on_exn(rdr->err, );
|
||||||
|
|
||||||
|
data[i] = equ;
|
||||||
|
}
|
||||||
|
*sto = seq;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
gu_raise_i(rdr->err, PgfReadTagExn,
|
gu_raise_i(rdr->err, PgfReadTagExn,
|
||||||
.type = type, .tag = tag);
|
.type = type, .tag = tag);
|
||||||
@@ -775,7 +798,7 @@ pgf_read_to_table = GU_TYPETABLE(
|
|||||||
PGF_READ_TO(GuString),
|
PGF_READ_TO(GuString),
|
||||||
PGF_READ_TO(double),
|
PGF_READ_TO(double),
|
||||||
PGF_READ_TO(pointer),
|
PGF_READ_TO(pointer),
|
||||||
PGF_READ_TO_FN(PgfEquationsM, pgf_read_to_maybe_seq),
|
PGF_READ_TO(PgfEquationsM),
|
||||||
PGF_READ_TO(GuSeq),
|
PGF_READ_TO(GuSeq),
|
||||||
PGF_READ_TO(PgfCCatId),
|
PGF_READ_TO(PgfCCatId),
|
||||||
PGF_READ_TO(PgfCCat),
|
PGF_READ_TO(PgfCCat),
|
||||||
|
|||||||
Reference in New Issue
Block a user