aboutsummaryrefslogtreecommitdiffhomepage
path: root/parse_util.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-01-13 13:14:18 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2014-01-13 13:19:58 -0800
commit212eeaa77c7408893df92aa9b312855bfc9dcd8e (patch)
tree74bee5635b75805f58a1714e1342f23169fd5170 /parse_util.cpp
parenteb28c710baa385cbd9b979e99736ef65b16de0db (diff)
Correctly report errors for 'and' and 'or' in pipelines with new parser
Diffstat (limited to 'parse_util.cpp')
-rw-r--r--parse_util.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/parse_util.cpp b/parse_util.cpp
index eded7b93..491e4732 100644
--- a/parse_util.cpp
+++ b/parse_util.cpp
@@ -1016,6 +1016,16 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
// an 'end' without source is an unclosed block
has_unclosed_block = true;
}
+ else if (node.type == symbol_boolean_statement)
+ {
+ // 'or' and 'and' can be in a pipeline, as long as they're first
+ // These numbers 0 and 1 correspond to productions for boolean_statement. This should be cleaned up.
+ bool is_and = (node.production_idx == 0), is_or = (node.production_idx == 1);
+ if ((is_and || is_or) && node_tree.statement_is_in_pipeline(node, false /* don't count first */))
+ {
+ errored = append_syntax_error(&parse_errors, node, EXEC_ERR_MSG, is_and ? L"and" : L"or");
+ }
+ }
else if (node.type == symbol_plain_statement)
{
wcstring command;
@@ -1028,12 +1038,10 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
}
// Check that pipes are sound
- bool is_boolean_command = contains(command, L"or", L"and");
- bool is_pipe_forbidden = parser_is_pipe_forbidden(command);
- if (! errored && (is_boolean_command || is_pipe_forbidden))
+ if (! errored && parser_is_pipe_forbidden(command))
{
- // 'or' and 'and' can be first in the pipeline. forbidden commands cannot be in a pipeline at all
- if (node_tree.plain_statement_is_in_pipeline(node, is_pipe_forbidden))
+ // forbidden commands cannot be in a pipeline at all
+ if (node_tree.statement_is_in_pipeline(node, true /* count first */))
{
errored = append_syntax_error(&parse_errors, node, EXEC_ERR_MSG, command.c_str());
}
@@ -1062,7 +1070,7 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src, pars
}
}
- // Check that we don't return from outside a function
+ // Check that we don't break or continue from outside a loop
if (! errored && (command == L"break" || command == L"continue"))
{
// Walk up until we hit a 'for' or 'while' loop. If we hit a function first, stop the search; we can't break an outer loop from inside a function.