python parser silently ignores malformed 'lam (arg : Type) body extra extra'
acl33 opened this issue · 2 comments
acl33 commented
>>> from ksc.parse_ks import parse_expr_string
>>> parse_expr_string("(lam (x : Integer) (y : Float) foo)")
<ksc.expr.Lam object at 0x7fbf0aff3910>
>>> e=parse_expr_string("(lam (x : Integer) (y : Float) foo)")
>>> print(e)
(Lam x : Integer (Call y [:, Float]))
>>> print(e.body)
(Call y [:, Float])
>>> print(e.body.args[0])
:
>>> print(e.body.args[1])
Float
>>> print(e.body.args[2])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>>
So parsing ":" and "Float" as 'Var's is one thing, but also, what has happened to the "foo"? Here's a simpler example of the latter:
>>> e2 = parse_expr_string("(lam (x : Integer) (add x 1) hello world)")
>>> print(e2)
(Lam x : Integer (Call add [x, 1]))
where the result is plausible but the hello world
has disappeared entirely.
toelli-msft commented
That's not a valid lam
. There should only be three components to a lam
:
lam
- A variable with its type
- The body
In your example (add x 1)
is the body. (Arguably the presence of hello
and world
should cause a parse failure.)
acl33 commented
Yes, I think a parse failure would be helpful. This hit me in an example when the first parsed successfully "by accident"...