[antlr-interest] Retaining comments
Gerald B. Rosenberg
gbr at newtechlaw.com
Wed Mar 12 14:22:55 PDT 2008
At 11:02 AM 3/12/2008, Thomas Brandon wrote:
>On Thu, Mar 13, 2008 at 3:53 AM, Stuart Watt <SWatt at infobal.com> wrote:
> >
> > The scenario I flagged is illustrative only of my particular task, where I
> > want the best of an AST and of the text. This is not quite associating
> > comments and structure, but of generating annotated/formatted text.
>
>Depending on your XPath processor you might even be able to easily
>write a DOM\SAX wrapper around your AST and use that to run XPath
>against your AST without having to do any XML<->AST. Then you could
>mix XPath and tree parser based passes.
>...
>Just thinking out loud here but seems like it might work.
In that vein ...
There are times where you just need to randomly muck around in the
AST. To use the AST interactively (to do user-driven refactorings in
my case), or where the selection conditions are context dependent, as
what sounds to be Stuart's case. An AST wrapper is, I think, the
right approach. The down-side is that it would be directly dependent
on the implementation/structure of the AST, requiring rewrite each
time the AST changed.
So, how to generate the implementation of a reasonably generic AST
random access/manipulation API?
One way, leveraging Antlr, would be to use a custom StringTemplate to
write the API implementing class directly dependent on the target
grammar: analogous to a "tree grammar", there would be an "access
grammar". Implementation could be based on a copy/modification of
the existing Antlr tree-walker generator.
Initial tool implementation effort would be non-trivial, but would
result in a big win for grammar writers/maintainers.
Still, bogus idea or not?
----
Gerald B. Rosenberg, Esq.
NewTechLaw
260 Sheridan Ave., Suite 208
Palo Alto, CA 94306-2009
650.325.2100 (office) / 650.703.1724 (cell)
650.325.2107 (facsimile)
www.newtechlaw.com
CONFIDENTIALITY NOTICE: This email message (including any
attachments) is being sent by an attorney, is for the sole use of the
intended recipient, and may contain confidential and privileged
information. Any unauthorized review, use, disclosure or
distribution is prohibited. If you are not the intended recipient,
please contact the sender immediately by reply email and delete all
copies of this message and any attachments without retaining a copy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080312/af0c6b31/attachment.html
More information about the antlr-interest
mailing list