Package org.mvel2.compiler
Class AbstractParser
java.lang.Object
org.mvel2.compiler.AbstractParser
- All Implemented Interfaces:
Serializable,Parser
- Direct Known Subclasses:
AbstractOptimizer,ExpressionCompiler,MacroProcessor,MVELInterpretedRuntime
This is the core parser that the subparsers extend.
- Author:
- Christopher Brock
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Objectprotected intprotected booleanprotected ExecutionStackprotected intprotected char[]protected intprotected static final intprotected static final intprotected booleanprotected intprotected ASTNodeprotected booleanprotected booleanprotected booleanprotected booleanprotected intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprotected intprotected intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected ParserContextprotected static final intprotected static final intprotected ExecutionStackprotected intprotected intprotected ExecutionStackprotected VariableResolverFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFatalError(String message) protected voidaddFatalError(String message, int start) protected intarithmeticFunctionReduction(int operator) Reduce the current operations on the stack.protected voidCapture to the end of the current identifier under the cursor.protected voidCapture from the current cursor position, to the end of the statement.protected voidFrom the current cursor position, capture to the end of statement, or the end of line, whichever comes first.protected voidFrom the current cursor position, capture to the end of the current token.protected voidFrom the current cursor position, capture to the end of the next token junction.protected voidThe parser should find a statement ending condition when this is called, otherwise everything should blow up.voidexpectNextChar_IW(char c) Expect the next specified character or failintchar[]protected ASTNodehandleUnion(ASTNode node) Handle a union between a closed statement and a residual property chain.protected booleanChecking from the current cursor position, check to see if the if-then-else block continues.intIncrement one cursor position, and move cursor to next non-blank part.protected static booleanisArithmeticOperator(int operator) protected booleanChecks to see if the next part of the statement is an identifier part.protected booleanReturns true if the next is an identifier or literal.protected booleanNOTE: This method assumes that the current position of the cursor is at the end of a logical statement, to begin with.protected booleanlastNonWhite(char c) loadLanguageFeaturesByLevel(int languageLevel) protected charReturn the next character (delta 1 of cursor position).protected charlookAhead(int range) Return the character, forward of the currrent cursor position based on the specified range delta.protected charReturn the last character (delta -1 of cursor position).protected charReturn the previous non-whitespace character.intMove to next cursor position from current cursor position.protected ASTNodeRetrieve the next token in the expression.protected ASTNodeprotected voidreduce()This method is called when we reach the point where we must subEval a trinary operation in the expression.protected voidsetExpression(char[] expression) Set and finesse the expression, trimming an leading or proceeding whitespace.protected voidsetExpression(String expression) Set and finesse the expression, trimming an leading or proceeding whitespace.static voidsetLanguageLevel(int level) static voidThis method is internally called by the static initializer for AbstractParser in order to setup the parser.protected voidIf the cursor is currently pointing to whitespace, move the cursor forward to the first non-whitespace character, but account for carriage returns in the script (updates parser field: line).protected booleanChecking from the current cursor position, check to see if we're inside a contiguous identifier.protected inttrimLeft(int pos) From the specified cursor position, trim out any whitespace between the current position and the end of the last non-whitespace character.protected inttrimRight(int pos) From the specified cursor position, trim out any whitespace between the current position and beginning of the first non-whitespace character.protected voidFrom the current cursor position, trim backward over any whitespace to the first non-whitespace character.
-
Field Details
-
expr
protected char[] expr -
cursor
protected int cursor -
start
protected int start -
length
protected int length -
end
protected int end -
st
protected int st -
fields
protected int fields -
OP_NOT_LITERAL
protected static final int OP_NOT_LITERAL- See Also:
-
OP_OVERFLOW
protected static final int OP_OVERFLOW- See Also:
-
OP_TERMINATE
protected static final int OP_TERMINATE- See Also:
-
OP_RESET_FRAME
protected static final int OP_RESET_FRAME- See Also:
-
OP_CONTINUE
protected static final int OP_CONTINUE- See Also:
-
greedy
protected boolean greedy -
lastWasIdentifier
protected boolean lastWasIdentifier -
lastWasLineLabel
protected boolean lastWasLineLabel -
lastWasComment
protected boolean lastWasComment -
compileMode
protected boolean compileMode -
lastWasVar
protected boolean lastWasVar -
literalOnly
protected int literalOnly -
lastLineStart
protected int lastLineStart -
line
protected int line -
lastNode
-
LITERALS
-
CLASS_LITERALS
-
OPERATORS
-
stk
-
splitAccumulator
-
pCtx
-
dStack
-
ctx
-
variableFactory
-
debugSymbols
protected boolean debugSymbols -
SET
protected static final int SET- See Also:
-
REMOVE
protected static final int REMOVE- See Also:
-
GET
protected static final int GET- See Also:
-
GET_OR_CREATE
protected static final int GET_OR_CREATE- See Also:
-
LEVEL_5_CONTROL_FLOW
public static final int LEVEL_5_CONTROL_FLOW- See Also:
-
LEVEL_4_ASSIGNMENT
public static final int LEVEL_4_ASSIGNMENT- See Also:
-
LEVEL_3_ITERATION
public static final int LEVEL_3_ITERATION- See Also:
-
LEVEL_2_MULTI_STATEMENT
public static final int LEVEL_2_MULTI_STATEMENT- See Also:
-
LEVEL_1_BASIC_LANG
public static final int LEVEL_1_BASIC_LANG- See Also:
-
LEVEL_0_PROPERTY_ONLY
public static final int LEVEL_0_PROPERTY_ONLY- See Also:
-
-
Constructor Details
-
AbstractParser
protected AbstractParser() -
AbstractParser
-
-
Method Details
-
setupParser
public static void setupParser()This method is internally called by the static initializer for AbstractParser in order to setup the parser. The static initialization populates the operator and literal tables for the parser. In some situations, like OSGi, it may be necessary to utilize this manually. -
nextTokenSkipSymbols
-
nextToken
Retrieve the next token in the expression.- Returns:
- -
-
handleSubstatement
-
handleUnion
Handle a union between a closed statement and a residual property chain.- Parameters:
node- an ast node- Returns:
- ASTNode
-
ifThenElseBlockContinues
protected boolean ifThenElseBlockContinues()Checking from the current cursor position, check to see if the if-then-else block continues.- Returns:
- boolean value
-
tokenContinues
protected boolean tokenContinues()Checking from the current cursor position, check to see if we're inside a contiguous identifier.- Returns:
- -
-
expectEOS
protected void expectEOS()The parser should find a statement ending condition when this is called, otherwise everything should blow up. -
isNextIdentifier
protected boolean isNextIdentifier()Checks to see if the next part of the statement is an identifier part.- Returns:
- boolean true if next part is identifier part.
-
captureToEOS
protected void captureToEOS()Capture from the current cursor position, to the end of the statement. -
captureToEOSorEOL
protected void captureToEOSorEOL()From the current cursor position, capture to the end of statement, or the end of line, whichever comes first. -
captureIdentifier
protected void captureIdentifier()Capture to the end of the current identifier under the cursor. -
captureToEOT
protected void captureToEOT()From the current cursor position, capture to the end of the current token. -
lastNonWhite
protected boolean lastNonWhite(char c) -
trimLeft
protected int trimLeft(int pos) From the specified cursor position, trim out any whitespace between the current position and the end of the last non-whitespace character.- Parameters:
pos- - current position- Returns:
- new position.
-
trimRight
protected int trimRight(int pos) From the specified cursor position, trim out any whitespace between the current position and beginning of the first non-whitespace character.- Parameters:
pos- -- Returns:
- -
-
skipWhitespace
protected void skipWhitespace()If the cursor is currently pointing to whitespace, move the cursor forward to the first non-whitespace character, but account for carriage returns in the script (updates parser field: line). -
captureToNextTokenJunction
protected void captureToNextTokenJunction()From the current cursor position, capture to the end of the next token junction. -
trimWhitespace
protected void trimWhitespace()From the current cursor position, trim backward over any whitespace to the first non-whitespace character. -
setExpression
Set and finesse the expression, trimming an leading or proceeding whitespace.- Parameters:
expression- the expression
-
setExpression
protected void setExpression(char[] expression) Set and finesse the expression, trimming an leading or proceeding whitespace.- Parameters:
expression- the expression
-
lookToLast
protected char lookToLast()Return the previous non-whitespace character.- Returns:
- -
-
lookBehind
protected char lookBehind()Return the last character (delta -1 of cursor position).- Returns:
- -
-
lookAhead
protected char lookAhead()Return the next character (delta 1 of cursor position).- Returns:
- -
-
lookAhead
protected char lookAhead(int range) Return the character, forward of the currrent cursor position based on the specified range delta.- Parameters:
range- -- Returns:
- -
-
isNextIdentifierOrLiteral
protected boolean isNextIdentifierOrLiteral()Returns true if the next is an identifier or literal.- Returns:
- true of false
-
incNextNonBlank
public int incNextNonBlank()Increment one cursor position, and move cursor to next non-blank part.- Returns:
- cursor position
-
nextNonBlank
public int nextNonBlank()Move to next cursor position from current cursor position.- Returns:
- cursor position
-
expectNextChar_IW
public void expectNextChar_IW(char c) Expect the next specified character or fail- Parameters:
c- character
-
isStatementNotManuallyTerminated
protected boolean isStatementNotManuallyTerminated()NOTE: This method assumes that the current position of the cursor is at the end of a logical statement, to begin with. Determines whether or not the logical statement is manually terminated with a statement separator (';').- Returns:
- -
-
addFatalError
-
addFatalError
-
setLanguageLevel
public static void setLanguageLevel(int level) -
loadLanguageFeaturesByLevel
-
isArithmeticOperator
protected static boolean isArithmeticOperator(int operator) -
arithmeticFunctionReduction
protected int arithmeticFunctionReduction(int operator) Reduce the current operations on the stack.- Parameters:
operator- the operator- Returns:
- a stack control code
-
reduce
protected void reduce()This method is called when we reach the point where we must subEval a trinary operation in the expression. (ie. val1 op val2). This is not the same as a binary operation, although binary operations would appear to have 3 structures as well. A binary structure (or also a junction in the expression) compares the current state against 2 downrange structures (usually an op and a val). -
getCursor
public int getCursor() -
getExpression
public char[] getExpression()- Specified by:
getExpressionin interfaceParser
-