diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2014-12-23 10:58:45 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2014-12-23 10:58:45 -0800 |
commit | 39fe9fcfcd146e726454458621700ca83700296f (patch) | |
tree | 958018be5500eb44f91ff0143bd83139963eb044 /parse_tree.h | |
parent | bf80b0db1976cdeffc8481d335b1940fb8d522fc (diff) |
Tweak comment handling. Mark a parse node with a new flag when it has comments
Diffstat (limited to 'parse_tree.h')
-rw-r--r-- | parse_tree.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/parse_tree.h b/parse_tree.h index 59739af4..74e9d436 100644 --- a/parse_tree.h +++ b/parse_tree.h @@ -59,8 +59,10 @@ enum parse_flag_accept_incomplete_tokens = 1 << 2, /* Indicate that the parser should not generate the terminate token, allowing an 'unfinished' tree where some nodes may have no productions. */ - parse_flag_leave_unterminated = 1 << 3 + parse_flag_leave_unterminated = 1 << 3, + /* Indicate that the parser should generate job_list entries for blank lines. */ + parse_flag_show_blank_lines = 1 << 4 }; typedef unsigned int parse_tree_flags_t; @@ -69,6 +71,13 @@ 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); +enum +{ + /* Flag indicating that the node has associated comment nodes */ + parse_node_flag_has_comments = 1 << 0 +}; +typedef uint8_t parse_node_flags_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 { @@ -94,11 +103,14 @@ public: /* Type of the node */ enum parse_token_type_t type; + /* Node flags */ + parse_node_flags_t flags; + /* 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) + 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) { } @@ -116,6 +128,12 @@ public: return this->source_length > 0; } + /* Indicate if the node has comment nodes */ + bool has_comments() const + { + return !! (this->flags & parse_node_flag_has_comments); + } + /* Gets source for the node, or the empty string if it has no source */ wcstring get_source(const wcstring &str) const { @@ -184,6 +202,9 @@ public: /* Given a job, return all of its statements. These are 'specific statements' (e.g. symbol_decorated_statement, not symbol_statement) */ parse_node_list_t specific_statements_for_job(const parse_node_t &job) const; + /* Given a node, return all of its comment nodes. */ + parse_node_list_t comment_nodes_for_node(const parse_node_t &node) const; + /* Returns the boolean type for a boolean node */ static enum parse_bool_statement_type_t statement_boolean_type(const parse_node_t &node); |