aboutsummaryrefslogtreecommitdiffhomepage
path: root/parse_tree.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-12-23 10:58:45 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-12-23 10:58:45 -0800
commit39fe9fcfcd146e726454458621700ca83700296f (patch)
tree958018be5500eb44f91ff0143bd83139963eb044 /parse_tree.cpp
parentbf80b0db1976cdeffc8481d335b1940fb8d522fc (diff)
Tweak comment handling. Mark a parse node with a new flag when it has comments
Diffstat (limited to 'parse_tree.cpp')
-rw-r--r--parse_tree.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/parse_tree.cpp b/parse_tree.cpp
index 39cee258..25ad5b61 100644
--- a/parse_tree.cpp
+++ b/parse_tree.cpp
@@ -216,7 +216,6 @@ wcstring token_type_description(parse_token_type_t type)
case parse_token_type_terminate:
return L"token_terminate";
-
case parse_special_type_parse_error:
return L"parse_error";
case parse_special_type_tokenizer_error:
@@ -339,7 +338,10 @@ static wcstring block_type_user_presentable_description(parse_token_type_t type)
wcstring parse_node_t::describe(void) const
{
wcstring result = token_type_description(type);
- append_format(result, L" (prod %d)", this->production_idx);
+ if (type < FIRST_TERMINAL_TYPE)
+ {
+ append_format(result, L" (prod %d)", this->production_idx);
+ }
return result;
}
@@ -437,6 +439,10 @@ static void dump_tree_recursive(const parse_node_tree_t &nodes, const wcstring &
{
append_format(*result, L" <%lu children>", node.child_count);
}
+ if (node.has_comments())
+ {
+ append_format(*result, L" <has_comments>", node.child_count);
+ }
if (node.has_source() && node.type == parse_token_type_string)
{
@@ -1120,6 +1126,12 @@ void parse_ll_t::accept_tokens(parse_token_t token1, parse_token_t token2)
nodes.push_back(special_node);
consumed = true;
+ /* Mark special flags */
+ if (token1.type == parse_special_type_comment)
+ {
+ this->node_for_top_symbol().flags |= parse_node_flag_has_comments;
+ }
+
/* tokenizer errors are fatal */
if (token1.type == parse_special_type_tokenizer_error)
this->fatal_errored = true;
@@ -1302,6 +1314,9 @@ bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t parse_flags,
if (parse_flags & parse_flag_accept_incomplete_tokens)
tok_options |= TOK_ACCEPT_UNFINISHED;
+ if (parse_flags & parse_flag_show_blank_lines)
+ tok_options |= TOK_SHOW_BLANK_LINES;
+
if (errors == NULL)
tok_options |= TOK_SQUASH_ERRORS;
@@ -1654,6 +1669,24 @@ parse_node_tree_t::parse_node_list_t parse_node_tree_t::specific_statements_for_
return result;
}
+parse_node_tree_t::parse_node_list_t parse_node_tree_t::comment_nodes_for_node(const parse_node_t &parent) const
+{
+ parse_node_list_t result;
+ if (parent.has_comments())
+ {
+ /* Walk all our nodes, looking for comment nodes that have the given node as a parent */
+ for (size_t i=0; i < this->size(); i++)
+ {
+ const parse_node_t &potential_comment = this->at(i);
+ if (potential_comment.type == parse_special_type_comment && this->get_parent(potential_comment) == &parent)
+ {
+ result.push_back(&potential_comment);
+ }
+ }
+ }
+ return result;
+}
+
enum parse_bool_statement_type_t parse_node_tree_t::statement_boolean_type(const parse_node_t &node)
{
assert(node.type == symbol_boolean_statement);