I am using grako utility of python to parse my OIL file to AST. but i want to re generate the source code back from the AST after modifying the AST. Is grako is having feature to do this or else any other utility in python is available for this source code re generation.
Asked
Active
Viewed 162 times
3
-
1possible duplicate of [Parse a .py file, read the AST, modify it, then write back the modified source code](http://stackoverflow.com/questions/768634/parse-a-py-file-read-the-ast-modify-it-then-write-back-the-modified-source-c) – Eric Mar 06 '15 at 09:02
-
1See this SO answer for what it takes to regenerate source text from an AST: http://stackoverflow.com/a/5834775/120163 – Ira Baxter Mar 06 '15 at 10:01
1 Answers
2
Grako-style code generation is done through in-line templates using string.Formatter
.
Look into the grako.codegen
and grako.model
modules/packages, and take a look at the examples/antlr2grako
example.
Code generation is one of the least documented parts of Grako (in the README), but it is all there.

Apalala
- 9,017
- 3
- 30
- 48