aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/parse_tree.h
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-12-15 14:59:03 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-12-19 11:17:13 -0800
commit8c707a4e2ffc30bae6d9ac3a28bd05fca0ff1195 (patch)
tree786b8ac916b5c873be902e8e3a1cbf9b38aaf53c /src/parse_tree.h
parent7188d94c1bdc483e6dca877631ca6dfa6af0ebbc (diff)
Simplify parser implementation
Rather than returning a list of productions and an index, return the relevant production directly from the rule function. Also introduce a tag value (replacing production_idx) which tracks information like command decorations, etc. with more clarity.
Diffstat (limited to 'src/parse_tree.h')
-rw-r--r--src/parse_tree.h17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/parse_tree.h b/src/parse_tree.h
index 31344639..55bb9c1a 100644
--- a/src/parse_tree.h
+++ b/src/parse_tree.h
@@ -66,13 +66,17 @@ wcstring parse_dump_tree(const parse_node_tree_t &tree, const wcstring &src);
wcstring token_type_description(parse_token_type_t type);
wcstring keyword_description(parse_keyword_t type);
+/* Node flags */
enum
{
/* Flag indicating that the node has associated comment nodes */
- parse_node_flag_has_comments = 1 << 0
+ parse_node_flag_has_comments = 1 << 0,
};
typedef uint8_t parse_node_flags_t;
+/* Node-type specific tag value */
+typedef uint8_t parse_node_tag_t;
+
/** Class for nodes of a parse tree. Since there's a lot of these, the size and order of the fields is important. */
class parse_node_t
{
@@ -92,20 +96,23 @@ public:
/* Number of children */
uint8_t child_count;
- /* Which production was used */
- uint8_t production_idx;
-
/* Type of the node */
enum parse_token_type_t type;
+
+ /* Keyword associated with node */
+ enum parse_keyword_t keyword;
/* Node flags */
parse_node_flags_t flags;
+
+ /* This is used to store e.g. the statement decoration. */
+ parse_node_tag_t tag;
/* Description */
wcstring describe(void) const;
/* Constructor */
- explicit parse_node_t(parse_token_type_t ty) : source_start(SOURCE_OFFSET_INVALID), source_length(0), parent(NODE_OFFSET_INVALID), child_start(0), child_count(0), production_idx(-1), type(ty), flags(0)
+ explicit parse_node_t(parse_token_type_t ty) : source_start(SOURCE_OFFSET_INVALID), source_length(0), parent(NODE_OFFSET_INVALID), child_start(0), child_count(0), type(ty), flags(0), tag(0)
{
}