Skip to content

[Parser] Tuples are not parsed by the new parser #719

Closed
@akshanshbhatt

Description

@akshanshbhatt

Issues #507 and #620 give insights on how nested tuples and function arguments with tuple type are not parsed correctly. While working on these issues, I realized that even the basic tuples are not parsed by the new parser. At present, we can only parse assignment operation of a tuple type to a variable (example a = (1, 2)). All the basic tuple code examples mentioned below fail to get get parsed -

(1, 2)
(1, 2, 3,)
1, 2
1, 2,

This according to me is because of the fact that tuple is not a component of expr node, which ideally it should be. Including it in among the expr syntax rules would close both of these issues. For instance, I can generate ast for an arbitrary nested list because it's an expr member -

❯ cat examples/expr2.py
[[[1, 2], 3], [1, 2], [1, ], 1, ]
❯ lpy --show-ast --new-parser examples/expr2.py  # New Parser
(Module [(Expr (List [(List [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) (ConstantInt 3 ())] Load) (List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) (List [(ConstantInt 1 ())] Load) (ConstantInt 1 ())] Load))] [])
❯ lpy --show-ast examples/expr2.py  # Old Parser
(Module [(Expr (List [(List [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) (ConstantInt 3 ())] Load) (List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) (List [(ConstantInt 1 ())] Load) (ConstantInt 1 ())] Load))] [])

Metadata

Metadata

Assignees

No one assigned

    Labels

    ParserIssues or improvements related to parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions