Permalink
Browse files
Implement C-style for loops.
Addresses issue #66.
Also:
- Improve the error message when a construct isn't implemented.
- Loading branch information...
Showing
with
30 additions
and
12 deletions.
-
+10
−2
core/cmd_exec.py
-
+19
−9
spec/for-expr.test.sh
-
+1
−1
test/spec.sh
|
|
@@ -971,7 +971,15 @@ def _Dispatch(self, node, fork_external): |
|
|
self.loop_level -= 1
|
|
|
|
|
|
elif node.tag == command_e.ForExpr:
|
|
|
raise NotImplementedError(node.tag)
|
|
|
status = 0
|
|
|
self.arith_ev.Eval(node.init)
|
|
|
while True:
|
|
|
b = self.arith_ev.Eval(node.cond)
|
|
|
if not b:
|
|
|
break
|
|
|
|
|
|
status = self._Execute(node.body)
|
|
|
self.arith_ev.Eval(node.update)
|
|
|
|
|
|
elif node.tag == command_e.DoGroup:
|
|
|
status = self._ExecuteList(node.children)
|
|
|
@@ -1045,7 +1053,7 @@ def _Dispatch(self, node, fork_external): |
|
|
print('sys\t%.3f' % sys_, file=sys.stderr)
|
|
|
|
|
|
else:
|
|
|
raise AssertionError(node.tag)
|
|
|
raise NotImplementedError(node.__class__.__name__)
|
|
|
|
|
|
return status, check_errexit
|
|
|
|
|
|
|
|
|
@@ -9,10 +9,15 @@ for ((a=1; a <= n ; a++)) # Double parentheses, and naked 'n' |
|
|
do
|
|
|
echo $a
|
|
|
done # A construct borrowed from ksh93.
|
|
|
# status: 0
|
|
|
# stdout-json: "1\n2\n3\n4\n5\n"
|
|
|
# N-I mksh status: 1
|
|
|
# N-I mksh stdout-json: ""
|
|
|
## status: 0
|
|
|
## STDOUT:
|
|
|
1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
## N-I mksh status: 1
|
|
|
## N-I mksh stdout-json: ""
|
|
|
|
|
|
### For loop with and without semicolon
|
|
|
for ((a=1; a <= 3; a++)); do
|
|
|
@@ -21,8 +26,13 @@ done # A construct borrowed from ksh93. |
|
|
for ((a=1; a <= 3; a++)) do
|
|
|
echo $a
|
|
|
done # A construct borrowed from ksh93.
|
|
|
# status: 0
|
|
|
# stdout-json: "1\n2\n3\n1\n2\n3\n"
|
|
|
# N-I mksh status: 1
|
|
|
# N-I mksh stdout-json: ""
|
|
|
|
|
|
## status: 0
|
|
|
## STDOUT:
|
|
|
1
|
|
|
2
|
|
|
3
|
|
|
1
|
|
|
2
|
|
|
3
|
|
|
## N-I mksh status: 1
|
|
|
## N-I mksh stdout-json: ""
|
|
|
@@ -529,7 +529,7 @@ let() { |
|
|
}
|
|
|
|
|
|
for-expr() {
|
|
|
sh-spec spec/for-expr.test.sh --osh-failures-allowed 2 \
|
|
|
sh-spec spec/for-expr.test.sh \
|
|
|
$MKSH $BASH $OSH "$@"
|
|
|
}
|
|
|
|
|
|
|
0 comments on commit
40c0c79