Methods Summary |
---|
private int | getIndex()
return index;
|
private boolean | hasNext()
skipSpaces();
return hasNextChar();
|
private boolean | hasNextChar()
return index < expression.length();
|
private boolean | isELReserved(java.lang.String id)Test if an id is a reserved word in EL
int i = 0;
int j = reservedWords.length;
while (i < j) {
int k = (i+j)/2;
int result = reservedWords[k].compareTo(id);
if (result == 0) {
return true;
}
if (result < 0) {
i = k+1;
} else {
j = k;
}
}
return false;
|
private char | nextChar()
if (index >= expression.length()) {
return (char)-1;
}
return expression.charAt(index++);
|
private org.apache.jasper.compiler.ELParser$Token | nextToken()
skipSpaces();
if (hasNextChar()) {
char ch = nextChar();
if (Character.isJavaIdentifierStart(ch)) {
StringBuffer buf = new StringBuffer();
buf.append(ch);
while ((ch = peekChar()) != -1 &&
Character.isJavaIdentifierPart(ch)) {
buf.append(ch);
nextChar();
}
return new Id(buf.toString());
}
if (ch == '\'" || ch == '"") {
return parseQuotedChars(ch);
} else {
// For now...
return new Char(ch);
}
}
return null;
|
public static ELNode.Nodes | parse(java.lang.String expression)Parse an EL expression
ELParser parser = new ELParser(expression);
while (parser.hasNextChar()) {
String text = parser.skipUntilEL();
if (text.length() > 0) {
parser.expr.add(new ELNode.Text(text));
}
ELNode.Nodes elexpr = parser.parseEL();
if (! elexpr.isEmpty()) {
parser.expr.add(new ELNode.Root(elexpr, parser.isDollarExpr));
}
}
return parser.expr;
|
private ELNode.Nodes | parseEL()Parse an EL expression string '${...} or #{...}'
StringBuffer buf = new StringBuffer();
ELexpr = new ELNode.Nodes();
while (hasNext()) {
curToken = nextToken();
if (curToken instanceof Char) {
if (curToken.toChar() == '}") {
break;
}
buf.append(curToken.toChar());
} else {
// Output whatever is in buffer
if (buf.length() > 0) {
ELexpr.add(new ELNode.ELText(buf.toString()));
}
if (!parseFunction()) {
ELexpr.add(new ELNode.ELText(curToken.toString()));
}
}
}
if (buf.length() > 0) {
ELexpr.add(new ELNode.ELText(buf.toString()));
}
return ELexpr;
|
private boolean | parseFunction()Parse for a function
FunctionInvokation ::= (identifier ':')? identifier '('
(Expression (,Expression)*)? ')'
Note: currently we don't parse arguments
if (! (curToken instanceof Id) || isELReserved(curToken.toString())) {
return false;
}
String s1 = null; // Function prefix
String s2 = curToken.toString(); // Function name
int mark = getIndex();
if (hasNext()) {
Token t = nextToken();
if (t.toChar() == ':") {
if (hasNext()) {
Token t2 = nextToken();
if (t2 instanceof Id) {
s1 = s2;
s2 = t2.toString();
if (hasNext()) {
t = nextToken();
}
}
}
}
if (t.toChar() == '(") {
ELexpr.add(new ELNode.Function(s1, s2));
return true;
}
}
setIndex(mark);
return false;
|
private org.apache.jasper.compiler.ELParser$Token | parseQuotedChars(char quote)
StringBuffer buf = new StringBuffer();
buf.append(quote);
while (hasNextChar()) {
char ch = nextChar();
if (ch == '\\") {
ch = nextChar();
if (ch == '\\" || ch == quote) {
buf.append(ch);
}
// else error!
} else if (ch == quote) {
buf.append(ch);
break;
} else {
buf.append(ch);
}
}
return new QuotedString(buf.toString());
|
private char | peekChar()
if (index >= expression.length()) {
return (char)-1;
}
return expression.charAt(index);
|
private void | setIndex(int i)
index = i;
|
private void | skipSpaces()
while (hasNextChar()) {
if (expression.charAt(index) > ' ")
break;
index++;
}
|
private java.lang.String | skipUntilEL()Skip until an EL expression ('${' or '#{') is reached, allowing escape
sequences '\\', '\$', and '\#'.
char prev = 0;
StringBuffer buf = new StringBuffer();
while (hasNextChar()) {
char ch = nextChar();
if (prev == '\\") {
prev = 0;
if (ch == '\\") {
buf.append('\\");
if (!escapeBS)
prev = '\\";
} else if (ch == '$" || ch == '#") {
buf.append(ch);
}
// else error!
} else if (prev == '$" || prev == '#") {
if (ch == '{") {
this.isDollarExpr = (prev == '$");
prev = 0;
break;
}
buf.append(prev);
if (ch == '\\" || ch == '$" || ch == '#") {
prev = ch;
} else {
buf.append(ch);
}
} else if (ch == '\\" || ch == '$" || ch == '#") {
prev = ch;
} else {
buf.append(ch);
}
}
if (prev != 0) {
buf.append(prev);
}
return buf.toString();
|