remove dead code

Remove code for the `__fish_parse` builin that has been commented out
for three years. Add a call to `parse_dump_tree()` to fish_indent.
This commit is contained in:
Kurtis Rader 2017-06-12 17:59:44 -07:00
parent a6227f6c3a
commit 7a6a766e0a
3 changed files with 12 additions and 59 deletions

View File

@ -3050,53 +3050,6 @@ static int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **ar
return status;
}
#if 0
// Disabled for the 2.2.0 release: https://github.com/fish-shell/fish-shell/issues/1809.
int builtin_parse(parser_t &parser, io_streams_t &streams, wchar_t **argv)
{
struct sigaction act;
sigemptyset(& act.sa_mask);
act.sa_flags=0;
act.sa_handler=SIG_DFL;
sigaction(SIGINT, &act, 0);
std::vector<char> txt;
for (;;)
{
char buff[256];
ssize_t amt = read_loop(streams.stdin_fd, buff, sizeof buff);
if (amt <= 0) break;
txt.insert(txt.end(), buff, buff + amt);
}
if (! txt.empty())
{
const wcstring src = str2wcstring(&txt.at(0), txt.size());
parse_node_tree_t parse_tree;
parse_error_list_t errors;
bool success = parse_tree_from_string(src, parse_flag_include_comments, &parse_tree,
&errors);
if (! success)
{
streams.out.append(L"Parsing failed:\n");
for (size_t i=0; i < errors.size(); i++)
{
streams.out.append(errors.at(i).describe(src));
streams.out.push_back(L'\n');
}
streams.out.append(L"(Reparsed with continue after error)\n");
parse_tree.clear();
errors.clear();
parse_tree_from_string(src, parse_flag_continue_after_error |
parse_flag_include_comments, &parse_tree, &errors);
}
const wcstring dump = parse_dump_tree(parse_tree, src);
streams.out.append(dump);
}
return STATUS_CMD_OK;
}
#endif
int builtin_true(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
UNUSED(parser);
UNUSED(streams);
@ -3152,10 +3105,6 @@ int builtin_realpath(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// NOTE: These must be kept in sorted order!
static const builtin_data_t builtin_datas[] = {
{L"[", &builtin_test, N_(L"Test a condition")},
#if 0
// Disabled for the 2.2.0 release: https://github.com/fish-shell/fish-shell/issues/1809.
{ L"__fish_parse", &builtin_parse, N_(L"Try out the new parser") },
#endif
{L"and", &builtin_generic, N_(L"Execute command if previous command suceeded")},
{L"begin", &builtin_generic, N_(L"Create a block of code")},
{L"bg", &builtin_bg, N_(L"Send job to background")},

View File

@ -172,23 +172,27 @@ static void prettify_node_recursive(const wcstring &source, const parse_node_tre
// Entry point for prettification.
static wcstring prettify(const wcstring &src, bool do_indent) {
parse_node_tree_t tree;
parse_node_tree_t parse_tree;
int parse_flags = (parse_flag_continue_after_error | parse_flag_include_comments |
parse_flag_leave_unterminated | parse_flag_show_blank_lines);
if (!parse_tree_from_string(src, parse_flags, &tree, NULL)) {
// We return the initial string on failure.
return src;
if (!parse_tree_from_string(src, parse_flags, &parse_tree, NULL)) {
return src; // we return the original string on failure
}
if (dump_parse_tree) {
const wcstring dump = parse_dump_tree(parse_tree, src);
fwprintf(stderr, L"%ls\n", dump.c_str());
}
// We may have a forest of disconnected trees on a parse failure. We have to handle all nodes
// that have no parent, and all parse errors.
bool has_new_line = true;
wcstring result;
for (node_offset_t i = 0; i < tree.size(); i++) {
const parse_node_t &node = tree.at(i);
for (node_offset_t i = 0; i < parse_tree.size(); i++) {
const parse_node_t &node = parse_tree.at(i);
if (node.parent == NODE_OFFSET_INVALID || node.type == parse_special_type_parse_error) {
// A root node.
prettify_node_recursive(src, tree, i, 0, symbol_job_list, &has_new_line, &result,
prettify_node_recursive(src, parse_tree, i, 0, symbol_job_list, &has_new_line, &result,
do_indent);
}
}

View File

@ -254,7 +254,7 @@ static inline parse_token_type_t parse_token_type_from_tokenizer_token(
return result;
}
#if 0
#if 1
// Disabled for the 2.2.0 release: https://github.com/fish-shell/fish-shell/issues/1809.
/// Helper function for parse_dump_tree().