Package org.apache.camel.language.simple
Class BaseSimpleParser
- java.lang.Object
-
- org.apache.camel.language.simple.BaseSimpleParser
-
- Direct Known Subclasses:
SimpleExpressionParser
,SimplePredicateParser
public abstract class BaseSimpleParser extends Object
Base class for Simple language parser. This parser is based on the principles of a recursive descent parser.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowEscape
protected org.apache.camel.CamelContext
camelContext
protected String
expression
protected int
index
protected List<SimpleNode>
nodes
protected int
previousIndex
protected SimpleToken
token
protected List<SimpleToken>
tokens
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseSimpleParser(org.apache.camel.CamelContext camelContext, String expression, boolean allowEscape)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
accept(TokenType accept)
Accept the given token.protected void
clear()
Clears the parser state, which means it can be used for parsing a new input.protected void
expect(TokenType expect)
Expect a given tokenprotected void
expectAndAcceptMore(TokenType expect)
Expect and accept a given number of tokens in sequence.protected void
nextToken()
Advances the parser position to the next knownSimpleToken
in the input.protected void
nextToken(TokenType... filter)
Advances the parser position to the next knownSimpleToken
in the input.protected void
prepareBlocks()
Prepares blocks, such as functions, single or double quoted texts.protected void
prepareUnaryExpressions()
Prepares unary expressions.
-
-
-
Field Detail
-
camelContext
protected org.apache.camel.CamelContext camelContext
-
expression
protected final String expression
-
tokens
protected final List<SimpleToken> tokens
-
nodes
protected final List<SimpleNode> nodes
-
token
protected SimpleToken token
-
previousIndex
protected int previousIndex
-
index
protected int index
-
allowEscape
protected boolean allowEscape
-
-
Constructor Detail
-
BaseSimpleParser
protected BaseSimpleParser(org.apache.camel.CamelContext camelContext, String expression, boolean allowEscape)
-
-
Method Detail
-
nextToken
protected void nextToken()
Advances the parser position to the next knownSimpleToken
in the input.
-
nextToken
protected void nextToken(TokenType... filter)
Advances the parser position to the next knownSimpleToken
in the input.- Parameters:
filter
- filter for accepted token types
-
clear
protected void clear()
Clears the parser state, which means it can be used for parsing a new input.
-
prepareBlocks
protected void prepareBlocks()
Prepares blocks, such as functions, single or double quoted texts. This process prepares theBlock
s in the AST. This is done by linking childnodes
which are within the start and end of the blocks, as child to the given block. This is done to have the AST graph updated and prepared properly. So when the AST node is later used to create thePredicate
s orExpression
s to be used by Camel then the AST graph has a linked and prepared graph of nodes which represent the input expression.
-
prepareUnaryExpressions
protected void prepareUnaryExpressions()
Prepares unary expressions. This process prepares the unary expressions in the AST. This is done by linking the unary operator with the left hand side node, to have the AST graph updated and prepared properly. So when the AST node is later used to create thePredicate
s orExpression
s to be used by Camel then the AST graph has a linked and prepared graph of nodes which represent the input expression.
-
accept
protected boolean accept(TokenType accept)
Accept the given token. This is to be used by the grammar to accept tokens and then continue parsing using the grammar, such as a function grammar.- Parameters:
accept
- the token- Returns:
- true if accepted, false otherwise.
-
expect
protected void expect(TokenType expect) throws SimpleParserException
Expect a given token- Parameters:
expect
- the token to expect- Throws:
SimpleParserException
- is thrown if the token is not as expected
-
expectAndAcceptMore
protected void expectAndAcceptMore(TokenType expect)
Expect and accept a given number of tokens in sequence. This is used to accept whitespace or string literals.- Parameters:
expect
- the token to accept
-
-