Eliminate parser_t::show_errors

Errors are now unconditionally shown
This commit is contained in:
ridiculousfish 2016-02-27 18:37:59 -08:00
parent cbd3fa6b01
commit d628fe0dea
5 changed files with 35 additions and 43 deletions

View File

@ -986,7 +986,6 @@ void completer_t::complete_from_args(const wcstring &str,
complete_flags_t flags)
{
bool is_autosuggest = (this->type() == COMPLETE_AUTOSUGGEST);
parser_t parser(false /* don't show errors */);
/* If type is COMPLETE_AUTOSUGGEST, it means we're on a background thread, so don't call proc_push_interactive */
if (! is_autosuggest)
@ -994,8 +993,14 @@ void completer_t::complete_from_args(const wcstring &str,
proc_push_interactive(0);
}
expand_flags_t eflags = is_autosuggest ? EXPAND_SKIP_CMDSUBST : 0;
expand_flags_t eflags = 0;
if (is_autosuggest)
{
eflags |= EXPAND_NO_DESCRIPTIONS | EXPAND_SKIP_CMDSUBST;
}
std::vector<completion_t> possible_comp;
const parser_t parser;
parser.expand_argument_list(args, eflags, &possible_comp);
if (! is_autosuggest)

View File

@ -593,7 +593,7 @@ static void test_parser()
{
say(L"Testing parser");
parser_t parser(true);
parser_t parser;
say(L"Testing block nesting");
if (!parse_util_detect_errors(L"if; end"))
@ -781,7 +781,6 @@ static void test_parser()
do_test(comps.at(0).completion == L"alpha");
do_test(comps.at(1).completion == L"beta gamma");
do_test(comps.at(2).completion == L"delta");
}
/* Wait a while and then SIGINT the main thread */
@ -1954,7 +1953,7 @@ static void test_is_potential_path()
int builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv);
static bool run_one_test_test(int expected, wcstring_list_t &lst, bool bracket)
{
parser_t parser(true);
parser_t parser;
size_t i, count = lst.size();
wchar_t **argv = new wchar_t *[count+3];
argv[0] = (wchar_t *)(bracket ? L"[" : L"test");
@ -1993,7 +1992,7 @@ static bool run_test_test(int expected, const wcstring &str)
static void test_test_brackets()
{
// Ensure [ knows it needs a ]
parser_t parser(true);
parser_t parser;
io_streams_t streams;
const wchar_t *argv1[] = {L"[", L"foo", NULL};
@ -4116,7 +4115,7 @@ static void test_wcstring_tok(void)
int builtin_string(parser_t &parser, io_streams_t &streams, wchar_t **argv);
static void run_one_string_test(const wchar_t **argv, int expected_rc, const wchar_t *expected_out)
{
parser_t parser(true);
parser_t parser;
io_streams_t streams;
streams.stdin_is_directly_redirected = false; // read from argv instead of stdin
int rc = builtin_string(parser, streams, const_cast<wchar_t**>(argv));

View File

@ -720,28 +720,25 @@ parse_execution_result_t parse_execution_context_t::run_while_statement(const pa
/* Reports an error. Always returns parse_execution_errored, so you can assign the result to an 'errored' variable */
parse_execution_result_t parse_execution_context_t::report_error(const parse_node_t &node, const wchar_t *fmt, ...) const
{
if (parser->show_errors)
{
/* Create an error */
parse_error_list_t error_list = parse_error_list_t(1);
parse_error_t *error = &error_list.at(0);
error->source_start = node.source_start;
error->source_length = node.source_length;
error->code = parse_error_syntax; //hackish
/* Create an error */
parse_error_list_t error_list = parse_error_list_t(1);
parse_error_t *error = &error_list.at(0);
error->source_start = node.source_start;
error->source_length = node.source_length;
error->code = parse_error_syntax; //hackish
va_list va;
va_start(va, fmt);
error->text = vformat_string(fmt, va);
va_end(va);
va_list va;
va_start(va, fmt);
error->text = vformat_string(fmt, va);
va_end(va);
this->report_errors(error_list);
}
this->report_errors(error_list);
return parse_execution_errored;
}
parse_execution_result_t parse_execution_context_t::report_errors(const parse_error_list_t &error_list) const
{
if (parser->show_errors && ! parser->cancellation_requested)
if (! parser->cancellation_requested)
{
if (error_list.empty())
{

View File

@ -162,8 +162,7 @@ static wcstring user_presentable_path(const wcstring &path)
}
parser_t::parser_t(bool errors) :
show_errors(errors),
parser_t::parser_t() :
cancellation_requested(false),
is_within_fish_initialization(false)
{
@ -176,7 +175,7 @@ parser_t &parser_t::principal_parser(void)
{
ASSERT_IS_NOT_FORKED_CHILD();
ASSERT_IS_MAIN_THREAD();
static parser_t parser(true);
static parser_t parser;
if (! s_principal_parser)
{
s_principal_parser = &parser;
@ -466,11 +465,9 @@ void parser_t::emit_profiling(const char *path) const
}
}
void parser_t::expand_argument_list(const wcstring &arg_list_src, expand_flags_t eflags, std::vector<completion_t> *output_arg_list)
void parser_t::expand_argument_list(const wcstring &arg_list_src, expand_flags_t eflags, std::vector<completion_t> *output_arg_list) const
{
assert(output_arg_list != NULL);
if (! show_errors)
eflags |= EXPAND_NO_DESCRIPTIONS;
/* Parse the string as an argument list */
parse_node_tree_t tree;
@ -831,17 +828,14 @@ int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t
/* Parse the source into a tree, if we can */
parse_node_tree_t tree;
parse_error_list_t error_list;
if (! parse_tree_from_string(cmd, parse_flag_none, &tree, this->show_errors ? &error_list : NULL))
if (! parse_tree_from_string(cmd, parse_flag_none, &tree, &error_list))
{
if (this->show_errors)
{
/* Get a backtrace */
wcstring backtrace_and_desc;
this->get_backtrace(cmd, error_list, &backtrace_and_desc);
/* Get a backtrace. This includes the message. */
wcstring backtrace_and_desc;
this->get_backtrace(cmd, error_list, &backtrace_and_desc);
/* Print it */
fprintf(stderr, "%ls", backtrace_and_desc.c_str());
}
/* Print it */
fprintf(stderr, "%ls", backtrace_and_desc.c_str());
return 1;
}

View File

@ -228,9 +228,6 @@ class parser_t
{
friend class parse_execution_context_t;
private:
/** Whether or not we output errors */
const bool show_errors;
/** Indication that we should skip all blocks */
bool cancellation_requested;
@ -283,8 +280,8 @@ public:
*/
static void skip_all_blocks();
/** Create a parser of the given type */
parser_t(bool show_errors);
/** Create a parser */
parser_t();
/** Global event blocks */
event_blockage_list_t global_event_blocks;
@ -312,7 +309,7 @@ public:
\param flags Some expand flags to use
\param output List to insert output into
*/
void expand_argument_list(const wcstring &arg_src, expand_flags_t flags, std::vector<completion_t> *output);
void expand_argument_list(const wcstring &arg_src, expand_flags_t flags, std::vector<completion_t> *output) const;
/**
Returns a string describing the current parser pisition in the format 'FILENAME (line LINE_NUMBER): LINE'.