1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:17:46 +00:00

Shell: Add runtime errors and implement break/continue

Such errors are raised when SyntaxError nodes are executed, and are also
used for internal control flow.
The 'break' and 'continue' commands are currently only allowed inside
for loops, and outside function bodies.

This also adds a 'loop' keyword for infinite loops.
This commit is contained in:
AnotherTest 2020-12-10 18:25:13 +03:30 committed by Andreas Kling
parent 9bd81f34a5
commit 5e5eb615ec
14 changed files with 384 additions and 62 deletions

View file

@ -4,6 +4,10 @@ singlecommand_ok=yes
multicommand_ok=yes
inlineexec_ok=yes
implicit_ok=yes
infinite_ok=''
break_ok=yes
continue_ok=yes
break_in_infinite_ok=''
# Full form
# Empty
@ -42,9 +46,32 @@ for ((test 1 = 1) (test 2 = 2)) {
$it || unset implicit_ok
}
# Infinite loop
loop {
infinite_ok=yes
break
unset break_ok
}
# 'Continue'
for (1 2 3) {
continue
unset continue_ok
}
# 'break' in infinite external loop
for $(yes) {
break_in_infinite_ok=yes
break
}
test $singlecommand_ok || echo Fail: Single command inside for body
test $multicommand_ok || echo Fail: Multiple commands inside for body
test $inlineexec_ok || echo Fail: Inline Exec
test $implicit_ok || echo Fail: implicit iter variable
test $infinite_ok || echo Fail: infinite loop
test $break_ok || echo Fail: break
test $continue_ok || echo Fail: continue
test $break_in_infinite_ok || echo Fail: break from external infinite loop
test "$singlecommand_ok $multicommand_ok $inlineexec_ok $implicit_ok" = "yes yes yes yes" || exit 1
test "$singlecommand_ok $multicommand_ok $inlineexec_ok $implicit_ok $infinite_ok $break_ok $continue_ok $break_in_infinite_ok" = "yes yes yes yes yes yes yes yes" || exit 1