You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Christian Trutz <ve...@smilebase.de> on 2002/03/14 09:23:41 UTC
[PATCH] merge with visitor
Hello velocitians,
I experimentize a little with ParserVisitors on AST and I think the following
patch is usefull:
it allows processing the AST nodes with a visitor, until now:
template.merge( context, writer );
now:
template.merge( context, writer );
and
template.merge( context, visitor );
are avaible. I think this is a trivial change, but it is usefull ...
Christian
Index: Template.java
===================================================================
RCS file:
/home/cvspublic/jakarta-velocity/src/java/org/apache/velocity/Template.java,v
retrieving revision 1.35
diff -r1.35 Template.java
66a67
> import org.apache.velocity.runtime.parser.node.ParserVisitor;
261a263
> * @param parser visitor for rendering template
268c270
< public void merge( Context context, Writer writer)
---
> public void merge( Context context, Writer writer, ParserVisitor
visitor)
296c298,312
< ( (SimpleNode) data ).render( ica, writer);
---
> if ( visitor == null )
> {
> /*
> * standard template rendering
> */
> ( (SimpleNode) data ).render( ica, writer);
> }
> else
> {
> /*
> * render template with a visitor
> */
> visitor.visit( (SimpleNode) data, data);
> }
>
318a335,376
> }
>
> /**
> * The AST node structure is merged with the
> * context to produce the final output.
> *
> * Throws IOException if failure is due to a file related
> * issue, and Exception otherwise
> *
> * @param context Conext with data elements accessed by template
> * @param writer output writer for rendered template
> * @throws ResourceNotFoundException if template not found
> * from any available source.
> * @throws ParseErrorException if template cannot be parsed due
> * to syntax (or other) error.
> * @throws Exception anything else.
> */
> public void merge( Context context, Writer writer)
> throws ResourceNotFoundException, ParseErrorException,
MethodInvocationException, Exception
> {
> merge( context, writer, null);
> }
>
> /**
> * The AST node structure is merged with the
> * context to produce the final output.
> *
> * Throws IOException if failure is due to a file related
> * issue, and Exception otherwise
> *
> * @param context Conext with data elements accessed by template
> * @param parser visitor for rendering template
> * @throws ResourceNotFoundException if template not found
> * from any available source.
> * @throws ParseErrorException if template cannot be parsed due
> * to syntax (or other) error.
> * @throws Exception anything else.
> */
> public void merge( Context context, ParserVisitor visitor)
> throws ResourceNotFoundException, ParseErrorException,
MethodInvocationException, Exception
> {
> merge( context, null, visitor);
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [PATCH] merge with visitor
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 3/14/02 9:27 AM, "Jason van Zyl" <jv...@zenplex.com> wrote:
> On Thu, 2002-03-14 at 03:23, Christian Trutz wrote:
>>
>> Hello velocitians,
>>
>> I experimentize a little with ParserVisitors on AST and I think the following
>> patch is usefull:
>>
>> it allows processing the AST nodes with a visitor, until now:
>>
>> template.merge( context, writer );
>>
>> now:
>>
>> template.merge( context, writer );
>> and
>> template.merge( context, visitor );
>>
>> are avaible. I think this is a trivial change, but it is usefull ...
>
> I actually don't like the idea of changing something so fundamental but
> I would be curious if you tried any profiling to see if there was any
> performance difference between using a visitor and the self-walking
> tree.
I can't imagine that it will be faster.
To me this appears to be of academic interest - I would only be in favor of
this if there was some kind of usecase that supported it.
Given the model is fairly well used and tested at this point, I can't
imagine what that use case would be.
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
My inner cowboy needs to yodel.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [PATCH] merge with visitor
Posted by Jason van Zyl <jv...@zenplex.com>.
On Thu, 2002-03-14 at 03:23, Christian Trutz wrote:
>
> Hello velocitians,
>
> I experimentize a little with ParserVisitors on AST and I think the following
> patch is usefull:
>
> it allows processing the AST nodes with a visitor, until now:
>
> template.merge( context, writer );
>
> now:
>
> template.merge( context, writer );
> and
> template.merge( context, visitor );
>
> are avaible. I think this is a trivial change, but it is usefull ...
I actually don't like the idea of changing something so fundamental but
I would be curious if you tried any profiling to see if there was any
performance difference between using a visitor and the self-walking
tree.
> Christian
>
>
> Index: Template.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-velocity/src/java/org/apache/velocity/Template.java,v
> retrieving revision 1.35
> diff -r1.35 Template.java
> 66a67
> > import org.apache.velocity.runtime.parser.node.ParserVisitor;
> 261a263
> > * @param parser visitor for rendering template
> 268c270
> < public void merge( Context context, Writer writer)
> ---
> > public void merge( Context context, Writer writer, ParserVisitor
> visitor)
> 296c298,312
> < ( (SimpleNode) data ).render( ica, writer);
> ---
> > if ( visitor == null )
> > {
> > /*
> > * standard template rendering
> > */
> > ( (SimpleNode) data ).render( ica, writer);
> > }
> > else
> > {
> > /*
> > * render template with a visitor
> > */
> > visitor.visit( (SimpleNode) data, data);
> > }
> >
> 318a335,376
> > }
> >
> > /**
> > * The AST node structure is merged with the
> > * context to produce the final output.
> > *
> > * Throws IOException if failure is due to a file related
> > * issue, and Exception otherwise
> > *
> > * @param context Conext with data elements accessed by template
> > * @param writer output writer for rendered template
> > * @throws ResourceNotFoundException if template not found
> > * from any available source.
> > * @throws ParseErrorException if template cannot be parsed due
> > * to syntax (or other) error.
> > * @throws Exception anything else.
> > */
> > public void merge( Context context, Writer writer)
> > throws ResourceNotFoundException, ParseErrorException,
> MethodInvocationException, Exception
> > {
> > merge( context, writer, null);
> > }
> >
> > /**
> > * The AST node structure is merged with the
> > * context to produce the final output.
> > *
> > * Throws IOException if failure is due to a file related
> > * issue, and Exception otherwise
> > *
> > * @param context Conext with data elements accessed by template
> > * @param parser visitor for rendering template
> > * @throws ResourceNotFoundException if template not found
> > * from any available source.
> > * @throws ParseErrorException if template cannot be parsed due
> > * to syntax (or other) error.
> > * @throws Exception anything else.
> > */
> > public void merge( Context context, ParserVisitor visitor)
> > throws ResourceNotFoundException, ParseErrorException,
> MethodInvocationException, Exception
> > {
> > merge( context, null, visitor);
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
jvz.
Jason van Zyl
jvanzyl@apache.org
http://tambora.zenplex.org
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>