Andy Chu
2016-03-15 04:29:32 UTC
This fixes 3 tests, and the delta in expr.c is +11 lines -- all
comments. The actual code is shorter.
It's a bit unnatural to me but I tried to compress the code, following
the existing style.
I'm going to fix the type coercion problems too, which will piggyback
on this change. Basically the OPS lookup table needs have another
field to specify coercion rules for the operation. The type
conversion has to be done with respect to the operation being
evaluated rather than globally up front.
# fails with type error, '21' should be coerced to integer and then added to 3
expr ab21xx : '[^0-9]*\([0-9]*\)' + 3
# segfaults because '3' is coerced to integer at parse time, and we
pass NULL to regexec
expr 3 : '\(.\)'
-----
expr now uses the precedence table specified by POSIX, implemented using
the "precedence climbing" algorithm. See the references at the top of
eval_expr().
This fixes 3 of 4 failing tests.
I also added more tests for correct behavior and for syntax errors.
This includes a new test exposing a segfault, related to type coercion.
comments. The actual code is shorter.
It's a bit unnatural to me but I tried to compress the code, following
the existing style.
I'm going to fix the type coercion problems too, which will piggyback
on this change. Basically the OPS lookup table needs have another
field to specify coercion rules for the operation. The type
conversion has to be done with respect to the operation being
evaluated rather than globally up front.
# fails with type error, '21' should be coerced to integer and then added to 3
expr ab21xx : '[^0-9]*\([0-9]*\)' + 3
# segfaults because '3' is coerced to integer at parse time, and we
pass NULL to regexec
expr 3 : '\(.\)'
-----
expr now uses the precedence table specified by POSIX, implemented using
the "precedence climbing" algorithm. See the references at the top of
eval_expr().
This fixes 3 of 4 failing tests.
I also added more tests for correct behavior and for syntax errors.
This includes a new test exposing a segfault, related to type coercion.