org.apache.velocity.runtime.parser

Class Parser

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,v 1.74 2002/04/27 19:33:30 geirm Exp $

Author: Jason van Zyl Geir Magnusson Jr.

Nested Class Summary
static classParser.JJCalls
Field Summary
StringcurrentTemplateName
Name of current template we are parsing.
Hashtabledirectives
This Hashtable contains a list of all of the dynamic directives.
protected JJTParserStatejjtree
Parser.JJCalls[]jj_2_rtns
intjj_endpos
Vectorjj_expentries
int[]jj_expentry
intjj_gc
intjj_gen
intjj_kind
intjj_la
int[]jj_la1
int[]jj_la1_0
int[]jj_la1_1
Tokenjj_lastpos
int[]jj_lasttokens
Tokenjj_nt
intjj_ntk
booleanjj_rescan
Tokenjj_scanpos
booleanjj_semLA
booleanlookingAhead
RuntimeServicesrsvc
Tokentoken
ParserTokenManagertoken_source
VelocityCharStreamvelcharstream
Constructor Summary
Parser(RuntimeServices rs)
This constructor was added to allow the re-use of parsers.
Parser(CharStream stream)
Parser(ParserTokenManager tm)
Method Summary
voidAdditiveExpression()
voidAssignment()
voidComment()
voidConditionalAndExpression()
voidConditionalOrExpression()
voiddisable_tracing()
SimpleNodeDirective()
Supports the Pluggable Directives #foo( arg+ )
intDirectiveArg()
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()
voidenable_tracing()
StringescapedDirective(String strImage)
Produces a processed output for an escaped control or pluggable directive
voidElseIfStatement()
voidElseStatement()
voidEqualityExpression()
voidEscape()
Used to catch and process escape sequences in grammatical constructs as escapes outside of VTL are just characters.
voidEscapedDirective()
used to separate the notion of a valid directive that has been escaped, versus something that looks like a directive and is just schmoo.
voidExpression()
voidFalse()
ParseExceptiongenerateParseException()
DirectivegetDirective(String directive)
This method gets a Directive from the directives Hashtable
TokengetNextToken()
TokengetToken(int index)
booleanisDirective(String directive)
This method finds out of the directive exists in the directives Hashtable.
voidIdentifier()
This method corresponds to variable references in Velocity templates.
voidIfStatement()
voidIntegerRange()
supports the [n..m] vector generator for use in the #foreach() to generate measured ranges w/o needing explicit support from the app/servlet
booleanjj_2_1(int xla)
booleanjj_2_10(int xla)
booleanjj_2_11(int xla)
booleanjj_2_2(int xla)
booleanjj_2_3(int xla)
booleanjj_2_4(int xla)
booleanjj_2_5(int xla)
booleanjj_2_6(int xla)
booleanjj_2_7(int xla)
booleanjj_2_8(int xla)
booleanjj_2_9(int xla)
booleanjj_3R_19()
booleanjj_3R_20()
booleanjj_3R_21()
booleanjj_3R_22()
booleanjj_3R_23()
booleanjj_3R_24()
booleanjj_3R_25()
booleanjj_3R_26()
booleanjj_3R_27()
booleanjj_3R_28()
booleanjj_3R_29()
booleanjj_3R_30()
booleanjj_3R_31()
booleanjj_3R_32()
booleanjj_3R_33()
booleanjj_3R_34()
booleanjj_3R_35()
booleanjj_3R_36()
booleanjj_3R_37()
booleanjj_3R_38()
booleanjj_3R_39()
booleanjj_3R_40()
booleanjj_3R_41()
booleanjj_3R_42()
booleanjj_3R_43()
booleanjj_3R_44()
booleanjj_3R_45()
booleanjj_3R_46()
booleanjj_3R_47()
booleanjj_3R_48()
booleanjj_3R_49()
booleanjj_3R_50()
booleanjj_3R_51()
booleanjj_3R_52()
booleanjj_3R_53()
booleanjj_3R_54()
booleanjj_3R_55()
booleanjj_3R_56()
booleanjj_3R_57()
booleanjj_3R_58()
booleanjj_3R_59()
booleanjj_3R_60()
booleanjj_3R_61()
booleanjj_3R_62()
booleanjj_3R_63()
booleanjj_3R_64()
booleanjj_3R_65()
booleanjj_3R_66()
booleanjj_3R_67()
booleanjj_3R_68()
booleanjj_3R_69()
booleanjj_3R_70()
booleanjj_3R_71()
booleanjj_3R_72()
booleanjj_3R_73()
booleanjj_3R_74()
booleanjj_3R_75()
booleanjj_3R_76()
booleanjj_3R_77()
booleanjj_3R_78()
booleanjj_3R_79()
booleanjj_3R_80()
booleanjj_3R_81()
booleanjj_3R_82()
booleanjj_3R_83()
booleanjj_3R_84()
booleanjj_3R_85()
booleanjj_3R_86()
booleanjj_3R_87()
booleanjj_3R_88()
booleanjj_3R_89()
booleanjj_3_1()
booleanjj_3_10()
booleanjj_3_11()
booleanjj_3_2()
booleanjj_3_3()
booleanjj_3_4()
booleanjj_3_5()
booleanjj_3_6()
booleanjj_3_7()
booleanjj_3_8()
booleanjj_3_9()
voidjj_add_error_token(int kind, int pos)
Tokenjj_consume_token(int kind)
intjj_ntk()
voidjj_rescan_token()
voidjj_save(int index, int xla)
booleanjj_scan_token(int kind)
voidMethod()
This method has yet to be fully implemented but will allow arbitrarily nested method calls
voidMultiplicativeExpression()
voidNumberLiteral()
voidObjectArray()
SimpleNodeparse(Reader reader, String templateName)
This was also added to allow parsers to be re-usable.
SimpleNodeprocess()
This method is what starts the whole parsing process.
voidParameter()
This method has yet to be fully implemented but will allow arbitrarily nested method calls
voidPrimaryExpression()
voidReference()
voidReInit(CharStream stream)
voidReInit(ParserTokenManager tm)
voidRelationalExpression()
voidsetDirectives(Hashtable directives)
This method sets the directives Hashtable
voidSetDirective()
Currently support both types of set : #set( expr ) #set expr
voidStatement()
These are the types of statements that are acceptable in Velocity templates.
voidStopStatement()
This method corresponds to the #stop directive which just simulates and EOF so that parsing stops.
voidStringLiteral()
voidText()
This method is responsible for allowing all non-grammar text to pass through unscathed.
voidTrue()
voidUnaryExpression()
voidWord()

Field Detail

currentTemplateName

String currentTemplateName
Name of current template we are parsing. Passed to us in parse()

directives

private Hashtable directives
This Hashtable contains a list of all of the dynamic directives.

jjtree

protected JJTParserState jjtree

jj_2_rtns

private final Parser.JJCalls[] jj_2_rtns

jj_endpos

private int jj_endpos

jj_expentries

private Vector jj_expentries

jj_expentry

private int[] jj_expentry

jj_gc

private int jj_gc

jj_gen

private int jj_gen

jj_kind

private int jj_kind

jj_la

private int jj_la

jj_la1

private final int[] jj_la1

jj_la1_0

private final int[] jj_la1_0

jj_la1_1

private final int[] jj_la1_1

jj_lastpos

private Token jj_lastpos

jj_lasttokens

private int[] jj_lasttokens

jj_nt

public Token jj_nt

jj_ntk

private int jj_ntk

jj_rescan

private boolean jj_rescan

jj_scanpos

private Token jj_scanpos

jj_semLA

private boolean jj_semLA

lookingAhead

public boolean lookingAhead

rsvc

private RuntimeServices rsvc

token

public Token token

token_source

public ParserTokenManager token_source

velcharstream

VelocityCharStream velcharstream

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

AdditiveExpression

public final void AdditiveExpression()

Assignment

public final void Assignment()

Comment

public final void Comment()

ConditionalAndExpression

public final void ConditionalAndExpression()

ConditionalOrExpression

public final void ConditionalOrExpression()

disable_tracing

public final void disable_tracing()

Directive

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

DirectiveArg

public final 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()

enable_tracing

public final void enable_tracing()

escapedDirective

private String escapedDirective(String strImage)
Produces a processed output for an escaped control or pluggable directive

ElseIfStatement

public final void ElseIfStatement()

ElseStatement

public final void ElseStatement()

EqualityExpression

public final void EqualityExpression()

Escape

public final void 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 # and here we don't. We just want the escapes to render correctly

EscapedDirective

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

Expression

public final void Expression()

False

public final void False()

generateParseException

public final ParseException generateParseException()

getDirective

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

getNextToken

public final Token getNextToken()

getToken

public final Token getToken(int index)

isDirective

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

Identifier

public final void 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

IfStatement

public final void IfStatement()

IntegerRange

public final 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

jj_2_1

private final boolean jj_2_1(int xla)

jj_2_10

private final boolean jj_2_10(int xla)

jj_2_11

private final boolean jj_2_11(int xla)

jj_2_2

private final boolean jj_2_2(int xla)

jj_2_3

private final boolean jj_2_3(int xla)

jj_2_4

private final boolean jj_2_4(int xla)

jj_2_5

private final boolean jj_2_5(int xla)

jj_2_6

private final boolean jj_2_6(int xla)

jj_2_7

private final boolean jj_2_7(int xla)

jj_2_8

private final boolean jj_2_8(int xla)

jj_2_9

private final boolean jj_2_9(int xla)

jj_3R_19

private final boolean jj_3R_19()

jj_3R_20

private final boolean jj_3R_20()

jj_3R_21

private final boolean jj_3R_21()

jj_3R_22

private final boolean jj_3R_22()

jj_3R_23

private final boolean jj_3R_23()

jj_3R_24

private final boolean jj_3R_24()

jj_3R_25

private final boolean jj_3R_25()

jj_3R_26

private final boolean jj_3R_26()

jj_3R_27

private final boolean jj_3R_27()

jj_3R_28

private final boolean jj_3R_28()

jj_3R_29

private final boolean jj_3R_29()

jj_3R_30

private final boolean jj_3R_30()

jj_3R_31

private final boolean jj_3R_31()

jj_3R_32

private final boolean jj_3R_32()

jj_3R_33

private final boolean jj_3R_33()

jj_3R_34

private final boolean jj_3R_34()

jj_3R_35

private final boolean jj_3R_35()

jj_3R_36

private final boolean jj_3R_36()

jj_3R_37

private final boolean jj_3R_37()

jj_3R_38

private final boolean jj_3R_38()

jj_3R_39

private final boolean jj_3R_39()

jj_3R_40

private final boolean jj_3R_40()

jj_3R_41

private final boolean jj_3R_41()

jj_3R_42

private final boolean jj_3R_42()

jj_3R_43

private final boolean jj_3R_43()

jj_3R_44

private final boolean jj_3R_44()

jj_3R_45

private final boolean jj_3R_45()

jj_3R_46

private final boolean jj_3R_46()

jj_3R_47

private final boolean jj_3R_47()

jj_3R_48

private final boolean jj_3R_48()

jj_3R_49

private final boolean jj_3R_49()

jj_3R_50

private final boolean jj_3R_50()

jj_3R_51

private final boolean jj_3R_51()

jj_3R_52

private final boolean jj_3R_52()

jj_3R_53

private final boolean jj_3R_53()

jj_3R_54

private final boolean jj_3R_54()

jj_3R_55

private final boolean jj_3R_55()

jj_3R_56

private final boolean jj_3R_56()

jj_3R_57

private final boolean jj_3R_57()

jj_3R_58

private final boolean jj_3R_58()

jj_3R_59

private final boolean jj_3R_59()

jj_3R_60

private final boolean jj_3R_60()

jj_3R_61

private final boolean jj_3R_61()

jj_3R_62

private final boolean jj_3R_62()

jj_3R_63

private final boolean jj_3R_63()

jj_3R_64

private final boolean jj_3R_64()

jj_3R_65

private final boolean jj_3R_65()

jj_3R_66

private final boolean jj_3R_66()

jj_3R_67

private final boolean jj_3R_67()

jj_3R_68

private final boolean jj_3R_68()

jj_3R_69

private final boolean jj_3R_69()

jj_3R_70

private final boolean jj_3R_70()

jj_3R_71

private final boolean jj_3R_71()

jj_3R_72

private final boolean jj_3R_72()

jj_3R_73

private final boolean jj_3R_73()

jj_3R_74

private final boolean jj_3R_74()

jj_3R_75

private final boolean jj_3R_75()

jj_3R_76

private final boolean jj_3R_76()

jj_3R_77

private final boolean jj_3R_77()

jj_3R_78

private final boolean jj_3R_78()

jj_3R_79

private final boolean jj_3R_79()

jj_3R_80

private final boolean jj_3R_80()

jj_3R_81

private final boolean jj_3R_81()

jj_3R_82

private final boolean jj_3R_82()

jj_3R_83

private final boolean jj_3R_83()

jj_3R_84

private final boolean jj_3R_84()

jj_3R_85

private final boolean jj_3R_85()

jj_3R_86

private final boolean jj_3R_86()

jj_3R_87

private final boolean jj_3R_87()

jj_3R_88

private final boolean jj_3R_88()

jj_3R_89

private final boolean jj_3R_89()

jj_3_1

private final boolean jj_3_1()

jj_3_10

private final boolean jj_3_10()

jj_3_11

private final boolean jj_3_11()

jj_3_2

private final boolean jj_3_2()

jj_3_3

private final boolean jj_3_3()

jj_3_4

private final boolean jj_3_4()

jj_3_5

private final boolean jj_3_5()

jj_3_6

private final boolean jj_3_6()

jj_3_7

private final boolean jj_3_7()

jj_3_8

private final boolean jj_3_8()

jj_3_9

private final boolean jj_3_9()

jj_add_error_token

private void jj_add_error_token(int kind, int pos)

jj_consume_token

private final Token jj_consume_token(int kind)

jj_ntk

private final int jj_ntk()

jj_rescan_token

private final void jj_rescan_token()

jj_save

private final void jj_save(int index, int xla)

jj_scan_token

private final boolean jj_scan_token(int kind)

Method

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

MultiplicativeExpression

public final void MultiplicativeExpression()

NumberLiteral

public final void NumberLiteral()

ObjectArray

public final void ObjectArray()

parse

public SimpleNode parse(Reader reader, String templateName)
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.

process

public final SimpleNode 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 ParserVisitor interface which is generated automatically by JavaCC

Parameter

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

PrimaryExpression

public final void PrimaryExpression()

Reference

public final void Reference()

ReInit

public void ReInit(CharStream stream)

ReInit

public void ReInit(ParserTokenManager tm)

RelationalExpression

public final void RelationalExpression()

setDirectives

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

SetDirective

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

Statement

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

StopStatement

public final void StopStatement()
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.

StringLiteral

public final void StringLiteral()

Text

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

True

public final void True()

UnaryExpression

public final void UnaryExpression()

Word

public final void Word()
Copyright B) 2002 Apache Software Foundation. All Rights Reserved.