Skip to content

Commit 7a7ec25

Browse files
committed
Fix comma treatment in arith
1 parent ff3e210 commit 7a7ec25

File tree

7 files changed

+26
-5
lines changed

7 files changed

+26
-5
lines changed

src/elements/arithmetic_expr/calculator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ fn bin_calc_operation(op: &str, stack: &mut Vec<Elem>, core: &mut ShellCore) ->
3232
Ok(v) => v,
3333
Err(e) => return Err(e),
3434
};
35+
3536
let left = match pop_operand(stack, core) {
3637
Ok(v) => v,
3738
Err(e) => return Err(e),
3839
};
3940

41+
if op == "," {
42+
stack.push(right);
43+
return Ok(());
44+
}
45+
4046
return match (left, right) {
4147
(Elem::Float(fl), Elem::Float(fr)) => float::bin_calc(op, fl, fr, stack),
4248
(Elem::Float(fl), Elem::Integer(nr)) => float::bin_calc(op, fl, nr as f64, stack),

src/elements/arithmetic_expr/elem.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ pub fn op_order(op: &Elem) -> u8 {
3939
"|" => 9,
4040
"&&" => 8,
4141
"||" => 7,
42-
_ => 2,
42+
"," => 0,
43+
_ => 2, //substitution
4344
}
4445
},
4546
Elem::Ternary(_, _) => 3,
46-
_ => 0,
47+
_ => 1,
4748
}
4849
}
4950

src/elements/arithmetic_expr/parser.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ impl ArithmeticExpr {
162162
loop {
163163
Self::eat_blank(feeder, &mut ans, core);
164164

165-
if feeder.starts_with(":")
166-
|| feeder.starts_with(",") {
165+
if feeder.starts_with(":") {
167166
break;
168167
}
169168

src/feeder/scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl Feeder {
203203
">", "=", "&", "|", "^", "/", "%"], core);
204204
self.scanner_one_of(&["<<=", ">>=",
205205
"&&", "||", "**", "==", "!=", "*=", "/=", "%=", "+=", "-=", "&=", "^=", "|=",
206-
">>", "<<", "<=", ">=", "&", "^", "=", "+", "-", "/", "*", "%", "<", ">", "|", "^"/*, ","*/])
206+
">>", "<<", "<=", ">=", "&", "^", "=", "+", "-", "/", "*", "%", "<", ">", "|", "^", ","])
207207
}
208208

209209
pub fn scanner_uint(&mut self, core: &mut ShellCore) -> usize {

test/error

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
../test/test_compound.bash
22
../test/test_others.bash
33
../test/test_others.bash
4+
../../test/test_others.bash
5+
../../../test/test_others.bash
6+
../../../test/test_others.bash
7+
../../../test/test_others.bash

test/ok

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
../test/test_compound.bash
99
../test/test_compound.bash
1010
../../test/test_others.bash
11+
../../test/test_others.bash
12+
../../../test/test_others.bash
13+
../../../test/test_others.bash

test/test_others.bash

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,14 @@ res=$($com<<<'echo $((A=1 && B=1))')
764764
[ "$?" == "1" ] || err $LINENO
765765
[ "$res" == "" ] || err $LINENO
766766

767+
res=$($com<<<'echo $((A=1 && (B=1) ))')
768+
[ "$?" == "0" ] || err $LINENO
769+
[ "$res" == "1" ] || err $LINENO
770+
771+
res=$($com<<<'echo $((A=1 && (B=1, 0) ))')
772+
[ "$?" == "0" ] || err $LINENO
773+
[ "$res" == "0" ] || err $LINENO
774+
767775
res=$($com <<< 'echo $(( 1? 20 : 30 )) $(( -5 + 5 ? 100 : 200))')
768776
[ "$res" == "20 200" ] || err $LINENO
769777

0 commit comments

Comments
 (0)