From a5218fce6b19591c9412a84a5088c260c0676f61 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 17 Apr 2021 12:09:12 +0200 Subject: First commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libparser.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 libparser.h (limited to 'libparser.h') diff --git a/libparser.h b/libparser.h new file mode 100644 index 0000000..74ab319 --- /dev/null +++ b/libparser.h @@ -0,0 +1,73 @@ +/* See LICENSE file for copyright and license details. */ +#include + +union libparser_sentence; + +enum libparser_sentence_type { + LIBPARSER_SENTENCE_TYPE_CONCATENATION, /* .binary */ + LIBPARSER_SENTENCE_TYPE_ALTERNATION, /* .binary */ + LIBPARSER_SENTENCE_TYPE_OPTIONAL, /* .unary */ + LIBPARSER_SENTENCE_TYPE_REPEATED, /* .unary */ + LIBPARSER_SENTENCE_TYPE_STRING, /* .string */ + LIBPARSER_SENTENCE_TYPE_CHAR_RANGE, /* .char_range */ /* TODO not supported yet: */ + LIBPARSER_SENTENCE_TYPE_RULE, /* .rule */ + LIBPARSER_SENTENCE_TYPE_EXCEPTION, /* (none) */ + LIBPARSER_SENTENCE_TYPE_EOF /* (none) */ +}; + +struct libparser_sentence_binary { + enum libparser_sentence_type type; + const union libparser_sentence *left; + const union libparser_sentence *right; +}; + +struct libparser_sentence_unary { + enum libparser_sentence_type type; + const union libparser_sentence *sentence; +}; + +struct libparser_sentence_string { + enum libparser_sentence_type type; + const char *string; + size_t length; +}; + +struct libparser_sentence_char_range { + enum libparser_sentence_type type; + unsigned char low; + unsigned char high; +}; + +struct libparser_sentence_rule { + enum libparser_sentence_type type; + const char *rule; +}; + +union libparser_sentence { + enum libparser_sentence_type type; + struct libparser_sentence_binary binary; + struct libparser_sentence_unary unary; + struct libparser_sentence_string string; + struct libparser_sentence_char_range char_range; + struct libparser_sentence_rule rule; +}; + +struct libparser_rule { + const char *name; + union libparser_sentence *sentence; +}; + +struct libparser_unit { + const char *rule; + struct libparser_unit *in; + struct libparser_unit *next; + size_t start; + size_t end; +}; + + +extern const struct libparser_rule *const libparser_rule_table[]; + + +struct libparser_unit *libparser_parse_file(const struct libparser_rule *const rules[], + const char *data, size_t length, int *exceptionp); -- cgit v1.2.3-70-g09d2