Permalink
Please sign in to comment.
Browse files
Properly implement break/continue/return.
The existing implementation was buggy, as exposed by the tests I added
in loop.test.sh and func.test.sh.
I removed break/continue/return as builtins, and I now parse them
**statically**. This will break some overly clever programs like:
b=break;
for i in a b c; done
echo $i
$b
done
But I'm being consistent with statically-parsed assignment, and it may
make it easier to convert to Oil and do other program analysis.
Representation (i.e. the thin waist of the interpreter):
- core/id_kind.py: Add Id for break/return/continue, under new Kind
ControlFlow
- osh.asdl: add a ControlFlow variant to the command type
Algorithm:
- osh/lex.py: the lexer will return the new Ids
- osh/word_parse.py: ControlFlow tokens are treated as literals here, like
Kind.KW, Kind.Assign, Kind.BoolUnary, etc.
- osh/cmd_parse.py: parse words consisting of only ControlFlow tokens
into a ControlFlow node.
- Consistently catch errors like redirects and env prefixes on
non-commands like ControlFlow and Assign. Tested in
command-parsing.test.sh.
- cmd/cmd_exec.py:
- Introduce a new _ControlFlow exception. Get rid of the cflow return
value.
- Loops catch break and continue; functions catch return
- Check some errors dynamically. Print an error when
break/continue/return bubble up to the top level. The error message
should be improved.
Tests:
- Rename func -> func-parsing, and func test
- Misc tweaks, e.g. fix a test that wasn't checking the error status.
- Bump down --osh-allowed-failures because the fix to print to stderr in
ui.PrintError() made several of them pass
- Fix bug where we were capped at 40 tests. Now 528 total cases, OSH
passing 305, OSH failing 165.
Other cleanup:
- Get rid of ExecuteTop function.- Loading branch information...
Showing
with
451 additions
and 243 deletions.
- +5 −5 bin/oil.py
- +6 −11 core/builtin.py
- +121 −83 core/cmd_exec.py
- +4 −0 core/id_kind.py
- +1 −1 core/shell_test.py
- +10 −10 core/ui.py
- +12 −10 core/word.py
- +49 −20 osh/cmd_parse.py
- +4 −0 osh/lex.py
- +1 −0 osh/osh.asdl
- +4 −3 osh/word_parse.py
- +1 −1 spec-runner.sh
- +11 −3 spec.sh
- +53 −0 tests/command-parsing.test.sh
- +97 −0 tests/func-parsing.test.sh
- +44 −92 tests/func.test.sh
- +28 −4 tests/loop.test.sh
Oops, something went wrong.
0 comments on commit
4da19bf