Class StandardParser
java.lang.Object
org.apache.velocity.runtime.parser.StandardParser
- All Implemented Interfaces:
StandardParserTreeConstants,Parser,StandardParserConstants
public class StandardParser
extends Object
implements StandardParserTreeConstants, Parser, StandardParserConstants
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$
- Author:
- Jason van Zyl, Geir Magnusson Jr., Henning P. Schmiedehausen
-
Field Summary
FieldsModifier and TypeFieldDescriptionCurrent template we are parsing.booleanSet to true if the propoerty RuntimeConstants.PARSER_HYPHEN_ALLOWED is set to trueNext token.protected JJTStandardParserStatebooleanSet to true if the property RuntimeConstants.RUNTIME_REFERENCES_STRICT_ESCAPE is set to trueCurrent token.Generated Token Manager.Fields inherited from interface org.apache.velocity.runtime.parser.StandardParserConstants
ALPHA_CHAR, ALT_VAL, BRACKETED_WORD, COLON, COMMA, DEFAULT, DIGIT, DIRECTIVE, DIRECTIVE_CHAR, DIRECTIVE_TERMINATOR, DIVIDE, DOLLAR, DOLLARBANG, DOT, DOUBLE_ESCAPE, DOUBLEDOT, ELSE, ELSEIF, EMPTY_INDEX, 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_MULTILINE_COMMENT, IN_SINGLE_LINE_COMMENT, IN_TEXTBLOCK, INDEX_LBRACKET, INDEX_RBRACKET, INLINE_TEXT, 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, LOGICAL_OR_2, LONE_SYMBOL, LPAREN, MINUS, MODULUS, MULTI_LINE_COMMENT, MULTIPLY, NEWLINE, OLD_ALPHA_CHAR, OLD_IDENTIFIER, OLD_IDENTIFIER_CHAR, OLD_REFMODIFIER, PIPE, PLUS, PRE_DIRECTIVE, PRE_OLD_REFERENCE, PRE_REFERENCE, RBRACKET, RCURLY, REFERENCE, REFERENCE_TERMINATOR, REFINDEX, REFMOD, REFMOD2, REFMOD2_RPAREN, REFMOD3, REFMODIFIER, RIGHT_CURLEY, RPAREN, SET_DIRECTIVE, SINGLE_LINE_COMMENT, SINGLE_LINE_COMMENT_START, STRING_LITERAL, SUFFIX, TEXT, TEXTBLOCK, tokenImage, TRUE, WHITESPACE, WORD, ZERO_WIDTH_WHITESPACEFields inherited from interface org.apache.velocity.runtime.parser.node.StandardParserTreeConstants
JJTADDNODE, JJTANDNODE, JJTASSIGNMENT, JJTBLOCK, JJTCOMMENT, JJTDIRECTIVE, JJTDIRECTIVEASSIGN, JJTDIVNODE, JJTELSEIFSTATEMENT, JJTELSESTATEMENT, JJTEQNODE, JJTESCAPE, JJTESCAPEDDIRECTIVE, JJTEXPRESSION, JJTFALSE, JJTFLOATINGPOINTLITERAL, JJTGENODE, JJTGTNODE, JJTIDENTIFIER, JJTIFSTATEMENT, JJTINDEX, JJTINTEGERLITERAL, JJTINTEGERRANGE, JJTLENODE, JJTLTNODE, JJTMAP, JJTMETHOD, JJTMODNODE, JJTMULNODE, JJTNEGATENODE, JJTNENODE, jjtNodeName, JJTNOTNODE, JJTOBJECTARRAY, JJTORNODE, JJTPROCESS, JJTREFERENCE, JJTSETDIRECTIVE, JJTSTRINGLITERAL, JJTSUBTRACTNODE, JJTTEXT, JJTTEXTBLOCK, JJTTRUE, JJTVOID, JJTWORD -
Constructor Summary
ConstructorsConstructorDescriptionStandardParser(CharStream stream) Constructor with user supplied CharStream.Constructor with generated Token Manager.This constructor was added to allow the re-use of parsers. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidfinal voidcharasterisk()charat()final booleanComment()final voidfinal voidfinal booleanDirective(boolean afterNewline) Supports the Pluggable Directives #foo( arg+ )final intSupports the arguments for the Pluggable Directivesfinal voidfinal voidDisable tracing.chardollar()final ASTBlockElseIfStatement(ASTBlock previousBlock, boolean afterNewline) final ASTBlockElseStatement(ASTBlock previousBlock, boolean afterNewline) final voidEnable tracing.final voidfinal voidfinal voidEscape()Used to catch and process escape sequences in grammatical constructs as escapes outside of VTL are just characters.final voidused to separate the notion of a valid directive that has been escaped, versus something that looks like a directive and is just schmoo.final voidfinal voidFalse()final voidGenerate ParseException.getDirective(String directive) This method gets a Directive from the directives Hashtablefinal TokenGet the next Token.final TokengetToken(int index) Get the specific Token.charhash()final voidThis method corresponds to variable references in Velocity templates.final booleanIfStatement(boolean afterNewline) final voidIndex()final voidA Simplified parameter more suitable for an index position: $foo[$index]final voidfinal voidsupports the [n..m] vector generator for use in the #foreach() to generate measured ranges w/o needing explicit support from the app/servletbooleanisDirective(String directive) This method finds out of the directive exists in the directives Map.final voidMap()for creating a map in a #set #set($foo = {$foo : $bar, $blargh : $thingy})final voidMethod()This method has yet to be fully implemented but will allow arbitrarily nested method callsfinal voidfinal voidfinal voidThis method has yet to be fully implemented but will allow arbitrarily nested method callsThis was also added to allow parsers to be re-usable.final voidfinal SimpleNodeprocess()This method is what starts the whole parsing process.final voidvoidReInit(CharStream stream) Reinitialise.voidReinitialise.final voidvoidfinal booleanSetDirective(boolean afterNewline) Currently support both types of set : #set( expr ) #set exprfinal booleanStatement(boolean afterNewline) These are the types of statements that are acceptable in Velocity templates.final voidfinal booleanText()This method is responsible for allowing all non-grammar text to pass through unscathed.final voidstatic voidOur own trace method.final booleanTrace enabled.final voidTrue()final voidfinal voidWord()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.velocity.runtime.parser.Parser
blockComment, lineComment
-
Field Details
-
jjtree
-
currentTemplate
Current template we are parsing. Passed to us in parse() -
strictEscape
public boolean strictEscapeSet to true if the property RuntimeConstants.RUNTIME_REFERENCES_STRICT_ESCAPE is set to true -
hyphenAllowedInIdentifiers
public boolean hyphenAllowedInIdentifiersSet to true if the propoerty RuntimeConstants.PARSER_HYPHEN_ALLOWED is set to true -
token_source
Generated Token Manager. -
token
Current token. -
jj_nt
Next token.
-
-
Constructor Details
-
StandardParser
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. -
StandardParser
Constructor with user supplied CharStream. -
StandardParser
Constructor with generated Token Manager.
-
-
Method Details
-
trace
Our own trace method. Use sparsingly in production, since each and every call will introduce an execution branch and slow down parsing. -
getRuntimeServices
- Specified by:
getRuntimeServicesin interfaceParser
-
parse
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.- Specified by:
parsein interfaceParser- Throws:
ParseException
-
getDirective
This method gets a Directive from the directives Hashtable- Specified by:
getDirectivein interfaceParser
-
isDirective
This method finds out of the directive exists in the directives Map.- Specified by:
isDirectivein interfaceParser
-
getCurrentTemplate
- Specified by:
getCurrentTemplatein interfaceParser
-
resetCurrentTemplate
public void resetCurrentTemplate()- Specified by:
resetCurrentTemplatein interfaceParser
-
dollar
public char dollar() -
hash
public char hash() -
at
public char at() -
asterisk
public char asterisk() -
process
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 StandardParserVisitor interface which is generated automatically by JavaCC- Throws:
ParseException
-
Statement
These are the types of statements that are acceptable in Velocity templates.- Throws:
ParseException
-
EndingZeroWidthWhitespace
- Throws:
ParseException
-
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. 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
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 #<directive> and here we don't. We just want the escapes to render correctly- Throws:
ParseException
-
Comment
- Throws:
ParseException
-
Textblock
- Throws:
ParseException
-
FloatingPointLiteral
- Throws:
ParseException
-
IntegerLiteral
- Throws:
ParseException
-
StringLiteral
- Throws:
ParseException
-
Identifier
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
- Throws:
ParseException
-
DirectiveArg
Supports the arguments for the Pluggable Directives- Throws:
ParseException
-
DirectiveAssign
- Throws:
ParseException
-
Directive
Supports the Pluggable Directives #foo( arg+ )- Returns:
- true if ends with a newline
- Throws:
ParseException
-
Map
for creating a map in a #set #set($foo = {$foo : $bar, $blargh : $thingy})- Throws:
ParseException
-
ObjectArray
- Throws:
ParseException
-
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- Throws:
ParseException
-
IndexParameter
A Simplified parameter more suitable for an index position: $foo[$index]- Throws:
ParseException
-
Parameter
This method has yet to be fully implemented but will allow arbitrarily nested method calls- Throws:
ParseException
-
Method
This method has yet to be fully implemented but will allow arbitrarily nested method calls- Throws:
ParseException
-
Index
- Throws:
ParseException
-
Reference
- Throws:
ParseException
-
True
- Throws:
ParseException
-
False
- Throws:
ParseException
-
Text
This method is responsible for allowing all non-grammar text to pass through unscathed.- Returns:
- true if last read token was a newline
- Throws:
ParseException
-
IfStatement
- Throws:
ParseException
-
ElseStatement
public final ASTBlock ElseStatement(ASTBlock previousBlock, boolean afterNewline) throws ParseException - Throws:
ParseException
-
ElseIfStatement
public final ASTBlock ElseIfStatement(ASTBlock previousBlock, boolean afterNewline) throws ParseException - Throws:
ParseException
-
SetDirective
Currently support both types of set : #set( expr ) #set expr- Throws:
ParseException
-
Expression
- Throws:
ParseException
-
Assignment
- Throws:
ParseException
-
ConditionalOrExpression
- Throws:
ParseException
-
ConditionalAndExpression
- Throws:
ParseException
-
EqualityExpression
- Throws:
ParseException
-
RelationalExpression
- Throws:
ParseException
-
AdditiveExpression
- Throws:
ParseException
-
MultiplicativeExpression
- Throws:
ParseException
-
UnaryExpression
- Throws:
ParseException
-
PrimaryExpression
- Throws:
ParseException
-
ReInit
Reinitialise. -
ReInit
Reinitialise. -
getNextToken
Get the next Token. -
getToken
Get the specific Token. -
generateParseException
Generate ParseException. -
trace_enabled
public final boolean trace_enabled()Trace enabled. -
enable_tracing
public final void enable_tracing()Enable tracing. -
disable_tracing
public final void disable_tracing()Disable tracing.
-