From 9a317e56f8a6126583f7d0c431bf878d9b1fe7b1 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 8 Jul 2023 12:30:21 +0800 Subject: Finished the Emacs binding. Now the binding part is finished. What remains is a bug encountered when planting a fragment to the forest which intersects a packed node, which would lead to invalid forests. This will also cause problem when planting a packed fragment, but until now my testing grammars do not produce packed fragments, so this problem is not encountered yet. I am still figuring out efficient ways to solve this problem. --- src/helper.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/helper.c (limited to 'src/helper.c') diff --git a/src/helper.c b/src/helper.c new file mode 100644 index 0000000..5d7e9f8 --- /dev/null +++ b/src/helper.c @@ -0,0 +1,73 @@ +#include "helper.h" + +struct Label +read_label(unsigned char *ptr) +{ + struct Label label = { 0 }; + + switch (*ptr) { + case Plain: + label.status = Plain; + break; + case Packed: + label.status = Packed; + break; + default: + label.status = Clone; + label.clone_index = from_big_endian(ptr+1); + break; + } + + label.start = from_big_endian(ptr+9); + label.end = from_big_endian(ptr+17); + + switch (*(ptr+25)) { + case Terminal: + label.variant = Terminal; + break; + case Nonterminal: + label.variant = Nonterminal; + break; + default: + label.variant = Rule; + break; + } + + label.content = from_big_endian(ptr+26); + + return label; +} + +void +print_label(struct Label label) +{ + switch (label.status) { + case Plain: + printf("a plain node "); + break; + case Packed: + printf("a packed node "); + break; + default: + printf("a cloned node with index %llu ", label.clone_index); + break; + } + + printf("spanning (%llu, %llu) ", label.start, label.end); + + printf("labelled as a "); + + switch (label.variant) { + case Terminal: + printf("terminal "); + break; + case Nonterminal: + printf("non-terminal "); + break; + default: + printf("rule "); + break; + } + + printf("%llu\n", label.content); +} -- cgit v1.2.3-18-g5258