fix parser error message

Fixes #4000
This commit is contained in:
Kurtis Rader 2017-04-29 21:33:50 -07:00
parent 4fde67fa50
commit 65c762f1e1
2 changed files with 6 additions and 8 deletions

View file

@ -29,13 +29,13 @@ static bool production_is_empty(const production_element_t *production) {
/// Returns a string description of this parse error. /// Returns a string description of this parse error.
wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring &prefix, wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring &prefix,
bool is_interactive, bool skip_caret) const { bool is_interactive, bool skip_caret) const {
if (skip_caret || source_start >= src.size() || source_start + source_length > src.size()) {
return L"";
}
wcstring result = prefix; wcstring result = prefix;
result.append(this->text); result.append(this->text);
if (skip_caret || source_start >= src.size() || source_start + source_length > src.size()) {
return result;
}
// Locate the beginning of this line of source. // Locate the beginning of this line of source.
size_t line_start = 0; size_t line_start = 0;
@ -64,15 +64,12 @@ wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring
// Don't include the caret and line if we're interactive this is the first line, because // Don't include the caret and line if we're interactive this is the first line, because
// then it's obvious. // then it's obvious.
bool interactive_skip_caret = is_interactive && source_start == 0; bool interactive_skip_caret = is_interactive && source_start == 0;
if (interactive_skip_caret) { if (interactive_skip_caret) {
return result; return result;
} }
// Append the line of text. // Append the line of text.
if (!result.empty()) { result.push_back(L'\n');
result.push_back(L'\n');
}
result.append(src, line_start, line_end - line_start); result.append(src, line_start, line_end - line_start);
// Append the caret line. The input source may include tabs; for that reason we // Append the caret line. The input source may include tabs; for that reason we

View file

@ -3,6 +3,7 @@
#define FISH_PARSER_H #define FISH_PARSER_H
#include <stddef.h> #include <stddef.h>
#include <unistd.h>
#include <csignal> #include <csignal>
#include <list> #include <list>