python - how to translate custom language to html -
i'm trying conversion of custom language html
.
following example should intuitive-easy enough understand without explaining:
input file...
css: define(style): if default: background-color=black if hovered: background-color=blue apply(style, tag=h1, tag=h2) html: body(id="hello"): paragraph(id=demo): "this paragraph. input(type="button", onclick="displaydate()"): "display date js: def displaydate(): document.getelementbyid("demo").innerhtml=date()
...should translated to...
h1 { background-color: black } h1 :hover { background-color: blue } id { background-color=black } id :hover { background-color=blue } <html> <body id="hello"> <p id="demo">this paragraph.</p> <input type="button", onclick="displaydate()">display date</button> </body> <script> function displaydate() { document.getelementbyid("demo").innerhtml=date() } </script> </html>
the input file has following rules:
it has same indent-based syntax python, there should indent checking.
lines starting in quotation marks interpreted content.
certain statements should exist in context, example, define statement should exist inside css block.
i've been writing parser using regex, halfway realised regex slow, , may not adequate since generation of html should quick, not 1 of regex strengths.
googling/surfing brings pyparsing
, ply
, antlr
eyes, don't know/understand , whether should use them.
which path should follow?
Comments
Post a Comment