org.apache.velocity.runtime.parser
Class Parser

java.lang.Object
  extended by org.apache.velocity.runtime.parser.Parser
All Implemented Interfaces:
ParserConstants, ParserTreeConstants

public class Parser
extends Object
implements ParserTreeConstants, ParserConstants

This class is responsible for parsing a Velocity template. This class was generated by JavaCC using the JJTree extension to produce an Abstract Syntax Tree (AST) of the template. Please look at the Parser.jjt file which is what controls the generation of this class.

Version:
$Id: Parser.java 151484 2005-02-05 07:09:52Z wglass $
Author:
Jason van Zyl, Geir Magnusson Jr.

Field Summary
 Token jj_nt
           
protected  org.apache.velocity.runtime.parser.JJTParserState jjtree
           
 boolean lookingAhead
           
 Token token
           
 ParserTokenManager token_source
           
 
Fields inherited from interface org.apache.velocity.runtime.parser.ParserTreeConstants
JJTADDNODE, JJTANDNODE, JJTASSIGNMENT, JJTBLOCK, JJTCOMMENT, JJTDIRECTIVE, JJTDIVNODE, JJTELSEIFSTATEMENT, JJTELSESTATEMENT, JJTEQNODE, JJTESCAPE, JJTESCAPEDDIRECTIVE, JJTEXPRESSION, JJTFALSE, JJTFLOATINGPOINTLITERAL, JJTGENODE, JJTGTNODE, JJTIDENTIFIER, JJTIFSTATEMENT, JJTINTEGERLITERAL, JJTINTEGERRANGE, JJTLENODE, JJTLTNODE, JJTMAP, JJTMETHOD, JJTMODNODE, JJTMULNODE, JJTNENODE, jjtNodeName, JJTNOTNODE, JJTOBJECTARRAY, JJTORNODE, JJTPROCESS, JJTREFERENCE, JJTSETDIRECTIVE, JJTSTOP, JJTSTRINGLITERAL, JJTSUBTRACTNODE, JJTTEXT, JJTTRUE, JJTVOID, JJTWORD
 
Fields inherited from interface org.apache.velocity.runtime.parser.ParserConstants
ALPHA_CHAR, ALPHANUM_CHAR, BRACKETED_WORD, COLON, COMMA, DEFAULT, DIGIT, DIRECTIVE, DIRECTIVE_CHAR, DIRECTIVE_TERMINATOR, DIVIDE, DOLLAR, DOLLARBANG, DOT, DOUBLE_ESCAPE, DOUBLEDOT, ELSE_DIRECTIVE, ELSEIF_DIRECTIVE, END, EOF, EQUALS, ESCAPE, ESCAPE_DIRECTIVE, EXPONENT, FALSE, FLOATING_POINT_LITERAL, FORMAL_COMMENT, HASH, IDENTIFIER, IDENTIFIER_CHAR, IF_DIRECTIVE, IN_FORMAL_COMMENT, IN_MULTI_LINE_COMMENT, IN_SINGLE_LINE_COMMENT, INTEGER_LITERAL, LBRACKET, LCURLY, LEFT_CURLEY, LETTER, LOGICAL_AND, LOGICAL_EQUALS, LOGICAL_GE, LOGICAL_GT, LOGICAL_LE, LOGICAL_LT, LOGICAL_NOT, LOGICAL_NOT_EQUALS, LOGICAL_OR, LPAREN, MINUS, MODULUS, MULTI_LINE_COMMENT, MULTIPLY, NEWLINE, PLUS, PRE_DIRECTIVE, RBRACKET, RCURLY, REFERENCE, REFERENCE_TERMINATOR, REFMOD2, REFMOD2_RPAREN, REFMODIFIER, RIGHT_CURLEY, RPAREN, SET_DIRECTIVE, SINGLE_LINE_COMMENT, STOP_DIRECTIVE, STRING_LITERAL, TEXT, tokenImage, TRUE, WHITESPACE, WORD
 
Constructor Summary
Parser(CharStream stream)
           
Parser(ParserTokenManager tm)
           
Parser(RuntimeServices rs)
          This constructor was added to allow the re-use of parsers.
 
Method Summary
 void AdditiveExpression()
           
 void Assignment()
           
 void Comment()
           
 void ConditionalAndExpression()
           
 void ConditionalOrExpression()
           
 SimpleNode Directive()
          Supports the Pluggable Directives #foo( arg+ )
 int DirectiveArg()
          Supports the arguments for the Pluggable Directives We add whitespace in here as a token so the VMs can easily reconstruct a macro body from the token stream See Directive()
 void disable_tracing()
           
 void ElseIfStatement()
           
 void ElseStatement()
           
 void enable_tracing()
           
 void EqualityExpression()
           
 void Escape()
          Used to catch and process escape sequences in grammatical constructs as escapes outside of VTL are just characters.
 void EscapedDirective()
          used to separate the notion of a valid directive that has been escaped, versus something that looks like a directive and is just schmoo.
 void Expression()
           
 void False()
           
 void FloatingPointLiteral()
           
 ParseException generateParseException()
           
 Directive getDirective(String directive)
          This method gets a Directive from the directives Hashtable
 Token getNextToken()
           
 Token getToken(int index)
           
 void Identifier()
          This method corresponds to variable references in Velocity templates.
 void IfStatement()
           
 void IntegerLiteral()
           
 void IntegerRange()
          supports the [n..m] vector generator for use in the #foreach() to generate measured ranges w/o needing explicit support from the app/servlet
 boolean isDirective(String directive)
          This method finds out of the directive exists in the directives Hashtable.
 void Map()
          for creating a map in a #set #set($foo = [$foo : $bar, $blargh : $thingy])
 void Method()
          This method has yet to be fully implemented but will allow arbitrarily nested method calls
 void MultiplicativeExpression()
           
 void ObjectArray()
           
 void Parameter()
          This method has yet to be fully implemented but will allow arbitrarily nested method calls
 SimpleNode parse(Reader reader, String templateName)
          This was also added to allow parsers to be re-usable.
 void PrimaryExpression()
           
 SimpleNode process()
          This method is what starts the whole parsing process.
 void Reference()
           
 void ReInit(CharStream stream)
           
 void ReInit(ParserTokenManager tm)
           
 void RelationalExpression()
           
 void SetDirective()
          Currently support both types of set : #set( expr ) #set expr
 void setDirectives(Hashtable directives)
          This method sets the directives Hashtable
 void Statement()
          These are the types of statements that are acceptable in Velocity templates.
 void StopStatement()
          This method corresponds to the #stop directive which just simulates and EOF so that parsing stops.
 void StringLiteral()
           
 void Text()
          This method is responsible for allowing all non-grammar text to pass through unscathed.
 void True()
           
 void UnaryExpression()
           
 void Word()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jjtree

protected org.apache.velocity.runtime.parser.JJTParserState jjtree

token_source

public ParserTokenManager token_source

token

public Token token

jj_nt

public Token jj_nt

lookingAhead

public boolean lookingAhead
Constructor Detail

Parser

public Parser(RuntimeServices rs)
This constructor was added to allow the re-use of parsers. The normal constructor takes a single argument which an InputStream. This simply creates a re-usable parser object, we satisfy the requirement of an InputStream by using a newline character as an input stream.


Parser

public Parser(CharStream stream)

Parser

public Parser(ParserTokenManager tm)
Method Detail

parse

public SimpleNode parse(Reader reader,
                        String templateName)
                 throws ParseException
This was also added to allow parsers to be re-usable. Normal JavaCC use entails passing an input stream to the constructor and the parsing process is carried out once. We want to be able to re-use parsers: we do this by adding this method and re-initializing the lexer with the new stream that we want parsed.

Throws:
ParseException

setDirectives

public void setDirectives(Hashtable directives)
This method sets the directives Hashtable


getDirective

public Directive getDirective(String directive)
This method gets a Directive from the directives Hashtable


isDirective

public boolean isDirective(String directive)
This method finds out of the directive exists in the directives Hashtable.


process

public final SimpleNode process()
                         throws ParseException
This method is what starts the whole parsing process. After the parsing is complete and the template has been turned into an AST, this method returns the root of AST which can subsequently be traversed by a visitor which implements the ParserVisitor interface which is generated automatically by JavaCC

Throws:
ParseException

Statement

public final void Statement()
                     throws ParseException
These are the types of statements that are acceptable in Velocity templates.

Throws:
ParseException

EscapedDirective

public final void EscapedDirective()
                            throws ParseException
used to separate the notion of a valid directive that has been escaped, versus something that looks like a directive and is just schmoo. This is important to do as a separate production that creates a node, because we want this, in either case, to stop the further parsing of the Directive() tree.

Throws:
ParseException

Escape

public final void Escape()
                  throws ParseException
Used to catch and process escape sequences in grammatical constructs as escapes outside of VTL are just characters. Right now we have both this and the EscapeDirective() construction because in the EscapeDirective() case, we want to suck in the # and here we don't. We just want the escapes to render correctly

Throws:
ParseException

Comment

public final void Comment()
                   throws ParseException
Throws:
ParseException

FloatingPointLiteral

public final void FloatingPointLiteral()
                                throws ParseException
Throws:
ParseException

IntegerLiteral

public final void IntegerLiteral()
                          throws ParseException
Throws:
ParseException

StringLiteral

public final void StringLiteral()
                         throws ParseException
Throws:
ParseException

Identifier

public final void Identifier()
                      throws ParseException
This method corresponds to variable references in Velocity templates. The following are examples of variable references that may be found in a template: $foo $bar

Throws:
ParseException

Word

public final void Word()
                throws ParseException
Throws:
ParseException

DirectiveArg

public final int DirectiveArg()
                       throws ParseException
Supports the arguments for the Pluggable Directives We add whitespace in here as a token so the VMs can easily reconstruct a macro body from the token stream See Directive()

Throws:
ParseException

Directive

public final SimpleNode Directive()
                           throws ParseException
Supports the Pluggable Directives #foo( arg+ )

Throws:
ParseException

Map

public final void Map()
               throws ParseException
for creating a map in a #set #set($foo = [$foo : $bar, $blargh : $thingy])

Throws:
ParseException

ObjectArray

public final void ObjectArray()
                       throws ParseException
Throws:
ParseException

IntegerRange

public final void IntegerRange()
                        throws ParseException
supports the [n..m] vector generator for use in the #foreach() to generate measured ranges w/o needing explicit support from the app/servlet

Throws:
ParseException

Parameter

public final void Parameter()
                     throws ParseException
This method has yet to be fully implemented but will allow arbitrarily nested method calls

Throws:
ParseException

Method

public final void Method()
                  throws ParseException
This method has yet to be fully implemented but will allow arbitrarily nested method calls

Throws:
ParseException

Reference

public final void Reference()
                     throws ParseException
Throws:
ParseException

True

public final void True()
                throws ParseException
Throws:
ParseException

False

public final void False()
                 throws ParseException
Throws:
ParseException

Text

public final void Text()
                throws ParseException
This method is responsible for allowing all non-grammar text to pass through unscathed.

Throws:
ParseException

IfStatement

public final void IfStatement()
                       throws ParseException
Throws:
ParseException

ElseStatement

public final void ElseStatement()
                         throws ParseException
Throws:
ParseException

ElseIfStatement

public final void ElseIfStatement()
                           throws ParseException
Throws:
ParseException

SetDirective

public final void SetDirective()
                        throws ParseException
Currently support both types of set : #set( expr ) #set expr

Throws:
ParseException

StopStatement

public final void StopStatement()
                         throws ParseException
This method corresponds to the #stop directive which just simulates and EOF so that parsing stops. The #stop directive is useful for end-user debugging purposes.

Throws:
ParseException

Expression

public final void Expression()
                      throws ParseException
Throws:
ParseException

Assignment

public final void Assignment()
                      throws ParseException
Throws:
ParseException

ConditionalOrExpression

public final void ConditionalOrExpression()
                                   throws ParseException
Throws:
ParseException

ConditionalAndExpression

public final void ConditionalAndExpression()
                                    throws ParseException
Throws:
ParseException

EqualityExpression

public final void EqualityExpression()
                              throws ParseException
Throws:
ParseException

RelationalExpression

public final void RelationalExpression()
                                throws ParseException
Throws:
ParseException

AdditiveExpression

public final void AdditiveExpression()
                              throws ParseException
Throws:
ParseException

MultiplicativeExpression

public final void MultiplicativeExpression()
                                    throws ParseException
Throws:
ParseException

UnaryExpression

public final void UnaryExpression()
                           throws ParseException
Throws:
ParseException

PrimaryExpression

public final void PrimaryExpression()
                             throws ParseException
Throws:
ParseException

ReInit

public void ReInit(CharStream stream)

ReInit

public void ReInit(ParserTokenManager tm)

getNextToken

public final Token getNextToken()

getToken

public final Token getToken(int index)

generateParseException

public ParseException generateParseException()

enable_tracing

public final void enable_tracing()

disable_tracing

public final void disable_tracing()


Copyright © 2002 Apache Software Foundation. All Rights Reserved.