|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.caja.plugin.stages.Splitter
final class Splitter
Splits a sequence of string literals containing ${...}
and
$name
into expressions, by looking for that pattern in the
string literals and parsing the content of substitutions as javascript.
The output contains alternating literal and substitutions, and is careful to preserve file positions into the original source.
This code takes a list of string literals and keeps track of positions as (stringLiteralIndex, characterIndexInUndecodedLiteral) pairs.
Nested Class Summary | |
---|---|
private static class |
Splitter.State
|
Field Summary | |
---|---|
(package private) int |
i
Indices into the literal list, and the current literal. |
(package private) int |
j
Indices into the literal list, and the current literal. |
(package private) java.util.List<StringLiteral> |
literals
The string literals being processed. |
(package private) MessageQueue |
mq
A queue to which parse errors are written. |
(package private) java.util.List<Expression> |
parts
Output array. |
(package private) int |
startOffset
|
(package private) int |
startString
Cursor that is moved from left to right as we process the string literals. |
(package private) Splitter.State |
state
Used to keep track of whether we're inside a substitution or not. |
Constructor Summary | |
---|---|
Splitter(java.util.List<StringLiteral> literals,
MessageQueue mq)
|
Method Summary | |
---|---|
(package private) static FilePosition |
clippedPos(FilePosition p,
int start,
int end)
Interpolate the position of a substring of a StringLiteral. |
private void |
finishBlock(int delta)
Parse a substitution expression and push it onto the output list. |
private void |
finishLiteral(int delta)
Push a literal part onto the output list. |
private void |
finishReference(int delta)
Push a reference onto the output list. |
private void |
mark(int delta)
Track the last position processed. |
(package private) void |
split()
Walk the literal list and generate the output parts list. |
private java.util.List<Pair<java.lang.String,FilePosition>> |
upTo(int delta)
Compute the pieces of the string literals that span from the mark to the given delta. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
int startString
int startOffset
java.util.List<StringLiteral> literals
eval(Template("Foo $bar" + " baz"))
then the two string literals
will be "Foo $bar"
and " baz"
.
java.util.List<Expression> parts
eval(Template("Foo $bar Baz"))
this is
[StringLiteral('Foo '), Reference("bar"), StringLiteral(' Baz')]
.
Note that not all StringLiteral
s are literals.
In eval(Template("Foo ${'bar'} Baz")), the sole substitution is a
StringLiteral.
Splitter.State state
int i
int j
MessageQueue mq
Constructor Detail |
---|
Splitter(java.util.List<StringLiteral> literals, MessageQueue mq)
Method Detail |
---|
void split()
private void mark(int delta)
delta
- number of characters from the current position in the
string literals.private void finishLiteral(int delta)
delta
- of the end of the literal relative to the cursor.private void finishReference(int delta)
delta
- of the end of the reference to the cursor.private void finishBlock(int delta)
delta
- of the end of the block to the cursor.private java.util.List<Pair<java.lang.String,FilePosition>> upTo(int delta)
static FilePosition clippedPos(FilePosition p, int start, int end)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |