class Reparser
extends java.lang.Object
Parser.parse()
for a description of the phases and why
we need them.Modifier and Type | Field and Description |
---|---|
private static com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> |
ELSE_ELSE_IF_END_SET |
private static com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> |
END_SET |
private static com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> |
EOF_SET |
private java.util.Map<java.lang.String,Macro> |
macros
Macros are removed from the input as they are found.
|
private int |
nodeIndex
The index of the node we are currently looking at while parsing.
|
private com.google.common.collect.ImmutableList<Node> |
nodes
The nodes that make up the input sequence.
|
Constructor and Description |
---|
Reparser(com.google.common.collect.ImmutableList<Node> nodes) |
Modifier and Type | Method and Description |
---|---|
private Node |
currentNode() |
private static boolean |
isWhitespaceLiteral(Node node) |
private void |
linkMacroCall(DirectiveNode.MacroCallNode macroCall) |
private void |
linkMacroCalls() |
private Node |
nextNode() |
private Node |
parseForEach(TokenNode.ForEachTokenNode forEach) |
private Node |
parseIfOrElseIf(TokenNode.IfOrElseIfTokenNode ifOrElseIf) |
private Node |
parseMacroDefinition(TokenNode.MacroDefinitionTokenNode macroDefinition) |
private Node |
parseTo(java.util.Set<java.lang.Class<? extends TokenNode>> stopSet,
TokenNode forWhat)
Parse subtrees until one of the token types in
stopSet is encountered. |
private Node |
parseTokenNode() |
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 static boolean |
shouldDeleteSpaceBetweenThisAndSet(Node node) |
private static final com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> END_SET
private static final com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> EOF_SET
private static final com.google.common.collect.ImmutableSet<java.lang.Class<? extends TokenNode>> ELSE_ELSE_IF_END_SET
private final com.google.common.collect.ImmutableList<Node> nodes
currentNode()
is the node being examined.private int nodeIndex
private final java.util.Map<java.lang.String,Macro> macros
Reparser(com.google.common.collect.ImmutableList<Node> nodes)
Template reparse()
private static com.google.common.collect.ImmutableList<Node> removeSpaceBeforeSet(com.google.common.collect.ImmutableList<Node> nodes)
#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
.private static boolean shouldDeleteSpaceBetweenThisAndSet(Node node)
private static boolean isWhitespaceLiteral(Node node)
private Node parseTo(java.util.Set<java.lang.Class<? extends TokenNode>> stopSet, TokenNode forWhat)
stopSet
is encountered.
If this is the top level, stopSet
will include TokenNode.EofNode
so parsing will stop
when it reaches the end of the input. Otherwise, if an EofNode
is encountered it is an
error because we have something like #if
without #end
.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.private Node currentNode()
private Node nextNode()
private Node parseTokenNode()
private Node parseForEach(TokenNode.ForEachTokenNode forEach)
private Node parseIfOrElseIf(TokenNode.IfOrElseIfTokenNode ifOrElseIf)
private Node parseMacroDefinition(TokenNode.MacroDefinitionTokenNode macroDefinition)
private void linkMacroCalls()
private void linkMacroCall(DirectiveNode.MacroCallNode macroCall)