diff options
author | JSDurand <mmemmew@gmail.com> | 2022-01-04 11:51:58 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-01-04 11:51:58 +0800 |
commit | 55dc897da6e81f2a26cfc7e66ac942824773498b (patch) | |
tree | fce0d7d57832907c991d551833bf5eecde947dd2 /src/test/check_grammar.c | |
parent | 53b8b6ffab5a968db75e9babddf4e2dbb2c688a3 (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_grammar.c')
-rw-r--r-- | src/test/check_grammar.c | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/test/check_grammar.c b/src/test/check_grammar.c index 39f66ee..98a07cd 100644 --- a/src/test/check_grammar.c +++ b/src/test/check_grammar.c @@ -37,8 +37,7 @@ main(U_ATTR int argc, U_ATTR char **argv) List *rules = new_list(); List *names = new_list(); - - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 4; i++) { tnt_string = new_tnt_string("ntn", 3, (NT) 3*(i+1), (T) 3*(i+1)*(i+1), @@ -48,18 +47,41 @@ main(U_ATTR int argc, U_ATTR char **argv) eprintf("i = %d, cannot create tnt string\n", i); map_list(rules, destroy_rule_and_free_all); - destroy_list(rules, 0); - destroy_list(names, 1); + + map_list(names, destroy_cpa_and_free_all); + destroy_list(names, 0); return 1; } - rule = new_rule(i, tnt_string); + rule = new_rule(i%3, tnt_string); add_to_list(rules, rule); char *name = MYALLOC(char, 7); snprintf(name, 7, "Rule %d", i); - add_to_list(names, name); + + utf8* uname = new_utf8(name, 6); + + str_info info = get_info((str *)uname, 0); + + NUM *varray = MYALLOC(NUM, 6); + NUM vindex = 0; + + for (NUM index = 0; + info.value >= 0 && index < str_length((str *) uname); + index += info.step, vindex++) { + info = get_info((str *)uname, index); + + *(varray+vindex) = info.value; + } + + destroy_str((str *) uname, 1); + + cpa *cpap = MYALLOC(cpa, 1); + cpap->array = varray; + cpap->size = vindex; + + add_to_list(names, cpap); } Grammar *g = new_grammar(); @@ -70,7 +92,7 @@ main(U_ATTR int argc, U_ATTR char **argv) destroy_grammar(g, 1); - free(g); + destroy_list(rules, 1); return 0; } |