[antlr-interest] Re: [stringtemplate-interest] Java In / Java Out

eric nelson wirecracker at gmail.com
Tue Nov 1 15:02:17 PST 2005


Oliver,
 Thank you very much for the ideas :) I am not sure that it answers my
original question, but it does look like another way of doing it. I may try
using Java Beans, but my understanding is that this should be possible to do
without them. If I am wrong I hope someone will correct me, but otherwise
I'd like to pursue this attempt a little longer ;)
  - e


 On 10/31/05, Oliver Zeigermann <oliver.zeigermann at gmail.com> wrote:
>
> Hi Eric,
>
> I was doing limited Java to Java conversions as well. An example that
> describes how to generate Java sources from Java interface definitions
> can be found here:
>
> http://www.zeigermann.de/genEJB.zip
>
> May idea there was to separate the Java analysis (using ANTLR and a
> Java grammar) from the Java generation part (using StringTemplate)
> with an intermediate step that uses Java Beans for the tree
> representation of the Java interface. Java Beans looked good as they
> are familiar to the Java programmer and make a very good input for
> StringTemplate.
>
> HTH
>
> Oliver
>
> 2005/10/29, eric nelson <wirecracker at gmail.com>:
> > I'm trying to modify the java.g grammar file so that I can use
> > StringTemplate for outputting the file. The input is a Java file. I
> would
> > like the output to be Java also. So, yes, basically no change in content
> > ... mabye some spacing will differ here or there. I am still learning to
> > use ANTLR and StringTemplate and I've written a Java.stg file based on
> what
> > I think I know so far. Exerpts from java.g and Java.stg appear below.
> One
> > of the questions I have is how to handle the "|" (or) symbol (i.e.
> > classDefinition | interfaceDefinition). The way I have it right now
> there
> > would be a list of "modifiers", a list of "classDefinitions", and a list
> of
> > interfaceDefinitions (then naturally I would have a question about the "
> |
> > s:SEMI!" ... but one question at a time ;) So, the problem in Java.stgis
> > how to match up the correct "modifiers" with the corresponding
> > "interfaceDefinition" or "classDefinition". Or what if there is a
> > classDefinition with no modifier, etc. I am quite convinced that my
> > Java.stg template (typeDefinition in particular) and/or my java.g code
> has
> > erred somewhere. Any thoughts? This is HUGE since this will help me
> > understand how to approach the "field" rule in java.g .... if anyone has
> > some hints on a "field" template that would also be great! Thanks :) - e
> >
> >
> > java.g exerpt (java 1.3 grammar)
> >
> >
> //////////////////////////////////////////////////////////////////////////////////////////////////
> > // A type definition in a file is either a class or interface
> definition.
> > typeDefinition returns [StringTemplate
> > code=template("typeDefinition")]
> > options {defaultErrorHandler = true;}
> > {StringTemplate mod=null, cd=null, id=null, semi=null;}
> > : mod=m:modifiers! {code.setAttribute("modifiers", mod);}
> > ( cd=classDefinition[#m] { code.setAttribute("classDefinitions",
> > cd);}
> > | id=interfaceDefinition[#m]
> > {code.setAttribute("interfaceDefinitions", id);}
> > )
> > | s:SEMI!
> > {semi=template("lexer_semi");semi.setAttribute("semi",
> > s.getText());code.setAttribute("semi", semi);}
> > ;
> >
> >
> >
> //////////////////////////////////////////////////////////////////////////////////////////////////
> >
> >
> > Java.stg exerpt
> >
> >
> //////////////////////////////////////////////////////////////////////////////////////////////////
> > typeDefinition(modifiers,classDefinitions,interfaceDefinitions,semi)
> > ::= <<
> > <modifiers><classDefinitions><interfaceDefinitions><semi>
> > >>
> >
> >
> > modifiers(modifiers) ::= "<modifiers>"
> >
> > modifier(modifier) ::= "<modifier>"
> >
> > classDefinition(ident,superClassClause,implementsClause,classBlock)
> > ::= <<
> > class <ident> <superClassClause> <implementsClause>
> > <classBlock>
> > >>
> >
> > interfaceDefinition() ::= <<
> > not yet completed
> > >>
> >
> >
> //////////////////////////////////////////////////////////////////////////////////////////////////
> >
> > _______________________________________________
> > stringtemplate-interest mailing list
> > stringtemplate-interest at antlr.org
> > http://www.antlr.org/mailman/listinfo/stringtemplate-interest
> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20051101/242d5a8a/attachment.html


More information about the antlr-interest mailing list