diff options
author | ptmcg <ptmcg@austin.rr.com> | 2020-06-27 08:26:16 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2020-06-27 08:26:16 -0500 |
commit | 20dfaac6b80ad42851d82f9d2be376e098f0a5ba (patch) | |
tree | 2cf9ef8ceee535a069a05399575ef763b2a6e066 /examples/make_diagram.py | |
parent | b3edef08a38b45c3a5fe74968e3589996761660c (diff) | |
download | pyparsing-git-20dfaac6b80ad42851d82f9d2be376e098f0a5ba.tar.gz |
Add make_diagram.py to examples to demonstrate creating railroad diags for selected examples
Diffstat (limited to 'examples/make_diagram.py')
-rw-r--r-- | examples/make_diagram.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/make_diagram.py b/examples/make_diagram.py new file mode 100644 index 0000000..f1de4bf --- /dev/null +++ b/examples/make_diagram.py @@ -0,0 +1,34 @@ +# +# make_diagram.py +# +# Sample railroad diagrams of selected pyparsing examples. +# +# Copyright 2020, Paul McGuire + +from pyparsing.diagram import to_railroad, railroad_to_html + + +def make_diagram(expr): + with open("output.html", "w", encoding="utf-8") as fp: + railroad = to_railroad(expr) + fp.write(railroad_to_html(railroad)) + + +# Uncomment the related import statement, and pass the imported parser to make_diagram + +# from examples.delta_time import time_expression +# from examples.sexpParser import sexp +# from examples.ebnftest import ebnf_parser +# from examples.jsonParser import jsonObject +# from examples.lucene_grammar import expression +# from examples.invRegex import parser +# from examples.oc import program +# from examples.mozillaCalendarParser import calendars +# from examples.pgn import pgnGrammar +# from examples.idlParse import CORBA_IDL_BNF +# from examples.chemicalFormulas import formula +# from examples.romanNumerals import romanNumeral +# from examples.protobuf_parser import parser +from examples.parsePythonValue import listItem + +make_diagram(listItem) |