Class Reparser
java.lang.Object
com.google.auto.value.processor.escapevelocity.Reparser
The second phase of parsing. See
Parser.parse()
for a description of the phases and why
we need them.-
Field Summary
FieldsModifier and TypeFieldDescriptionMacros are removed from the input as they are found.private int
The index of the node we are currently looking at while parsing.private final com.google.common.collect.ImmutableList<Node>
The nodes that make up the input sequence. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Node
private static boolean
isWhitespaceLiteral
(Node node) private void
linkMacroCall
(DirectiveNode.MacroCallNode macroCall) private void
private Node
nextNode()
private Node
parseForEach
(TokenNode.ForEachTokenNode forEach) private Node
parseIfOrElseIf
(TokenNode.IfOrElseIfTokenNode ifOrElseIf) private Node
parseMacroDefinition
(TokenNode.MacroDefinitionTokenNode macroDefinition) private Node
parseNested
(TokenNode.NestedTokenNode nested) private Node
Parse subtrees until one of the token types instopSet
is encountered.private Node
private static com.google.common.collect.ImmutableList<Node>
removeSpaceBeforeSet
(com.google.common.collect.ImmutableList<Node> nodes) Returns a copy of the given list where spaces have been moved where appropriate after#set
.(package private) Template
reparse()
private Node
private static boolean
-
Field Details
-
END_SET
-
EOF_SET
-
ELSE_ELSE_IF_END_SET
-
nodes
The nodes that make up the input sequence. Nodes are removed one by one from this list as parsing proceeds. At any time,currentNode()
is the node being examined. -
nodeIndex
private int nodeIndexThe index of the node we are currently looking at while parsing. -
macros
Macros are removed from the input as they are found. They do not appear in the output parse tree. Macro definitions are not executed in place but are all applied before template rendering starts. This means that a macro can be referenced before it is defined.
-
-
Constructor Details
-
Reparser
Reparser(com.google.common.collect.ImmutableList<Node> nodes) -
Reparser
-
-
Method Details
-
reparse
Template reparse() -
reparseNodes
-
removeSpaceBeforeSet
private static com.google.common.collect.ImmutableList<Node> removeSpaceBeforeSet(com.google.common.collect.ImmutableList<Node> nodes) Returns a copy of the given list where spaces have been moved where appropriate after#set
. This hack is needed to match what appears to be special treatment in Apache Velocity of spaces before#set
directives. If you have thing whitespace#set
, then the whitespace is deleted if the thing is a comment (##...\n
); a reference ($x
or$x.foo
etc); a macro definition; or another#set
. -
shouldDeleteSpaceBetweenThisAndSet
-
isWhitespaceLiteral
-
parseTo
Parse subtrees until one of the token types instopSet
is encountered. If this is the top level,stopSet
will includeTokenNode.EofNode
so parsing will stop when it reaches the end of the input. Otherwise, if anEofNode
is encountered it is an error because we have something like#if
without#end
.- Parameters:
stopSet
- the kinds of tokens that will stop the parse. For example, if we are parsing after an#if
, we will stop at any of#else
,#elseif
, or#end
.forWhat
- the token that triggered this call, for example the#if
whose#end
etc we are looking for.- Returns:
- a Node that is the concatenation of the parsed subtrees
-
currentNode
-
nextNode
-
parseTokenNode
-
parseForEach
-
parseIfOrElseIf
-
parseNested
-
parseMacroDefinition
-
linkMacroCalls
private void linkMacroCalls() -
linkMacroCall
-