<div dir="ltr"><div class="gmail_extra"><div>Grako is a PEG parser builder in Python:</div><div><br></div><div><a href="https://bitbucket.org/apalala/grako">https://bitbucket.org/apalala/grako</a><br></div><div><br></div><div>In grako, there's code to synthesize AST node types according to annotations in the grammar whenever a type is not previously provided. This is the code:</div><div><br></div><div><div>    def _get_nodetype(self, typename):</div><div>        typename = str(typename)</div><div>        if typename in self.nodetypes:</div><div>            return self.nodetypes[typename]</div><div><br></div><div>        # synthethize a new type</div><div>        nodetype = type(typename, (self.baseType,), {})</div><div>        self._register_nodetype(nodetype)</div><div>        return nodetype</div><div><br></div></div><div>It works, but the classes thus created are "weird". I don't remember the details right now, but I think they don't have a proper module or qualname.</div><div><br></div><div>This particular feature (exploiting this Python capability) is very useful in the early stages of developing a parser, while most of the work goes into debugging the grammar. Having a nice AST produced cheaply is of great value.</div><div><br></div><div>Cheers,</div><div><br></div>-- <br><span style="color:rgb(0,102,0)">Juancarlo </span><b style="color:rgb(0,102,0)">Añez</b>
</div></div>