mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-16 00:09:31 -06:00
a major refactoring in the C runtime. GuList is now removed and replaced with GuSeq. The GuSeq/GuBuf API is simplified
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <math.h>
|
||||
|
||||
bool
|
||||
pgf_tokens_equal(PgfTokens t1, PgfTokens t2)
|
||||
pgf_tokens_equal(PgfTokens* t1, PgfTokens* t2)
|
||||
{
|
||||
size_t len1 = gu_seq_length(t1);
|
||||
size_t len2 = gu_seq_length(t2);
|
||||
@@ -36,7 +36,8 @@ GU_DEFINE_TYPE(PgfDummyVariant, GuVariant);
|
||||
|
||||
GU_DEFINE_TYPE(PgfFlags, GuStringMap, gu_type(PgfDummyVariant), &gu_null_variant);
|
||||
|
||||
GU_DEFINE_TYPE(PgfProductionSeq, GuSeq, gu_type(PgfDummyVariant));
|
||||
GU_DEFINE_TYPE(PgfProductionSeq, abstract);
|
||||
GU_DEFINE_TYPE(PgfProductionBuf, abstract);
|
||||
|
||||
GU_DEFINE_TYPE(PgfAbsFun, abstract);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef PGF_DATA_H_
|
||||
#define PGF_DATA_H_
|
||||
|
||||
#include <gu/list.h>
|
||||
#include <gu/variant.h>
|
||||
#include <gu/map.h>
|
||||
#include <gu/string.h>
|
||||
@@ -12,7 +11,7 @@
|
||||
typedef struct PgfCCat PgfCCat;
|
||||
extern GU_DECLARE_TYPE(PgfCCat, abstract);
|
||||
|
||||
typedef GuList(PgfCCat*) PgfCCats;
|
||||
typedef GuSeq PgfCCats;
|
||||
|
||||
#define PgfCIdMap GuStringMap
|
||||
typedef PgfCIdMap PgfFlags; // PgfCId -> PgfLiteral
|
||||
@@ -74,7 +73,7 @@ typedef struct {
|
||||
PgfCId name;
|
||||
PgfType* type;
|
||||
int arity;
|
||||
PgfEquations defns; // maybe null
|
||||
PgfEquations* defns; // maybe null
|
||||
PgfExprProb ep;
|
||||
void* predicate;
|
||||
} PgfAbsFun;
|
||||
@@ -86,7 +85,7 @@ extern GU_DECLARE_TYPE(PgfMetaChildMap, GuMap);
|
||||
|
||||
typedef struct {
|
||||
PgfCId name;
|
||||
PgfHypos context;
|
||||
PgfHypos* context;
|
||||
|
||||
prob_t meta_prob;
|
||||
prob_t meta_token_prob;
|
||||
@@ -130,15 +129,13 @@ typedef struct {
|
||||
extern GU_DECLARE_TYPE(PgfCncCat, abstract);
|
||||
|
||||
bool
|
||||
pgf_tokens_equal(PgfTokens t1, PgfTokens t2);
|
||||
|
||||
typedef GuList(GuString) GuStringL;
|
||||
pgf_tokens_equal(PgfTokens* t1, PgfTokens* t2);
|
||||
|
||||
typedef struct {
|
||||
PgfTokens form;
|
||||
PgfTokens* form;
|
||||
/**< The form of this variant as a list of tokens. */
|
||||
|
||||
GuStringL* prefixes;
|
||||
GuStrings* prefixes;
|
||||
/**< The prefixes of the following symbol that trigger this
|
||||
* form. */
|
||||
} PgfAlternative;
|
||||
@@ -189,14 +186,14 @@ typedef struct {
|
||||
typedef PgfSymbolIdx PgfSymbolCat, PgfSymbolLit, PgfSymbolVar;
|
||||
|
||||
typedef struct {
|
||||
PgfTokens tokens;
|
||||
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;
|
||||
PgfTokens* default_form;
|
||||
/**< Default form that this symbol takes if none of of the
|
||||
* variant forms is triggered. */
|
||||
|
||||
@@ -210,17 +207,17 @@ typedef struct {
|
||||
} PgfSymbolNE;
|
||||
|
||||
typedef GuSeq PgfSequence; // -> PgfSymbol
|
||||
typedef GuList(PgfSequence) PgfSequences;
|
||||
typedef GuSeq PgfSequences;
|
||||
|
||||
typedef struct {
|
||||
PgfAbsFun* absfun;
|
||||
PgfExprProb *ep;
|
||||
int funid;
|
||||
GuLength n_lins;
|
||||
PgfSequence lins[];
|
||||
PgfSequence* lins[];
|
||||
} PgfCncFun;
|
||||
|
||||
typedef GuList(PgfCncFun*) PgfCncFuns;
|
||||
typedef GuSeq PgfCncFuns;
|
||||
|
||||
struct PgfConcr {
|
||||
PgfCId name;
|
||||
@@ -261,7 +258,7 @@ typedef GuSeq PgfPArgs;
|
||||
|
||||
typedef struct {
|
||||
PgfCncFun* fun;
|
||||
PgfPArgs args;
|
||||
PgfPArgs* args;
|
||||
} PgfProductionApply;
|
||||
|
||||
typedef struct PgfProductionCoerce
|
||||
@@ -275,26 +272,30 @@ typedef struct PgfProductionCoerce
|
||||
typedef struct {
|
||||
PgfLiteralCallback *callback;
|
||||
PgfExprProb *ep;
|
||||
GuSeq lins;
|
||||
GuSeq* lins;
|
||||
} PgfProductionExtern;
|
||||
|
||||
typedef struct {
|
||||
PgfExprProb *ep;
|
||||
PgfPArgs args;
|
||||
PgfPArgs* args;
|
||||
} PgfProductionMeta;
|
||||
|
||||
typedef GuSeq PgfProductionSeq;
|
||||
extern GU_DECLARE_TYPE(PgfProductionSeq, GuSeq);
|
||||
typedef GuSeq PgfProductionSeq;
|
||||
extern GU_DECLARE_TYPE(PgfProductionSeq, abstract);
|
||||
|
||||
typedef GuBuf PgfProductionBuf;
|
||||
extern GU_DECLARE_TYPE(PgfProductionBuf, abstract);
|
||||
|
||||
struct PgfCCat {
|
||||
PgfCncCat* cnccat;
|
||||
PgfCncFuns* lindefs;
|
||||
size_t n_synprods;
|
||||
PgfProductionSeq prods;
|
||||
PgfProductionSeq* prods;
|
||||
float viterbi_prob;
|
||||
int fid;
|
||||
PgfItemConts* conts;
|
||||
struct PgfAnswers* answers;
|
||||
GuFinalizer fin[0];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -91,20 +91,12 @@ GU_DEFINE_TYPE(PgfHypo, struct,
|
||||
GU_MEMBER(PgfHypo, cid, PgfCId),
|
||||
GU_MEMBER_P(PgfHypo, type, PgfType));
|
||||
|
||||
GU_DEFINE_TYPE(PgfHypos, GuSeq, gu_type(PgfHypo));
|
||||
|
||||
GU_DEFINE_TYPE(PgfType, struct,
|
||||
GU_MEMBER(PgfType, hypos, PgfHypos),
|
||||
GU_MEMBER(PgfType, cid, PgfCId),
|
||||
GU_MEMBER(PgfType, n_exprs, GuLength),
|
||||
GU_FLEX_MEMBER(PgfType, exprs, PgfExpr));
|
||||
|
||||
GU_DEFINE_TYPE(
|
||||
PgfExpr, GuVariant,
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_ABS, PgfExprAbs,
|
||||
GU_MEMBER(PgfExprAbs, bind_type, PgfBindType),
|
||||
GU_MEMBER(PgfExprAbs, id, GuStr),
|
||||
GU_MEMBER(PgfExprAbs, id, GuString),
|
||||
GU_MEMBER(PgfExprAbs, body, PgfExpr)),
|
||||
GU_CONSTRUCTOR_S(
|
||||
PGF_EXPR_APP, PgfExprApp,
|
||||
@@ -160,7 +152,7 @@ struct PgfExprParser {
|
||||
GuPool* expr_pool;
|
||||
GuPool* tmp_pool;
|
||||
PGF_TOKEN_TAG token_tag;
|
||||
GuChars token_value;
|
||||
GuCharBuf* token_value;
|
||||
int ch;
|
||||
};
|
||||
|
||||
@@ -182,7 +174,7 @@ pgf_expr_parser_token(PgfExprParser* parser)
|
||||
}
|
||||
|
||||
parser->token_tag = PGF_TOKEN_UNKNOWN;
|
||||
parser->token_value = gu_null_seq;
|
||||
parser->token_value = NULL;
|
||||
|
||||
switch (parser->ch) {
|
||||
case EOF:
|
||||
@@ -250,7 +242,7 @@ pgf_expr_parser_token(PgfExprParser* parser)
|
||||
pgf_expr_parser_getc(parser);
|
||||
}
|
||||
parser->token_tag = PGF_TOKEN_IDENT;
|
||||
parser->token_value = gu_buf_seq(chars);
|
||||
parser->token_value = chars;
|
||||
} else if (isdigit(parser->ch)) {
|
||||
while (isdigit(parser->ch)) {
|
||||
gu_buf_push(chars, char, parser->ch);
|
||||
@@ -266,10 +258,10 @@ pgf_expr_parser_token(PgfExprParser* parser)
|
||||
pgf_expr_parser_getc(parser);
|
||||
}
|
||||
parser->token_tag = PGF_TOKEN_FLT;
|
||||
parser->token_value = gu_buf_seq(chars);
|
||||
parser->token_value = chars;
|
||||
} else {
|
||||
parser->token_tag = PGF_TOKEN_INT;
|
||||
parser->token_value = gu_buf_seq(chars);
|
||||
parser->token_value = chars;
|
||||
}
|
||||
} else if (parser->ch == '"') {
|
||||
pgf_expr_parser_getc(parser);
|
||||
@@ -282,7 +274,7 @@ pgf_expr_parser_token(PgfExprParser* parser)
|
||||
if (parser->ch == '"') {
|
||||
pgf_expr_parser_getc(parser);
|
||||
parser->token_tag = PGF_TOKEN_STR;
|
||||
parser->token_value = gu_buf_seq(chars);
|
||||
parser->token_value = chars;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -350,7 +342,7 @@ pgf_expr_parser_term(PgfExprParser* parser)
|
||||
}
|
||||
case PGF_TOKEN_IDENT: {
|
||||
char* str =
|
||||
gu_chars_str(parser->token_value, parser->tmp_pool);
|
||||
gu_char_buf_str(parser->token_value, parser->tmp_pool);
|
||||
PgfCId id = gu_str_string(str, parser->expr_pool);
|
||||
pgf_expr_parser_token(parser);
|
||||
return gu_new_variant_i(parser->expr_pool,
|
||||
@@ -360,7 +352,7 @@ pgf_expr_parser_term(PgfExprParser* parser)
|
||||
}
|
||||
case PGF_TOKEN_INT: {
|
||||
char* str =
|
||||
gu_chars_str(parser->token_value, parser->tmp_pool);
|
||||
gu_char_buf_str(parser->token_value, parser->tmp_pool);
|
||||
int n = atoi(str);
|
||||
pgf_expr_parser_token(parser);
|
||||
PgfLiteral lit =
|
||||
@@ -375,7 +367,7 @@ pgf_expr_parser_term(PgfExprParser* parser)
|
||||
}
|
||||
case PGF_TOKEN_STR: {
|
||||
char* str =
|
||||
gu_chars_str(parser->token_value, parser->tmp_pool);
|
||||
gu_char_buf_str(parser->token_value, parser->tmp_pool);
|
||||
GuString s = gu_str_string(str, parser->expr_pool);
|
||||
pgf_expr_parser_token(parser);
|
||||
PgfLiteral lit =
|
||||
@@ -390,7 +382,7 @@ pgf_expr_parser_term(PgfExprParser* parser)
|
||||
}
|
||||
case PGF_TOKEN_FLT: {
|
||||
char* str =
|
||||
gu_chars_str(parser->token_value, parser->tmp_pool);
|
||||
gu_char_buf_str(parser->token_value, parser->tmp_pool);
|
||||
double d = atof(str);
|
||||
pgf_expr_parser_token(parser);
|
||||
PgfLiteral lit =
|
||||
@@ -451,7 +443,7 @@ pgf_expr_parser_bind(PgfExprParser* parser, GuBuf* binds)
|
||||
for (;;) {
|
||||
if (parser->token_tag == PGF_TOKEN_IDENT) {
|
||||
char* str =
|
||||
gu_chars_str(parser->token_value, parser->tmp_pool);
|
||||
gu_char_buf_str(parser->token_value, parser->tmp_pool);
|
||||
var = gu_str_string(str, parser->expr_pool);
|
||||
pgf_expr_parser_token(parser);
|
||||
} else if (parser->token_tag == PGF_TOKEN_WILD) {
|
||||
@@ -571,7 +563,7 @@ pgf_expr_parser_hypos(PgfExprParser* parser, GuBuf* hypos)
|
||||
|
||||
if (parser->token_tag == PGF_TOKEN_IDENT) {
|
||||
char* str =
|
||||
gu_chars_str(parser->token_value, parser->tmp_pool);
|
||||
gu_char_buf_str(parser->token_value, parser->tmp_pool);
|
||||
var = gu_str_string(str, parser->expr_pool);
|
||||
pgf_expr_parser_token(parser);
|
||||
} else if (parser->token_tag == PGF_TOKEN_WILD) {
|
||||
@@ -612,7 +604,7 @@ pgf_expr_parser_atom(PgfExprParser* parser)
|
||||
return NULL;
|
||||
|
||||
char* str =
|
||||
gu_chars_str(parser->token_value, parser->tmp_pool);
|
||||
gu_char_buf_str(parser->token_value, parser->tmp_pool);
|
||||
PgfCId cid = gu_str_string(str, parser->expr_pool);
|
||||
pgf_expr_parser_token(parser);
|
||||
|
||||
@@ -712,7 +704,7 @@ pgf_expr_parser_type(PgfExprParser* parser)
|
||||
}
|
||||
}
|
||||
|
||||
type->hypos = gu_buf_seq(hypos);
|
||||
type->hypos = gu_buf_data_seq(hypos);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ typedef GuVariant PgfExpr;
|
||||
|
||||
extern GU_DECLARE_TYPE(PgfExpr, GuVariant);
|
||||
|
||||
typedef GuList(PgfExpr) PgfExprs;
|
||||
|
||||
typedef struct PgfHypo PgfHypo;
|
||||
typedef struct PgfType PgfType;
|
||||
|
||||
@@ -63,10 +61,9 @@ struct PgfHypo {
|
||||
};
|
||||
|
||||
typedef GuSeq PgfHypos;
|
||||
extern GU_DECLARE_TYPE(PgfHypos, GuSeq);
|
||||
|
||||
struct PgfType {
|
||||
PgfHypos hypos;
|
||||
PgfHypos* hypos;
|
||||
PgfCId cid; /// XXX: resolve to PgfCat*?
|
||||
size_t n_exprs;
|
||||
PgfExpr exprs[];
|
||||
|
||||
@@ -116,7 +116,7 @@ typedef struct {
|
||||
} PgfBracketLznState;
|
||||
|
||||
static void
|
||||
pgf_bracket_lzn_symbol_tokens(PgfLinFuncs** funcs, PgfTokens toks)
|
||||
pgf_bracket_lzn_symbol_tokens(PgfLinFuncs** funcs, PgfTokens* toks)
|
||||
{
|
||||
PgfBracketLznState* state = gu_container(funcs, PgfBracketLznState, funcs);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include <gu/list.h>
|
||||
#include <gu/utf8.h>
|
||||
#include <pgf/pgf.h>
|
||||
#include <pgf/data.h>
|
||||
|
||||
@@ -237,7 +237,7 @@ pgf_lzn_resolve_def(PgfLzn* lzn, PgfCncFuns* lindefs, GuString s, GuPool* pool)
|
||||
return lit;
|
||||
|
||||
int index =
|
||||
gu_choice_next(lzn->ch, gu_list_length(lindefs));
|
||||
gu_choice_next(lzn->ch, gu_seq_length(lindefs));
|
||||
if (index < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -245,7 +245,7 @@ pgf_lzn_resolve_def(PgfLzn* lzn, PgfCncFuns* lindefs, GuString s, GuPool* pool)
|
||||
gu_new_flex_variant(PGF_CNC_TREE_APP,
|
||||
PgfCncTreeApp,
|
||||
args, 1, &ret, pool);
|
||||
capp->fun = gu_list_index(lindefs, index);
|
||||
capp->fun = gu_seq_get(lindefs, PgfCncFun*, index);
|
||||
capp->fid = lzn->fid++;
|
||||
capp->n_args = 1;
|
||||
capp->args[0] = lit;
|
||||
@@ -472,7 +472,7 @@ pgf_lzr_linearize(PgfConcr* concr, PgfCncTree ctree, size_t lin_idx, PgfLinFuncs
|
||||
}
|
||||
|
||||
gu_require(lin_idx < fun->n_lins);
|
||||
PgfSequence seq = fun->lins[lin_idx];
|
||||
PgfSequence* seq = fun->lins[lin_idx];
|
||||
size_t nsyms = gu_seq_length(seq);
|
||||
PgfSymbol* syms = gu_seq_data(seq);
|
||||
for (size_t i = 0; i < nsyms; i++) {
|
||||
@@ -572,7 +572,7 @@ struct PgfSimpleLin {
|
||||
};
|
||||
|
||||
static void
|
||||
pgf_file_lzn_symbol_tokens(PgfLinFuncs** funcs, PgfTokens toks)
|
||||
pgf_file_lzn_symbol_tokens(PgfLinFuncs** funcs, PgfTokens* toks)
|
||||
{
|
||||
PgfSimpleLin* flin = gu_container(funcs, PgfSimpleLin, funcs);
|
||||
if (!gu_ok(flin->err)) {
|
||||
|
||||
@@ -51,7 +51,7 @@ typedef struct PgfLinFuncs PgfLinFuncs;
|
||||
struct PgfLinFuncs
|
||||
{
|
||||
/// Output tokens
|
||||
void (*symbol_tokens)(PgfLinFuncs** self, PgfTokens toks);
|
||||
void (*symbol_tokens)(PgfLinFuncs** self, PgfTokens* toks);
|
||||
|
||||
/// Output literal
|
||||
void (*expr_literal)(PgfLinFuncs** self, PgfLiteral lit);
|
||||
|
||||
@@ -18,7 +18,7 @@ pgf_match_string_lit(PgfConcr* concr, PgfItem* item, PgfToken tok,
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
|
||||
size_t lin_idx;
|
||||
PgfSequence seq;
|
||||
PgfSequence* seq;
|
||||
pgf_item_sequence(item, &lin_idx, &seq, tmp_pool);
|
||||
gu_assert(lin_idx == 0);
|
||||
|
||||
@@ -66,7 +66,7 @@ pgf_match_int_lit(PgfConcr* concr, PgfItem* item, PgfToken tok,
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
|
||||
size_t lin_idx;
|
||||
PgfSequence seq;
|
||||
PgfSequence* seq;
|
||||
pgf_item_sequence(item, &lin_idx, &seq, tmp_pool);
|
||||
gu_assert(lin_idx == 0);
|
||||
|
||||
@@ -123,7 +123,7 @@ pgf_match_float_lit(PgfConcr* concr, PgfItem* item, PgfToken tok,
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
|
||||
size_t lin_idx;
|
||||
PgfSequence seq;
|
||||
PgfSequence* seq;
|
||||
pgf_item_sequence(item, &lin_idx, &seq, tmp_pool);
|
||||
gu_assert(lin_idx == 0);
|
||||
|
||||
@@ -180,7 +180,7 @@ pgf_match_name_lit(PgfConcr* concr, PgfItem* item, PgfToken tok,
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
|
||||
size_t lin_idx;
|
||||
PgfSequence seq;
|
||||
PgfSequence* seq;
|
||||
pgf_item_sequence(item, &lin_idx, &seq, tmp_pool);
|
||||
|
||||
gu_assert(lin_idx == 0);
|
||||
|
||||
@@ -24,8 +24,8 @@ struct PgfItemConts {
|
||||
|
||||
static GU_DEFINE_TYPE(PgfItemConts, abstract, _);
|
||||
|
||||
typedef GuList(PgfItemConts*) PgfItemContss;
|
||||
static GU_DEFINE_TYPE(PgfItemContss, abstract, _);
|
||||
typedef GuSeq PgfItemContss;
|
||||
static GU_DEFINE_TYPE(PgfItemContss, abstract);
|
||||
|
||||
typedef GuMap PgfContsMap;
|
||||
static GU_DEFINE_TYPE(PgfContsMap, GuMap,
|
||||
@@ -71,7 +71,7 @@ extern GuHasher pgf_cfcat_hasher;
|
||||
|
||||
GU_DEFINE_TYPE(PgfProductionIdx, GuMap,
|
||||
gu_type(PgfCFCat), &pgf_cfcat_hasher,
|
||||
gu_type(PgfProductionSeq), &gu_null_seq);
|
||||
gu_ptr_type(PgfProductionBuf), &gu_null_struct);
|
||||
|
||||
typedef struct PgfTokenState PgfTokenState;
|
||||
|
||||
@@ -110,7 +110,7 @@ typedef struct PgfAnswers {
|
||||
typedef struct {
|
||||
PgfAnswers* answers;
|
||||
PgfExprProb ep;
|
||||
PgfPArgs args;
|
||||
PgfPArgs* args;
|
||||
size_t arg_idx;
|
||||
} PgfExprState;
|
||||
|
||||
@@ -130,7 +130,7 @@ struct PgfItem {
|
||||
};
|
||||
|
||||
PgfProduction prod;
|
||||
PgfPArgs args;
|
||||
PgfPArgs* args;
|
||||
PgfSymbol curr_sym;
|
||||
uint16_t seq_idx;
|
||||
uint8_t tok_idx;
|
||||
@@ -183,10 +183,10 @@ pgf_item_sequence_length(PgfItem* item)
|
||||
}
|
||||
case PGF_PRODUCTION_EXTERN: {
|
||||
PgfProductionExtern* pext = i.data;
|
||||
PgfSequence seq;
|
||||
PgfSequence* seq;
|
||||
|
||||
if (!gu_seq_is_null(pext->lins) &&
|
||||
!gu_seq_is_null(seq = gu_seq_get(pext->lins,PgfSequence,item->conts->lin_idx))) {
|
||||
if (pext->lins != NULL &&
|
||||
(seq = gu_seq_get(pext->lins,PgfSequence*,item->conts->lin_idx)) != NULL) {
|
||||
return gu_seq_length(seq);
|
||||
} else {
|
||||
int seq_len = 0;
|
||||
@@ -215,12 +215,12 @@ pgf_item_sequence_length(PgfItem* item)
|
||||
}
|
||||
}
|
||||
|
||||
static PgfSequence
|
||||
static PgfSequence*
|
||||
pgf_extern_seq_get(PgfItem* item, GuPool* pool)
|
||||
{
|
||||
int seq_len = pgf_item_sequence_length(item);
|
||||
|
||||
PgfSequence seq =
|
||||
PgfSequence* seq =
|
||||
gu_new_seq(PgfSymbol, seq_len, pool);
|
||||
PgfSymbol sym = item->curr_sym;
|
||||
while (!gu_variant_is_null(sym)) {
|
||||
@@ -233,7 +233,7 @@ pgf_extern_seq_get(PgfItem* item, GuPool* pool)
|
||||
|
||||
void
|
||||
pgf_item_sequence(PgfItem* item,
|
||||
size_t* lin_idx, PgfSequence* seq,
|
||||
size_t* lin_idx, PgfSequence** seq,
|
||||
GuPool* pool) {
|
||||
*lin_idx = item->conts->lin_idx;
|
||||
|
||||
@@ -249,15 +249,15 @@ pgf_item_sequence(PgfItem* item,
|
||||
gu_new_variant_i(pool, PGF_SYMBOL_CAT,
|
||||
PgfSymbolCat,
|
||||
.d = 0, .r = item->conts->lin_idx);
|
||||
*seq = gu_new_seq(PgfSequence, 1, pool);
|
||||
*seq = gu_new_seq(PgfSequence*, 1, pool);
|
||||
gu_seq_set(*seq, PgfSymbol, 0, sym);
|
||||
break;
|
||||
}
|
||||
case PGF_PRODUCTION_EXTERN: {
|
||||
PgfProductionExtern* pext = i.data;
|
||||
|
||||
if (gu_seq_is_null(pext->lins) ||
|
||||
gu_seq_is_null(*seq = gu_seq_get(pext->lins, PgfSequence, item->conts->lin_idx))) {
|
||||
if (pext->lins == NULL ||
|
||||
(*seq = gu_seq_get(pext->lins, PgfSequence*, item->conts->lin_idx)) == NULL) {
|
||||
*seq = pgf_extern_seq_get(item, pool);
|
||||
}
|
||||
break;
|
||||
@@ -284,10 +284,10 @@ pgf_print_production_args(PgfPArgs args,
|
||||
PgfPArg arg = gu_seq_get(args, PgfPArg, j);
|
||||
|
||||
if (arg.hypos != NULL &&
|
||||
gu_list_length(arg.hypos) > 0) {
|
||||
size_t n_hypos = gu_list_length(arg.hypos);
|
||||
gu_seq_length(arg.hypos) > 0) {
|
||||
size_t n_hypos = gu_seq_length(arg.hypos);
|
||||
for (size_t k = 0; k < n_hypos; k++) {
|
||||
PgfCCat *hypo = gu_list_index(arg.hypos, k);
|
||||
PgfCCat *hypo = gu_seq_get(arg.hypos, PgfCCat*, k);
|
||||
gu_printf(out,err,"C%d ",hypo->fid);
|
||||
}
|
||||
gu_printf(out,err,"-> ");
|
||||
@@ -501,11 +501,11 @@ static PgfItemContss*
|
||||
pgf_parsing_get_contss(PgfContsMap* conts_map, PgfCCat* cat, GuPool *pool)
|
||||
{
|
||||
PgfItemContss* contss = gu_map_get(conts_map, cat, PgfItemContss*);
|
||||
if (!contss) {
|
||||
if (contss == NULL) {
|
||||
size_t n_lins = cat->cnccat->n_lins;
|
||||
contss = gu_new_list(PgfItemContss, pool, n_lins);
|
||||
contss = gu_new_seq(PgfItemConts*, n_lins, pool);
|
||||
for (size_t i = 0; i < n_lins; i++) {
|
||||
gu_list_index(contss, i) = NULL;
|
||||
gu_seq_set(contss, PgfItemConts*, i, NULL);
|
||||
}
|
||||
gu_map_put(conts_map, cat, PgfItemContss*, contss);
|
||||
}
|
||||
@@ -521,7 +521,7 @@ pgf_parsing_get_conts(PgfContsMap* conts_map,
|
||||
gu_require(lin_idx < ccat->cnccat->n_lins);
|
||||
PgfItemContss* contss =
|
||||
pgf_parsing_get_contss(conts_map, ccat, pool);
|
||||
PgfItemConts* conts = gu_list_index(contss, lin_idx);
|
||||
PgfItemConts* conts = gu_seq_get(contss, PgfItemConts*, lin_idx);
|
||||
if (!conts) {
|
||||
conts = gu_new(PgfItemConts, pool);
|
||||
conts->ccat = ccat;
|
||||
@@ -530,7 +530,7 @@ pgf_parsing_get_conts(PgfContsMap* conts_map,
|
||||
conts->items = gu_new_buf(PgfItem*, pool);
|
||||
conts->outside_prob = 0;
|
||||
conts->ref_count = 0;
|
||||
gu_list_index(contss, lin_idx) = conts;
|
||||
gu_seq_get(contss, PgfItemConts*, lin_idx) = conts;
|
||||
|
||||
#ifdef PGF_COUNTS_DEBUG
|
||||
if (state != NULL) {
|
||||
@@ -541,19 +541,30 @@ pgf_parsing_get_conts(PgfContsMap* conts_map,
|
||||
return conts;
|
||||
}
|
||||
|
||||
static void
|
||||
gu_ccat_fini(GuFinalizer* fin)
|
||||
{
|
||||
PgfCCat* cat = gu_container(fin, PgfCCat, fin);
|
||||
if (cat->prods != NULL)
|
||||
gu_seq_free(cat->prods);
|
||||
}
|
||||
|
||||
static PgfCCat*
|
||||
pgf_parsing_create_completed(PgfParseState* state, PgfItemConts* conts,
|
||||
prob_t viterbi_prob)
|
||||
{
|
||||
PgfCCat* cat = gu_new(PgfCCat, state->ps->pool);
|
||||
PgfCCat* cat = gu_new_flex(state->ps->pool, PgfCCat, fin, 1);
|
||||
cat->cnccat = conts->ccat->cnccat;
|
||||
cat->viterbi_prob = viterbi_prob;
|
||||
cat->fid = state->ps->max_fid++;
|
||||
cat->conts = conts;
|
||||
cat->answers = NULL;
|
||||
cat->prods = gu_buf_seq(gu_new_buf(PgfProduction, state->ps->pool));
|
||||
cat->prods = NULL;
|
||||
cat->n_synprods = 0;
|
||||
gu_map_put(state->generated_cats, conts, PgfCCat*, cat);
|
||||
|
||||
cat->fin[0].fn = gu_ccat_fini;
|
||||
gu_pool_finally(state->ps->pool, cat->fin);
|
||||
|
||||
#ifdef PGF_COUNTS_DEBUG
|
||||
state->ps->ccat_full_count++;
|
||||
@@ -562,6 +573,15 @@ pgf_parsing_create_completed(PgfParseState* state, PgfItemConts* conts,
|
||||
return cat;
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_parsing_add_production(PgfCCat* ccat, PgfProduction prod)
|
||||
{
|
||||
if (ccat->prods == NULL || ccat->n_synprods >= gu_seq_length(ccat->prods)) {
|
||||
ccat->prods = gu_realloc_seq(ccat->prods, PgfProduction, ccat->n_synprods+1);
|
||||
}
|
||||
gu_seq_set(ccat->prods, PgfProduction, ccat->n_synprods++, prod);
|
||||
}
|
||||
|
||||
static PgfCCat*
|
||||
pgf_parsing_get_completed(PgfParseState* state, PgfItemConts* conts)
|
||||
{
|
||||
@@ -577,7 +597,7 @@ pgf_item_set_curr_symbol(PgfItem* item, GuPool* pool)
|
||||
PgfProductionApply* papp = i.data;
|
||||
PgfCncFun* fun = papp->fun;
|
||||
gu_assert(item->conts->lin_idx < fun->n_lins);
|
||||
PgfSequence seq = fun->lins[item->conts->lin_idx];
|
||||
PgfSequence* seq = fun->lins[item->conts->lin_idx];
|
||||
gu_assert(item->seq_idx <= gu_seq_length(seq));
|
||||
if (item->seq_idx == gu_seq_length(seq)) {
|
||||
item->curr_sym = gu_null_variant;
|
||||
@@ -868,16 +888,15 @@ pgf_parsing_new_production(PgfItem* item, PgfExprProb *ep, GuPool *pool)
|
||||
PgfProductionCoerce,
|
||||
&prod, pool);
|
||||
PgfPArg* parg = gu_seq_index(item->args, PgfPArg, 0);
|
||||
gu_assert(!parg->hypos || !parg->hypos->len);
|
||||
new_pcoerce->coerce = parg->ccat;
|
||||
break;
|
||||
}
|
||||
case PGF_PRODUCTION_EXTERN: {
|
||||
PgfProductionExtern* pext = i.data;
|
||||
|
||||
if (gu_seq_is_null(pext->lins) ||
|
||||
gu_seq_is_null(gu_seq_get(pext->lins,PgfSequence,item->conts->lin_idx))) {
|
||||
PgfSequence seq =
|
||||
if (pext->lins == NULL ||
|
||||
gu_seq_get(pext->lins,PgfSequence*,item->conts->lin_idx) == NULL) {
|
||||
PgfSequence* seq =
|
||||
pgf_extern_seq_get(item, pool);
|
||||
|
||||
size_t n_lins = item->conts->ccat->cnccat->n_lins;
|
||||
@@ -888,20 +907,20 @@ pgf_parsing_new_production(PgfItem* item, PgfExprProb *ep, GuPool *pool)
|
||||
&prod, pool);
|
||||
new_pext->callback = pext->callback;
|
||||
new_pext->ep = ep;
|
||||
new_pext->lins = gu_new_seq(PgfSequence, n_lins, pool);
|
||||
new_pext->lins = gu_new_seq(PgfSequence*, n_lins, pool);
|
||||
|
||||
if (gu_seq_is_null(pext->lins)) {
|
||||
if (pext->lins == NULL) {
|
||||
for (size_t i = 0; i < n_lins; i++) {
|
||||
gu_seq_set(new_pext->lins,PgfSequence,i,
|
||||
gu_null_seq);
|
||||
gu_seq_set(new_pext->lins,PgfSequence*,i,
|
||||
NULL);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < n_lins; i++) {
|
||||
gu_seq_set(new_pext->lins,PgfSequence,i,
|
||||
gu_seq_get(pext->lins,PgfSequence,i));
|
||||
gu_seq_set(new_pext->lins,PgfSequence*,i,
|
||||
gu_seq_get(pext->lins,PgfSequence*,i));
|
||||
}
|
||||
}
|
||||
gu_seq_set(new_pext->lins,PgfSequence,item->conts->lin_idx,seq);
|
||||
gu_seq_set(new_pext->lins,PgfSequence*,item->conts->lin_idx,seq);
|
||||
} else {
|
||||
prod = item->prod;
|
||||
}
|
||||
@@ -940,9 +959,7 @@ pgf_parsing_complete(PgfParseState* before, PgfParseState* after,
|
||||
item->inside_prob);
|
||||
}
|
||||
|
||||
GuBuf* prodbuf = gu_seq_buf(cat->prods);
|
||||
gu_buf_push(prodbuf, PgfProduction, prod);
|
||||
cat->n_synprods++;
|
||||
pgf_parsing_add_production(cat, prod);
|
||||
|
||||
#ifdef PGF_PARSER_DEBUG
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
@@ -962,9 +979,9 @@ pgf_parsing_complete(PgfParseState* before, PgfParseState* after,
|
||||
if (tmp_cat != NULL) {
|
||||
PgfItemContss* contss =
|
||||
pgf_parsing_get_contss(before->conts_map, cat, before->ps->pool);
|
||||
size_t n_contss = gu_list_length(contss);
|
||||
size_t n_contss = gu_seq_length(contss);
|
||||
for (size_t i = 0; i < n_contss; i++) {
|
||||
PgfItemConts* conts2 = gu_list_index(contss, i);
|
||||
PgfItemConts* conts2 = gu_seq_get(contss, PgfItemConts*, i);
|
||||
/* If there are continuations for
|
||||
* linearization index i, then (cat, i) has
|
||||
* already been predicted. Add the new
|
||||
@@ -981,9 +998,9 @@ pgf_parsing_complete(PgfParseState* before, PgfParseState* after,
|
||||
while (state != NULL) {
|
||||
PgfItemContss* contss =
|
||||
pgf_parsing_get_contss(state->conts_map, cat, state->ps->pool);
|
||||
size_t n_contss = gu_list_length(contss);
|
||||
size_t n_contss = gu_seq_length(contss);
|
||||
for (size_t i = 0; i < n_contss; i++) {
|
||||
PgfItemConts* conts2 = gu_list_index(contss, i);
|
||||
PgfItemConts* conts2 = gu_seq_get(contss, PgfItemConts*, i);
|
||||
/* If there are continuations for
|
||||
* linearization index i, then (cat, i) has
|
||||
* already been predicted. Add the new
|
||||
@@ -1034,7 +1051,7 @@ pgf_parsing_td_predict(PgfParseState* before, PgfParseState* after,
|
||||
|
||||
// we don't know the current token.
|
||||
// probably we just compute the list of completions
|
||||
if (lexicon_idx == NULL)
|
||||
if (lexicon_idx == NULL && ccat->fid < after->ps->concr->total_cats)
|
||||
n_prods = gu_seq_length(ccat->prods);
|
||||
}
|
||||
|
||||
@@ -1049,14 +1066,14 @@ pgf_parsing_td_predict(PgfParseState* before, PgfParseState* after,
|
||||
|
||||
if (lexicon_idx != NULL) {
|
||||
PgfCFCat cfc = {ccat, lin_idx};
|
||||
PgfProductionSeq tok_prods =
|
||||
gu_map_get(lexicon_idx, &cfc, PgfProductionSeq);
|
||||
PgfProductionBuf* tok_prods =
|
||||
gu_map_get(lexicon_idx, &cfc, PgfProductionBuf*);
|
||||
|
||||
if (!gu_seq_is_null(tok_prods)) {
|
||||
size_t n_prods = gu_seq_length(tok_prods);
|
||||
if (tok_prods != NULL) {
|
||||
size_t n_prods = gu_buf_length(tok_prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
PgfProduction prod =
|
||||
gu_seq_get(tok_prods, PgfProduction, i);
|
||||
gu_buf_get(tok_prods, PgfProduction, i);
|
||||
|
||||
pgf_parsing_production(before, conts, prod);
|
||||
}
|
||||
@@ -1065,14 +1082,14 @@ pgf_parsing_td_predict(PgfParseState* before, PgfParseState* after,
|
||||
|
||||
// Bottom-up prediction for epsilon rules
|
||||
PgfCFCat cfc = {ccat, lin_idx};
|
||||
PgfProductionSeq eps_prods =
|
||||
gu_map_get(before->ps->concr->epsilon_idx, &cfc, PgfProductionSeq);
|
||||
PgfProductionBuf* eps_prods =
|
||||
gu_map_get(before->ps->concr->epsilon_idx, &cfc, PgfProductionBuf*);
|
||||
|
||||
if (!gu_seq_is_null(eps_prods)) {
|
||||
size_t n_prods = gu_seq_length(eps_prods);
|
||||
if (eps_prods != NULL) {
|
||||
size_t n_prods = gu_buf_length(eps_prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
PgfProduction prod =
|
||||
gu_seq_get(eps_prods, PgfProduction, i);
|
||||
gu_buf_get(eps_prods, PgfProduction, i);
|
||||
|
||||
pgf_parsing_production(before, conts, prod);
|
||||
}
|
||||
@@ -1145,10 +1162,10 @@ pgf_parsing_meta_predict(GuMapItor* fn, const void* key, void* value, GuExn* err
|
||||
if (cnccat == NULL)
|
||||
return;
|
||||
|
||||
size_t n_cats = gu_list_length(cnccat->cats);
|
||||
size_t n_cats = gu_seq_length(cnccat->cats);
|
||||
for (size_t i = 0; i < n_cats; i++) {
|
||||
PgfCCat* ccat = gu_list_index(cnccat->cats, i);
|
||||
if (gu_seq_is_null(ccat->prods)) {
|
||||
PgfCCat* ccat = gu_seq_get(cnccat->cats, PgfCCat*, i);
|
||||
if (ccat->prods == NULL) {
|
||||
// empty category
|
||||
continue;
|
||||
}
|
||||
@@ -1188,9 +1205,8 @@ pgf_parsing_symbol(PgfParseState* before, PgfParseState* after,
|
||||
case PGF_SYMBOL_CAT: {
|
||||
PgfSymbolCat* scat = gu_variant_data(sym);
|
||||
PgfPArg* parg = gu_seq_index(item->args, PgfPArg, scat->d);
|
||||
gu_assert(!parg->hypos || !parg->hypos->len);
|
||||
|
||||
if (gu_seq_is_null(parg->ccat->prods)) {
|
||||
if (parg->ccat->prods == NULL) {
|
||||
// empty category
|
||||
pgf_item_free(before, after, item);
|
||||
return;
|
||||
@@ -1234,11 +1250,11 @@ pgf_parsing_symbol(PgfParseState* before, PgfParseState* after,
|
||||
|
||||
for (size_t i = 0; i < skp->n_forms; i++) {
|
||||
// XXX: do nubbing properly
|
||||
PgfTokens toks = skp->forms[i].form;
|
||||
PgfTokens toks2 = skp->default_form;
|
||||
PgfTokens* toks = skp->forms[i].form;
|
||||
PgfTokens* toks2 = skp->default_form;
|
||||
bool skip = pgf_tokens_equal(toks, toks2);
|
||||
for (size_t j = 0; j < i; j++) {
|
||||
PgfTokens toks2 = skp->forms[j].form;
|
||||
PgfTokens* toks2 = skp->forms[j].form;
|
||||
skip |= pgf_tokens_equal(toks, toks2);
|
||||
}
|
||||
if (!skip) {
|
||||
@@ -1264,7 +1280,7 @@ pgf_parsing_symbol(PgfParseState* before, PgfParseState* after,
|
||||
pgf_parsing_add_transition(before, after, tok, item);
|
||||
} else {
|
||||
gu_assert(alt <= skp->n_forms);
|
||||
PgfTokens toks = skp->forms[alt - 1].form;
|
||||
PgfTokens* toks = skp->forms[alt - 1].form;
|
||||
PgfToken tok = gu_seq_get(toks, PgfToken, idx);
|
||||
item->tok_idx++;
|
||||
if (item->tok_idx == gu_seq_length(toks)) {
|
||||
@@ -1280,7 +1296,6 @@ pgf_parsing_symbol(PgfParseState* before, PgfParseState* after,
|
||||
if (after != NULL) {
|
||||
PgfSymbolLit* slit = gu_variant_data(sym);
|
||||
PgfPArg* parg = gu_seq_index(item->args, PgfPArg, slit->d);
|
||||
gu_assert(!parg->hypos || !parg->hypos->len);
|
||||
|
||||
if (parg->ccat->fid > 0 &&
|
||||
parg->ccat->fid >= before->ps->concr->total_cats) {
|
||||
@@ -1310,7 +1325,7 @@ pgf_parsing_symbol(PgfParseState* before, PgfParseState* after,
|
||||
&prod, before->ps->pool);
|
||||
pext->callback = callback;
|
||||
pext->ep = NULL;
|
||||
pext->lins = gu_null_seq;
|
||||
pext->lins = NULL;
|
||||
|
||||
pgf_parsing_production(before, conts, prod);
|
||||
}
|
||||
@@ -1366,7 +1381,7 @@ pgf_parsing_item(PgfParseState* before, PgfParseState* after, PgfItem* item)
|
||||
case PGF_PRODUCTION_APPLY: {
|
||||
PgfProductionApply* papp = i.data;
|
||||
PgfCncFun* fun = papp->fun;
|
||||
PgfSequence seq = fun->lins[item->conts->lin_idx];
|
||||
PgfSequence* seq = fun->lins[item->conts->lin_idx];
|
||||
if (item->seq_idx == gu_seq_length(seq)) {
|
||||
pgf_parsing_complete(before, after, item, NULL);
|
||||
pgf_item_free(before, after, item);
|
||||
@@ -1379,7 +1394,7 @@ pgf_parsing_item(PgfParseState* before, PgfParseState* after, PgfItem* item)
|
||||
PgfProductionCoerce* pcoerce = i.data;
|
||||
switch (item->seq_idx) {
|
||||
case 0:
|
||||
if (gu_seq_is_null(pcoerce->coerce->prods)) {
|
||||
if (pcoerce->coerce->prods == NULL) {
|
||||
// empty category
|
||||
pgf_item_free(before, after, item);
|
||||
return;
|
||||
@@ -1401,9 +1416,9 @@ pgf_parsing_item(PgfParseState* before, PgfParseState* after, PgfItem* item)
|
||||
case PGF_PRODUCTION_EXTERN: {
|
||||
PgfProductionExtern* pext = i.data;
|
||||
|
||||
PgfSequence seq;
|
||||
if (!gu_seq_is_null(pext->lins) &&
|
||||
!gu_seq_is_null(seq = gu_seq_get(pext->lins,PgfSequence,item->conts->lin_idx))) {
|
||||
PgfSequence* seq;
|
||||
if (pext->lins != NULL &&
|
||||
(seq = gu_seq_get(pext->lins,PgfSequence*,item->conts->lin_idx)) != NULL) {
|
||||
if (item->seq_idx == gu_seq_length(seq)) {
|
||||
pgf_parsing_complete(before, after, item, NULL);
|
||||
pgf_item_free(before, after, item);
|
||||
@@ -1626,15 +1641,15 @@ static void
|
||||
pgf_parser_compute_lexicon_prob(GuMapItor* fn, const void* key, void* value, GuExn* err)
|
||||
{
|
||||
PgfTokenState* ts = ((PgfLexiconFn*) fn)->ts;
|
||||
PgfProductionSeq prods = *((PgfProductionSeq*) value);
|
||||
|
||||
if (gu_seq_is_null(prods))
|
||||
PgfProductionBuf* prods = *((PgfProductionBuf**) value);
|
||||
|
||||
if (prods == NULL)
|
||||
return;
|
||||
|
||||
size_t n_prods = gu_seq_length(prods);
|
||||
size_t n_prods = gu_buf_length(prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
PgfProduction prod =
|
||||
gu_seq_get(prods, PgfProduction, i);
|
||||
gu_buf_get(prods, PgfProduction, i);
|
||||
|
||||
GuVariantInfo pi = gu_variant_open(prod);
|
||||
switch (pi.tag) {
|
||||
@@ -1740,7 +1755,7 @@ typedef struct {
|
||||
} PgfPrefixTokenState;
|
||||
|
||||
static GuString
|
||||
pgf_get_tokens(PgfSequence seq,
|
||||
pgf_get_tokens(PgfSequence* seq,
|
||||
uint16_t seq_idx, uint8_t tok_idx,
|
||||
GuPool* pool)
|
||||
{
|
||||
@@ -1791,7 +1806,7 @@ pgf_prefix_match_token(PgfTokenState* ts0, PgfToken tok, PgfItem* item)
|
||||
|
||||
if (gu_string_is_prefix(ts->prefix, tok)) {
|
||||
size_t lin_idx;
|
||||
PgfSequence seq;
|
||||
PgfSequence* seq;
|
||||
pgf_item_sequence(item, &lin_idx, &seq, ts->pool);
|
||||
|
||||
uint16_t seq_idx = item->seq_idx;
|
||||
@@ -1911,8 +1926,7 @@ pgf_result_production(PgfParsing* ps,
|
||||
PgfProductionCoerce* pcoerce = pi.data;
|
||||
|
||||
PgfCCat* ccat = pcoerce->coerce;
|
||||
size_t n_prods = gu_seq_length(ccat->prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
for (size_t i = 0; i < ccat->n_synprods; i++) {
|
||||
PgfProduction prod =
|
||||
gu_seq_get(ccat->prods, PgfProduction, i);
|
||||
pgf_result_production(ps, answers, prod);
|
||||
@@ -1978,12 +1992,11 @@ pgf_result_predict(PgfParsing* ps,
|
||||
gu_buf_push(answers->conts, PgfExprState*, cont);
|
||||
|
||||
if (gu_buf_length(answers->conts) == 1) {
|
||||
if (gu_seq_is_null(ccat->prods))
|
||||
if (ccat->prods == NULL)
|
||||
return;
|
||||
|
||||
// Generation
|
||||
size_t n_prods = gu_seq_length(ccat->prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
for (size_t i = 0; i < ccat->n_synprods; i++) {
|
||||
PgfProduction prod =
|
||||
gu_seq_get(ccat->prods, PgfProduction, i);
|
||||
pgf_result_production(ps, answers, prod);
|
||||
@@ -2239,11 +2252,11 @@ pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx,
|
||||
PgfParseState* state =
|
||||
pgf_new_parse_state(ps, NULL, NULL, pool);
|
||||
|
||||
size_t n_ccats = gu_list_length(cnccat->cats);
|
||||
size_t n_ccats = gu_seq_length(cnccat->cats);
|
||||
for (size_t i = 0; i < n_ccats; i++) {
|
||||
PgfCCat* ccat = gu_list_index(cnccat->cats, i);
|
||||
PgfCCat* ccat = gu_seq_get(cnccat->cats, PgfCCat*, i);
|
||||
if (ccat != NULL) {
|
||||
if (gu_seq_is_null(ccat->prods)) {
|
||||
if (ccat->prods == NULL) {
|
||||
// Empty category
|
||||
continue;
|
||||
}
|
||||
@@ -2295,7 +2308,7 @@ pgf_parser_add_literal(PgfConcr *concr, PgfCId cat,
|
||||
|
||||
typedef struct {
|
||||
GuMapItor fn;
|
||||
PgfTokens tokens;
|
||||
PgfTokens* tokens;
|
||||
PgfMorphoCallback* callback;
|
||||
} PgfMorphoFn;
|
||||
|
||||
@@ -2304,27 +2317,27 @@ pgf_morpho_iter(GuMapItor* fn, const void* key, void* value, GuExn* err)
|
||||
{
|
||||
PgfMorphoFn* clo = (PgfMorphoFn*) fn;
|
||||
PgfCFCat cfc = *((PgfCFCat*) key);
|
||||
PgfProductionSeq prods = *((PgfProductionSeq*) value);
|
||||
PgfProductionBuf* prods = *((PgfProductionBuf**) value);
|
||||
|
||||
if (gu_seq_is_null(prods))
|
||||
if (prods == NULL)
|
||||
return;
|
||||
|
||||
GuString analysis = cfc.ccat->cnccat->labels[cfc.lin_idx];
|
||||
|
||||
size_t n_prods = gu_seq_length(prods);
|
||||
size_t n_prods = gu_buf_length(prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
PgfProduction prod =
|
||||
gu_seq_get(prods, PgfProduction, i);
|
||||
gu_buf_get(prods, PgfProduction, i);
|
||||
|
||||
GuVariantInfo i = gu_variant_open(prod);
|
||||
switch (i.tag) {
|
||||
case PGF_PRODUCTION_APPLY: {
|
||||
PgfProductionApply* papp = i.data;
|
||||
|
||||
if (!gu_seq_is_null(clo->tokens)) {
|
||||
if (clo->tokens != NULL) {
|
||||
// match the tokens with the production
|
||||
size_t pos = 0;
|
||||
PgfSequence seq = papp->fun->lins[cfc.lin_idx];
|
||||
PgfSequence* seq = papp->fun->lins[cfc.lin_idx];
|
||||
size_t len = gu_seq_length(seq);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
PgfSymbol sym = gu_seq_get(seq, PgfSymbol, i);
|
||||
@@ -2392,7 +2405,7 @@ pgf_lookup_morpho(PgfConcr *concr, PgfLexer *lexer,
|
||||
tok = pgf_lexer_read_token(lexer, lex_err);
|
||||
} while (!gu_exn_is_raised(lex_err));
|
||||
|
||||
PgfMorphoFn clo = { { pgf_morpho_iter }, gu_buf_seq(tokens), callback };
|
||||
PgfMorphoFn clo = { { pgf_morpho_iter }, gu_buf_data_seq(tokens), callback };
|
||||
gu_map_iter(lexicon_idx, &clo.fn, err);
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
@@ -2414,22 +2427,22 @@ pgf_fullform_iter(GuMapItor* fn, const void* key, void* value, GuExn* err)
|
||||
{
|
||||
PgfFullFormState* st = gu_container(fn, PgfFullFormState, fn);
|
||||
PgfCFCat cfc = *((PgfCFCat*) key);
|
||||
PgfProductionSeq prods = *((PgfProductionSeq*) value);
|
||||
PgfProductionBuf* prods = *((PgfProductionBuf**) value);
|
||||
|
||||
if (gu_seq_is_null(prods))
|
||||
if (prods == NULL)
|
||||
return;
|
||||
|
||||
size_t n_prods = gu_seq_length(prods);
|
||||
size_t n_prods = gu_buf_length(prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
PgfProduction prod =
|
||||
gu_seq_get(prods, PgfProduction, i);
|
||||
gu_buf_get(prods, PgfProduction, i);
|
||||
|
||||
GuVariantInfo i = gu_variant_open(prod);
|
||||
switch (i.tag) {
|
||||
case PGF_PRODUCTION_APPLY: {
|
||||
PgfProductionApply* papp = i.data;
|
||||
|
||||
PgfSequence seq = papp->fun->lins[cfc.lin_idx];
|
||||
PgfSequence* seq = papp->fun->lins[cfc.lin_idx];
|
||||
GuString tokens = pgf_get_tokens(seq, 0, 0, st->pool);
|
||||
|
||||
// create a new production index with keys that
|
||||
@@ -2441,14 +2454,14 @@ pgf_fullform_iter(GuMapItor* fn, const void* key, void* value, GuExn* err)
|
||||
gu_map_put(st->new_idx, &tokens, PgfProductionIdx*, lexicon_idx);
|
||||
}
|
||||
|
||||
PgfProductionSeq prods =
|
||||
gu_map_get(lexicon_idx, &cfc, PgfProductionSeq);
|
||||
if (gu_seq_is_null(prods)) {
|
||||
prods = gu_buf_seq(gu_new_buf(PgfProduction, st->pool));
|
||||
gu_map_put(lexicon_idx, &cfc, PgfProductionSeq, prods);
|
||||
PgfProductionBuf* prods =
|
||||
gu_map_get(lexicon_idx, &cfc, PgfProductionBuf*);
|
||||
if (prods == NULL) {
|
||||
prods = gu_new_buf(PgfProduction, st->pool);
|
||||
gu_map_put(lexicon_idx, &cfc, PgfProductionBuf*, prods);
|
||||
}
|
||||
|
||||
gu_buf_push(gu_seq_buf(prods), PgfProduction, prod);
|
||||
gu_buf_push(prods, PgfProduction, prod);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2512,13 +2525,13 @@ pgf_fullform_get_analyses(PgfFullFormEntry* entry,
|
||||
PgfMorphoCallback* callback, GuExn* err)
|
||||
{
|
||||
PgfProductionIdx* lexicon_idx = *((PgfProductionIdx**) entry->value);
|
||||
PgfMorphoFn clo = { { pgf_morpho_iter }, gu_null_seq, callback };
|
||||
PgfMorphoFn clo = { { pgf_morpho_iter }, NULL, callback };
|
||||
gu_map_iter(lexicon_idx, &clo.fn, err);
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_parser_index_token(PgfConcr* concr,
|
||||
PgfTokens tokens,
|
||||
PgfTokens* tokens,
|
||||
PgfCCat* ccat, size_t lin_idx, PgfProduction prod,
|
||||
GuPool *pool)
|
||||
{
|
||||
@@ -2532,13 +2545,13 @@ pgf_parser_index_token(PgfConcr* concr,
|
||||
}
|
||||
|
||||
PgfCFCat cfc = {ccat, lin_idx};
|
||||
PgfProductionSeq prods = gu_map_get(set, &cfc, PgfProductionSeq);
|
||||
if (gu_seq_is_null(prods)) {
|
||||
prods = gu_buf_seq(gu_new_buf(PgfProduction, pool));
|
||||
gu_map_put(set, &cfc, PgfProductionSeq, prods);
|
||||
PgfProductionBuf* prods = gu_map_get(set, &cfc, PgfProductionBuf*);
|
||||
if (prods == NULL) {
|
||||
prods = gu_new_buf(PgfProduction, pool);
|
||||
gu_map_put(set, &cfc, PgfProductionBuf*, prods);
|
||||
}
|
||||
|
||||
gu_buf_push(gu_seq_buf(prods), PgfProduction, prod);
|
||||
gu_buf_push(prods, PgfProduction, prod);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2547,14 +2560,14 @@ pgf_parser_index_epsilon(PgfConcr* concr,
|
||||
GuPool *pool)
|
||||
{
|
||||
PgfCFCat cfc = {ccat, lin_idx};
|
||||
PgfProductionSeq prods =
|
||||
gu_map_get(concr->epsilon_idx, &cfc, PgfProductionSeq);
|
||||
if (gu_seq_is_null(prods)) {
|
||||
prods = gu_buf_seq(gu_new_buf(PgfProduction, pool));
|
||||
gu_map_put(concr->epsilon_idx, &cfc, PgfProductionSeq, prods);
|
||||
PgfProductionBuf* prods =
|
||||
gu_map_get(concr->epsilon_idx, &cfc, PgfProductionBuf*);
|
||||
if (prods == NULL) {
|
||||
prods = gu_new_buf(PgfProduction, pool);
|
||||
gu_map_put(concr->epsilon_idx, &cfc, PgfProductionBuf*, prods);
|
||||
}
|
||||
|
||||
gu_buf_push(gu_seq_buf(prods), PgfProduction, prod);
|
||||
gu_buf_push(prods, PgfProduction, prod);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2571,7 +2584,7 @@ pgf_parser_index(PgfConcr* concr,
|
||||
if (gu_seq_length(papp->args) > 0)
|
||||
break;
|
||||
|
||||
PgfSequence seq = papp->fun->lins[lin_idx];
|
||||
PgfSequence* seq = papp->fun->lins[lin_idx];
|
||||
if (gu_seq_length(seq) > 0) {
|
||||
GuVariantInfo i = gu_variant_open(gu_seq_get(seq, PgfSymbol, 0));
|
||||
switch (i.tag) {
|
||||
@@ -2630,7 +2643,7 @@ pgf_ccat_set_viterbi_prob(PgfCCat* ccat) {
|
||||
if (ccat->viterbi_prob == 0) { // uninitialized
|
||||
ccat->viterbi_prob = INFINITY; // set to infinity to avoid loops
|
||||
|
||||
if (gu_seq_is_null(ccat->prods))
|
||||
if (ccat->prods == NULL)
|
||||
return INFINITY;
|
||||
|
||||
prob_t viterbi_prob = INFINITY;
|
||||
|
||||
@@ -112,7 +112,7 @@ pgf_item_lin_idx(PgfItem* item);
|
||||
|
||||
void
|
||||
pgf_item_sequence(PgfItem* item,
|
||||
size_t* lin_idx, PgfSequence* seq,
|
||||
size_t* lin_idx, PgfSequence** seq,
|
||||
GuPool* pool);
|
||||
|
||||
int
|
||||
|
||||
@@ -19,7 +19,7 @@ typedef struct {
|
||||
} PgfMetricsLznState;
|
||||
|
||||
static void
|
||||
pgf_metrics_lzn_symbol_tokens(PgfLinFuncs** funcs, PgfTokens toks)
|
||||
pgf_metrics_lzn_symbol_tokens(PgfLinFuncs** funcs, PgfTokens* toks)
|
||||
{
|
||||
PgfMetricsLznState* state = gu_container(funcs, PgfMetricsLznState, funcs);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ pgf_print_absfun(GuMapItor* fn, const void* key, void* value,
|
||||
PgfAbsFun *fun = *((PgfAbsFun **) value);
|
||||
GuOut *out = clo->out;
|
||||
|
||||
gu_puts(gu_seq_is_null(fun->defns) ? " data " : " fun ", out, err);
|
||||
gu_puts((fun->defns == NULL) ? " data " : " fun ", out, err);
|
||||
gu_string_write(name, out, err);
|
||||
gu_puts(" : ", out, err);
|
||||
pgf_print_type(fun->type, NULL, 0, out, err);
|
||||
@@ -94,7 +94,7 @@ pgf_print_productions(GuMapItor* fn, const void* key, void* value,
|
||||
PgfCCat* ccat = *((PgfCCat**) value);
|
||||
GuOut *out = clo->out;
|
||||
|
||||
if (!gu_seq_is_null(ccat->prods)) {
|
||||
if (ccat->prods != NULL) {
|
||||
size_t n_prods = gu_seq_length(ccat->prods);
|
||||
for (size_t i = 0; i < n_prods; i++) {
|
||||
PgfProduction prod = gu_seq_get(ccat->prods, PgfProduction, i);
|
||||
@@ -114,11 +114,11 @@ pgf_print_productions(GuMapItor* fn, const void* key, void* value,
|
||||
PgfPArg arg = gu_seq_get(papp->args, PgfPArg, j);
|
||||
|
||||
if (arg.hypos != NULL) {
|
||||
size_t n_hypos = gu_list_length(arg.hypos);
|
||||
size_t n_hypos = gu_seq_length(arg.hypos);
|
||||
for (size_t k = 0; k < n_hypos; k++) {
|
||||
if (k > 0)
|
||||
gu_putc(' ',out,err);
|
||||
PgfCCat *hypo = gu_list_index(arg.hypos, k);
|
||||
PgfCCat *hypo = gu_seq_get(arg.hypos, PgfCCat*, k);
|
||||
gu_printf(out,err,"C%d",hypo->fid);
|
||||
}
|
||||
}
|
||||
@@ -152,11 +152,11 @@ pgf_print_lindefs(GuMapItor* fn, const void* key, void* value,
|
||||
if (ccat->lindefs != NULL) {
|
||||
gu_printf(out,err," C%d -> ",fid);
|
||||
|
||||
size_t n_lindefs = gu_list_length(ccat->lindefs);
|
||||
size_t n_lindefs = gu_seq_length(ccat->lindefs);
|
||||
for (size_t i = 0; i < n_lindefs; i++) {
|
||||
if (i > 0) gu_putc(' ', out, err);
|
||||
|
||||
PgfCncFun* fun = gu_list_index(ccat->lindefs, i);
|
||||
PgfCncFun* fun = gu_seq_get(ccat->lindefs, PgfCncFun*, i);
|
||||
gu_printf(out,err,"F%d",fun->funid);
|
||||
}
|
||||
|
||||
@@ -165,19 +165,19 @@ pgf_print_lindefs(GuMapItor* fn, const void* key, void* value,
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_print_cncfun(PgfCncFun *cncfun, PgfSequences *sequences,
|
||||
pgf_print_cncfun(PgfCncFun *cncfun, PgfSequences* sequences,
|
||||
GuOut *out, GuExn *err)
|
||||
{
|
||||
gu_printf(out,err," F%d := (", cncfun->funid);
|
||||
|
||||
size_t n_seqs = gu_list_length(sequences);
|
||||
size_t n_seqs = gu_seq_length(sequences);
|
||||
|
||||
for (size_t i = 0; i < cncfun->n_lins; i++) {
|
||||
if (i > 0) gu_putc(',', out, err);
|
||||
PgfSequence seq = cncfun->lins[i];
|
||||
PgfSequence* seq = cncfun->lins[i];
|
||||
|
||||
for (size_t seqid = 0; seqid < n_seqs; seqid++) {
|
||||
if (gu_seq_data(gu_list_index(sequences, seqid)) == gu_seq_data(seq)) {
|
||||
if (gu_seq_data(gu_seq_get(sequences, PgfSequence*, seqid)) == gu_seq_data(seq)) {
|
||||
gu_printf(out,err,"S%d", seqid);
|
||||
break;
|
||||
}
|
||||
@@ -196,7 +196,7 @@ pgf_print_cncfun(PgfCncFun *cncfun, PgfSequences *sequences,
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_print_tokens(PgfTokens tokens, GuOut *out, GuExn *err)
|
||||
pgf_print_tokens(PgfTokens* tokens, GuOut *out, GuExn *err)
|
||||
{
|
||||
gu_putc('"', out, err);
|
||||
size_t n_toks = gu_seq_length(tokens);
|
||||
@@ -234,11 +234,11 @@ pgf_print_symbol(PgfSymbol sym, GuOut *out, GuExn *err)
|
||||
pgf_print_tokens(skp->forms[i].form, out, err);
|
||||
gu_puts(" / ", out, err);
|
||||
|
||||
size_t n_prefixes = gu_list_length(skp->forms[i].prefixes);
|
||||
size_t n_prefixes = gu_seq_length(skp->forms[i].prefixes);
|
||||
for (size_t j = 0; j < n_prefixes; j++) {
|
||||
if (j > 0) gu_putc(' ', out, err);
|
||||
|
||||
GuString prefix = gu_list_index(skp->forms[i].prefixes, j);
|
||||
GuString prefix = gu_seq_get(skp->forms[i].prefixes, GuString, j);
|
||||
gu_putc('"', out, err);
|
||||
gu_string_write(prefix, out, err);
|
||||
gu_putc('"', out, err);
|
||||
@@ -268,7 +268,7 @@ pgf_print_symbol(PgfSymbol sym, GuOut *out, GuExn *err)
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_print_sequence(size_t seqid, PgfSequence seq, GuOut *out, GuExn *err)
|
||||
pgf_print_sequence(size_t seqid, PgfSequence* seq, GuOut *out, GuExn *err)
|
||||
{
|
||||
gu_printf(out,err," S%d := ", seqid);
|
||||
|
||||
@@ -296,8 +296,8 @@ pgf_print_cnccat(GuMapItor* fn, const void* key, void* value,
|
||||
gu_string_write(name, out, err);
|
||||
gu_puts(" :=\n", out, err);
|
||||
|
||||
PgfCCat *start = gu_list_index(cnccat->cats, 0);
|
||||
PgfCCat *end = gu_list_index(cnccat->cats, gu_list_length(cnccat->cats)-1);
|
||||
PgfCCat *start = gu_seq_get(cnccat->cats, PgfCCat*, 0);
|
||||
PgfCCat *end = gu_seq_get(cnccat->cats, PgfCCat*, gu_seq_length(cnccat->cats)-1);
|
||||
|
||||
gu_printf(out, err, " range [C%d..C%d]\n", start->fid, end->fid);
|
||||
|
||||
@@ -332,16 +332,16 @@ pgf_print_concrete(PgfCId cncname, PgfConcr* concr,
|
||||
gu_map_iter(concr->ccats, &clo3.fn, err);
|
||||
|
||||
gu_puts(" lin\n", out, err);
|
||||
size_t n_funs = gu_list_length(concr->cncfuns);
|
||||
size_t n_funs = gu_seq_length(concr->cncfuns);
|
||||
for (size_t i = 0; i < n_funs; i++) {
|
||||
PgfCncFun* cncfun = gu_list_index(concr->cncfuns, i);
|
||||
PgfCncFun* cncfun = gu_seq_get(concr->cncfuns, PgfCncFun*, i);
|
||||
pgf_print_cncfun(cncfun, concr->sequences, out, err);
|
||||
}
|
||||
|
||||
gu_puts(" sequences\n", out, err);
|
||||
size_t n_seqs = gu_list_length(concr->sequences);
|
||||
size_t n_seqs = gu_seq_length(concr->sequences);
|
||||
for (size_t i = 0; i < n_seqs; i++) {
|
||||
PgfSequence seq = gu_list_index(concr->sequences, i);
|
||||
PgfSequence* seq = gu_seq_get(concr->sequences, PgfSequence*, i);
|
||||
pgf_print_sequence(i, seq, out, err);
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ pgf_read_type_(PgfReader* rdr)
|
||||
{
|
||||
size_t n_hypos = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
GuSeq hypos = gu_new_seq(PgfHypo, n_hypos, rdr->opool);
|
||||
GuSeq* hypos = gu_new_seq(PgfHypo, n_hypos, rdr->opool);
|
||||
for (size_t i = 0; i < n_hypos; i++) {
|
||||
PgfHypo* hypo = gu_seq_index(hypos, PgfHypo, i);
|
||||
pgf_read_hypo(rdr, hypo);
|
||||
@@ -415,7 +415,7 @@ pgf_read_absfun(PgfReader* rdr)
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
switch (tag) {
|
||||
case 0:
|
||||
absfun->defns = gu_null_seq;
|
||||
absfun->defns = NULL;
|
||||
break;
|
||||
case 1: {
|
||||
GuLength length = pgf_read_len(rdr);
|
||||
@@ -586,16 +586,16 @@ pgf_read_printnames(PgfReader* rdr)
|
||||
return printnames;
|
||||
}
|
||||
|
||||
static PgfTokens
|
||||
static PgfTokens*
|
||||
pgf_read_tokens(PgfReader* rdr)
|
||||
{
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, gu_null_seq);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfTokens tokens = gu_new_seq(PgfToken, len, rdr->opool);
|
||||
PgfTokens* tokens = gu_new_seq(PgfToken, len, rdr->opool);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
PgfToken token = pgf_read_string(rdr);
|
||||
gu_return_on_exn(rdr->err, gu_null_seq);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
gu_seq_set(tokens, PgfToken, i, token);
|
||||
}
|
||||
@@ -612,12 +612,12 @@ pgf_read_alternative(PgfReader* rdr, PgfAlternative* alt)
|
||||
size_t n_prefixes = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err,);
|
||||
|
||||
alt->prefixes = gu_new_list(GuStringL, rdr->opool, n_prefixes);
|
||||
alt->prefixes = gu_new_seq(GuString, n_prefixes, rdr->opool);
|
||||
for (size_t i = 0; i < n_prefixes; i++) {
|
||||
GuString prefix = pgf_read_string(rdr);
|
||||
gu_return_on_exn(rdr->err,);
|
||||
|
||||
gu_list_index(alt->prefixes, i) = prefix;
|
||||
gu_seq_set(alt->prefixes, GuString, i, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -677,7 +677,7 @@ pgf_read_symbol(PgfReader* rdr)
|
||||
break;
|
||||
}
|
||||
case PGF_SYMBOL_KP: {
|
||||
PgfTokens default_form = pgf_read_tokens(rdr);
|
||||
PgfTokens* default_form = pgf_read_tokens(rdr);
|
||||
gu_return_on_exn(rdr->err, gu_null_variant);
|
||||
|
||||
size_t n_forms = pgf_read_len(rdr);
|
||||
@@ -710,17 +710,17 @@ pgf_read_symbol(PgfReader* rdr)
|
||||
return sym;
|
||||
}
|
||||
|
||||
static PgfSequence
|
||||
static PgfSequence*
|
||||
pgf_read_sequence(PgfReader* rdr)
|
||||
{
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, gu_null_seq);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfSequence seq = gu_new_seq(PgfSymbol, len, rdr->opool);
|
||||
PgfSequence* seq = gu_new_seq(PgfSymbol, len, rdr->opool);
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
PgfSymbol sym = pgf_read_symbol(rdr);
|
||||
gu_return_on_exn(rdr->err, gu_null_seq);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
gu_seq_set(seq, PgfSymbol, i, sym);
|
||||
}
|
||||
|
||||
@@ -733,12 +733,12 @@ pgf_read_sequences(PgfReader* rdr)
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfSequences* seqs = gu_new_list(PgfSequences, rdr->opool, len);
|
||||
PgfSequences* seqs = gu_new_seq(PgfSequence*, len, rdr->opool);
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
PgfSequence seq = pgf_read_sequence(rdr);
|
||||
PgfSequence* seq = pgf_read_sequence(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
gu_list_index(seqs, i) = seq;
|
||||
gu_seq_set(seqs, PgfSequence*, i, seq);
|
||||
}
|
||||
|
||||
return seqs;
|
||||
@@ -763,15 +763,15 @@ pgf_read_cncfun(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, int funid)
|
||||
cncfun->n_lins = len;
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
int seqid = pgf_read_int(rdr);
|
||||
size_t seqid = pgf_read_int(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
if (seqid < 0 || seqid >= gu_list_length(concr->sequences)) {
|
||||
if (seqid >= gu_seq_length(concr->sequences)) {
|
||||
gu_raise(rdr->err, PgfReadExn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cncfun->lins[i] = gu_list_elems(concr->sequences)[seqid];
|
||||
cncfun->lins[i] = gu_seq_get(concr->sequences, PgfSequence*, seqid);
|
||||
}
|
||||
|
||||
return cncfun;
|
||||
@@ -783,13 +783,13 @@ pgf_read_cncfuns(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr)
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfCncFuns* cncfuns = gu_new_list(PgfCncFuns, rdr->opool, len);
|
||||
PgfCncFuns* cncfuns = gu_new_seq(PgfCncFun*, len, rdr->opool);
|
||||
|
||||
for (size_t funid = 0; funid < len; funid++) {
|
||||
PgfCncFun* cncfun = pgf_read_cncfun(rdr, abstr, concr, funid);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
gu_list_index(cncfuns, funid) = cncfun;
|
||||
gu_seq_set(cncfuns, PgfCncFun*, funid, cncfun);
|
||||
}
|
||||
|
||||
return cncfuns;
|
||||
@@ -807,7 +807,7 @@ pgf_read_fid(PgfReader* rdr, PgfConcr* concr)
|
||||
ccat->cnccat = NULL;
|
||||
ccat->lindefs = NULL;
|
||||
ccat->n_synprods = 0;
|
||||
ccat->prods = gu_null_seq;
|
||||
ccat->prods = NULL;
|
||||
ccat->viterbi_prob = 0;
|
||||
ccat->fid = fid;
|
||||
ccat->conts = NULL;
|
||||
@@ -822,15 +822,15 @@ pgf_read_fid(PgfReader* rdr, PgfConcr* concr)
|
||||
static PgfCncFun*
|
||||
pgf_read_funid(PgfReader* rdr, PgfConcr* concr)
|
||||
{
|
||||
int32_t funid = pgf_read_int(rdr);
|
||||
size_t funid = pgf_read_int(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
if (funid < 0 || funid >= gu_list_length(concr->cncfuns)) {
|
||||
if (funid >= gu_seq_length(concr->cncfuns)) {
|
||||
gu_raise(rdr->err, PgfReadExn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return gu_list_elems(concr->cncfuns)[funid];
|
||||
return gu_seq_get(concr->cncfuns, PgfCncFun*, funid);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -845,10 +845,10 @@ 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(PgfCncFuns, rdr->opool, n_funs);
|
||||
ccat->lindefs = gu_new_seq(PgfCncFun*, n_funs, rdr->opool);
|
||||
for (size_t j = 0; j < n_funs; j++) {
|
||||
PgfCncFun* fun = pgf_read_funid(rdr, concr);
|
||||
gu_list_index(ccat->lindefs, j) = fun;
|
||||
gu_seq_set(ccat->lindefs, PgfCncFun*, j, fun);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -859,9 +859,9 @@ 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(PgfCCats, rdr->opool, n_hoas);
|
||||
parg->hypos = gu_new_seq(PgfCCat*, n_hoas, rdr->opool);
|
||||
for (size_t i = 0; i < n_hoas; i++) {
|
||||
gu_list_index(parg->hypos, i) = pgf_read_fid(rdr, concr);
|
||||
gu_seq_set(parg->hypos, PgfCCat*, i, pgf_read_fid(rdr, concr));
|
||||
gu_return_on_exn(rdr->err, );
|
||||
}
|
||||
|
||||
@@ -869,13 +869,13 @@ pgf_read_parg(PgfReader* rdr, PgfConcr* concr, PgfPArg* parg)
|
||||
gu_return_on_exn(rdr->err, );
|
||||
}
|
||||
|
||||
static PgfPArgs
|
||||
static PgfPArgs*
|
||||
pgf_read_pargs(PgfReader* rdr, PgfConcr* concr)
|
||||
{
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, gu_null_seq);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
PgfPArgs pargs = gu_new_seq(PgfPArg, len, rdr->opool);
|
||||
PgfPArgs* pargs = gu_new_seq(PgfPArg, len, rdr->opool);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
PgfPArg* parg = gu_seq_index(pargs, PgfPArg, i);
|
||||
pgf_read_parg(rdr, concr, parg);
|
||||
@@ -967,7 +967,7 @@ pgf_read_cnccat(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, PgfCId name)
|
||||
gu_assert(cnccat->abscat != NULL);
|
||||
|
||||
int len = last + 1 - first;
|
||||
cnccat->cats = gu_new_list(PgfCCats, rdr->opool, len);
|
||||
cnccat->cats = gu_new_seq(PgfCCat*, len, rdr->opool);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
int fid = first + i;
|
||||
@@ -977,7 +977,7 @@ pgf_read_cnccat(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, PgfCId name)
|
||||
ccat->cnccat = NULL;
|
||||
ccat->lindefs = NULL;
|
||||
ccat->n_synprods = 0;
|
||||
ccat->prods = gu_null_seq;
|
||||
ccat->prods = NULL;
|
||||
ccat->viterbi_prob = 0;
|
||||
ccat->fid = fid;
|
||||
ccat->conts = NULL;
|
||||
@@ -985,7 +985,7 @@ pgf_read_cnccat(PgfReader* rdr, PgfAbstr* abstr, PgfConcr* concr, PgfCId name)
|
||||
|
||||
gu_map_put(concr->ccats, &fid, PgfCCat*, ccat);
|
||||
}
|
||||
gu_list_index(cnccat->cats, i) = ccat;
|
||||
gu_seq_set(cnccat->cats, PgfCCat*, i, ccat);
|
||||
|
||||
ccat->cnccat = cnccat;
|
||||
}
|
||||
@@ -1079,7 +1079,7 @@ pgf_read_ccat_cb(GuMapItor* fn, const void* key, void* value, GuExn* err)
|
||||
PgfConcr *concr = clo->concr;
|
||||
GuPool *pool = clo->pool;
|
||||
|
||||
if (gu_seq_is_null(ccat->prods))
|
||||
if (ccat->prods == NULL)
|
||||
return;
|
||||
|
||||
size_t n_prods = gu_seq_length(ccat->prods);
|
||||
|
||||
Reference in New Issue
Block a user