Tobias-Kohn / TigerPython-Parser

Enhanced error recognition in Python
Mozilla Public License 2.0
39 stars 6 forks source link

Python AST raises a JS error for comparators #6

Closed pierrewtLanca closed 2 years ago

pierrewtLanca commented 2 years ago

Context: TigerPython is used in a Vue project. I am calling the parser to get the python AST of some small code portions.

When the parser finds a comparison, the returned expression object contains a left property that I can access. However, the comparators and ops properties cannot be accessed, because I get the following error : "Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.r"

Tobias-Kohn commented 2 years ago

There are some some differences between the AST generated by this parser and the AST in Python proper. Concerning the Compare objects, it groups the ops and comparators together into one field comparators, but has no ops field. Here is the relevant portion of code if that is of any help:

class Compare(pos: Int, left: Expression, comparators: Array[(BinOp.Value, Expression)])

When I wrote the parser I clearly had error checking in mind and did not bother to generate an AST that is fully compatible with Python's—after all, Python already delivered that, anyway. In other words, generating a compliant AST was never a goal of the project.