Top Description Inners Fields Constructors Methods
com.google.escapevelocity

pack-priv Class Parser

extends Object
Class Inheritance
Imports
com.google.common.base.CharMatcher, .Joiner, .Verify, com.google.common.collect.ContiguousSet, .ForwardingSortedSet, .ImmutableList, .ImmutableListMultimap, .ImmutableMap, .ImmutableSet, .ImmutableSortedSet, .Iterables, com.google.common.primitives.Chars, .Ints, com.google.escapevelocity.DirectiveNode.BreakNode, .DirectiveNode.DefineNode, .DirectiveNode.ForEachNode, .DirectiveNode.IfNode, .DirectiveNode.SetNode, .ExpressionNode.BinaryExpressionNode, .ExpressionNode.NotExpressionNode, .ReferenceNode.IndexReferenceNode, .ReferenceNode.MemberReferenceNode, .ReferenceNode.MethodReferenceNode, .ReferenceNode.PlainReferenceNode, .StopNode.ElseIfNode, .StopNode.ElseNode, .StopNode.EndNode, .StopNode.EofNode, java.io.IOException, .LineNumberReader, .Reader, .StringReader, java.util.ArrayList, .Collections, .List, .Map, .TreeMap, java.util.function.Supplier

A parser that reads input from the given Reader and parses it to produce a Template.
Author
[email protected] (Éamonn McManus)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Parser.CommentNode

A node in the parse tree representing a comment.

private class
Parser.EvaluateNode

An #evaluate directive.

private static class
pack-priv static enum
private class
Parser.OperatorParser

An operator-precedence parser for the binary operations we understand.

private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final CharMatcher
private static final CharMatcher
private int
c

The invariant of this parser is that c is always the next character of interest.

private static final ImmutableListMultimap<Integer, Parser.Operator>
CODE_POINT_TO_OPERATORS

Maps a code point to the operators that begin with that code point.

private static final ImmutableSet<Class<? extends StopNode>>
private static final ImmutableSet<Class<? extends StopNode>>
private static final int
private static final ImmutableSet<Class<? extends StopNode>>
private static final CharMatcher
private final Map<String, Macro>
macros

Macros that have been defined during this parse.

private final Map<String, Template>
parseCache

Map from resource name to already-parsed template.

private int
pushback

A single character of pushback.

private final LineNumberReader
private final String
private final Template.ResourceOpener
private static final ImmutableSet<String>
UNSUPPORTED_VELOCITY_DIRECTIVES

#directives that Velocity supports but we currently don't, and that don't have to be followed by (.

Constructor Summary

AccessConstructor and Description
pack-priv
Parser(Reader reader, String resourceName, Template.ResourceOpener resourceOpener, Map<String, Template> parseCache)

Method Summary

Modifier and TypeMethod and Description
private void
expect(char expected)

Skips any space in the reader, and then throws an exception if the first non-space character found is not the expected one.

private static boolean
isAsciiDigit(int c)

private static boolean
private static boolean
isIdChar(int c)

private int
private void
next()

Gets the next character from the reader and assigns it to c.

private void
nextNonSpace()

Gets the next character from the reader, and if it is a space character, keeps reading until a non-space character is found.

pack-priv Template
parse()

Parse the input completely to produce a Template.

private Node
parseBlockComment()

Parses a block comment, which is #* followed by everything up to and including the next *#.

private Node
parseBreak()

Parses a #break token from the reader.

private Node
parseDefine()

Parses a #define directive from the reader.

private Node
parseDirective()

Parses a single directive token from the reader.

private Node
private Node
parseEvaluate()

Parses an #evaluate token from the reader.

private ParseException
parseException(String message)

Returns an exception to be thrown describing a parse error with the given message, and including information about where it occurred.

private ExpressionNode
parseExpression()

Parses an expression, which can occur within a directive like #if or #set.

private Node
parseForEach()

Parses a #foreach token from the reader.

private Node
private String
parseId(String what)

Parse an identifier as specified by the VTL .

private Node
parseIfOrElseIf(String directive)

Parses an #if construct, or an #elseif within one.

private ExpressionNode
private Node
parseLineComment()

Parses a line comment, which is ## followed by any number of characters up to and including the next newline.

private ExpressionNode
parseListLiteral()

Parses a list or range literal.

private Node
parseMacroCall(String prefix, String directive)

Parses an identifier after # that is not one of the standard directives.

private Node
private Node
parseMacroDefinition()

Parses a #macro token from the reader.

private Node
parseNode()

Parses a single node from the reader.

private Node
parseNonDirective()

Parses a single non-directive node from the reader.

private ExpressionNode
parseNotOrBooleanOrNullLiteral(boolean nullAllowed)

Parses a boolean literal, either true or false.

private Node
parseParse()

Parses a #parse token from the reader.

private Node
parsePlainText(int firstChar)

Parses plain text, which is text that contains neither $ nor #.

private Node
parsePlainText(String initialChars)

Parses plain text, which is text that contains neither $ nor #.

private Node
private ExpressionNode
parsePrimary()

Parses an expression containing only literals or references.

private ExpressionNode
parsePrimary(boolean nullAllowed)

private ExpressionNode
private Node
parseReference(boolean
true if this is $!.
silent
)

Parses a reference, which is everything that can start with a $.

private ReferenceNode
parseReferenceIndex(ReferenceNode
the reference node representing what appears to the left of the dot, like the $x in $x[$i].
lhs
,
boolean silent)

Parses an index suffix to a reference, like $x[$i].

private ReferenceNode
parseReferenceMember(ReferenceNode
the reference node representing what appears to the left of the dot, like the $x in $x.foo or $x.foo().
lhs
,
boolean silent)

Parses a reference member, which is either a property reference like $x.y or a method call like $x.y($z).

private ReferenceNode
parseReferenceMethodParams(ReferenceNode
the reference node representing what appears to the left of the dot, like the $x in $x.foo().
lhs
,
String id, boolean silent)

Parses the parameters to a method reference, like $foo.bar($a, $b).

private ReferenceNode
parseReferenceNoBrace(boolean silent)

Parses a reference, in the simple form without braces.

private ReferenceNode
parseReferenceSuffix(ReferenceNode
the reference node representing the first part of the reference $x in $x.foo or $x.foo(), or later $x.y in $x.y.z.
lhs
,
boolean silent)

Parses the modifiers that can appear at the tail of a reference.

private ExpressionNode
private ReferenceNode
parseRequiredReference()

Same as parseReference, except it really must be a reference.

private Node
parseSet()

Parses a #set token from the reader.

private ExpressionNode
parseStringLiteral(char quote, boolean expand)

Parses a string literal, which may contain template text to be expanded.

private Parser.ParseResult

Returns:

the nodes that were parsed, plus the StopNode that caused parsing to stop.
parseToStop
(ImmutableSet<Class<? extends StopNode>> stopClasses, Supplier<String> contextDescription)

Parse until reaching a StopNode.

private ExpressionNode
parseUnaryExpression()

Parses an expression not containing any operators (except inside parentheses).

private void
pushback(int c1)

Saves the current character c to be read again, and sets c to the given c1.

private Parser.ParseResult
skipNewlineAndParseToStop(ImmutableSet<Class<? extends StopNode>> stopClasses, Supplier<String> contextDescription)

Skip the current character if it is a newline, then parse until reaching a StopNode.

private void
skipSpace()

If c is a space character, keeps reading until c is a non-space character or there are no more characters.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait