mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Migrate argument_list_is_root out of parse_node_tree_t
This commit is contained in:
parent
c1b60fa8e1
commit
242512f0df
3 changed files with 13 additions and 21 deletions
|
@ -1101,8 +1101,8 @@ const highlighter_t::color_array_t &highlighter_t::highlight() {
|
|||
}
|
||||
// Only work on root lists, so that we don't re-color child lists.
|
||||
case symbol_arguments_or_redirections_list: {
|
||||
if (parse_tree.argument_list_is_root(node)) {
|
||||
tnode_t<g::arguments_or_redirections_list> list(&parse_tree, &node);
|
||||
if (argument_list_is_root(list)) {
|
||||
bool cmd_is_cd = is_cd(list.try_get_parent<g::plain_statement>());
|
||||
this->color_arguments(list.descendants<g::argument>(), cmd_is_cd);
|
||||
this->color_redirections(list);
|
||||
|
@ -1110,8 +1110,8 @@ const highlighter_t::color_array_t &highlighter_t::highlight() {
|
|||
break;
|
||||
}
|
||||
case symbol_argument_list: {
|
||||
if (parse_tree.argument_list_is_root(node)) {
|
||||
tnode_t<g::argument_list> list(&parse_tree, &node);
|
||||
if (argument_list_is_root(list)) {
|
||||
this->color_arguments(list.descendants<g::argument>());
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1307,18 +1307,6 @@ const parse_node_t *parse_node_tree_t::find_node_matching_source_location(
|
|||
return result;
|
||||
}
|
||||
|
||||
bool parse_node_tree_t::argument_list_is_root(const parse_node_t &node) const {
|
||||
bool result = true;
|
||||
assert(node.type == symbol_argument_list || node.type == symbol_arguments_or_redirections_list);
|
||||
const parse_node_t *parent = this->get_parent(node);
|
||||
if (parent != NULL) {
|
||||
// We have a parent - check to make sure it's not another list!
|
||||
result = parent->type != symbol_arguments_or_redirections_list &&
|
||||
parent->type != symbol_argument_list;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
enum parse_statement_decoration_t get_decoration(tnode_t<grammar::plain_statement> stmt) {
|
||||
parse_statement_decoration_t decoration = parse_statement_decoration_none;
|
||||
if (auto decorated_statement = stmt.try_get_parent<grammar::decorated_statement>()) {
|
||||
|
|
|
@ -188,11 +188,6 @@ class parse_node_tree_t : public std::vector<parse_node_t> {
|
|||
const parse_node_t *find_node_matching_source_location(parse_token_type_t type,
|
||||
size_t source_loc,
|
||||
const parse_node_t *parent) const;
|
||||
|
||||
// Indicate if the given argument_list or arguments_or_redirections_list is a root list, or has
|
||||
// a parent.
|
||||
bool argument_list_is_root(const parse_node_t &node) const;
|
||||
|
||||
// Utilities
|
||||
|
||||
/// Given a plain statement, return true if the statement is part of a pipeline. If
|
||||
|
@ -442,6 +437,15 @@ arguments_node_list_t get_argument_nodes(tnode_t<grammar::arguments_or_redirecti
|
|||
/// Return whether the given job is background because it has a & symbol.
|
||||
bool job_node_is_background(tnode_t<grammar::job>);
|
||||
|
||||
/// Check whether an argument_list is a root list.
|
||||
inline bool argument_list_is_root(tnode_t<grammar::argument_list> list) {
|
||||
return !list.try_get_parent<grammar::argument_list>();
|
||||
}
|
||||
|
||||
inline bool argument_list_is_root(tnode_t<grammar::arguments_or_redirections_list> list) {
|
||||
return !list.try_get_parent<grammar::arguments_or_redirections_list>();
|
||||
}
|
||||
|
||||
/// The big entry point. Parse a string, attempting to produce a tree for the given goal type.
|
||||
bool parse_tree_from_string(const wcstring &str, parse_tree_flags_t flags,
|
||||
parse_node_tree_t *output, parse_error_list_t *errors,
|
||||
|
|
Loading…
Reference in a new issue