diff --git a/src/runtime/c/Makefile.am b/src/runtime/c/Makefile.am
index 81c1b698a..4b22ba745 100644
--- a/src/runtime/c/Makefile.am
+++ b/src/runtime/c/Makefile.am
@@ -117,15 +117,11 @@ libpgf_la_SOURCES = \
pgf/pgf.h
bin_PROGRAMS = \
- utils/pgf2yaml \
utils/pgf-print \
utils/pgf-translate \
utils/pgf-parse \
utils/pgf-chunk
-utils_pgf2yaml_SOURCES = utils/pgf2yaml.c
-utils_pgf2yaml_LDADD = libpgf.la libgu.la
-
utils_pgf_print_SOURCES = utils/pgf-print.c
utils_pgf_print_LDADD = libpgf.la libgu.la
diff --git a/src/runtime/c/pgf/data.c b/src/runtime/c/pgf/data.c
index d7a44e31c..3e159fa6f 100644
--- a/src/runtime/c/pgf/data.c
+++ b/src/runtime/c/pgf/data.c
@@ -22,218 +22,33 @@ pgf_tokens_equal(PgfTokens t1, PgfTokens t2)
return true;
}
-
-
-GU_DEFINE_TYPE(PgfTokens, GuSeq, gu_type(GuString));
-
GU_DEFINE_TYPE(PgfCId, typedef, gu_type(GuString));
-GU_DEFINE_TYPE(GuStringL, GuList, gu_type(GuString));
-
-
#define gu_type__PgfCIdMap gu_type__GuStringMap
typedef GuType_GuStringMap GuType_PgfCIdMap;
#define GU_TYPE_INIT_PgfCIdMap GU_TYPE_INIT_GuStringMap
-GU_DEFINE_TYPE(PgfCCat, struct,
- GU_MEMBER_S(PgfCCat, cnccat, PgfCncCat),
- GU_MEMBER_P(PgfCCat, lindefs, PgfFunIds),
- GU_MEMBER(PgfCCat, prods, PgfProductionSeq));
+GU_DEFINE_TYPE(PgfCCat, abstract);
-GU_DEFINE_TYPE(PgfCCatId, shared, gu_type(PgfCCat));
+GU_DEFINE_TYPE(PgfCncCat, abstract);
-GU_DEFINE_TYPE(PgfCCatIds, GuList, gu_type(PgfCCatId));
+GU_DEFINE_TYPE(PgfFlags, GuStringMap, gu_type(GuVariant), &gu_null_variant);
-GU_DEFINE_TYPE(PgfCCatSeq, GuSeq, gu_type(PgfCCatId));
+GU_DEFINE_TYPE(PgfProductionSeq, GuSeq, gu_type(GuVariant));
-GU_DEFINE_TYPE(PgfAlternative, struct,
- GU_MEMBER(PgfAlternative, form, PgfTokens),
- GU_MEMBER_P(PgfAlternative, prefixes, GuStringL));
-
-
-GU_DEFINE_TYPE(
- PgfSymbol, GuVariant,
- GU_CONSTRUCTOR_S(
- PGF_SYMBOL_CAT, PgfSymbolCat,
- GU_MEMBER(PgfSymbolCat, d, int),
- GU_MEMBER(PgfSymbolCat, r, int)),
- GU_CONSTRUCTOR_S(
- PGF_SYMBOL_LIT, PgfSymbolLit,
- GU_MEMBER(PgfSymbolLit, d, int),
- GU_MEMBER(PgfSymbolLit, r, int)),
- GU_CONSTRUCTOR_S(
- PGF_SYMBOL_VAR, PgfSymbolVar,
- GU_MEMBER(PgfSymbolVar, d, int),
- GU_MEMBER(PgfSymbolVar, r, int)),
- GU_CONSTRUCTOR_S(
- PGF_SYMBOL_KS, PgfSymbolKS,
- GU_MEMBER(PgfSymbolKS, tokens, PgfTokens)),
- GU_CONSTRUCTOR_S(
- PGF_SYMBOL_KP, PgfSymbolKP,
- GU_MEMBER(PgfSymbolKP, default_form, PgfTokens),
- GU_MEMBER(PgfSymbolKP, n_forms, GuLength),
- GU_FLEX_MEMBER(PgfSymbolKP, forms, PgfAlternative)));
-
-GU_DEFINE_TYPE(
- PgfCncCat, struct,
- GU_MEMBER(PgfCncCat, abscat, PgfCat),
- GU_MEMBER_P(PgfCncCat, cats, PgfCCatIds),
- GU_MEMBER(PgfCncCat, n_lins, size_t),
- GU_FLEX_MEMBER(PgfCncCat, labels, GuString));
-
-// GU_DEFINE_TYPE(PgfSequence, GuList, gu_ptr_type(PgfSymbol));
-// GU_DEFINE_TYPE(PgfSequence, GuList, gu_type(PgfSymbol));
-GU_DEFINE_TYPE(PgfSequence, GuSeq, gu_type(PgfSymbol));
-
-GU_DEFINE_TYPE(PgfFlags, GuStringMap, gu_type(PgfLiteral), &gu_null_variant);
-
-typedef PgfFlags* PgfFlagsP;
-
-GU_DEFINE_TYPE(PgfFlagsP, pointer, gu_type(PgfFlags));
-
-GU_DEFINE_TYPE(PgfSequences, GuList, gu_type(PgfSequence));
-
-GU_DEFINE_TYPE(PgfSeqId, typedef, gu_type(PgfSequence));
-
-GU_DEFINE_TYPE(
- PgfCncFun, struct,
- GU_MEMBER(PgfCncFun, name, PgfCId),
- GU_MEMBER(PgfCncFun, n_lins, GuLength),
- GU_FLEX_MEMBER(PgfCncFun, lins, PgfSeqId));
-
-GU_DEFINE_TYPE(PgfCncFuns, GuList,
- GU_TYPE_LIT(referenced, _, gu_ptr_type(PgfCncFun)));
-
-GU_DEFINE_TYPE(PgfFunId, shared, gu_type(PgfCncFun));
-
-GU_DEFINE_TYPE(PgfFunIds, GuList, gu_type(PgfFunId));
-
-GU_DEFINE_TYPE(
- PgfPArg, struct,
- GU_MEMBER_P(PgfPArg, hypos, PgfCCatIds),
- GU_MEMBER(PgfPArg, ccat, PgfCCatId));
-
-GU_DEFINE_TYPE(PgfPArgs, GuSeq, gu_type(PgfPArg));
-
-GU_DEFINE_TYPE(
- PgfProduction, GuVariant,
- GU_CONSTRUCTOR_S(
- PGF_PRODUCTION_APPLY, PgfProductionApply,
- GU_MEMBER(PgfProductionApply, fun, PgfFunId),
- GU_MEMBER(PgfProductionApply, args, PgfPArgs)),
- GU_CONSTRUCTOR_S(
- PGF_PRODUCTION_COERCE, PgfProductionCoerce,
- GU_MEMBER(PgfProductionCoerce, coerce, PgfCCatId)),
- GU_CONSTRUCTOR_S(
- PGF_PRODUCTION_EXTERN, PgfProductionExtern,
- GU_MEMBER(PgfProductionExtern, callback, PgfLiteralCallback),
- GU_MEMBER(PgfProductionExtern, lins, GuSeq)),
- GU_CONSTRUCTOR_S(
- PGF_PRODUCTION_META, PgfProductionMeta,
- GU_MEMBER(PgfProductionMeta, args, PgfPArgs)));
-
-GU_DEFINE_TYPE(PgfProductions, GuList, gu_type(PgfProduction));
-GU_DEFINE_TYPE(PgfProductionSeq, GuSeq, gu_type(PgfProduction));
-
-GU_DEFINE_TYPE(
- PgfPatt, GuVariant,
- GU_CONSTRUCTOR_S(
- PGF_PATT_APP, PgfPattApp,
- GU_MEMBER(PgfPattApp, ctor, PgfCId),
- GU_MEMBER(PgfPattApp, n_args, GuLength),
- GU_FLEX_MEMBER(PgfPattApp, args, PgfPatt)),
- GU_CONSTRUCTOR_S(
- PGF_PATT_VAR, PgfPattVar,
- GU_MEMBER(PgfPattVar, var, PgfCId)),
- GU_CONSTRUCTOR_S(
- PGF_PATT_AS, PgfPattAs,
- GU_MEMBER(PgfPattAs, var, PgfCId),
- GU_MEMBER(PgfPattAs, patt, PgfPatt)),
- GU_CONSTRUCTOR(
- PGF_PATT_WILD, void),
- GU_CONSTRUCTOR_S(
- PGF_PATT_LIT, PgfPattLit,
- GU_MEMBER(PgfPattLit, lit, PgfLiteral)),
- GU_CONSTRUCTOR_S(
- PGF_PATT_IMPL_ARG, PgfPattImplArg,
- GU_MEMBER(PgfPattImplArg, patt, PgfPatt)),
- GU_CONSTRUCTOR_S(
- PGF_PATT_TILDE, PgfPattTilde,
- GU_MEMBER(PgfPattTilde, expr, PgfExpr)));
-
-GU_DEFINE_TYPE(
- PgfEquation, struct,
- GU_MEMBER(PgfEquation, body, PgfExpr),
- GU_MEMBER(PgfEquation, n_patts, GuLength),
- GU_FLEX_MEMBER(PgfEquation, patts, PgfPatt));
-
-// Distinct type so we can give it special treatment in the reader
-GU_DEFINE_TYPE(PgfEquationsM, GuSeq, gu_type(PgfEquation));
-
-GU_DEFINE_TYPE(PgfExprProb, struct,
- GU_MEMBER(PgfExprProb, prob, double),
- GU_MEMBER(PgfExprProb, expr, PgfExpr));
-
-GU_DEFINE_TYPE(
- PgfFunDecl, struct,
- GU_MEMBER_P(PgfFunDecl, type, PgfType),
- GU_MEMBER(PgfFunDecl, arity, int),
- GU_MEMBER(PgfFunDecl, defns, PgfEquationsM),
- GU_MEMBER(PgfFunDecl, ep, PgfExprProb));
+GU_DEFINE_TYPE(PgfAbsFun, abstract);
static prob_t inf_prob = INFINITY;
GU_DEFINE_TYPE(prob_t, GuFloating, _);
GU_DEFINE_TYPE(PgfMetaChildMap, GuMap,
- gu_type(PgfCat), NULL,
+ gu_type(PgfAbsCat), NULL,
gu_type(prob_t), &inf_prob);
-GU_DEFINE_TYPE(
- PgfCat, struct,
- GU_MEMBER(PgfCat, context, PgfHypos));
-
-
-GU_DEFINE_TYPE(
- PgfAbstr, struct,
- GU_MEMBER(PgfAbstr, aflags, PgfFlagsP),
- GU_MEMBER_V(PgfAbstr, funs,
- GU_TYPE_LIT(pointer, PgfCIdMap*,
- GU_TYPE_LIT(PgfCIdMap, _,
- gu_ptr_type(PgfFunDecl),
- &gu_null_struct))),
- GU_MEMBER_V(PgfAbstr, cats,
- GU_TYPE_LIT(pointer, PgfCIdMap*,
- GU_TYPE_LIT(PgfCIdMap, _,
- gu_ptr_type(PgfCat),
- &gu_null_struct))));
+GU_DEFINE_TYPE(PgfAbsCat, abstract);
GU_DEFINE_TYPE(
PgfPrintNames, PgfCIdMap, gu_type(GuString), &gu_empty_string);
-GU_DEFINE_TYPE(
- PgfConcr, struct,
- GU_MEMBER(PgfConcr, cflags, PgfFlagsP),
- GU_MEMBER_P(PgfConcr, ccats, GuMap),
- GU_MEMBER_P(PgfConcr, cncfuns, PgfCncFuns),
- GU_MEMBER_P(PgfConcr, sequences, PgfSequences),
- GU_MEMBER_P(PgfConcr, printnames, PgfPrintNames),
- GU_MEMBER_V(PgfConcr, cnccats,
- GU_TYPE_LIT(pointer, PgfCIdMap*,
- GU_TYPE_LIT(PgfCIdMap, _,
- gu_ptr_type(PgfCncCat),
- &gu_null_struct))));
-
-GU_DEFINE_TYPE(
- PgfPGF, struct,
- GU_MEMBER(PgfPGF, major_version, uint16_t),
- GU_MEMBER(PgfPGF, minor_version, uint16_t),
- GU_MEMBER(PgfPGF, gflags, PgfFlagsP),
- GU_MEMBER(PgfPGF, absname, PgfCId),
- GU_MEMBER(PgfPGF, abstract, PgfAbstr),
- GU_MEMBER_V(PgfPGF, concretes,
- GU_TYPE_LIT(pointer, PgfCIdMap*,
- GU_TYPE_LIT(PgfCIdMap, _,
- gu_ptr_type(PgfConcr),
- &gu_null_struct))));
-
+GU_DEFINE_TYPE(PgfConcr, abstract);
diff --git a/src/runtime/c/pgf/data.h b/src/runtime/c/pgf/data.h
index 8c3919b8d..a726519a1 100644
--- a/src/runtime/c/pgf/data.h
+++ b/src/runtime/c/pgf/data.h
@@ -1,22 +1,3 @@
-/*
- * Copyright 2010 University of Helsinki.
- *
- * This file is part of libpgf.
- *
- * Libpgf is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
- *
- * Libpgf is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with libpgf. If not, see .
- */
-
#ifndef PGF_DATA_H_
#define PGF_DATA_H_
@@ -29,310 +10,18 @@
#include
typedef struct PgfCCat PgfCCat;
-typedef PgfCCat* PgfCCatId;
-extern GU_DECLARE_TYPE(PgfCCat, struct);
-extern GU_DECLARE_TYPE(PgfCCatId, shared);
-typedef GuList(PgfCCatId) PgfCCatIds;
-extern GU_DECLARE_TYPE(PgfCCatIds, GuList);
-typedef GuSeq PgfCCatSeq;
-extern GU_DECLARE_TYPE(PgfCCatSeq, GuSeq);
+extern GU_DECLARE_TYPE(PgfCCat, abstract);
-typedef struct PgfAbstr PgfAbstr;
-extern GU_DECLARE_TYPE(PgfAbstr, struct);
+typedef GuList(PgfCCat*) PgfCCats;
-typedef struct PgfFunDecl PgfFunDecl;
-
-typedef int PgfLength;
-typedef struct GuVariant PgfSymbol;
-typedef struct PgfAlternative PgfAlternative;
-typedef struct PgfCncFun PgfCncFun;
-
-
-typedef GuSeq PgfSequence; // -> PgfSymbol
-
-typedef PgfCncFun* PgfFunId; // key to PgfCncFuns
-extern GU_DECLARE_TYPE(PgfFunId, shared);
-typedef GuList(PgfCncFun*) PgfCncFuns;
-extern GU_DECLARE_TYPE(PgfCncFuns, GuList);
-typedef GuList(PgfFunId) PgfFunIds;
-extern GU_DECLARE_TYPE(PgfFunIds, GuList);
-// typedef GuStringMap PgfCIdMap; // PgfCId -> ?
#define PgfCIdMap GuStringMap
typedef PgfCIdMap PgfFlags; // PgfCId -> PgfLiteral
extern GU_DECLARE_TYPE(PgfFlags, GuMap);
-extern GU_DECLARE_TYPE(PgfType, struct);
-typedef GuVariant PgfProduction;
-typedef GuList(PgfProduction) PgfProductions;
-extern GU_DECLARE_TYPE(PgfProductions, GuList);
-typedef GuSeq PgfProductionSeq;
-extern GU_DECLARE_TYPE(PgfProductionSeq, GuSeq);
-
-typedef struct PgfCatFun PgfCatFun;
-typedef struct PgfCncCat PgfCncCat;
-extern GU_DECLARE_TYPE(PgfCncCat, struct);
-typedef GuVariant PgfPatt;
-
-typedef GuList(GuString) GuStringL;
-extern GU_DECLARE_TYPE(GuStringL, GuList);
-typedef GuSeq PgfTokens; // -> PgfToken
-extern GU_DECLARE_TYPE(PgfTokens, GuSeq);
-
-bool
-pgf_tokens_equal(PgfTokens t1, PgfTokens t2);
-
-
-
-typedef PgfExpr PgfTree;
-
-typedef struct PgfEquation PgfEquation;
-typedef GuSeq PgfEquations;
-typedef PgfEquations PgfEquationsM; // can be null
-extern GU_DECLARE_TYPE(PgfEquationsM, GuSeq);
-
-typedef struct PgfCat PgfCat;
-extern GU_DECLARE_TYPE(PgfCat, struct);
-
-typedef PgfSequence PgfSeqId; // shared reference
-
-extern GU_DECLARE_TYPE(PgfSeqId, typedef);
-
-typedef GuList(PgfSequence) PgfSequences;
-
-extern GU_DECLARE_TYPE(PgfSequences, GuList);
-
-
-
-
-struct PgfAbstr {
- PgfFlags* aflags;
- PgfCIdMap* funs; // |-> PgfFunDecl*
- PgfCIdMap* cats; // |-> PgfCat*
-};
-
-struct PgfPGF {
- uint16_t major_version;
- uint16_t minor_version;
- PgfFlags* gflags;
- PgfCId absname;
- PgfAbstr abstract;
- PgfCIdMap* concretes; // |-> PgfConcr*
- GuPool* pool;
-};
-
-extern GU_DECLARE_TYPE(PgfPGF, struct);
-
-struct PgfFunDecl {
- PgfType* type;
- int arity;
- PgfEquationsM defns; // maybe null
- PgfExprProb ep;
-};
-
-extern GU_DECLARE_TYPE(PgfFunDecl, struct);
-
-typedef GuMap PgfMetaChildMap;
-extern GU_DECLARE_TYPE(PgfMetaChildMap, GuMap);
-
-struct PgfCat {
- PgfCId name;
- PgfHypos context;
-
- prob_t meta_prob;
- prob_t meta_token_prob;
- PgfMetaChildMap* meta_child_probs;
-
- GuBuf* functions; // -->PgfFunDecl
-};
-
-
-struct PgfCncCat {
- PgfCat *abscat;
- PgfCCatIds* cats;
-
- size_t n_lins;
- GuString labels[];
- /**< Labels for tuples. All nested tuples, records and tables
- * in the GF linearization types are flattened into a single
- * tuple in the corresponding PGF concrete category. This
- * field holds the labels that indicate which GF field or
- * parameter (or their combination) each tuple element
- * represents. */
-};
-
-struct PgfCncFun {
- PgfCId name;
- PgfExprProb *ep;
- int funid;
- GuLength n_lins;
- PgfSeqId lins[];
-};
-
-struct PgfAlternative {
- PgfTokens form;
- /**< The form of this variant as a list of tokens. */
-
- GuStringL* prefixes;
- /**< The prefixes of the following symbol that trigger this
- * form. */
-};
-
-typedef struct PgfItemConts PgfItemConts;
-
-struct PgfCCat {
- PgfCncCat* cnccat;
- PgfFunIds* lindefs;
- size_t n_synprods;
- PgfProductionSeq prods;
- float viterbi_prob;
- int fid;
- PgfItemConts* conts;
-};
-
-extern PgfCCat pgf_ccat_string, pgf_ccat_int, pgf_ccat_float, pgf_ccat_var;
-
-typedef PgfCIdMap PgfPrintNames;
-extern GU_DECLARE_TYPE(PgfPrintNames, GuStringMap);
-
-typedef GuStringMap PgfCncFunOverloadMap;
-extern GU_DECLARE_TYPE(PgfCncFunOverloadMap, GuStringMap);
-
-typedef GuMap PgfCncOverloadMap;
-extern GU_DECLARE_TYPE(PgfCncOverloadMap, GuMap);
-
-typedef GuMap PgfProductionIdx;
-extern GU_DECLARE_TYPE(PgfProductionIdx, GuMap);
-
-typedef GuMap PgfLeftcornerCatIdx;
-extern GU_DECLARE_TYPE(PgfLeftcornerCatIdx, GuMap);
-
-typedef GuMap PgfLeftcornerTokIdx;
-extern GU_DECLARE_TYPE(PgfLeftcornerTokIdx, GuMap);
-
-typedef struct PgfLiteralCallback PgfLiteralCallback;
-extern GU_DECLARE_TYPE(PgfLiteralCallback, struct);
-
-typedef struct PgfItem PgfItem;
-
-struct PgfLiteralCallback {
- bool (*match)(PgfConcr* concr, PgfItem* item, PgfToken tok,
- PgfExprProb** out_ep, GuPool *pool);
-};
-
-typedef GuMap PgfCallbacksMap;
-extern GU_DECLARE_TYPE(PgfCallbacksMap, GuMap);
-
-struct PgfConcr {
- PgfFlags* cflags;
- PgfPrintNames* printnames;
- GuMap* ccats;
- PgfCncFunOverloadMap* fun_indices;
- PgfCncOverloadMap* coerce_idx;
- PgfProductionIdx* epsilon_idx;
- PgfLeftcornerCatIdx* leftcorner_cat_idx;
- PgfLeftcornerTokIdx* leftcorner_tok_idx;
- PgfCncFuns* cncfuns;
- PgfSequences* sequences;
- PgfCIdMap* cnccats;
- PgfCallbacksMap* callbacks;
- int total_cats;
-};
-
-extern GU_DECLARE_TYPE(PgfConcr, struct);
-
-typedef enum {
- PGF_SYMBOL_CAT,
- PGF_SYMBOL_LIT,
- PGF_SYMBOL_VAR,
- PGF_SYMBOL_KS,
- PGF_SYMBOL_KP
-} PgfSymbolTag;
-
-typedef struct PgfSymbolIdx PgfSymbolIdx;
-
-struct PgfSymbolIdx {
- int d;
- int r;
-};
-
-typedef PgfSymbolIdx PgfSymbolCat, PgfSymbolLit, PgfSymbolVar;
-
-typedef struct {
- PgfTokens tokens;
-} PgfSymbolKS;
-
-typedef struct PgfSymbolKP
-/** A prefix-dependent symbol. The form that this symbol takes
- * depends on the form of a prefix of the following symbol. */
-{
- PgfTokens default_form;
- /**< Default form that this symbol takes if none of of the
- * variant forms is triggered. */
-
- GuLength n_forms;
- PgfAlternative forms[];
- /**< Variant forms whose choise depends on the following
- * symbol. */
-} PgfSymbolKP;
-
-
-
-
-// PgfProduction
-
-typedef enum {
- PGF_PRODUCTION_APPLY,
- PGF_PRODUCTION_COERCE,
- PGF_PRODUCTION_EXTERN,
- PGF_PRODUCTION_META
-} PgfProductionTag;
-
-typedef struct PgfPArg PgfPArg;
-
-struct PgfPArg {
- PgfCCatId ccat;
- PgfCCatIds* hypos;
-};
-
-extern GU_DECLARE_TYPE(PgfPArg, struct);
-
-typedef GuSeq PgfPArgs;
-
-extern GU_DECLARE_TYPE(PgfPArgs, GuSeq);
-
-typedef struct {
- PgfFunId fun;
- PgfPArgs args;
-} PgfProductionApply;
-
-typedef struct PgfProductionCoerce
-/** A coercion. This production is a logical union of the coercions of
- * another FId. This allows common subsets of productions to be
- * shared. */
-{
- PgfCCatId coerce;
-} PgfProductionCoerce;
-
-typedef struct {
- PgfLiteralCallback *callback;
- PgfExprProb *ep;
- GuSeq lins;
-} PgfProductionExtern;
-
-typedef struct {
- PgfExprProb *ep;
- PgfPArgs args;
-} PgfProductionMeta;
-
-extern GU_DECLARE_TYPE(PgfPatt, GuVariant);
-
-extern GU_DECLARE_TYPE(PgfProduction, GuVariant);
-extern GU_DECLARE_TYPE(PgfBindType, enum);
-extern GU_DECLARE_TYPE(PgfLiteral, GuVariant);
-
-
// PgfPatt
+typedef GuVariant PgfPatt;
+
typedef enum {
PGF_PATT_APP,
PGF_PATT_VAR,
@@ -373,12 +62,238 @@ typedef struct {
PgfExpr expr;
} PgfPattTilde;
-struct PgfEquation {
+typedef struct {
PgfExpr body;
GuLength n_patts;
PgfPatt patts[];
+} PgfEquation;
+
+typedef GuSeq PgfEquations;
+
+typedef struct {
+ PgfType* type;
+ int arity;
+ PgfEquations defns; // maybe null
+ PgfExprProb ep;
+} PgfAbsFun;
+
+extern GU_DECLARE_TYPE(PgfAbsFun, abstract);
+
+typedef GuMap PgfMetaChildMap;
+extern GU_DECLARE_TYPE(PgfMetaChildMap, GuMap);
+
+typedef struct {
+ PgfCId name;
+ PgfHypos context;
+
+ prob_t meta_prob;
+ prob_t meta_token_prob;
+ PgfMetaChildMap* meta_child_probs;
+
+ GuBuf* functions; // -->PgfFunDecl
+} PgfAbsCat;
+
+extern GU_DECLARE_TYPE(PgfAbsCat, abstract);
+
+typedef struct {
+ PgfFlags* aflags;
+ PgfCIdMap* funs; // |-> PgfAbsFun*
+ PgfCIdMap* cats; // |-> PgfAbsCat*
+} PgfAbstr;
+
+struct PgfPGF {
+ uint16_t major_version;
+ uint16_t minor_version;
+ PgfFlags* gflags;
+ PgfCId absname;
+ PgfAbstr abstract;
+ PgfCIdMap* concretes; // |-> PgfConcr*
+ GuPool* pool;
};
+typedef struct {
+ PgfAbsCat *abscat;
+ PgfCCats* cats;
+
+ size_t n_lins;
+ GuString labels[];
+ /**< Labels for tuples. All nested tuples, records and tables
+ * in the GF linearization types are flattened into a single
+ * tuple in the corresponding PGF concrete category. This
+ * field holds the labels that indicate which GF field or
+ * parameter (or their combination) each tuple element
+ * represents. */
+} PgfCncCat;
+
+extern GU_DECLARE_TYPE(PgfCncCat, abstract);
+
+typedef GuSeq PgfTokens; // -> PgfToken
+
+bool
+pgf_tokens_equal(PgfTokens t1, PgfTokens t2);
+
+typedef GuList(GuString) GuStringL;
+
+typedef struct {
+ PgfTokens form;
+ /**< The form of this variant as a list of tokens. */
+
+ GuStringL* prefixes;
+ /**< The prefixes of the following symbol that trigger this
+ * form. */
+} PgfAlternative;
+
+typedef struct PgfItemConts PgfItemConts;
+
+typedef PgfCIdMap PgfPrintNames;
+extern GU_DECLARE_TYPE(PgfPrintNames, GuStringMap);
+
+typedef GuStringMap PgfCncFunOverloadMap;
+extern GU_DECLARE_TYPE(PgfCncFunOverloadMap, GuStringMap);
+
+typedef GuMap PgfCncOverloadMap;
+extern GU_DECLARE_TYPE(PgfCncOverloadMap, GuMap);
+
+typedef GuMap PgfProductionIdx;
+extern GU_DECLARE_TYPE(PgfProductionIdx, GuMap);
+
+typedef GuMap PgfLeftcornerCatIdx;
+extern GU_DECLARE_TYPE(PgfLeftcornerCatIdx, GuMap);
+
+typedef GuMap PgfLeftcornerTokIdx;
+extern GU_DECLARE_TYPE(PgfLeftcornerTokIdx, GuMap);
+
+typedef struct PgfItem PgfItem;
+
+typedef struct {
+ bool (*match)(PgfConcr* concr, PgfItem* item, PgfToken tok,
+ PgfExprProb** out_ep, GuPool *pool);
+} PgfLiteralCallback;
+
+typedef GuMap PgfCallbacksMap;
+extern GU_DECLARE_TYPE(PgfCallbacksMap, GuMap);
+
+typedef struct GuVariant PgfSymbol;
+
+typedef enum {
+ PGF_SYMBOL_CAT,
+ PGF_SYMBOL_LIT,
+ PGF_SYMBOL_VAR,
+ PGF_SYMBOL_KS,
+ PGF_SYMBOL_KP
+} PgfSymbolTag;
+
+typedef struct {
+ int d;
+ int r;
+} PgfSymbolIdx;
+
+typedef PgfSymbolIdx PgfSymbolCat, PgfSymbolLit, PgfSymbolVar;
+
+typedef struct {
+ PgfTokens tokens;
+} PgfSymbolKS;
+
+typedef struct PgfSymbolKP
+/** A prefix-dependent symbol. The form that this symbol takes
+ * depends on the form of a prefix of the following symbol. */
+{
+ PgfTokens default_form;
+ /**< Default form that this symbol takes if none of of the
+ * variant forms is triggered. */
+
+ GuLength n_forms;
+ PgfAlternative forms[];
+ /**< Variant forms whose choise depends on the following
+ * symbol. */
+} PgfSymbolKP;
-#endif /* PGF_PRIVATE_H_ */
+typedef GuSeq PgfSequence; // -> PgfSymbol
+typedef GuList(PgfSequence) PgfSequences;
+
+typedef struct {
+ PgfCId name;
+ PgfExprProb *ep;
+ int funid;
+ GuLength n_lins;
+ PgfSequence lins[];
+} PgfCncFun;
+
+typedef GuList(PgfCncFun*) PgfCncFuns;
+
+struct PgfConcr {
+ PgfFlags* cflags;
+ PgfPrintNames* printnames;
+ GuMap* ccats;
+ PgfCncFunOverloadMap* fun_indices;
+ PgfCncOverloadMap* coerce_idx;
+ PgfProductionIdx* epsilon_idx;
+ PgfLeftcornerCatIdx* leftcorner_cat_idx;
+ PgfLeftcornerTokIdx* leftcorner_tok_idx;
+ PgfCncFuns* cncfuns;
+ PgfSequences* sequences;
+ PgfCIdMap* cnccats;
+ PgfCallbacksMap* callbacks;
+ int total_cats;
+};
+
+extern GU_DECLARE_TYPE(PgfConcr, abstract);
+
+
+// PgfProduction
+
+typedef GuVariant PgfProduction;
+
+typedef enum {
+ PGF_PRODUCTION_APPLY,
+ PGF_PRODUCTION_COERCE,
+ PGF_PRODUCTION_EXTERN,
+ PGF_PRODUCTION_META
+} PgfProductionTag;
+
+typedef struct {
+ PgfCCat* ccat;
+ PgfCCats* hypos;
+} PgfPArg;
+
+typedef GuSeq PgfPArgs;
+
+typedef struct {
+ PgfCncFun* fun;
+ PgfPArgs args;
+} PgfProductionApply;
+
+typedef struct PgfProductionCoerce
+/** A coercion. This production is a logical union of the coercions of
+ * another FId. This allows common subsets of productions to be
+ * shared. */
+{
+ PgfCCat* coerce;
+} PgfProductionCoerce;
+
+typedef struct {
+ PgfLiteralCallback *callback;
+ PgfExprProb *ep;
+ GuSeq lins;
+} PgfProductionExtern;
+
+typedef struct {
+ PgfExprProb *ep;
+ PgfPArgs args;
+} PgfProductionMeta;
+
+typedef GuSeq PgfProductionSeq;
+extern GU_DECLARE_TYPE(PgfProductionSeq, GuSeq);
+
+struct PgfCCat {
+ PgfCncCat* cnccat;
+ PgfCncFuns* lindefs;
+ size_t n_synprods;
+ PgfProductionSeq prods;
+ float viterbi_prob;
+ int fid;
+ PgfItemConts* conts;
+};
+
+#endif
diff --git a/src/runtime/c/pgf/linearizer.c b/src/runtime/c/pgf/linearizer.c
index 923484ada..18d7ab627 100644
--- a/src/runtime/c/pgf/linearizer.c
+++ b/src/runtime/c/pgf/linearizer.c
@@ -208,7 +208,7 @@ redo:;
}
static PgfCncTree
-pgf_lzn_resolve_def(PgfLzn* lzn, PgfFunIds* lindefs, GuString s, GuPool* pool)
+pgf_lzn_resolve_def(PgfLzn* lzn, PgfCncFuns* lindefs, GuString s, GuPool* pool)
{
PgfCncTree lit = gu_null_variant;
PgfCncTree ret = gu_null_variant;
@@ -286,13 +286,12 @@ pgf_lzn_resolve(PgfLzn* lzn, PgfExpr expr, PgfCCat* ccat, GuPool* pool)
goto done;
}
case PGF_EXPR_META: {
- PgfFunIds* lindefs = NULL;
if (ccat != NULL && ccat->lindefs == NULL) {
goto done;
}
GuString s = gu_str_string("?", pool);
- ret = pgf_lzn_resolve_def(lzn, lindefs, s, pool);
+ ret = pgf_lzn_resolve_def(lzn, ccat->lindefs, s, pool);
goto done;
}
case PGF_EXPR_FUN: {
@@ -301,7 +300,6 @@ pgf_lzn_resolve(PgfLzn* lzn, PgfExpr expr, PgfCCat* ccat, GuPool* pool)
PgfCncOverloadMap* overl_table =
gu_map_get(lzn->concr->fun_indices, &efun->fun, PgfCncOverloadMap*);
if (overl_table == NULL) {
- PgfFunIds* lindefs = NULL;
if (ccat != NULL && ccat->lindefs == NULL) {
goto done;
}
@@ -316,7 +314,7 @@ pgf_lzn_resolve(PgfLzn* lzn, PgfExpr expr, PgfCCat* ccat, GuPool* pool)
gu_putc(']', wtr, err);
GuString s = gu_string_buf_freeze(sbuf, tmp_pool);
- ret = pgf_lzn_resolve_def(lzn, lindefs, s, pool);
+ ret = pgf_lzn_resolve_def(lzn, ccat->lindefs, s, pool);
gu_pool_free(tmp_pool);
goto done;
diff --git a/src/runtime/c/pgf/parser.c b/src/runtime/c/pgf/parser.c
index 808938d4c..e69ff173e 100644
--- a/src/runtime/c/pgf/parser.c
+++ b/src/runtime/c/pgf/parser.c
@@ -1093,7 +1093,7 @@ pgf_parsing_meta_predict(GuMapItor* fn, const void* key, void* value, GuExn* err
{
(void) (err);
- PgfCat* abscat = (PgfCat*) key;
+ PgfAbsCat* abscat = (PgfAbsCat*) key;
prob_t meta_prob = *((prob_t*) value);
PgfMetaPredictFn* clo = (PgfMetaPredictFn*) fn;
PgfParseState* before = clo->before;
diff --git a/src/runtime/c/pgf/pgf.c b/src/runtime/c/pgf/pgf.c
index e9e25e25c..9f836150a 100644
--- a/src/runtime/c/pgf/pgf.c
+++ b/src/runtime/c/pgf/pgf.c
@@ -58,8 +58,8 @@ pgf_load_meta_child_probs(PgfPGF* pgf, const char* fpath,
prob = - log(prob);
GuString cat1 = gu_str_string(cat1_s, tmp_pool);
- PgfCat* abscat1 =
- gu_map_get(pgf->abstract.cats, &cat1, PgfCat*);
+ PgfAbsCat* abscat1 =
+ gu_map_get(pgf->abstract.cats, &cat1, PgfAbsCat*);
if (abscat1 == NULL) {
gu_raise(err, PgfExn);
goto close;
@@ -71,7 +71,7 @@ pgf_load_meta_child_probs(PgfPGF* pgf, const char* fpath,
abscat1->meta_token_prob = prob;
} else {
GuString cat2 = gu_str_string(cat2_s, tmp_pool);
- PgfCat* abscat2 = gu_map_get(pgf->abstract.cats, &cat2, PgfCat*);
+ PgfAbsCat* abscat2 = gu_map_get(pgf->abstract.cats, &cat2, PgfAbsCat*);
if (abscat2 == NULL) {
gu_raise(err, PgfExn);
goto close;
@@ -148,8 +148,8 @@ void
pgf_iter_functions_by_cat(PgfPGF* pgf, PgfCId catname,
GuMapItor* fn, GuExn* err)
{
- PgfCat* abscat =
- gu_map_get(pgf->abstract.cats, &catname, PgfCat*);
+ PgfAbsCat* abscat =
+ gu_map_get(pgf->abstract.cats, &catname, PgfAbsCat*);
if (abscat == NULL) {
gu_raise(err, PgfExn);
return;
@@ -157,8 +157,8 @@ pgf_iter_functions_by_cat(PgfPGF* pgf, PgfCId catname,
size_t n_functions = gu_buf_length(abscat->functions);
for (size_t i = 0; i < n_functions; i++) {
- PgfFunDecl* fun =
- gu_buf_get(abscat->functions, PgfFunDecl*, i);
+ PgfAbsFun* fun =
+ gu_buf_get(abscat->functions, PgfAbsFun*, i);
GuVariantInfo i = gu_variant_open(fun->ep.expr);
switch (i.tag) {
diff --git a/src/runtime/c/pgf/pgf.h b/src/runtime/c/pgf/pgf.h
index 1f3947bff..032834d77 100644
--- a/src/runtime/c/pgf/pgf.h
+++ b/src/runtime/c/pgf/pgf.h
@@ -42,10 +42,8 @@ extern GU_DECLARE_TYPE(PgfExn, abstract);
/// @{
typedef struct PgfPGF PgfPGF;
-extern GU_DECLARE_TYPE(PgfPGF, struct);
typedef struct PgfConcr PgfConcr;
-extern GU_DECLARE_TYPE(PgfConcr, struct);
/**< A representation of a PGF grammar.
diff --git a/src/runtime/c/pgf/printer.c b/src/runtime/c/pgf/printer.c
index 140688eb5..cf851d386 100644
--- a/src/runtime/c/pgf/printer.c
+++ b/src/runtime/c/pgf/printer.c
@@ -27,7 +27,7 @@ pgf_print_cat(GuMapItor* fn, const void* key, void* value,
{
PgfPrintFn* clo = (PgfPrintFn*) fn;
PgfCId name = *((PgfCId *) key);
- PgfCat *cat = *((PgfCat **) value);
+ PgfAbsCat *cat = *((PgfAbsCat **) value);
GuWriter *wtr = clo->wtr;
gu_puts(" cat ", wtr, err);
@@ -49,7 +49,7 @@ pgf_print_absfun(GuMapItor* fn, const void* key, void* value,
{
PgfPrintFn* clo = (PgfPrintFn*) fn;
PgfCId name = *((PgfCId *) key);
- PgfFunDecl *fun = *((PgfFunDecl **) value);
+ PgfAbsFun *fun = *((PgfAbsFun **) value);
GuWriter *wtr = clo->wtr;
gu_puts(gu_seq_is_null(fun->defns) ? " data " : " fun ", wtr, err);
@@ -149,8 +149,8 @@ pgf_print_lindefs(GuMapItor* fn, const void* key, void* value,
for (size_t i = 0; i < n_lindefs; i++) {
if (i > 0) gu_putc(' ', wtr, err);
- PgfFunId funid = gu_list_index(ccat->lindefs, i);
- gu_printf(wtr,err,"F%d",funid->funid);
+ PgfCncFun* fun = gu_list_index(ccat->lindefs, i);
+ gu_printf(wtr,err,"F%d",fun->funid);
}
gu_putc('\n', wtr,err);
diff --git a/src/runtime/c/pgf/reader.c b/src/runtime/c/pgf/reader.c
index dafa51626..874f90fb3 100644
--- a/src/runtime/c/pgf/reader.c
+++ b/src/runtime/c/pgf/reader.c
@@ -412,10 +412,10 @@ pgf_read_patt(PgfReader* rdr)
return patt;
}
-static PgfFunDecl*
-pgf_read_fundecl(PgfReader* rdr, PgfCId name)
+static PgfAbsFun*
+pgf_read_absfun(PgfReader* rdr, PgfCId name)
{
- PgfFunDecl* absfun = gu_new(PgfFunDecl, rdr->opool);
+ PgfAbsFun* absfun = gu_new(PgfAbsFun, rdr->opool);
absfun->type = pgf_read_type(rdr);
gu_return_on_exn(rdr->err, NULL);
@@ -474,7 +474,7 @@ pgf_read_absfuns(PgfReader* rdr)
{
GuMapType* map_type = (GuMapType*)
GU_TYPE_LIT(GuStringMap, _,
- gu_ptr_type(PgfFunDecl),
+ gu_ptr_type(PgfAbsFun),
&gu_null_struct);
PgfCIdMap* absfuns = gu_map_type_make(map_type, rdr->opool);
@@ -485,19 +485,19 @@ pgf_read_absfuns(PgfReader* rdr)
PgfCId name = pgf_read_cid(rdr);
gu_return_on_exn(rdr->err, NULL);
- PgfFunDecl* decl = pgf_read_fundecl(rdr, name);
+ PgfAbsFun* decl = pgf_read_absfun(rdr, name);
gu_return_on_exn(rdr->err, NULL);
- gu_map_put(absfuns, &name, PgfFunDecl*, decl);
+ gu_map_put(absfuns, &name, PgfAbsFun*, decl);
}
return absfuns;
}
-static PgfCat*
+static PgfAbsCat*
pgf_read_abscat(PgfReader* rdr, PgfAbstr* abstr, PgfCId name)
{
- PgfCat* abscat = gu_new(PgfCat, rdr->opool);
+ PgfAbsCat* abscat = gu_new(PgfAbsCat, rdr->opool);
abscat->name = name;
@@ -514,7 +514,7 @@ pgf_read_abscat(PgfReader* rdr, PgfAbstr* abstr, PgfCId name)
abscat->meta_token_prob = INFINITY;
abscat->meta_child_probs = NULL;
- abscat->functions = gu_new_buf(PgfFunDecl*, rdr->opool);
+ abscat->functions = gu_new_buf(PgfAbsFun*, rdr->opool);
size_t n_functions = pgf_read_len(rdr);
gu_return_on_exn(rdr->err, NULL);
@@ -526,9 +526,9 @@ pgf_read_abscat(PgfReader* rdr, PgfAbstr* abstr, PgfCId name)
PgfCId name = pgf_read_cid(rdr);
gu_return_on_exn(rdr->err, NULL);
- PgfFunDecl* absfun =
- gu_map_get(abstr->funs, &name, PgfFunDecl*);
- gu_buf_push(abscat->functions, PgfFunDecl*, absfun);
+ PgfAbsFun* absfun =
+ gu_map_get(abstr->funs, &name, PgfAbsFun*);
+ gu_buf_push(abscat->functions, PgfAbsFun*, absfun);
}
return abscat;
@@ -539,7 +539,7 @@ pgf_read_abscats(PgfReader* rdr, PgfAbstr* abstr)
{
GuMapType* map_type = (GuMapType*)
GU_TYPE_LIT(GuStringMap, _,
- gu_ptr_type(PgfCat),
+ gu_ptr_type(PgfAbsCat),
&gu_null_struct);
PgfCIdMap* abscats = gu_map_type_make(map_type, rdr->opool);
@@ -550,10 +550,10 @@ pgf_read_abscats(PgfReader* rdr, PgfAbstr* abstr)
PgfCId name = pgf_read_cid(rdr);
gu_return_on_exn(rdr->err, NULL);
- PgfCat* abscat = pgf_read_abscat(rdr, abstr, name);
+ PgfAbsCat* abscat = pgf_read_abscat(rdr, abstr, name);
gu_return_on_exn(rdr->err, NULL);
- gu_map_put(abscats, &name, PgfCat*, abscat);
+ gu_map_put(abscats, &name, PgfAbsCat*, abscat);
}
return abscats;
@@ -763,8 +763,8 @@ pgf_read_cncfun(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, int funid)
cncfun->funid = funid;
cncfun->n_lins = len;
- PgfFunDecl* absfun =
- gu_map_get(abstr->funs, &cncfun->name, PgfFunDecl*);
+ PgfAbsFun* absfun =
+ gu_map_get(abstr->funs, &cncfun->name, PgfAbsFun*);
cncfun->ep = (absfun == NULL) ? NULL : &absfun->ep;
for (size_t i = 0; i < len; i++) {
@@ -849,7 +849,7 @@ pgf_read_lindefs(PgfReader* rdr, PgfConcr* concr)
size_t n_funs = pgf_read_len(rdr);
gu_return_on_exn(rdr->err, );
- ccat->lindefs = gu_new_list(PgfFunIds, rdr->opool, n_funs);
+ ccat->lindefs = gu_new_list(PgfCncFuns, rdr->opool, n_funs);
for (size_t j = 0; j < n_funs; j++) {
PgfCncFun* fun = pgf_read_funid(rdr, concr);
gu_list_index(ccat->lindefs, j) = fun;
@@ -863,7 +863,7 @@ pgf_read_parg(PgfReader* rdr, PgfConcr* concr, PgfPArg* parg)
size_t n_hoas = pgf_read_len(rdr);
gu_return_on_exn(rdr->err, );
- parg->hypos = gu_new_list(PgfCCatIds, rdr->opool, n_hoas);
+ parg->hypos = gu_new_list(PgfCCats, rdr->opool, n_hoas);
for (size_t i = 0; i < n_hoas; i++) {
gu_list_index(parg->hypos, i) = pgf_read_fid(rdr, concr);
gu_return_on_exn(rdr->err, );
@@ -967,11 +967,11 @@ pgf_read_cnccat(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, PgfCId name)
gu_malloc(rdr->opool, sizeof(PgfCncCat)+n_lins*sizeof(GuString));
cnccat->abscat =
- gu_map_get(abstr->cats, &name, PgfCat*);
+ gu_map_get(abstr->cats, &name, PgfAbsCat*);
gu_assert(cnccat->abscat != NULL);
int len = last + 1 - first;
- cnccat->cats = gu_new_list(PgfCCatIds, rdr->opool, len);
+ cnccat->cats = gu_new_list(PgfCCats, rdr->opool, len);
for (int i = 0; i < len; i++) {
int fid = first + i;
diff --git a/src/runtime/c/pgf/reasoner.c b/src/runtime/c/pgf/reasoner.c
index 07bd3735a..67ef077ed 100644
--- a/src/runtime/c/pgf/reasoner.c
+++ b/src/runtime/c/pgf/reasoner.c
@@ -154,7 +154,7 @@ pgf_reasoner_predict(PgfReasoner* rs, PgfExprState* cont,
gu_buf_push(answers->conts, PgfExprState*, cont);
if (gu_buf_length(answers->conts) == 1) {
- PgfCat* abscat = gu_map_get(rs->abstract->cats, &cat, PgfCat*);
+ PgfAbsCat* abscat = gu_map_get(rs->abstract->cats, &cat, PgfAbsCat*);
if (abscat == NULL) {
return;
}
@@ -166,7 +166,7 @@ pgf_reasoner_predict(PgfReasoner* rs, PgfExprState* cont,
q->choice_idx = 0;
q->choices = abscat->functions;
- q->prob = answers->outside_prob + gu_buf_get(q->choices, PgfFunDecl*, 0)->ep.prob;
+ q->prob = answers->outside_prob + gu_buf_get(q->choices, PgfAbsFun*, 0)->ep.prob;
gu_buf_heap_push(rs->pqueue, &pgf_expr_qstate_order, &q);
}
} else {
@@ -196,8 +196,8 @@ pgf_reasoner_next(PgfReasoner* rs, GuPool* pool)
PgfExprState* st = NULL;
switch (q->kind) {
case PGF_EXPR_QSTATE_PREDICT: {
- PgfFunDecl* absfun =
- gu_buf_get(q->choices, PgfFunDecl*, q->choice_idx);
+ PgfAbsFun* absfun =
+ gu_buf_get(q->choices, PgfAbsFun*, q->choice_idx);
st = gu_new(PgfExprState, pool);
st->answers = q->single;
@@ -207,7 +207,7 @@ pgf_reasoner_next(PgfReasoner* rs, GuPool* pool)
q->choice_idx++;
if (q->choice_idx < gu_buf_length(q->choices)) {
- q->prob = st->answers->outside_prob + gu_buf_get(q->choices, PgfFunDecl*, q->choice_idx)->ep.prob;
+ q->prob = st->answers->outside_prob + gu_buf_get(q->choices, PgfAbsFun*, q->choice_idx)->ep.prob;
gu_buf_heap_push(rs->pqueue, &pgf_expr_qstate_order, &q);
}
break;
diff --git a/src/runtime/c/utils/pgf2yaml.c b/src/runtime/c/utils/pgf2yaml.c
deleted file mode 100644
index 0d32bf3e3..000000000
--- a/src/runtime/c/utils/pgf2yaml.c
+++ /dev/null
@@ -1,34 +0,0 @@
-#include
-
-#include
-#include
-#include
-
-int main(int argc, char* argv[]) {
- if (argc != 1) {
- fprintf(stderr, "usage: %s pgf\n", argv[0]);
- return 1;
- }
- char* filename = argv[1];
-
- GuPool* pool = gu_new_pool();
- GuExn* err = gu_exn(NULL, type, pool);
- PgfPGF* pgf = pgf_read(filename, pool, err);
- int status = 0;
- if (!gu_ok(err)) {
- fprintf(stderr, "Reading PGF failed\n");
- status = 1;
- goto fail_read;
- }
- GuOut* out = gu_file_out(stdout, pool);
- GuOut* bout = gu_out_buffered(out, pool);
- // GuWriter* wtr = gu_locale_writer(bout, pool);
- GuWriter* wtr = gu_new_utf8_writer(bout, pool);
- GuDump* ctx = gu_new_dump(wtr, NULL, err, pool);
- gu_dump(gu_type(PgfPGF), pgf, ctx);
- gu_writer_flush(wtr, err);
-fail_read:
- gu_pool_free(pool);
- return status;
-}
-