aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parse_productions.h
diff options
context:
space:
mode:
authorGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-07-26 10:20:13 +0800
committerGravatar David Adam <zanchey@ucc.gu.uwa.edu.au>2015-07-26 10:20:13 +0800
commit3929e9de0e69666b37df87347d5ce15663e81347 (patch)
treeb2701c439c0260840ce1c68beaebf7de1178cc53 /src/parse_productions.h
parent793e1afa084982dac92c4fe19e50c25e326a79c2 (diff)
parentf4d1657c22c81a7720a91026f915b80d2d6aa6e8 (diff)
Merge branch 'master' into iwyu
Diffstat (limited to 'src/parse_productions.h')
-rw-r--r--src/parse_productions.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/parse_productions.h b/src/parse_productions.h
new file mode 100644
index 00000000..1d64ccfc
--- /dev/null
+++ b/src/parse_productions.h
@@ -0,0 +1,74 @@
+/**\file parse_tree.h
+
+ Programmatic representation of fish code.
+*/
+
+#ifndef FISH_PARSE_TREE_CONSTRUCTION_H
+#define FISH_PARSE_TREE_CONSTRUCTION_H
+
+#include <stdint.h> // for uint8_t, uint32_t
+#include "common.h" // for wcstring
+#include "parse_constants.h" // for parse_token_type_t, etc
+
+struct parse_token_t;
+
+namespace parse_productions
+{
+
+#define MAX_PRODUCTIONS 5
+#define MAX_SYMBOLS_PER_PRODUCTION 6
+
+typedef uint32_t production_tag_t;
+
+/* A production is an array of unsigned char. Symbols are encoded directly as their symbol value. Keywords are encoded with an offset of LAST_TOKEN_OR_SYMBOL + 1. So essentially we glom together keywords and symbols. */
+typedef uint8_t production_element_t;
+
+/* An index into a production option list */
+typedef uint8_t production_option_idx_t;
+
+/* A production is an array of production elements */
+typedef production_element_t const production_t[MAX_SYMBOLS_PER_PRODUCTION];
+
+/* A production options is an array of (possible) productions */
+typedef production_t production_options_t[MAX_PRODUCTIONS];
+
+/* Resolve the type from a production element */
+inline parse_token_type_t production_element_type(production_element_t elem)
+{
+ if (elem > LAST_TOKEN_OR_SYMBOL)
+ {
+ return parse_token_type_string;
+ }
+ else
+ {
+ return static_cast<parse_token_type_t>(elem);
+ }
+}
+
+/* Resolve the keyword from a production element */
+inline parse_keyword_t production_element_keyword(production_element_t elem)
+{
+ if (elem > LAST_TOKEN_OR_SYMBOL)
+ {
+ // First keyword is LAST_TOKEN_OR_SYMBOL + 1
+ return static_cast<parse_keyword_t>(elem - LAST_TOKEN_OR_SYMBOL - 1);
+ }
+ else
+ {
+ return parse_keyword_none;
+ }
+}
+
+/* Check if an element is valid */
+inline bool production_element_is_valid(production_element_t elem)
+{
+ return elem != token_type_invalid;
+}
+
+/* Fetch a production. We are passed two input tokens. The first input token is guaranteed to not be invalid; the second token may be invalid if there's no more tokens. */
+const production_t *production_for_token(parse_token_type_t node_type, const parse_token_t &input1, const parse_token_t &input2, production_option_idx_t *out_which_production, wcstring *out_error_text);
+
+}
+
+
+#endif