public Tokenizer(final String expression) { typeDectector = new EdmSimpleTypeFacadeImpl(); this.expression = expression; expressionLength = expression.length(); tokens = new TokenList(); }
private boolean checkForLiteral(final int oldPosition, final char curCharacter, final String rem_expr) { final Matcher matcher = OTHER_LIT.matcher(rem_expr); boolean isLiteral = false; if (matcher.lookingAt()) { String token = matcher.group(); try { EdmLiteral edmLiteral = typeDectector.parseUriLiteral(token); curPosition = curPosition + token.length(); // It is a simple type. tokens.appendEdmTypedToken(oldPosition, TokenKind.SIMPLE_TYPE, token, edmLiteral); isLiteral = true; } catch (EdmLiteralException e) { // We treat it as normal untyped literal. // The '-' is checked here (and not in the switch statement) because it may be // part of a negative number. if (curCharacter == '-') { curPosition = curPosition + 1; tokens.appendToken(oldPosition, TokenKind.SYMBOL, curCharacter); isLiteral = true; } else { curPosition = curPosition + token.length(); tokens.appendToken(oldPosition, TokenKind.LITERAL, token); isLiteral = true; } } } return isLiteral; }
public Token expectToken(final String literal) throws TokenizerExpectError { Token actual = next(); if (actual == null) { throw TokenizerExpectError.createNO_TOKEN_AVAILABLE(literal); } if (!literal.equals(actual.getUriLiteral())) { throw TokenizerExpectError.createINVALID_TOKEN_AT(literal, actual); } return actual; }
if (!tokenList.hasTokens()) { return new FilterExpressionImpl(filterExpression); if (tokenList.tokenCount() > tokenList.currentToken) // this indicates that not all tokens have been read .elementAt(tokenList.currentToken), filterExpression);
tokenList.next(); // eat the operator Token token = tokenList.lookToken(); if (token != null) { if ((leftNode.getKind() == ExpressionKind.PROPERTY) && (tokenList.lookToken().getKind() == TokenKind.OPENPAREN)) { throw FilterParserExceptionImpl.createINVALID_METHOD_CALL(leftNode, tokenList.lookPrevToken(), curExpression);
Token openParenthesis = tokenList.expectToken(TokenKind.OPENPAREN, true); // throws FilterParserInternalError Token token = tokenList.lookToken(); if (token == null) { .lookPrevToken(), curExpression); token = tokenList.lookToken(); if (token == null) { .lookPrevToken(), curExpression); tokenList.expectToken(",", true); readComma = true; } else { tokenList.expectToken(TokenKind.CLOSEPAREN, true);
private boolean checkForBinary(final int oldPosition, final String rem_expr) { boolean isBinary = false; Matcher matcher1 = AND_SUB.matcher(rem_expr); if (matcher1.find()) { String token = matcher1.group(1); curPosition = curPosition + token.length(); tokens.appendToken(oldPosition, TokenKind.LITERAL, token); isBinary = true; } return isBinary; }
Token token = tokenList.lookToken(); if (token == null) { orderNode.setSortOrder(SortOrder.asc); } else if ((token.getKind() == TokenKind.LITERAL) && ("asc".equals(token.getUriLiteral()))) { orderNode.setSortOrder(SortOrder.asc); tokenList.next(); token = tokenList.lookToken(); } else if ((token.getKind() == TokenKind.LITERAL) && ("desc".equals(token.getUriLiteral()))) { orderNode.setSortOrder(SortOrder.desc); tokenList.next(); token = tokenList.lookToken(); } else if (token.getKind() == TokenKind.COMMA) { orderNode.setSortOrder(SortOrder.asc); } else if (token.getKind() == TokenKind.COMMA) { Token oldToken = token; tokenList.next(); token = tokenList.lookToken();
Token token; Token lookToken; lookToken = tokenList.lookToken(); if (lookToken == null) { return null; token = tokenList.expectToken(lookToken.getUriLiteral(), true); lookToken = tokenList.lookToken();
private void eatWhiteSpaces(final int oldPosition, char curCharacter) { int lv_token_len; String expression_sub; while ((curCharacter == ' ') && (curPosition < expressionLength)) { curPosition = curPosition + 1; if (curPosition < expressionLength) { curCharacter = expression.charAt(curPosition); } } lv_token_len = curPosition - oldPosition; if (flagIncludeWhitespace == true) { expression_sub = expression.substring(oldPosition, oldPosition + lv_token_len); tokens.appendEdmTypedToken(oldPosition, TokenKind.WHITESPACE, expression_sub, null); } }
/** * 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 { tokenList.expectToken(TokenKind.CLOSEPAREN); // TokenizerMessage } catch (TokenizerExpectError e) { // Internal parsing error, even if there are no more token (then there should be a different exception). // Tested with TestParserExceptions.TestPMreadParenthesis throw FilterParserExceptionImpl.createMISSING_CLOSING_PHARENTHESIS(openParenthesis.getPosition(), curExpression, e); } return parenthesisExpression; }
protected ActualBinaryOperator readBinaryOperator() { InfoBinaryOperator operator = null; Token token = tokenList.lookToken(); if (token == null) { return null; } if ((token.getKind() == TokenKind.SYMBOL) && (token.getUriLiteral().equals("/"))) { operator = availableBinaryOperators.get(token.getUriLiteral()); } else if (token.getKind() == TokenKind.LITERAL) { operator = availableBinaryOperators.get(token.getUriLiteral()); } if (operator == null) { return null; } return new ActualBinaryOperator(operator, token); }
if (!tokenList.hasTokens()) { return new FilterExpressionImpl(filterExpression); if (tokenList.tokenCount() > tokenList.currentToken) // this indicates that not all tokens have been read .elementAt(tokenList.currentToken), filterExpression);
tokenList.next(); // eat the operator Token token = tokenList.lookToken(); if (token != null) { if ((leftNode.getKind() == ExpressionKind.PROPERTY) && (tokenList.lookToken().getKind() == TokenKind.OPENPAREN)) { throw FilterParserExceptionImpl.createINVALID_METHOD_CALL(leftNode, tokenList.lookPrevToken(), curExpression);
Token openParenthesis = tokenList.expectToken(TokenKind.OPENPAREN, true); // throws FilterParserInternalError Token token = tokenList.lookToken(); if (token == null) { .lookPrevToken(), curExpression); token = tokenList.lookToken(); if (token == null) { .lookPrevToken(), curExpression); tokenList.expectToken(",", true); readComma = true; } else { tokenList.expectToken(TokenKind.CLOSEPAREN, true);
private boolean checkForMethod(final int oldPosition, final String rem_expr) { boolean isMethod = false; Matcher matcher = FUNK.matcher(rem_expr); if (matcher.find()) { String token = matcher.group(1); curPosition = curPosition + token.length(); tokens.appendToken(oldPosition, TokenKind.LITERAL, token); isMethod = true; } return isMethod; }
Token token = tokenList.lookToken(); if (token == null) { orderNode.setSortOrder(SortOrder.asc); } else if ((token.getKind() == TokenKind.LITERAL) && (token.getUriLiteral().equals("asc"))) { orderNode.setSortOrder(SortOrder.asc); tokenList.next(); token = tokenList.lookToken(); } else if ((token.getKind() == TokenKind.LITERAL) && (token.getUriLiteral().equals("desc"))) { orderNode.setSortOrder(SortOrder.desc); tokenList.next(); token = tokenList.lookToken(); } else if (token.getKind() == TokenKind.COMMA) { orderNode.setSortOrder(SortOrder.asc); } else if (token.getKind() == TokenKind.COMMA) { Token oldToken = token; tokenList.next(); token = tokenList.lookToken();
Token token; Token lookToken; lookToken = tokenList.lookToken(); if (lookToken == null) { return null; token = tokenList.expectToken(lookToken.getUriLiteral(), true); lookToken = tokenList.lookToken();
private void eatWhiteSpaces(final int oldPosition, char curCharacter) { int lv_token_len; String expression_sub; while ((curCharacter == ' ') && (curPosition < expressionLength)) { curPosition = curPosition + 1; if (curPosition < expressionLength) { curCharacter = expression.charAt(curPosition); } } lv_token_len = curPosition - oldPosition; if (flagIncludeWhitespace == true) { expression_sub = expression.substring(oldPosition, oldPosition + lv_token_len); tokens.appendEdmTypedToken(oldPosition, TokenKind.WHITESPACE, expression_sub, null); } }
/** * 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 { tokenList.expectToken(TokenKind.CLOSEPAREN); // TokenizerMessage } catch (TokenizerExpectError e) { // Internal parsing error, even if there are no more token (then there should be a different exception). // Tested with TestParserExceptions.TestPMreadParenthesis throw FilterParserExceptionImpl.createMISSING_CLOSING_PARENTHESIS(openParenthesis.getPosition(), curExpression, e); } return parenthesisExpression; }