summaryrefslogtreecommitdiff
path: root/src/helper.h
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-07-08 12:30:21 +0800
committerJSDurand <mmemmew@gmail.com>2023-07-08 12:31:13 +0800
commit9a317e56f8a6126583f7d0c431bf878d9b1fe7b1 (patch)
tree7bb6004196b38446a5ab0cb3a0ab642d35f113e9 /src/helper.h
parent691f969eb104fa3d4c2a1667693fd0382eb9d6b5 (diff)
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.
Diffstat (limited to 'src/helper.h')
-rw-r--r--src/helper.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/helper.h b/src/helper.h
new file mode 100644
index 0000000..8be7497
--- /dev/null
+++ b/src/helper.h
@@ -0,0 +1,75 @@
+#ifndef HELPER_H
+#define HELPER_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+#include "big_endian.h"
+
+struct SignedVec {
+ unsigned char *len;
+ unsigned char *capacity;
+ char *data;
+};
+
+struct UnsignedVec {
+ unsigned char *len;
+ unsigned char *capacity;
+ unsigned char *data;
+};
+
+struct parser;
+
+struct parser *new_parser(char *grammar_string,
+ struct SignedVec *error_vec);
+
+void clean_parser(void *parser);
+
+int parser_recognize(struct parser *parser,
+ struct UnsignedVec *input_vec,
+ struct SignedVec *error_vec,
+ unsigned char reset_p);
+
+struct UnsignedVec *
+parser_parse
+(struct parser *parser,
+ struct UnsignedVec *input_vec,
+ struct SignedVec *error_vec,
+ unsigned char reset_p );
+
+struct UnsignedVec *
+parser_parse(struct parser *parser,
+ struct UnsignedVec *input_vec,
+ struct SignedVec *error_vec,
+ unsigned char reset_p);
+
+void clean_signed(struct SignedVec *vec, unsigned char flag);
+void clean_unsigned(struct UnsignedVec *vec, unsigned char flag);
+
+typedef enum Status {
+ Plain = 0,
+ Packed = 1,
+ Clone = 2,
+} Status;
+
+typedef enum Variant {
+ Terminal = 0,
+ Nonterminal = 1,
+ Rule = 2,
+} Variant;
+
+struct Label {
+ Status status;
+ uint64_t clone_index;
+ uint64_t start;
+ uint64_t end;
+ Variant variant;
+ uint64_t content;
+};
+
+struct Label read_label(unsigned char *ptr);
+
+void print_label(struct Label label);
+
+#endif