remove the read and write modules from libgu. this simplifies the i/o layer

This commit is contained in:
kr.angelov
2013-09-05 11:20:39 +00:00
parent d0f527d0dd
commit 83ca6c4f9f
32 changed files with 418 additions and 670 deletions

View File

@@ -1,6 +1,5 @@
#include <gu/variant.h>
#include <gu/map.h>
#include <gu/dump.h>
#include <gu/log.h>
#include <gu/enum.h>
#include <gu/file.h>
@@ -75,11 +74,6 @@ int main(int argc, char* argv[]) {
// Create an output stream for stdout
GuOut* out = gu_file_out(stdout, pool);
// Locale-encoding writers are currently unsupported
// GuWriter* wtr = gu_locale_writer(out, pool);
// Use a writer with hard-coded utf-8 encoding for now.
GuWriter* wtr = gu_new_utf8_writer(out, pool);
// We will keep the latest results in the 'ppool' and
// we will iterate over them by using 'result'.
GuPool* ppool = NULL;
@@ -118,8 +112,8 @@ int main(int argc, char* argv[]) {
clock_t start = clock();
GuReader *rdr = gu_string_reader(gu_str_string(line, ppool), ppool);
PgfLexer *lexer = pgf_new_simple_lexer(rdr, ppool);
GuIn *in = gu_string_in(gu_str_string(line, ppool), ppool);
PgfLexer *lexer = pgf_new_simple_lexer(in, ppool);
GuEnum* result = pgf_parse_with_heuristics(concr, cat, lexer, heuristics, ppool, ppool);
PgfExprProb* ep = NULL;
@@ -129,15 +123,15 @@ int main(int argc, char* argv[]) {
clock_t end = clock();
double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
gu_printf(wtr, err, "%d (%.0f ms): ", ctr, 1000.0 * cpu_time_used);
gu_printf(out, err, "%d (%.0f ms): ", ctr, 1000.0 * cpu_time_used);
if (ep != NULL) {
gu_printf(wtr, err, "[%.4f] (", ep->prob);
pgf_print_expr(ep->expr, NULL, 0, wtr, err);
gu_printf(wtr, err, ")\n");
gu_printf(out, err, "[%.4f] (", ep->prob);
pgf_print_expr(ep->expr, NULL, 0, out, err);
gu_printf(out, err, ")\n");
} else {
gu_printf(wtr, err, "---\n");
gu_printf(out, err, "---\n");
}
gu_writer_flush(wtr, err);
gu_out_flush(out, err);
}
fail:

View File

@@ -1,7 +1,6 @@
#include <pgf/pgf.h>
#include <pgf/data.h>
#include <gu/dump.h>
#include <gu/file.h>
#include <gu/utf8.h>
@@ -30,9 +29,8 @@ int main(int argc, char* argv[]) {
goto fail_read;
}
GuOut* out = gu_file_out(stdout, pool);
GuWriter* wtr = gu_new_utf8_writer(out, pool);
pgf_print(pgf, wtr, err);
gu_writer_flush(wtr, err);
pgf_print(pgf, out, err);
gu_out_flush(out, err);
fail_read:
gu_pool_free(pool);
return status;

View File

@@ -91,10 +91,9 @@ render(PgfPGF* pgf, PgfExpr expr, GuPool* pool)
/* Parent. */
FILE* fstream = fdopen(pc[1], "w");
GuOut* out = gu_file_out(fstream, pool);
GuWriter* wtr = gu_new_utf8_writer(out, pool);
GuExn* err = gu_new_exn(NULL, gu_kind(type), pool);
pgf_graphviz_abstract_tree(pgf, expr, wtr, err);
pgf_graphviz_abstract_tree(pgf, expr, out, err);
fclose(fstream);
close(cp[1]);
@@ -138,11 +137,11 @@ static void
linearize(PgfConcr* concr, PgfExpr expr, GuPool* pool)
{
GuStringBuf* sbuf = gu_string_buf(pool);
GuWriter* wtr = gu_string_buf_writer(sbuf);
GuOut* out = gu_string_buf_out(sbuf);
GuExn* err = gu_new_exn(NULL, gu_kind(type), pool);
pgf_linearize(concr, expr, wtr, err);
pgf_linearize(concr, expr, out, err);
GuString s = gu_string_buf_freeze(sbuf, pool);
put_gu_string(s);

View File

@@ -1,6 +1,5 @@
#include <gu/variant.h>
#include <gu/map.h>
#include <gu/dump.h>
#include <gu/log.h>
#include <gu/enum.h>
#include <gu/file.h>
@@ -17,12 +16,12 @@
static void
print_result(PgfExprProb* ep, PgfConcr* to_concr,
GuWriter* wtr, GuExn* err, GuPool* ppool)
GuOut* out, GuExn* err, GuPool* ppool)
{
// Write out the abstract syntax tree
gu_printf(wtr, err, " [%f] ", ep->prob);
pgf_print_expr(ep->expr, NULL, 0, wtr, err);
gu_putc('\n', wtr, err);
gu_printf(out, err, " [%f] ", ep->prob);
pgf_print_expr(ep->expr, NULL, 0, out, err);
gu_putc('\n', out, err);
// Enumerate the concrete syntax trees corresponding
// to the abstract tree.
@@ -33,12 +32,12 @@ print_result(PgfExprProb* ep, PgfConcr* to_concr,
if (gu_variant_is_null(ctree)) {
break;
}
gu_putc(' ', wtr, err);
gu_putc(' ', out, err);
// Linearize the concrete tree as a simple
// sequence of strings.
pgf_lzr_linearize_simple(to_concr , ctree, 0, wtr, err);
gu_putc('\n', wtr, err);
gu_writer_flush(wtr, err);
pgf_lzr_linearize_simple(to_concr , ctree, 0, out, err);
gu_putc('\n', out, err);
gu_out_flush(out, err);
}
}
@@ -100,11 +99,6 @@ int main(int argc, char* argv[]) {
// Create an output stream for stdout
GuOut* out = gu_file_out(stdout, pool);
// Locale-encoding writers are currently unsupported
// GuWriter* wtr = gu_locale_writer(out, pool);
// Use a writer with hard-coded utf-8 encoding for now.
GuWriter* wtr = gu_new_utf8_writer(out, pool);
// We will keep the latest results in the 'ppool' and
// we will iterate over them by using 'result'.
GuPool* ppool = NULL;
@@ -145,7 +139,7 @@ int main(int argc, char* argv[]) {
goto fail_parse;
}
print_result(ep, to_concr, wtr, err, ppool);
print_result(ep, to_concr, out, err, ppool);
}
continue;
}
@@ -161,10 +155,10 @@ int main(int argc, char* argv[]) {
// sentence, so our memory usage doesn't increase over time.
ppool = gu_new_pool();
GuReader *rdr =
gu_string_reader(gu_str_string(line, ppool), ppool);
GuIn *in =
gu_string_in(gu_str_string(line, ppool), ppool);
PgfLexer *lexer =
pgf_new_simple_lexer(rdr, ppool);
pgf_new_simple_lexer(in, ppool);
clock_t start = clock();
@@ -175,11 +169,11 @@ int main(int argc, char* argv[]) {
pgf_lexer_current_token(lexer);
if (gu_string_eq(tok, gu_empty_string))
gu_puts("Couldn't begin parsing", wtr, err);
gu_puts("Couldn't begin parsing", out, err);
else {
gu_puts("Unexpected token: \"", wtr, err);
gu_string_write(tok, wtr, err);
gu_puts("\"\n", wtr, err);
gu_puts("Unexpected token: \"", out, err);
gu_string_write(tok, out, err);
gu_puts("\"\n", out, err);
}
goto fail_parse;
@@ -196,7 +190,7 @@ int main(int argc, char* argv[]) {
goto fail_parse;
}
print_result(ep, to_concr, wtr, err, ppool);
print_result(ep, to_concr, out, err, ppool);
continue;
fail_parse: