I have been using pyparsing 3.0.0a2 to generate railroads (the versions 3.0.0b generates only horizontal diagrams as it seems the vertical
parameter doesn't have any effect, which is annoying).
The following code is using two expressions sim
and sim_expr
and I am trying to create the corresponding railroads as HTML files. Note that I also would like to create the standalone SVG files for documentation but I am not sure how to do it. So if you have at least this information, please let me know in a comment.
The results are two HTML files, sim.html
contains a picture but the sim_expr.html
is empty.
How can I solve the problem of an empty file?
from pyparsing import *
LPAR, RPAR, COMMA, DOT, EQ, COLON = map(Suppress, "(),.=:")
sim_a = (Literal('1') ^ Literal('2'))('elm*')
+ COMMA
+ (Literal('a')
^ Literal('b')
^ Literal('c')
^ Literal('d'))
sim_b = (Literal('4') ^ Literal('5'))('elm*')
+ COMMA
+ (Literal('a')
^ Literal('b')
^ Literal('c')
^ Literal('d'))
sim = sim_a ^ sim_b
sim_expr = Group(Literal('sim')('directive')
+ LPAR
+ sim.setName('List')
+ RPAR).setName('SIM')
if __name__ == '__main__':
if '3.0.0b' in __version__:
sim.create_diagram('sim.html')
sim_expr.create_diagram('sim_expr.html')
elif '3.0.0' in __version__:
from pyparsing.diagram import to_railroad, railroad_to_html
with open('sim.html', 'w') as fp:
rr = to_railroad(sim)
fp.write(railroad_to_html(rr))
with open('sim_expr.html', 'w') as fp:
rr = to_railroad(sim_expr)
fp.write(railroad_to_html(rr))
sim_expr.html
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…