mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Support for break/continue with new parser execution
This commit is contained in:
parent
c632307eaa
commit
a42711e31c
4 changed files with 76 additions and 2 deletions
|
@ -47,7 +47,7 @@ node_offset_t parse_execution_context_t::get_offset(const parse_node_t &node) co
|
||||||
|
|
||||||
bool parse_execution_context_t::should_cancel_execution(const block_t *block) const
|
bool parse_execution_context_t::should_cancel_execution(const block_t *block) const
|
||||||
{
|
{
|
||||||
return block && block->skip;
|
return block && (block->skip || block->loop_status != LOOP_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_execution_context_t::run_if_statement(const parse_node_t &statement)
|
int parse_execution_context_t::run_if_statement(const parse_node_t &statement)
|
||||||
|
@ -228,6 +228,19 @@ int parse_execution_context_t::run_for_statement(const parse_node_t &header, con
|
||||||
fb->skip = 0;
|
fb->skip = 0;
|
||||||
|
|
||||||
this->run_job_list(block_contents, fb);
|
this->run_job_list(block_contents, fb);
|
||||||
|
|
||||||
|
/* Handle break or continue */
|
||||||
|
if (fb->loop_status == LOOP_CONTINUE)
|
||||||
|
{
|
||||||
|
/* Reset the loop state */
|
||||||
|
fb->loop_status = LOOP_NORMAL;
|
||||||
|
fb->skip = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (fb->loop_status == LOOP_BREAK)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return proc_get_last_status();
|
return proc_get_last_status();
|
||||||
|
@ -358,7 +371,21 @@ int parse_execution_context_t::run_while_statement(const parse_node_t &header, c
|
||||||
/* A while loop is a while loop! */
|
/* A while loop is a while loop! */
|
||||||
while (! this->should_cancel_execution(wb) && this->run_1_job(while_condition, wb) == EXIT_SUCCESS)
|
while (! this->should_cancel_execution(wb) && this->run_1_job(while_condition, wb) == EXIT_SUCCESS)
|
||||||
{
|
{
|
||||||
|
/* The block ought to go inside the loop (see #1212) */
|
||||||
this->run_job_list(block_contents, wb);
|
this->run_job_list(block_contents, wb);
|
||||||
|
|
||||||
|
/* Handle break or continue */
|
||||||
|
if (wb->loop_status == LOOP_CONTINUE)
|
||||||
|
{
|
||||||
|
/* Reset the loop state */
|
||||||
|
wb->loop_status = LOOP_NORMAL;
|
||||||
|
wb->skip = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (wb->loop_status == LOOP_BREAK)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Done */
|
/* Done */
|
||||||
|
@ -562,7 +589,7 @@ wcstring_list_t parse_execution_context_t::determine_arguments(const parse_node_
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return if we had a wildcard problem */
|
/* Return if we had a wildcard problem */
|
||||||
if (unmatched_wildcard && ! matched_wildcard)
|
if (out_unmatched_wildcard_node != NULL && unmatched_wildcard && ! matched_wildcard)
|
||||||
{
|
{
|
||||||
*out_unmatched_wildcard_node = unmatched_wildcard_node;
|
*out_unmatched_wildcard_node = unmatched_wildcard_node;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2602,6 +2602,13 @@ int parser_t::eval_new_parser(const wcstring &cmd, const io_chain_t &io, enum bl
|
||||||
{
|
{
|
||||||
CHECK_BLOCK(1);
|
CHECK_BLOCK(1);
|
||||||
|
|
||||||
|
if (block_type != TOP && block_type != SUBST)
|
||||||
|
{
|
||||||
|
debug(1, INVALID_SCOPE_ERR_MSG, parser_t::get_block_desc(block_type));
|
||||||
|
bugreport();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse the source into a tree, if we can */
|
/* Parse the source into a tree, if we can */
|
||||||
parse_node_tree_t tree;
|
parse_node_tree_t tree;
|
||||||
if (! parse_t::parse(cmd, parse_flag_none, &tree, NULL))
|
if (! parse_t::parse(cmd, parse_flag_none, &tree, NULL))
|
||||||
|
|
|
@ -35,3 +35,37 @@ emit test3 foo bar
|
||||||
|
|
||||||
# test empty argument
|
# test empty argument
|
||||||
emit
|
emit
|
||||||
|
|
||||||
|
echo "Test break and continue"
|
||||||
|
# This should output Ping once
|
||||||
|
for i in a b c
|
||||||
|
if not contains $i c ; continue ; end
|
||||||
|
echo Ping
|
||||||
|
end
|
||||||
|
|
||||||
|
# This should output Pong not at all
|
||||||
|
for i in a b c
|
||||||
|
if not contains $i c ; break ; end
|
||||||
|
echo Pong
|
||||||
|
end
|
||||||
|
|
||||||
|
# This should output Foop three times, and Boop not at all
|
||||||
|
set i a a a
|
||||||
|
while contains $i a
|
||||||
|
set -e i[-1]
|
||||||
|
echo Foop
|
||||||
|
continue
|
||||||
|
echo Boop
|
||||||
|
end
|
||||||
|
|
||||||
|
# This should output Doop once
|
||||||
|
set i a a a
|
||||||
|
while contains $i a
|
||||||
|
set -e i[-1]
|
||||||
|
echo Doop
|
||||||
|
break
|
||||||
|
echo Darp
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
false
|
||||||
|
|
|
@ -2,3 +2,9 @@ Testing that builtins can truncate files
|
||||||
abc
|
abc
|
||||||
before:test1
|
before:test1
|
||||||
received event test3 with args: foo bar
|
received event test3 with args: foo bar
|
||||||
|
Test break and continue
|
||||||
|
Ping
|
||||||
|
Foop
|
||||||
|
Foop
|
||||||
|
Foop
|
||||||
|
Doop
|
||||||
|
|
Loading…
Reference in a new issue