Allow newlines after && and ||

We do the same for pipes (#1285). This matches POSIX sh behavior.
This commit is contained in:
Johannes Altmanninger
2020-08-04 21:39:37 +02:00
parent e6616d7017
commit b947e360db
6 changed files with 62 additions and 5 deletions

View File

@@ -1215,6 +1215,10 @@ parser_test_error_bits_t parse_util_detect_errors(const ast::ast_t &ast, const w
// detecting job_continuations that have source for pipes but not the statement.
bool has_unclosed_pipe = false;
// Whether we encounter a missing job, i.e. a newline after && or ||. This is found by
// detecting job_conjunction_continuations that have source for && or || but not the job.
bool has_unclosed_conjunction = false;
// Expand all commands.
// Verify 'or' and 'and' not used inside pipelines.
// Verify pipes via parser_is_pipe_forbidden.
@@ -1229,6 +1233,12 @@ parser_test_error_bits_t parse_util_detect_errors(const ast::ast_t &ast, const w
if (!jc->pipe.unsourced && !jc->statement.try_source_range().has_value()) {
has_unclosed_pipe = true;
}
} else if (const auto *jcc = node.try_as<job_conjunction_continuation_t>()) {
// Somewhat clumsy way of checking for a job without source in a conjunction.
// See if our conjunction operator (&& or ||) has source but our job does not.
if (!jcc->conjunction.unsourced && !jcc->job.try_source_range().has_value()) {
has_unclosed_conjunction = true;
}
} else if (const argument_t *arg = node.try_as<argument_t>()) {
const wcstring &arg_src = arg->source(buff_src, &storage);
res |= parse_util_detect_errors_in_argument(*arg, arg_src, out_errors);
@@ -1262,7 +1272,8 @@ parser_test_error_bits_t parse_util_detect_errors(const ast::ast_t &ast, const w
if (errored) res |= PARSER_TEST_ERROR;
if (has_unclosed_block || has_unclosed_pipe) res |= PARSER_TEST_INCOMPLETE;
if (has_unclosed_block || has_unclosed_pipe || has_unclosed_conjunction)
res |= PARSER_TEST_INCOMPLETE;
return res;
}