use of com.pogeyan.cmis.api.uri.expression.CommonExpression in project copper-cms by PogeyanOSS.
the class FilterParserImpl method readParenthesis.
/**
* Reads the content between parenthesis. Its is expected that the current
* token is of kind {@link TokenKind#OPENPAREN} because it MUST be check in
* the calling method ( when read the method name and the '(' is read).
*
* @return An expression which reflects the content within the parenthesis
* @throws ExpressionParserException
* While reading the elements in the parenthesis an error
* occurred
* @throws TokenizerMessage
* The next token did not match the expected token
*/
protected CommonExpression readParenthesis() throws ExpressionParserException, ExpressionParserInternalError {
// The existing of a '(' is verified BEFORE this method is called --> so
// it's a internal error
Token openParenthesis = tokenList.expectToken(TokenKind.OPENPAREN, true);
CommonExpression firstExpression = readElement(null);
CommonExpression parenthesisExpression = readElements(firstExpression, 0);
// check for ')'
try {
// TokenizerMessage
tokenList.expectToken(TokenKind.CLOSEPAREN);
} catch (TokenizerExpectError e) {
// Tested with TestParserExceptions.TestPMreadParenthesis
throw FilterParserExceptionImpl.createMISSING_CLOSING_PARENTHESIS(openParenthesis.getPosition(), curExpression, e);
}
return parenthesisExpression;
}
use of com.pogeyan.cmis.api.uri.expression.CommonExpression in project copper-cms by PogeyanOSS.
the class FilterParserImpl method readUnaryoperator.
protected CommonExpression readUnaryoperator(final Token lookToken, final InfoUnaryOperator unaryOperator) throws ExpressionParserException, ExpressionParserInternalError {
tokenList.expectToken(lookToken.getUriLiteral(), true);
CommonExpression operand = readElement(null);
UnaryExpression unaryExpression = new UnaryExpressionImpl(unaryOperator, operand);
return unaryExpression;
}
use of com.pogeyan.cmis.api.uri.expression.CommonExpression in project copper-cms by PogeyanOSS.
the class MethodExpressionImpl method accept.
@Override
public Object accept(final ExpressionVisitor visitor) throws ExceptionVisitExpression {
ArrayList<Object> retParameters = new ArrayList<Object>();
for (CommonExpression parameter : actualParameters) {
Object retParameter = parameter.accept(visitor);
retParameters.add(retParameter);
}
Object ret = visitor.visitMethod(this, getMethod(), retParameters);
return ret;
}
use of com.pogeyan.cmis.api.uri.expression.CommonExpression in project copper-cms by PogeyanOSS.
the class FilterParserImpl method readElements.
protected CommonExpression readElements(final CommonExpression leftExpression, final int priority) throws ExpressionParserException, ExpressionParserInternalError {
CommonExpression leftNode = leftExpression;
CommonExpression rightNode;
BinaryExpression binaryNode;
ActualBinaryOperator operator = readBinaryOperator();
ActualBinaryOperator nextOperator;
while ((operator != null) && (operator.getOP().getPriority() >= priority)) {
// eat the operator
tokenList.next();
// throws
rightNode = readElement(leftNode, operator);
// FilterParserInternalError
if (rightNode == null) {
// Tested with TestParserExceptions.testAdditionalStuff CASE 10
throw FilterParserExceptionImpl.createEXPRESSION_EXPECTED_AFTER_POS(operator.getToken().getPosition() + operator.getToken().getUriLiteral().length(), curExpression);
}
nextOperator = readBinaryOperator();
// a higher priority than "or"
while ((nextOperator != null) && (nextOperator.getOP().getPriority() > operator.getOP().getPriority())) {
// recurse until the a binary operator with a lower priority is
// detected
rightNode = readElements(rightNode, nextOperator.getOP().getPriority());
nextOperator = readBinaryOperator();
}
// some special handling in the filterTree
if (operator.getOP().getOperator() == BinaryOperator.PROPERTY_ACCESS) {
binaryNode = new MemberExpressionImpl(leftNode, rightNode);
} else {
binaryNode = new BinaryExpressionImpl(operator.getOP(), leftNode, rightNode, operator.getToken());
}
// try {
// validateBinaryOperatorTypes(binaryNode);
// } catch (ExpressionParserException expressionException) {
// // Extend the error information
// // Tested for original throw point
// expressionException.setFilterTree(binaryNode);
// throw expressionException;
// }
leftNode = binaryNode;
operator = readBinaryOperator();
}
// Add special handling for expressions like
// $filter=notsupportedfunction('a')
// If this special handling is not in place the error text would be
// -->Invalid token "(" detected after parsing at position 21 in
// "notsupportedfunction('a')".
// with this special handling we ensure that the error text would be
Token token = tokenList.lookToken();
if (token != null) {
if ((leftNode.getKind() == ExpressionKind.PROPERTY) && (tokenList.lookToken().getKind() == TokenKind.OPENPAREN)) {
// Tested with TestParserExceptions.testAdditionalStuff CASE 2
throw FilterParserExceptionImpl.createINVALID_METHOD_CALL(leftNode, tokenList.lookPrevToken(), curExpression);
}
}
return leftNode;
}
use of com.pogeyan.cmis.api.uri.expression.CommonExpression in project copper-cms by PogeyanOSS.
the class FilterParserImpl method parseFilterString.
public FilterExpression parseFilterString(final String filterExpression, final boolean allowOnlyBinary) throws ExpressionParserException {
CommonExpression node = null;
curExpression = filterExpression;
try {
// Throws TokenizerException and FilterParserException.
// FilterParserException is caught somewhere above
tokenList = new Tokenizer(filterExpression).tokenize();
if (!tokenList.hasTokens()) {
return new FilterExpressionImpl(filterExpression);
}
} catch (TokenizerException tokenizerException) {
// Tested with TestParserExceptions.TestPMparseFilterString
throw FilterParserExceptionImpl.createERROR_IN_TOKENIZER(tokenizerException, curExpression);
}
try {
CommonExpression nodeLeft = readElement(null);
node = readElements(nodeLeft, 0);
} catch (ExpressionParserException filterParserException) {
// Add empty filterTree to Exception
// Tested for original throw point
filterParserException.setFilterTree(new FilterExpressionImpl(filterExpression));
throw filterParserException;
} catch (ExpressionParserInternalError ex) {
// throw FilterParserExceptionImpl.COMMON_ERROR(ex, curExpression);
ex.printStackTrace();
}
// Post check
if (// this indicates
tokenList.tokenCount() > tokenList.currentToken) // that not all
// tokens have
// been read
{
// Tested with TestParserExceptions.TestPMparseFilterString
throw FilterParserExceptionImpl.createINVALID_TRAILING_TOKEN_DETECTED_AFTER_PARSING(tokenList.elementAt(tokenList.currentToken), filterExpression);
}
return new FilterExpressionImpl(filterExpression, node);
}
Aggregations