|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--freemarker.template.compiler.StandardTemplateParser
Parses standard template language and generates
Instruction
s. Uses
ExpressionBuilder
to build expressions.
Field Summary | |
protected static java.lang.String |
ASSIGN_TAG
|
protected static char |
BOOLEAN_ESCAPE_CHAR
|
protected static java.lang.String |
BREAK_TAG
|
protected static java.lang.String |
CALL_TAG
|
protected static java.lang.String |
CASE_TAG
|
protected static java.lang.String |
COMMENT_END_TAG
|
protected static java.lang.String |
COMMENT_TAG
|
protected static java.lang.String |
DEFAULT_TAG
|
protected static char |
DOUBLE_QUOTE_CHAR
|
protected static java.lang.String |
ELSE_IF_TAG
|
protected static java.lang.String |
ELSE_TAG
|
protected static char |
END_TAG_START_CHAR
|
protected static char |
ESCAPE_CHAR
|
protected static java.lang.String |
FALSE_LITERAL
|
protected static java.lang.String |
FOREACH_END_TAG
|
protected static java.lang.String |
FOREACH_INDEX_KEYWORD
|
protected static java.lang.String |
FOREACH_TAG
|
protected int |
foundPos
The position at which the current instruction was found. |
protected static java.lang.String |
FUNCTION_END_TAG
|
protected static java.lang.String |
FUNCTION_TAG
|
protected static char |
HASH_LITERAL_END_CHAR
|
protected static char |
HASH_LITERAL_START_CHAR
|
protected static java.lang.String |
IF_END_TAG
|
protected static java.lang.String |
IF_TAG
|
protected static java.lang.String |
INCLUDE_TAG
|
protected static java.lang.String |
LIST_END_TAG
|
protected static java.lang.String |
LIST_INDEX_KEYWORD
|
protected static char |
LIST_LITERAL_END_CHAR
|
protected static java.lang.String |
LIST_LITERAL_RANGE
|
protected static char |
LIST_LITERAL_START_CHAR
|
protected static java.lang.String |
LIST_TAG
|
protected static int |
LONG_OPERATOR_LENGTH
Length of operators that are more than one character long. |
protected Instruction |
nextFMInstruction
The next non-text instruction found by the parser. |
protected static java.lang.String |
NOPARSE_TAG
|
protected static java.lang.String |
NOPARSE_TAG_END
|
protected int |
parsePos
The current parse position. |
protected int |
previousParsePos
The parse position before the current instruction was found. |
protected static char |
QUOTE_CHAR
|
protected static java.lang.String |
SWITCH_END_TAG
|
protected static java.lang.String |
SWITCH_TAG
|
protected static char |
TAG_END_CHAR
|
protected static char |
TAG_START_CHAR
|
protected FunctionTemplateProcessor |
template
The Template being parsed. |
protected java.lang.String |
text
The text to be parsed. |
protected int |
textLen
The number of characters in the text. |
protected static java.lang.String |
TRANSFORM_END_TAG
|
protected static java.lang.String |
TRANSFORM_TAG
|
protected static java.lang.String |
TRUE_LITERAL
|
protected static char |
VAR_INSTR_END_CHAR
|
protected static char |
VAR_INSTR_START_CHAR
|
protected static java.lang.String |
VAR_INSTR_START_CHARS
|
Constructor Summary | |
StandardTemplateParser()
Default constructor. |
|
StandardTemplateParser(FunctionTemplateProcessor template,
java.lang.String text)
Constructs a new StandardTemplateParser with the given
template and text to be parsed. |
Method Summary | |
java.lang.String |
atChar()
Adds text to an error message indicating the line number where the error was found. |
protected java.lang.String |
atChar(int pos)
Adds text to an error message indicating the line number where the error was found. |
protected boolean |
findTagEnd()
Requires a TAG_END_CHAR , optionally preceded by whitespace,
and advances parsePos after the TAG_END_CHAR . |
protected void |
findTagNameEnd()
Advances parsePos through any remaining alphanumeric
characters. |
Instruction |
getNextInstruction()
Searches the text for an instruction, starting at the current parse position. |
protected Instruction |
getNextInstructionTag()
Searches the text for a tagged instruction, starting at the current parse position. |
protected boolean |
isIdentifierStartChar(char c)
Determines whether a character is legal at the start of an identifier. |
boolean |
isMoreInstructions()
Are there any more instructions left to be parsed? |
protected AssignInstruction |
parseAssign()
Parses an AssignInstruction 's tag. |
protected boolean |
parseBinaryElement(java.util.List elements)
Parse an optional binary element. |
protected BooleanLiteral |
parseBooleanLiteral()
Parses a BooleanLiteral . |
protected CallInstruction |
parseCall()
Parses a CallInstruction 's tag. |
protected CaseInstruction |
parseCase()
Parses a CaseInstruction 's tag. |
protected CommentInstruction |
parseComment()
Parses a CommentInstruction 's tag. |
protected DefaultCaseInstruction |
parseDefault()
Parses a default CaseInstruction 's tag. |
protected Dot |
parseDot()
Parses the Dot operator. |
protected DynamicKeyName |
parseDynamicKeyName()
Parses a DynamicKeyName . |
protected java.util.List |
parseElements()
Retrieve the next ExpressionElement (s)
following parsePos . |
protected ElseInstruction |
parseElse()
Parses an IfInstruction
<else> tag. |
protected IfInstruction |
parseElseIf()
Parses an IfInstruction
<elseif> tag. |
protected Expression |
parseExpression()
Parses and builds an Expression ,
which may also be a sub-expression. |
protected ListInstruction |
parseForeachStart()
Parses a ListInstruction 's
start tag with the "foreach" keyword. |
protected FunctionInstruction |
parseFunction()
Parses a FunctionInstruction 's tag. |
protected HashLiteral |
parseHashLiteral()
Parses a HashLiteral . |
protected Identifier |
parseIdentifier()
Tries to parse an Identifier . |
protected IfElseInstruction |
parseIfStart()
Parses an IfElseInstruction 's start tag. |
protected IncludeInstruction |
parseInclude()
Parses an IncludeInstruction 's tag. |
protected Expression |
parseListLiteral()
Parses a ListLiteral . |
protected ListInstruction |
parseListStart()
Parses a ListInstruction 's start tag. |
protected MethodCall |
parseMethodCall()
Parses a MethodCall . |
protected NoParseInstruction |
parseNoparseStart()
Parses a NoParseInstruction 's tag. |
protected NumberLiteral |
parseNumberLiteral()
Parses a NumberLiteral . |
protected StringLiteral |
parseStringLiteral()
Parses a StringLiteral . |
protected SwitchInstruction |
parseSwitch()
Parses a SwitchInstruction 's tag. |
protected TransformInstruction |
parseTransformStart()
Parses a TransformInstruction 's tag. |
protected Variable |
parseVariable()
Parses an Expression and ensures
that it's a Variable . |
protected ExpressionElement |
parseVariableElement()
Retrieve the next ExpressionElement
following parsePos , and ensure its a
Variable . |
protected VariableInstruction |
parseVariableInstruction()
Parses a VariableInstruction . |
protected Expression |
parseVariableOrList()
Parses either a variable name or a list literal. |
protected void |
requireChar(char c)
Requires a given character, optionally preceded by by whitespace. |
protected void |
requireWhitespace()
Advances parsePos beyond required whitespace. |
void |
setTemplate(FunctionTemplateProcessor template)
Sets the template to receive the parsed instructions. |
void |
setText(java.lang.String text)
Sets the text to be parsed. |
protected boolean |
skipChar(char c)
Advances beyond any whitespace; then, if the next character matches a given character, advances beyond it and returns true ,
otherwise returns false . |
protected boolean |
skipKeyword(java.lang.String keyword)
Skip over a given keyword. |
java.lang.String |
skipToEndInstruction(ContainerInstruction beginInstruction)
Searches the text for a matching end instruction, starting at the current parse position. |
protected void |
skipWhitespace()
Advances parsePos beyond any whitespace. |
java.lang.String |
toString()
Returns a string representation of the object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected java.lang.String text
protected int textLen
protected FunctionTemplateProcessor template
protected int parsePos
protected int previousParsePos
protected int foundPos
protected Instruction nextFMInstruction
protected static final java.lang.String VAR_INSTR_START_CHARS
protected static final char VAR_INSTR_START_CHAR
protected static final char VAR_INSTR_END_CHAR
protected static final java.lang.String LIST_TAG
protected static final java.lang.String LIST_INDEX_KEYWORD
protected static final java.lang.String LIST_END_TAG
protected static final java.lang.String IF_TAG
protected static final java.lang.String ELSE_TAG
protected static final java.lang.String ELSE_IF_TAG
protected static final java.lang.String IF_END_TAG
protected static final java.lang.String SWITCH_TAG
protected static final java.lang.String SWITCH_END_TAG
protected static final java.lang.String CASE_TAG
protected static final java.lang.String BREAK_TAG
protected static final java.lang.String DEFAULT_TAG
protected static final java.lang.String ASSIGN_TAG
protected static final java.lang.String INCLUDE_TAG
protected static final java.lang.String FUNCTION_TAG
protected static final java.lang.String FUNCTION_END_TAG
protected static final java.lang.String CALL_TAG
protected static final char TAG_START_CHAR
protected static final char TAG_END_CHAR
protected static final char END_TAG_START_CHAR
protected static final char QUOTE_CHAR
protected static final char DOUBLE_QUOTE_CHAR
protected static final char ESCAPE_CHAR
protected static final char BOOLEAN_ESCAPE_CHAR
protected static final char LIST_LITERAL_START_CHAR
protected static final char LIST_LITERAL_END_CHAR
protected static final char HASH_LITERAL_START_CHAR
protected static final char HASH_LITERAL_END_CHAR
protected static final java.lang.String LIST_LITERAL_RANGE
protected static final java.lang.String COMMENT_TAG
protected static final java.lang.String COMMENT_END_TAG
protected static final java.lang.String NOPARSE_TAG
protected static final java.lang.String NOPARSE_TAG_END
protected static final java.lang.String FOREACH_TAG
protected static final java.lang.String FOREACH_INDEX_KEYWORD
protected static final java.lang.String FOREACH_END_TAG
protected static final java.lang.String TRANSFORM_TAG
protected static final java.lang.String TRANSFORM_END_TAG
protected static final java.lang.String TRUE_LITERAL
protected static final java.lang.String FALSE_LITERAL
protected static final int LONG_OPERATOR_LENGTH
Constructor Detail |
public StandardTemplateParser()
public StandardTemplateParser(FunctionTemplateProcessor template, java.lang.String text)
StandardTemplateParser
with the given
template and text to be parsed.template
- a new template that will received the parsed instructionstext
- the text to be parsedMethod Detail |
public void setText(java.lang.String text)
text
- the text to be parsed.public void setTemplate(FunctionTemplateProcessor template)
template
- the template being parsed.public Instruction getNextInstruction() throws ParseException
Searches the text for an instruction, starting at the current
parse position. If one is found, parses it into an
Instruction
. Before changing
parsePos
, sets previousParsePos = parsePos
.
If no instruction is found, leaves parsePos
unchanged.
getNextInstruction
in interface TemplateParser
Instruction
representing the
next instruction following parsePos
, or null
if none is found.ParseException
- the next instruction couldn't be parsedprotected Instruction getNextInstructionTag() throws ParseException
Searches the text for a tagged instruction, starting at the current
parse position. If one is found, parses it into a
Instruction
. Before changing
parsePos
, sets previousParsePos = parsePos
.
If no instruction is found, parsePos
will be equal
to textLen
, which will be equal to foundPos
.
Instruction
representing the
next instruction following parsePos
, or null
if none is found.ParseException
- the next instruction couldn't be parsedpublic boolean isMoreInstructions()
isMoreInstructions
in interface TemplateParser
true
if there is more text to parse, otherwise
false
public java.lang.String skipToEndInstruction(ContainerInstruction beginInstruction)
Searches the text for a matching end instruction, starting at the
current parse position. If we find it, parse it and return. Before
changing parsePos
, should set previousParsePos =
parsePos
.
If no instruction is found, set parsePos
to
textLen
which equals foundPos
.
skipToEndInstruction
in interface TemplateParser
String
containing the intermediate text if we
find the end instruction we're after, otherwise null
public java.lang.String atChar()
atChar
in interface TemplateParser
String
containing the message.protected void findTagNameEnd()
parsePos
through any remaining alphanumeric
characters. Leaves parsePos
unchanged if not found.protected boolean findTagEnd() throws ParseException
TAG_END_CHAR
, optionally preceded by whitespace,
and advances parsePos
after the TAG_END_CHAR
.true
if we found the end of the tag, otherwise false
ParseException
- an error occurred while scanning for the end tagprotected java.lang.String atChar(int pos)
String
containing the message.protected Expression parseExpression() throws ParseException
Expression
,
which may also be a sub-expression. An expression in parenthesis is
considered a sub-expression.Expression
.protected java.util.List parseElements() throws ParseException
ExpressionElement
(s)
following parsePos
.ExpressionElement
s containing any
elements encounteredParseException
- something went wrong during parsingprotected boolean parseBinaryElement(java.util.List elements) throws ParseException
elements
- a list of elements to which we add any elements parsedtrue
if a binary operator was found, otherwise
false
ParseException
- something went wrong during parsingprotected DynamicKeyName parseDynamicKeyName() throws ParseException
DynamicKeyName
.
Expects parsePos
to be on the open bracket.DynamicKeyName
.protected Dot parseDot() throws ParseException
Dot
operator.
Expects parsePos
to be one character beyond the dot itself.Dot
.protected StringLiteral parseStringLiteral() throws ParseException
StringLiteral
.
Expects parsePos
to be on the open quote. This is so
we can determine whether a single- or double-quote was used to open
the String, and thus what close quote we should look for.StringLiteral
.protected Expression parseListLiteral() throws ParseException
ListLiteral
.
Expects parsePos
to be just beyond open square bracket.ListLiteral
.protected HashLiteral parseHashLiteral() throws ParseException
HashLiteral
.
Expects parsePos
to be just beyond the open brace.HashLiteral
.protected NumberLiteral parseNumberLiteral() throws ParseException
NumberLiteral
.
Expects parsePos
to be on the first digit or optional
minus sign.NumberLiteral
.protected BooleanLiteral parseBooleanLiteral() throws ParseException
BooleanLiteral
.
Expects parsePos
to be immediately following the '#' symbol.BooleanLiteral
.protected Variable parseVariable() throws ParseException
Expression
and ensures
that it's a Variable
.Variable
.protected ExpressionElement parseVariableElement() throws ParseException
ExpressionElement
following parsePos
, and ensure its a
Variable
.ExpressionElement
, or null
if none is found.protected Identifier parseIdentifier() throws ParseException
Identifier
.
Skips any whitespace prior to the identifier.Identifier
.protected boolean isIdentifierStartChar(char c)
Determines whether a character is legal at the start of an identifier. An identifier is either something like a tag name, such as "foreach", or a variable name, such as "myHash".
In this implementation, an identifier can only start with either a letter or an underscore.
Note that this method does not affect identifiers inside a dynamic key name.
protected MethodCall parseMethodCall() throws ParseException
MethodCall
.MethodCall
object initialized with the arguments.protected Expression parseVariableOrList() throws ParseException
ParseException
- the next expression element couldn't be parsedprotected VariableInstruction parseVariableInstruction() throws ParseException
VariableInstruction
.
Expects parsePos
to be at the beginning of the
VAR_INSTR_START_CHARS
.VariableInstruction
.protected ListInstruction parseListStart() throws ParseException
ListInstruction
's start tag.ListInstruction
initialized with the values
from the tag.protected ListInstruction parseForeachStart() throws ParseException
ListInstruction
's
start tag with the "foreach" keyword.ListInstruction
initialized with the values
from the tag.protected IfElseInstruction parseIfStart() throws ParseException
IfElseInstruction
's start tag.IfElseInstruction
initialized with the expression
in the tag.protected IfInstruction parseElseIf() throws ParseException
IfInstruction
<elseif> tag.IfInstruction
initialised with the expression
in the tag.protected ElseInstruction parseElse() throws ParseException
IfInstruction
<else> tag.IfInstruction
initialised with the constant
expression true
.protected AssignInstruction parseAssign() throws ParseException
AssignInstruction
's tag.AssignInstruction
initialized with the values
from the tag.protected IncludeInstruction parseInclude() throws ParseException
IncludeInstruction
's tag.IncludeInstruction
initialized with the name
in the tag.protected SwitchInstruction parseSwitch() throws ParseException
SwitchInstruction
's tag.SwitchInstruction
initialized with the expression
in the tag.protected CaseInstruction parseCase() throws ParseException
CaseInstruction
's tag.CaseInstruction
initialized with the expression
in the tag.protected DefaultCaseInstruction parseDefault() throws ParseException
CaseInstruction
's tag.CaseInstruction
with default
status set to true
.protected FunctionInstruction parseFunction() throws ParseException
FunctionInstruction
's tag.FunctionInstruction
intialized with the
argument names in the tag.protected CallInstruction parseCall() throws ParseException
CallInstruction
's tag.
This essentially looks like a method call, so we parse it the same way.CallInstruction
initialized with the arguments
in the tag.protected CommentInstruction parseComment() throws ParseException
CommentInstruction
's tag.CommentInstruction
protected NoParseInstruction parseNoparseStart() throws ParseException
NoParseInstruction
's tag.NoParseInstruction
protected TransformInstruction parseTransformStart() throws ParseException
TransformInstruction
's tag.
This tag consists of one parameter: the variable representing the
TemplateTransformModel
to be used for the
transformation.TransformInstruction
protected boolean skipChar(char c) throws ParseException
true
,
otherwise returns false
.true
if the character was found, otherwise false
protected void requireChar(char c) throws ParseException
ParseException
- the required character couldn't be foundprotected boolean skipKeyword(java.lang.String keyword) throws ParseException
keyword
- the keyword to skip overParseException
- there are no more characters
before the keyword is expected.protected void skipWhitespace() throws ParseException
parsePos
beyond any whitespace.ParseException
- there are no more characters
after whitespace has been skipped.protected void requireWhitespace() throws ParseException
parsePos
beyond required whitespace.ParseException
- there are no more characters
after whitespace has been skipped, or if no whitespace
could be found.public java.lang.String toString()
toString
in class java.lang.Object
String
representation of the object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |