Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break out base_operand infix_notation #529

Open
RoDuth opened this issue Dec 11, 2023 · 0 comments
Open

break out base_operand infix_notation #529

RoDuth opened this issue Dec 11, 2023 · 0 comments

Comments

@RoDuth
Copy link

RoDuth commented Dec 11, 2023

relates to #278

Example:

from pyparsing import *

binop = one_of("= == != <> < <= > >=").set_name("binary operator")
identifier = Word(alphas, alphanums)
binary_clause = Group(identifier + binop + quoted_string).set_name("binary clause")
on_date_clause = Group(identifier + Keyword("on") + quoted_string).set_name("on date clause")
base_clause = (binary_clause | on_date_clause).set_name("base clause")
query = infix_notation(
    base_clause,
    [
        (Keyword("NOT"), 1, OpAssoc.RIGHT),
        (Keyword("AND"), 2, OpAssoc.LEFT),
        (Keyword("OR"), 2, OpAssoc.LEFT),
    ],
).set_name("clause")
query.create_diagram("test2.html")

In this example even though base_clause has .set_name it is not broken out and hence I get:
image
where I would expect:
image
This example is trivial but in my real use case there are 6 parts to base_clause which makes it excessively long.

I can get the expected outcome by wraping in a pointless Group, i.e.

base_clause = Group(binary_clause | on_date_clause).set_parse_action(lambda t: t[0]).set_name("base clause")

Which smells like a dirty hack to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant