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);
}
}
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);
}
}
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();
}
}
}
}
Aggregations