/* Generated By:JavaCC: Do not edit this line. FMParserTokenManager.java */
package freemarker.core;
import freemarker.template.*;
import freemarker.template.utility.StringUtil;
import freemarker.template.utility.DeepUnwrap;
import java.io.*;
import java.util.*;
class FMParserTokenManager implements FMParserConstants
{
/**
The noparseTag is set when we enter
a block of text that the parser more or less ignores.
These are <noparse> and <comment>. This variable
tells us what the closing tag should be, and when
we hit that, we resume parsing. Note that with this
scheme, <comment> and <noparse> tags cannot nest
recursively, but it is not clear how important that is.
*/
String noparseTag;
/**
Keeps track of how deeply nested
we have the hash literals.
This is necessary since we need to be
able to distinguish the } used to close
a hash literal and the one used to
close a ${
*/
private int hashLiteralNesting;
private int parenthesisNesting;
private int bracketNesting;
private boolean inFTLHeader;
boolean strictEscapeSyntax,
onlyTextOutput,
altDirectiveSyntax,
autodetectTagSyntax,
directiveSyntaxEstablished,
inInvocation;
String templateName;
// This method checks if we are in a strict mode where all
// FreeMarker directives must start with <#
private void strictSyntaxCheck(Token tok, int newLexState) {
if (onlyTextOutput) {
tok.kind = PRINTABLE_CHARS;
return;
}
char firstChar = tok.image.charAt(0);
if (autodetectTagSyntax && !directiveSyntaxEstablished) {
altDirectiveSyntax = (firstChar == '[');
}
if ((firstChar == '[' && !altDirectiveSyntax) || (firstChar == '<' && altDirectiveSyntax)) {
tok.kind = PRINTABLE_CHARS;
return;
}
if (!strictEscapeSyntax) {
SwitchTo(newLexState);
return;
}
if (!altDirectiveSyntax) {
if (!tok.image.startsWith("<#") && !tok.image.startsWith("</#")) {
tok.kind = PRINTABLE_CHARS;
return;
}
}
directiveSyntaxEstablished = true;
SwitchTo(newLexState);
}
private void unifiedCall(Token tok) {
char firstChar = tok.image.charAt(0);
if (autodetectTagSyntax && !directiveSyntaxEstablished) {
altDirectiveSyntax = (firstChar == '[');
}
if (altDirectiveSyntax && firstChar == '<') {
tok.kind = PRINTABLE_CHARS;
return;
}
if (!altDirectiveSyntax && firstChar == '[') {
tok.kind = PRINTABLE_CHARS;
return;
}
directiveSyntaxEstablished = true;
SwitchTo(NO_SPACE_EXPRESSION);
}
private void unifiedCallEnd(Token tok) {
char firstChar = tok.image.charAt(0);
if (altDirectiveSyntax && firstChar == '<') {
tok.kind = PRINTABLE_CHARS;
return;
}
if (!altDirectiveSyntax && firstChar == '[') {
tok.kind = PRINTABLE_CHARS;
return;
}
}
private void closeBracket(Token tok) {
if (bracketNesting >0) {
--bracketNesting;
} else {
tok.kind=DIRECTIVE_END;
if (inFTLHeader) {
eatNewline();
inFTLHeader = false;
}
SwitchTo(DEFAULT);
}
}
private void eatNewline() {
int charsRead = 0;
try {
while (true) {
char c = input_stream.readChar();
++charsRead;
if (!Character.isWhitespace(c)) {
input_stream.backup(charsRead);
return;
} else if (c=='\r') {
char next = input_stream.readChar();
++charsRead;
if (next != '\n') {
input_stream.backup(1);
}
return;
} else if (c=='\n') {
return;
}
}
} catch (IOException ioe) {
input_stream.backup(charsRead);
}
}
private void ftlHeader(Token matchedToken) {
if (!directiveSyntaxEstablished) {
altDirectiveSyntax = matchedToken.image.charAt(0) == '[';
directiveSyntaxEstablished = true;
autodetectTagSyntax = false;
}
String img = matchedToken.image;
char firstChar = img.charAt(0);
char lastChar = img.charAt(img.length() -1);
if ((firstChar == '[' && !altDirectiveSyntax) || (firstChar == '<' && altDirectiveSyntax)) {
matchedToken.kind = PRINTABLE_CHARS;
}
if (matchedToken.kind != PRINTABLE_CHARS) {
if (lastChar != '>' && lastChar != ']') {
SwitchTo(FM_EXPRESSION);
inFTLHeader = true;
} else {
eatNewline();
}
}
}
public java.io.PrintStream debugStream = System.out;
public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
private final int jjMoveStringLiteralDfa0_7()
{
return jjMoveNfa_7(0, 0);
}
private final void jjCheckNAdd(int state)
{
if (jjrounds[state] != jjround)
{
jjstateSet[jjnewStateCnt++] = state;
jjrounds[state] = jjround;
}
}
private final void jjAddStates(int start, int end)
{
do {
jjstateSet[jjnewStateCnt++] = jjnextStates[start];
} while (start++ != end);
}
private final void jjCheckNAddTwoStates(int state1, int state2)
{
jjCheckNAdd(state1);
jjCheckNAdd(state2);
}
private final void jjCheckNAddStates(int start, int end)
{
do {
jjCheckNAdd(jjnextStates[start]);
} while (start++ != end);
}
private final void jjCheckNAddStates(int start)
{
jjCheckNAdd(jjnextStates[start]);
jjCheckNAdd(jjnextStates[start + 1]);
}
static final long[] jjbitVec0 = {
0xfffffffffffffffeL, 0xffffffffffffffffL, 0xffffffffffffffffL, 0xffffffffffffffffL
};
static final long[] jjbitVec2 = {
0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
};
private final int jjMoveNfa_7(int startState, int curPos)
{
int[] nextStates;
int startsAt = 0;
jjnewStateCnt = 13;
int i = 1;
jjstateSet[0] = startState;
int j, kind = 0x7fffffff;
for (;;)
{
if (++jjround == 0x7fffffff)
ReInitRounds();
if (curChar < 64)
{
long l = 1L << curChar;
MatchLoop: do
{
switch(jjstateSet[--i])
{
case 0:
if ((0xefffdfffffffffffL & l) != 0L)
{
if (kind > 131)
kind = 131;
jjCheckNAdd(6);
}
else if ((0x1000200000000000L & l) != 0L)
{
if (kind > 132)
kind = 132;
}
if (curChar == 45)
jjAddStates(0, 1);
else if (curChar == 60)
jjstateSet[jjnewStateCnt++] = 1;
break;
case 1:
if (curChar == 47)
jjCheckNAddTwoStates(2, 3);
break;
case 2:
if (curChar == 35)
jjCheckNAdd(3);
break;
case 4:
if ((0x100002600L & l) != 0L)
jjAddStates(2, 3);
break;
case 5:
if (curChar == 62 && kind > 130)
kind = 130;
break;
case 6:
if ((0xefffdfffffffffffL & l) == 0L)
break;
if (kind > 131)
kind = 131;
jjCheckNAdd(6);
break;
case 7:
if ((0x1000200000000000L & l) != 0L && kind > 132)
kind = 132;
break;
case 8:
if (curChar == 45)
jjAddStates(0, 1);
break;
case 9:
if (curChar == 62 && kind > 129)
kind = 129;