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 Details

    • jjtree

      protected JJTStandardParserState jjtree
    • currentTemplate

      public Template currentTemplate
      Current template we are parsing. Passed to us in parse()
    • strictEscape

      public boolean strictEscape
      Set to true if the property RuntimeConstants.RUNTIME_REFERENCES_STRICT_ESCAPE is set to true
    • hyphenAllowedInIdentifiers

      public boolean hyphenAllowedInIdentifiers
      Set to true if the propoerty RuntimeConstants.PARSER_HYPHEN_ALLOWED is set to true
    • token_source

      public StandardParserTokenManager token_source
      Generated Token Manager.
    • token

      public Token token
      Current token.
    • jj_nt

      public Token jj_nt
      Next token.
  • Constructor Details

    • StandardParser

      public StandardParser(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.
    • StandardParser

      public StandardParser(CharStream stream)
      Constructor with user supplied CharStream.
    • StandardParser

      public StandardParser(StandardParserTokenManager tm)
      Constructor with generated Token Manager.
  • Method Details

    • trace

      public static void trace(String message)
      Our own trace method. Use sparsingly in production, since each and every call will introduce an execution branch and slow down parsing.
    • getRuntimeServices

      public RuntimeServices getRuntimeServices()
      Specified by:
      getRuntimeServices in interface Parser
    • parse

      public SimpleNode parse(Reader reader, Template t) 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.
      Specified by:
      parse in interface Parser
      Throws:
      ParseException
    • getDirective

      public Directive getDirective(String directive)
      This method gets a Directive from the directives Hashtable
      Specified by:
      getDirective in interface Parser
    • isDirective

      public boolean isDirective(String directive)
      This method finds out of the directive exists in the directives Map.
      Specified by:
      isDirective in interface Parser
    • getCurrentTemplate

      public Template getCurrentTemplate()
      Specified by:
      getCurrentTemplate in interface Parser
    • resetCurrentTemplate

      public void resetCurrentTemplate()
      Specified by:
      resetCurrentTemplate in interface Parser
    • dollar

      public char dollar()
      Specified by:
      dollar in interface Parser
    • hash

      public char hash()
      Specified by:
      hash in interface Parser
    • at

      public char at()
      Specified by:
      at in interface Parser
    • asterisk

      public char asterisk()
      Specified by:
      asterisk in interface Parser
    • 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 StandardParserVisitor interface which is generated automatically by JavaCC
      Throws:
      ParseException
    • Statement

      public final boolean Statement(boolean afterNewline) throws ParseException
      These are the types of statements that are acceptable in Velocity templates.
      Throws:
      ParseException
    • EndingZeroWidthWhitespace

      public final void EndingZeroWidthWhitespace() throws ParseException
      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 #<directive> and here we don't. We just want the escapes to render correctly
      Throws:
      ParseException
    • Comment

      public final boolean Comment() throws ParseException
      Throws:
      ParseException
    • Textblock

      public final void Textblock() 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
      Throws:
      ParseException
    • DirectiveAssign

      public final void DirectiveAssign() throws ParseException
      Throws:
      ParseException
    • Directive

      public final boolean Directive(boolean afterNewline) throws ParseException
      Supports the Pluggable Directives #foo( arg+ )
      Returns:
      true if ends with a newline
      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
    • IndexParameter

      public final void IndexParameter() throws ParseException
      A Simplified parameter more suitable for an index position: $foo[$index]
      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
    • Index

      public final void Index() throws ParseException
      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 boolean Text() throws ParseException
      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

      public final boolean IfStatement(boolean afterNewline) throws ParseException
      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

      public final boolean SetDirective(boolean afterNewline) throws ParseException
      Currently support both types of set : #set( expr ) #set expr
      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)
      Reinitialise.
      Specified by:
      ReInit in interface Parser
    • ReInit

      public void ReInit(StandardParserTokenManager tm)
      Reinitialise.
    • getNextToken

      public final Token getNextToken()
      Get the next Token.
    • getToken

      public final Token getToken(int index)
      Get the specific Token.
      Specified by:
      getToken in interface Parser
    • generateParseException

      public ParseException 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.