diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-04-09 18:56:13 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-04-10 18:40:11 -0700 |
commit | 59f0261dba993a5d632ce6e9963270a582d162e6 (patch) | |
tree | ebc0be44c6259fc090c2612703f7e66366cc0ef3 /src/fish_indent.cpp | |
parent | 7ad6a90ea2e75388d42b5b223d9273119994037e (diff) |
enhance fish_indent to normalize keywords
Fish keywords can be quoted and split across lines. Prior to this change
`fish_indent` would retain such odd, obfuscated, formatting. This change
results in all keywords being converted to their canonical form.
This required fixing a bug: the keyword member of parse_node_t wasn't being
populated. This hadn't been noticed prior to now because it wasn't used.
Fixes #2921
Diffstat (limited to 'src/fish_indent.cpp')
-rw-r--r-- | src/fish_indent.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index d2e23943..39d296e5 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -102,10 +102,10 @@ static void dump_node(indent_t node_indent, const parse_node_t &node, const wcst nextc_str[1] = L'c'; nextc_str[2] = nextc + '@'; } - fwprintf(stderr, L"{off %4d, len %4d, indent %2u, %ls} [%ls|%ls|%ls]\n", + fwprintf(stderr, L"{off %4d, len %4d, indent %2u, kw %ls, %ls} [%ls|%ls|%ls]\n", node.source_start, node.source_length, node_indent, - parser_token_types[node.type], prevc_str, source.substr(node.source_start, - node.source_length).c_str(), nextc_str); + keyword_description(node.keyword).c_str(), parser_token_types[node.type], + prevc_str, source.substr(node.source_start, node.source_length).c_str(), nextc_str); } static void prettify_node_recursive(const wcstring &source, const parse_node_tree_t &tree, @@ -153,7 +153,13 @@ static void prettify_node_recursive(const wcstring &source, const parse_node_tre else if ((node_type >= FIRST_PARSE_TOKEN_TYPE && node_type <= LAST_PARSE_TOKEN_TYPE) || node_type == parse_special_type_parse_error) { - if (node.has_source()) + if (node.keyword != parse_keyword_none) + { + append_whitespace(node_indent, do_indent, *has_new_line, out_result); + out_result->append(keyword_description(node.keyword)); + *has_new_line = false; + } + else if (node.has_source()) { // Some type representing a particular token. if (prev_node_type != parse_token_type_redirection) |