summaryrefslogtreecommitdiff
path: root/src/runtime/c/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/runtime/c/utils')
-rw-r--r--src/runtime/c/utils/pgf-parse.c7
-rw-r--r--src/runtime/c/utils/pgf-translate.c23
2 files changed, 13 insertions, 17 deletions
diff --git a/src/runtime/c/utils/pgf-parse.c b/src/runtime/c/utils/pgf-parse.c
index 2790e49de..cb5fc6c7e 100644
--- a/src/runtime/c/utils/pgf-parse.c
+++ b/src/runtime/c/utils/pgf-parse.c
@@ -110,12 +110,11 @@ int main(int argc, char* argv[]) {
clock_t start = clock();
- GuIn *in = gu_string_in(line, ppool);
- PgfLexer *lexer = pgf_new_simple_lexer(in, ppool);
- GuEnum* result = pgf_parse_with_heuristics(concr, cat, lexer, heuristics, ppool, ppool);
+ GuExn* parse_err = gu_new_exn(NULL, gu_kind(type), ppool);
+ GuEnum* result = pgf_parse_with_heuristics(concr, cat, line, heuristics, parse_err, ppool, ppool);
PgfExprProb* ep = NULL;
- if (result != NULL)
+ if (gu_ok(parse_err))
ep = gu_next(result, PgfExprProb*, ppool);
clock_t end = clock();
diff --git a/src/runtime/c/utils/pgf-translate.c b/src/runtime/c/utils/pgf-translate.c
index aa98f1a7a..abd22267c 100644
--- a/src/runtime/c/utils/pgf-translate.c
+++ b/src/runtime/c/utils/pgf-translate.c
@@ -2,6 +2,7 @@
#include <gu/map.h>
#include <gu/enum.h>
#include <gu/file.h>
+#include <gu/exn.h>
#include <pgf/pgf.h>
#include <pgf/parser.h>
#include <pgf/literals.h>
@@ -153,23 +154,19 @@ int main(int argc, char* argv[]) {
// sentence, so our memory usage doesn't increase over time.
ppool = gu_new_pool();
- GuIn *in =
- gu_string_in(line, ppool);
- PgfLexer *lexer =
- pgf_new_simple_lexer(in, ppool);
-
clock_t start = clock();
+ GuExn* parse_err = gu_new_exn(NULL, gu_kind(type), ppool);
result =
- pgf_parse(from_concr, cat, lexer, ppool, ppool);
- if (result == NULL) {
- PgfToken tok =
- pgf_lexer_current_token(lexer);
-
- if (*tok == 0)
- gu_puts("Couldn't begin parsing", out, err);
- else {
+ pgf_parse(from_concr, cat, line, parse_err, ppool, ppool);
+ if (!gu_ok(parse_err)) {
+ if (gu_exn_caught(parse_err) == gu_type(PgfExn)) {
+ GuString msg = gu_exn_caught_data(parse_err);
+ gu_string_write(msg, out, err);
+ gu_putc('\n', out, err);
+ } else if (gu_exn_caught(parse_err) == gu_type(PgfParseError)) {
gu_puts("Unexpected token: \"", out, err);
+ GuString tok = gu_exn_caught_data(parse_err);
gu_string_write(tok, out, err);
gu_puts("\"\n", out, err);
}