Class Reparser
- java.lang.Object
-
- com.google.auto.value.processor.escapevelocity.Reparser
-
class Reparser extends java.lang.ObjectThe second phase of parsing. SeeParser.parse()for a description of the phases and why we need them.
-
-
Field Summary
Fields Modifier and Type Field Description private static com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>>ELSE_ELSE_IF_END_SETprivate static com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>>END_SETprivate static com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>>EOF_SETprivate java.util.Map<java.lang.String,Macro>macrosMacros are removed from the input as they are found.private intnodeIndexThe index of the node we are currently looking at while parsing.private com.google.common.collect.ImmutableList<Node>nodesThe nodes that make up the input sequence.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private NodecurrentNode()private static booleanisWhitespaceLiteral(Node node)private voidlinkMacroCall(DirectiveNode.MacroCallNode macroCall)private voidlinkMacroCalls()private NodenextNode()private NodeparseForEach(TokenNode.ForEachTokenNode forEach)private NodeparseIfOrElseIf(TokenNode.IfOrElseIfTokenNode ifOrElseIf)private NodeparseMacroDefinition(TokenNode.MacroDefinitionTokenNode macroDefinition)private NodeparseNested(TokenNode.NestedTokenNode nested)private NodeparseTo(java.util.Set<java.lang.Class<? extends TokenNode>> stopSet, TokenNode forWhat)Parse subtrees until one of the token types instopSetis encountered.private NodeparseTokenNode()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) Templatereparse()private NodereparseNodes()private static booleanshouldDeleteSpaceBetweenThisAndSet(Node node)
-
-
-
Field Detail
-
END_SET
private static final com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> END_SET
-
EOF_SET
private static final com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> EOF_SET
-
ELSE_ELSE_IF_END_SET
private static final com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> ELSE_ELSE_IF_END_SET
-
nodes
private final com.google.common.collect.ImmutableList<Node> 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 nodeIndex
The index of the node we are currently looking at while parsing.
-
macros
private final java.util.Map<java.lang.String,Macro> 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.
-
-
Method Detail
-
reparse
Template reparse()
-
reparseNodes
private Node 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#setdirectives. If you have thing whitespace#set, then the whitespace is deleted if the thing is a comment (##...\n); a reference ($xor$x.fooetc); a macro definition; or another#set.
-
shouldDeleteSpaceBetweenThisAndSet
private static boolean shouldDeleteSpaceBetweenThisAndSet(Node node)
-
isWhitespaceLiteral
private static boolean isWhitespaceLiteral(Node node)
-
parseTo
private Node parseTo(java.util.Set<java.lang.Class<? extends TokenNode>> stopSet, TokenNode forWhat)
Parse subtrees until one of the token types instopSetis encountered. If this is the top level,stopSetwill includeTokenNode.EofNodeso parsing will stop when it reaches the end of the input. Otherwise, if anEofNodeis encountered it is an error because we have something like#ifwithout#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#ifwhose#endetc we are looking for.- Returns:
- a Node that is the concatenation of the parsed subtrees
-
currentNode
private Node currentNode()
-
nextNode
private Node nextNode()
-
parseTokenNode
private Node parseTokenNode()
-
parseForEach
private Node parseForEach(TokenNode.ForEachTokenNode forEach)
-
parseIfOrElseIf
private Node parseIfOrElseIf(TokenNode.IfOrElseIfTokenNode ifOrElseIf)
-
parseNested
private Node parseNested(TokenNode.NestedTokenNode nested)
-
parseMacroDefinition
private Node parseMacroDefinition(TokenNode.MacroDefinitionTokenNode macroDefinition)
-
linkMacroCalls
private void linkMacroCalls()
-
linkMacroCall
private void linkMacroCall(DirectiveNode.MacroCallNode macroCall)
-
-