Search in sources :

Example 6 with SimpleToken

use of org.apache.camel.language.simple.types.SimpleToken in project camel by apache.

the class BaseSimpleParser method nextToken.

/**
     * Advances the parser position to the next known {@link SimpleToken}
     * in the input.
     */
protected void nextToken() {
    if (index < expression.length()) {
        SimpleToken next = SimpleTokenizer.nextToken(expression, index, allowEscape);
        // add token
        tokens.add(next);
        token = next;
        // position index after the token
        previousIndex = index;
        index += next.getLength();
    } else {
        // end of tokens
        token = new SimpleToken(new SimpleTokenType(TokenType.eol, null), index);
    }
}
Also used : SimpleTokenType(org.apache.camel.language.simple.types.SimpleTokenType) SimpleToken(org.apache.camel.language.simple.types.SimpleToken)

Example 7 with SimpleToken

use of org.apache.camel.language.simple.types.SimpleToken in project camel by apache.

the class BaseSimpleParser method nextToken.

/**
     * Advances the parser position to the next known {@link SimpleToken}
     * in the input.
     *
     * @param filter filter for accepted token types
     */
protected void nextToken(TokenType... filter) {
    if (index < expression.length()) {
        SimpleToken next = SimpleTokenizer.nextToken(expression, index, allowEscape, filter);
        // add token
        tokens.add(next);
        token = next;
        // position index after the token
        previousIndex = index;
        index += next.getLength();
    } else {
        // end of tokens
        token = new SimpleToken(new SimpleTokenType(TokenType.eol, null), index);
    }
}
Also used : SimpleTokenType(org.apache.camel.language.simple.types.SimpleTokenType) SimpleToken(org.apache.camel.language.simple.types.SimpleToken)

Example 8 with SimpleToken

use of org.apache.camel.language.simple.types.SimpleToken in project camel by apache.

the class SimplePredicateParser method removeIgnorableWhiteSpaceTokens.

/**
     * Removes any ignorable whitespace tokens.
     * <p/>
     * During the initial parsing (input -> tokens), then there may
     * be excessive whitespace tokens, which can safely be removed,
     * which makes the succeeding parsing easier.
     */
private void removeIgnorableWhiteSpaceTokens() {
    // white space can be removed if its not part of a quoted text or within function(s)
    boolean quote = false;
    int functionCount = 0;
    Iterator<SimpleToken> it = tokens.iterator();
    while (it.hasNext()) {
        SimpleToken token = it.next();
        if (token.getType().isSingleQuote()) {
            quote = !quote;
        } else if (!quote) {
            if (token.getType().isFunctionStart()) {
                functionCount++;
            } else if (token.getType().isFunctionEnd()) {
                functionCount--;
            } else if (token.getType().isWhitespace() && functionCount == 0) {
                it.remove();
            }
        }
    }
}
Also used : SimpleToken(org.apache.camel.language.simple.types.SimpleToken)

Aggregations

SimpleToken (org.apache.camel.language.simple.types.SimpleToken)8 SimpleTokenType (org.apache.camel.language.simple.types.SimpleTokenType)4 LiteralExpression (org.apache.camel.language.simple.ast.LiteralExpression)2 LiteralNode (org.apache.camel.language.simple.ast.LiteralNode)2 SimpleNode (org.apache.camel.language.simple.ast.SimpleNode)2 SimpleParserException (org.apache.camel.language.simple.types.SimpleParserException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Exchange (org.apache.camel.Exchange)1 Expression (org.apache.camel.Expression)1 DoubleQuoteStart (org.apache.camel.language.simple.ast.DoubleQuoteStart)1 SimpleFunctionExpression (org.apache.camel.language.simple.ast.SimpleFunctionExpression)1 SimpleFunctionStart (org.apache.camel.language.simple.ast.SimpleFunctionStart)1 SingleQuoteStart (org.apache.camel.language.simple.ast.SingleQuoteStart)1 SimpleIllegalSyntaxException (org.apache.camel.language.simple.types.SimpleIllegalSyntaxException)1