use of org.springframework.expression.spel.InternalParseException in project spring-framework by spring-projects.
the class Tokenizer method lexDoubleQuotedStringLiteral.
// DQ_STRING_LITERAL: '"'! (~'"')* '"'!;
private void lexDoubleQuotedStringLiteral() {
int start = this.pos;
boolean terminated = false;
while (!terminated) {
this.pos++;
char ch = this.toProcess[this.pos];
if (ch == '"') {
// may not be the end if the char after is also a "
if (this.toProcess[this.pos + 1] == '"') {
// skip over that too, and continue
this.pos++;
} else {
terminated = true;
}
}
if (ch == 0) {
throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING));
}
}
this.pos++;
this.tokens.add(new Token(TokenKind.LITERAL_STRING, subarray(start, this.pos), start, this.pos));
}
use of org.springframework.expression.spel.InternalParseException in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method doParseExpression.
@Override
protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
try {
this.expressionString = expressionString;
Tokenizer tokenizer = new Tokenizer(expressionString);
tokenizer.process();
this.tokenStream = tokenizer.getTokens();
this.tokenStreamLength = this.tokenStream.size();
this.tokenStreamPointer = 0;
this.constructedNodes.clear();
SpelNodeImpl ast = eatExpression();
if (moreTokens()) {
throw new SpelParseException(peekToken().startPos, SpelMessage.MORE_INPUT, toString(nextToken()));
}
Assert.isTrue(this.constructedNodes.isEmpty(), "At least one node expected");
return new SpelExpression(expressionString, ast, this.configuration);
} catch (InternalParseException ex) {
throw ex.getCause();
}
}
use of org.springframework.expression.spel.InternalParseException in project spring-framework by spring-projects.
the class InternalSpelExpressionParser method eatConstructorArgs.
private void eatConstructorArgs(List<SpelNodeImpl> accumulatedArguments) {
if (!peekToken(TokenKind.LPAREN)) {
throw new InternalParseException(new SpelParseException(this.expressionString, positionOf(peekToken()), SpelMessage.MISSING_CONSTRUCTOR_ARGS));
}
consumeArguments(accumulatedArguments);
eatToken(TokenKind.RPAREN);
}
use of org.springframework.expression.spel.InternalParseException in project spring-framework by spring-projects.
the class Tokenizer method lexQuotedStringLiteral.
// STRING_LITERAL: '\''! (APOS|~'\'')* '\''!;
private void lexQuotedStringLiteral() {
int start = this.pos;
boolean terminated = false;
while (!terminated) {
this.pos++;
char ch = this.toProcess[this.pos];
if (ch == '\'') {
// may not be the end if the char after is also a '
if (this.toProcess[this.pos + 1] == '\'') {
// skip over that too, and continue
this.pos++;
} else {
terminated = true;
}
}
if (ch == 0) {
throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.NON_TERMINATING_QUOTED_STRING));
}
}
this.pos++;
this.tokens.add(new Token(TokenKind.LITERAL_STRING, subarray(start, this.pos), start, this.pos));
}
use of org.springframework.expression.spel.InternalParseException in project spring-framework by spring-projects.
the class Tokenizer method lexNumericLiteral.
// REAL_LITERAL :
// ('.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? (REAL_TYPE_SUFFIX)?) |
// ((DECIMAL_DIGIT)+ '.' (DECIMAL_DIGIT)+ (EXPONENT_PART)? (REAL_TYPE_SUFFIX)?) |
// ((DECIMAL_DIGIT)+ (EXPONENT_PART) (REAL_TYPE_SUFFIX)?) |
// ((DECIMAL_DIGIT)+ (REAL_TYPE_SUFFIX));
// fragment INTEGER_TYPE_SUFFIX : ( 'L' | 'l' );
// fragment HEX_DIGIT :
// '0'|'1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'A'|'B'|'C'|'D'|'E'|'F'|'a'|'b'|'c'|'d'|'e'|'f';
//
// fragment EXPONENT_PART : 'e' (SIGN)* (DECIMAL_DIGIT)+ | 'E' (SIGN)*
// (DECIMAL_DIGIT)+ ;
// fragment SIGN : '+' | '-' ;
// fragment REAL_TYPE_SUFFIX : 'F' | 'f' | 'D' | 'd';
// INTEGER_LITERAL
// : (DECIMAL_DIGIT)+ (INTEGER_TYPE_SUFFIX)?;
private void lexNumericLiteral(boolean firstCharIsZero) {
boolean isReal = false;
int start = this.pos;
char ch = this.toProcess[this.pos + 1];
boolean isHex = ch == 'x' || ch == 'X';
// deal with hexadecimal
if (firstCharIsZero && isHex) {
this.pos = this.pos + 1;
do {
this.pos++;
} while (isHexadecimalDigit(this.toProcess[this.pos]));
if (isChar('L', 'l')) {
pushHexIntToken(subarray(start + 2, this.pos), true, start, this.pos);
this.pos++;
} else {
pushHexIntToken(subarray(start + 2, this.pos), false, start, this.pos);
}
return;
}
// Consume first part of number
do {
this.pos++;
} while (isDigit(this.toProcess[this.pos]));
// a '.' indicates this number is a real
ch = this.toProcess[this.pos];
if (ch == '.') {
isReal = true;
int dotpos = this.pos;
// carry on consuming digits
do {
this.pos++;
} while (isDigit(this.toProcess[this.pos]));
if (this.pos == dotpos + 1) {
// the number is something like '3.'. It is really an int but may be
// part of something like '3.toString()'. In this case process it as
// an int and leave the dot as a separate token.
this.pos = dotpos;
pushIntToken(subarray(start, this.pos), false, start, this.pos);
return;
}
}
int endOfNumber = this.pos;
// is it a long ?
if (isChar('L', 'l')) {
if (isReal) {
// 3.4L - not allowed
throw new InternalParseException(new SpelParseException(this.expressionString, start, SpelMessage.REAL_CANNOT_BE_LONG));
}
pushIntToken(subarray(start, endOfNumber), true, start, endOfNumber);
this.pos++;
} else if (isExponentChar(this.toProcess[this.pos])) {
// if it wasn't before, it is now
isReal = true;
this.pos++;
char possibleSign = this.toProcess[this.pos];
if (isSign(possibleSign)) {
this.pos++;
}
// exponent digits
do {
this.pos++;
} while (isDigit(this.toProcess[this.pos]));
boolean isFloat = false;
if (isFloatSuffix(this.toProcess[this.pos])) {
isFloat = true;
endOfNumber = ++this.pos;
} else if (isDoubleSuffix(this.toProcess[this.pos])) {
endOfNumber = ++this.pos;
}
pushRealToken(subarray(start, this.pos), isFloat, start, this.pos);
} else {
ch = this.toProcess[this.pos];
boolean isFloat = false;
if (isFloatSuffix(ch)) {
isReal = true;
isFloat = true;
endOfNumber = ++this.pos;
} else if (isDoubleSuffix(ch)) {
isReal = true;
endOfNumber = ++this.pos;
}
if (isReal) {
pushRealToken(subarray(start, endOfNumber), isFloat, start, endOfNumber);
} else {
pushIntToken(subarray(start, endOfNumber), false, start, endOfNumber);
}
}
}
Aggregations