summaryrefslogtreecommitdiff
path: root/src/test/check_reader.c
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2022-01-04 20:24:07 +0800
committerJSDurand <mmemmew@gmail.com>2022-01-04 20:24:07 +0800
commit949888ad5d0cd0f9f9a87f9938a632b3e32df051 (patch)
treeae9155484a3a5b4124c6d3fae14ada9d718c8579 /src/test/check_reader.c
parent55dc897da6e81f2a26cfc7e66ac942824773498b (diff)
Fix problems
Now some problems are fixed. It can now read grammar correctly (hopefully) from a file, in the BNF format. And strings (terminals) are handled fine as well. So glad that there are no leak problems now.
Diffstat (limited to 'src/test/check_reader.c')
-rw-r--r--src/test/check_reader.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/test/check_reader.c b/src/test/check_reader.c
index 8769cd7..3184e41 100644
--- a/src/test/check_reader.c
+++ b/src/test/check_reader.c
@@ -6,7 +6,6 @@
#include "../grammar.h"
#include "../reader.h"
-/* TODO: check string */
int
main(U_ATTR int argc, U_ATTR char **argv)
{
@@ -17,7 +16,7 @@ main(U_ATTR int argc, U_ATTR char **argv)
NUM buffer_size = 0;
if (read_entire_file(file_name, &buffer, &buffer_size)) {
- fleprintf("%s:%d, Cannot read file %s", file_name);
+ fleprintf("Cannot read file %s", file_name);
free(buffer);
return 1;
}
@@ -26,9 +25,13 @@ main(U_ATTR int argc, U_ATTR char **argv)
Grammar *g = read_grammar_from_bnf((str *) s);
- print_grammar(g);
- destroy_grammar(g, 2);
- destroy_str((str *)s, 1);
+ if (g) {
+ print_grammar(g);
+ destroy_grammar(g, 2);
+ destroy_str((str *)s, 1);
- return 0;
+ return 0;
+ }
+
+ return 1;
}