diff options
| author | kr.angelov <kr.angelov@gmail.com> | 2013-10-09 12:08:51 +0000 |
|---|---|---|
| committer | kr.angelov <kr.angelov@gmail.com> | 2013-10-09 12:08:51 +0000 |
| commit | 8cf03bc5b6895568eb08be1415985a64793bb81c (patch) | |
| tree | 814e95e1b0422362066fef389e8b03741e8478ad /src/runtime/c/pgf/pgf.c | |
| parent | 20e4970ec19949da10b86facd3c6a5a4abb03acb (diff) | |
a major redesign in the C runtime. The parser and the linearizer now fully support BIND. The following things are still broken: parseval, word completion, handling 'pre', the robust mode
Diffstat (limited to 'src/runtime/c/pgf/pgf.c')
| -rw-r--r-- | src/runtime/c/pgf/pgf.c | 76 |
1 files changed, 4 insertions, 72 deletions
diff --git a/src/runtime/c/pgf/pgf.c b/src/runtime/c/pgf/pgf.c index a1eb62c95..39b032adb 100644 --- a/src/runtime/c/pgf/pgf.c +++ b/src/runtime/c/pgf/pgf.c @@ -4,7 +4,6 @@ #include <pgf/reader.h> #include <pgf/linearizer.h> #include <pgf/parser.h> -#include <pgf/lexer.h> #include <gu/file.h> #include <gu/string.h> #include <gu/enum.h> @@ -61,7 +60,8 @@ pgf_load_meta_child_probs(PgfPGF* pgf, const char* fpath, PgfAbsCat* abscat1 = gu_map_get(pgf->abstract.cats, cat1, PgfAbsCat*); if (abscat1 == NULL) { - gu_raise(err, PgfExn); + GuExnData* exn = gu_raise(err, PgfExn); + exn->data = "Unknown category name"; goto close; } @@ -73,6 +73,8 @@ pgf_load_meta_child_probs(PgfPGF* pgf, const char* fpath, PgfAbsCat* abscat2 = gu_map_get(pgf->abstract.cats, cat2, PgfAbsCat*); if (abscat2 == NULL) { gu_raise(err, PgfExn); + GuExnData* exn = gu_raise(err, PgfExn); + exn->data = "Unknown category name"; goto close; } @@ -228,73 +230,3 @@ pgf_linearize(PgfConcr* concr, PgfExpr expr, GuOut* out, GuExn* err) gu_pool_free(tmp_pool); } - -GuEnum* -pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, - GuPool* pool, GuPool* out_pool) -{ - return pgf_parse_with_heuristics(concr, cat, lexer, -1.0, pool, out_pool); -} - -GuEnum* -pgf_parse_with_heuristics(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, - double heuristics, - GuPool* pool, GuPool* out_pool) -{ - // Begin parsing a sentence of the specified category - PgfParseState* state = - pgf_parser_init_state(concr, cat, 0, heuristics, pool, out_pool); - if (state == NULL) { - return NULL; - } - - // Tokenization - GuExn* lex_err = gu_new_exn(NULL, gu_kind(type), pool); - PgfToken tok = pgf_lexer_read_token(lexer, lex_err); - while (!gu_exn_is_raised(lex_err)) { - // feed the token to get a new parse state - state = pgf_parser_next_state(state, tok); - if (state == NULL) { - return NULL; - } - - tok = pgf_lexer_read_token(lexer, lex_err); - } - - if (gu_exn_caught(lex_err) != gu_type(GuEOF)) - return NULL; - - // Now begin enumerating the resulting syntax trees - return pgf_parse_result(state); -} - -GuEnum* -pgf_complete(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, - GuString prefix, GuPool* pool) -{ - // Begin parsing a sentence of the specified category - PgfParseState* state = - pgf_parser_init_state(concr, cat, 0, -1, pool, pool); - if (state == NULL) { - return NULL; - } - - // Tokenization - GuExn* lex_err = gu_new_exn(NULL, gu_kind(type), pool); - PgfToken tok = pgf_lexer_read_token(lexer, lex_err); - while (!gu_exn_is_raised(lex_err)) { - // feed the token to get a new parse state - state = pgf_parser_next_state(state, tok); - if (state == NULL) { - return NULL; - } - - tok = pgf_lexer_read_token(lexer, lex_err); - } - - if (gu_exn_caught(lex_err) != gu_type(GuEOF)) - return NULL; - - // Now begin enumerating the resulting syntax trees - return pgf_parser_completions(state, prefix); -} |
