summaryrefslogtreecommitdiff
path: root/src/test/check_reader.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-04 11:51:58 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-04 11:51:58 +0800
commit55dc897da6e81f2a26cfc7e66ac942824773498b (patch)
treefce0d7d57832907c991d551833bf5eecde947dd2 /src/test/check_reader.c
parent53b8b6ffab5a968db75e9babddf4e2dbb2c688a3 (diff)
temporary commit
Now we can read grammars from a file. But we need to check if it works for reading strings still.
Diffstat (limited to 'src/test/check_reader.c')
-rw-r--r--src/test/check_reader.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/test/check_reader.c b/src/test/check_reader.c
index 1d73b3f..8769cd7 100644
--- a/src/test/check_reader.c
+++ b/src/test/check_reader.c
@@ -6,17 +6,29 @@
#include "../grammar.h"
#include "../reader.h"
-/* The test of reading grammars should be postponed till later. */
-
-/* Grammar *
- * read_grammar(List *args)
- * {
- *
- * } */
-
-
+/* TODO: check string */
int
main(U_ATTR int argc, U_ATTR char **argv)
{
- return 77;
+ /* return 77; */
+
+ char *file_name = "test.txt";
+ char *buffer = MYALLOC(char, 512);
+ NUM buffer_size = 0;
+
+ if (read_entire_file(file_name, &buffer, &buffer_size)) {
+ fleprintf("%s:%d, Cannot read file %s", file_name);
+ free(buffer);
+ return 1;
+ }
+
+ utf8 *s = new_utf8(buffer, buffer_size);
+
+ Grammar *g = read_grammar_from_bnf((str *) s);
+
+ print_grammar(g);
+ destroy_grammar(g, 2);
+ destroy_str((str *)s, 1);
+
+ return 0;
}