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

Empty railroad diagrams with Combine #361

Closed
jwhite242 opened this issue Feb 1, 2022 · 4 comments
Closed

Empty railroad diagrams with Combine #361

jwhite242 opened this issue Feb 1, 2022 · 4 comments

Comments

@jwhite242
Copy link

So, I seem to have found a corner case in the railroad diagram creation that's triggered by specific uses of Combine() in the grammars. If the Combine only wraps part of the grammar then the diagram looks as expected, however if the combine wraps the entire grammar, then the diagram is empty. The snippets below demonstrate the working case and the broken case for a simple time string grammar:

  • Empty railroad diagram: Combine wrapping entire grammar

    import pyparsing as pp
    
    ints = pp.Word(pp.nums).setParseAction(lambda toks: int(toks[0]))
    
    time_parser_1 = pp.Combine(ints('hours') + pp.Literal(":") + ints('minutes') + pp.Literal(":") + ints('seconds'))
     
    time_parser_1.create_diagram("time_parser_1.html")
  • Expected railroad diagram: Combine wrapping only part of grammar

    import pyparsing as pp
    
    ints = pp.Word(pp.nums).setParseAction(lambda toks: int(toks[0]))
    
    time_parser_2 = pp.Combine(ints('hours') + pp.Literal(":") + ints('minutes')) + pp.Literal(":") + ints('seconds')
    
    time_parser_2.create_diagram("time_parser_2.html")

    Note the difference is the last ":" + integer part of the grammar is outside the Combine in this case

ON a side note, this is looking to be a pretty great way to document parsers and love that it's been added!

@ptmcg
Copy link
Member

ptmcg commented Feb 1, 2022

Nice report, and thanks for providing an easy-to-repro example.

@ptmcg
Copy link
Member

ptmcg commented Mar 25, 2022

Sorry this took so long, I think I am near to a fix, to go out in 3.0.8.

ptmcg added a commit that referenced this issue Mar 29, 2022
@jwhite242
Copy link
Author

Oh, no worries on the time. Thanks for digging into it and finding a fix!

@ptmcg
Copy link
Member

ptmcg commented Apr 10, 2022

Released in 3.0.8

@ptmcg ptmcg closed this as completed Apr 10, 2022
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

2 participants