You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know there's a ticket open for generating strings which conform to a grammar, but it'd be awesome if there was a way to take a tree (as if parsed from a grammar & transformed remaining legal within that grammar) and a grammar, then generate a (the?) string which would parse the same way.
This would make it super easy to write source to source transformation tools, because you just parse a tree in, manipulate it, emit another tree in the same language and get re-encoding of the new expression tree "for free". Obviously for a whitespace sensitive grammar or a rewriting tool which cares about newlines/whitespace the parsing and manipulation language would have to encode those features as such but for simple expression oriented languages I'd think this is straightforwards.
The text was updated successfully, but these errors were encountered:
arrdem
changed the title
[FR] tree -> string emitter
[FR] tree → string emitter
Jun 29, 2016
The leaves of the parse tree are strings, so can't you just do a depth-first traversal of the tree and concatenate the strings at the leaves together in order to recover the original string?
I'm pretty sure I've seen someone use this strategy before with instaparse, but I can't quite remember where I've seen it.
mnemion did some related work on this shortly after instaparse's release to do further parse transformations on the tree, and he called his pull request "re-parse". I like the idea but haven't (yet?) integrated it into instaparse.
I know there's a ticket open for generating strings which conform to a grammar, but it'd be awesome if there was a way to take a tree (as if parsed from a grammar & transformed remaining legal within that grammar) and a grammar, then generate a (the?) string which would parse the same way.
This would make it super easy to write source to source transformation tools, because you just parse a tree in, manipulate it, emit another tree in the same language and get re-encoding of the new expression tree "for free". Obviously for a whitespace sensitive grammar or a rewriting tool which cares about newlines/whitespace the parsing and manipulation language would have to encode those features as such but for simple expression oriented languages I'd think this is straightforwards.
The text was updated successfully, but these errors were encountered: