diff options
author | Paul McGuire <ptmcg@users.noreply.github.com> | 2021-09-08 09:03:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-08 09:03:40 -0500 |
commit | dfc7d7524ed9bb74a04865a68a06982bb54fcc5c (patch) | |
tree | d7655f624998dd910caf5c833dda2cb4a68aad85 /examples/make_diagram.py | |
parent | 11fda2880df71ce6661807b3b5921bc09bd6e003 (diff) | |
download | pyparsing-git-dfc7d7524ed9bb74a04865a68a06982bb54fcc5c.tar.gz |
226 railroad updates (#298)
* Add line separators to HowToUsePyparsing.rst to call attention to PEP-8 naming in this document
* Update railroad diagram generation code, to show results names as group annotations, and break out all expressions with a name set using setName.
* Revert dataclasses back to NamedTuples for 3.6-7 compat; add setName calls in simpleBool.py; add simpleBool to make_diagram.py
* Remove default setName calls on delimitedList
* Add setName calls to simpleSQL for better diagram
* Remove hard-coded debug mode
* Move setName on delimitedList into test code
* Restore default setName() calls for delimitedList; set default vertical=3; update jsonParser.py and simpleSQL.py with better setName() calls (and update test_diagram.py accordingly); update test_diagram.py to move asserts after tempfiles are written, moved tempfiles to local dir instead of hard-to-find temp dir
* Get proper railroad diags for infixNotation
* Undo forced railroad_debug
* Code cleanup from PR comments
* Remove hard-coded base_expr name from infix_notation
* Add special EachItem to compose DiagramItem for Group-OneOrMore-Choice; refactored tests to move duplicated code to function; added names to mozillaCalendarParser.py for better diagram
* Make sure root element gets in the diagram, even if it has no custom name
* Update tests to reflect diagram structure changes
* Add LOOKAHEAD and LOOKBEHIND annotations for FollowedBy and PrecededBy elements, and changed the annotation on Each to [ALL]; renamed _first to _element_diagram_states; add expr.streamline() in create_diagram() to collapse nested exprs; added railroad_diagram_demo.py example general blackening; update CHANGES with latest enhancements; bump version date
* Fix pip command
* Update CHANGES and whats_new_in_3_0_0.rst with some features and acknowledgements
* Updates from PR review: change user instructions to use pyparsing[diagrams]; consistent annotations for NotAny along with FollowedBy and PrecededBy; fixed up comments and type annotations
* Remove unneeded pip installs for tox (already handled in tox.ini)
* Refactor duplicate code into decorator; drop unused group_results_name argument
* Add diagram handling for SkipTo, and for And's constructed using `expr*N` notation (use a OneOrMore diagram with a repeat count instead of a sequence of N exprs)
* Fix parsing ambiguity in railroad_diagram_demo.py so that parser can actually parse a valid input string
Diffstat (limited to 'examples/make_diagram.py')
-rw-r--r-- | examples/make_diagram.py | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/examples/make_diagram.py b/examples/make_diagram.py index 5508f4e..23e435b 100644 --- a/examples/make_diagram.py +++ b/examples/make_diagram.py @@ -3,16 +3,7 @@ # # Sample railroad diagrams of selected pyparsing examples. # -# Copyright 2020, Paul McGuire - -from pyparsing.diagram import to_railroad, railroad_to_html - - -def make_diagram(expr, output_html="output.html"): - with open(output_html, "w", encoding="utf-8") as fp: - railroad = to_railroad(expr) - fp.write(railroad_to_html(railroad)) - +# Copyright 2021, Paul McGuire # Uncomment the related import statement and rerun to construct railroad diagram @@ -22,14 +13,22 @@ from examples.delta_time import time_expression as imported_expr # from examples.ebnftest import ebnf_parser as imported_expr # from examples.jsonParser import jsonObject as imported_expr # from examples.lucene_grammar import expression as imported_expr -# from examples.invRegex import parser as imported_expr +# from examples.invRegex import parser; imported_expr = parser() # from examples.oc import program as imported_expr # from examples.mozillaCalendarParser import calendars as imported_expr # from examples.pgn import pgnGrammar as imported_expr -# from examples.idlParse import CORBA_IDL_BNF as imported_expr +# from examples.idlParse import CORBA_IDL_BNF; imported_expr = CORBA_IDL_BNF() # from examples.chemicalFormulas import formula as imported_expr # from examples.romanNumerals import romanNumeral as imported_expr # from examples.protobuf_parser import parser as imported_expr # from examples.parsePythonValue import listItem as imported_expr +# from examples.one_to_ninety_nine import one_to_99 as imported_expr +# from examples.simpleSQL import simpleSQL as imported_expr +# from examples.simpleBool import boolExpr as imported_expr +grammar = imported_expr + +# or define a custom grammar here +# import pyparsing as pp +# grammar = pp.Or(["foo", "bar"]) + pp.Word(pp.nums) + pp.pyparsing_common.uuid -make_diagram(imported_expr) +grammar.create_diagram(output_html="output.html", show_results_names=True) |