Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

python - pyparsing generates empty railroad HTML file in some cases

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

<!DOCTYPE html>
<html>
<head>
    
        <style type="text/css">
            .railroad-heading {
                font-family: monospace;
            }
        </style>
    
</head>
<body>


</body>
</html>
question from:https://stackoverflow.com/questions/66065501/pyparsing-generates-empty-railroad-html-file-in-some-cases

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...