Package org.apache.commons.jexl3.parser
Class JexlParser
java.lang.Object
org.apache.commons.jexl3.parser.StringParser
org.apache.commons.jexl3.parser.JexlParser
- Direct Known Subclasses:
Parser
The base class for parsing, manages the parameter/local variable frame.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA lexical unit is the container defining local symbols and their visibility boundaries. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe set of assignment operators as classes.protected JexlParser.LexicalUnitThe current lexical block.protected final Deque<JexlParser.LexicalUnit> Stack of lexical blocks.protected final Map<JexlParser.LexicalUnit, Scope> The map of lexical to functional blocks.protected final FeatureControllerThe associated controller.protected JexlInfoThe basic source info.protected intThe number of nested loops.Stack of parsing loop counts.The known namespaces.static final StringThe import pragma.static final StringThe prefix of a namespace pragma.static final StringThe prefix of a module pragma.static final StringThe name of the options pragma.The list of pragma declarations.protected ScopeThe map of named registers aka script parameters.When parsing inner functions/lambda, need to stack the scope (sic).protected StringThe source being processed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidallowRegisters(boolean registers) Internal, for debug purpose only.protected booleanallowVariable(String image) Whether a given variable name is allowed.protected voidcheckLambda(Token token) Check fat vs thin arrow syntax feature.protected StringcheckVariable(ASTIdentifier identifier, String name) Checks whether an identifier is a local variable or argument, ie a symbol, stored in a register.protected voidcleanup(JexlFeatures features) Cleanup.protected voidDisables pragma feature if pragma-anywhere feature is disabled.protected voiddeclareFunction(ASTVar variable, Token token) Declares a local function.protected voiddeclareParameter(Token token, boolean lexical, boolean constant) Declares a local parameter.protected voiddeclarePragma(String key, Object value) Adds a pragma declaration.private booleandeclareSymbol(int symbol) Declares a symbol.protected voiddeclareVariable(ASTVar variable, Token token, boolean lexical, boolean constant) Declares a local variable.protected static TokenerrorToken(Token... tokens) Pick the most significant token for error reporting.protected JexlFeaturesprotected ScopegetScope()Gets the frame used by this parser.protected abstract TokengetToken(int index) Overridden in actual parser to access tokens stack.protected JexlParser.LexicalUnitgetUnit()Gets the lexical unit used by this parser.protected voidIdentifier(boolean top) Default implementation does nothing but is overridden by generated code.private booleanisConstant(int symbol) Checks whether a symbol has been declared as a const in the current stack of lexical units.private booleanisNamespace(String name) Checks whether a name is a declared namespace.protected booleanisNamespaceFuncall(Token ns, Token colon, Token fun, Token paren) Semantic check identifying whether a list of 4 tokens forms a namespace function call.private booleanisSymbolDeclared(JexlNode.Info info, int symbol) Checks if a symbol is defined in lexical scopes.protected booleanisVariable(String name) Checks whether an identifier is a local variable or argument.protected voidjjtreeCloseNodeScope(JexlNode node) Called by parser at end of node construction.protected voidjjtreeOpenNodeScope(JexlNode node) Called by parser at beginning of node construction.protected voidpopScope()Pops back to previous local variable scope.protected voidRestores the previous lexical unit.protected voidCreate a new local variable scope and push it as current.protected voidPushes a new lexical unit.protected static StringreadSourceLine(String src, int lineno) Read a given source line.protected voidsetFeatures(JexlFeatures features) Sets a new set of options.protected static StringUtility function to create '.' separated string from a list of string.protected voidThrows Ambiguous exception.protected voidthrowFeatureException(int feature, JexlInfo info) Throws a feature exception.protected voidthrowFeatureException(int feature, Token trigger) Throws a feature exception.protected voidthrowParsingException(Token parsed) Throws a parsing exception.Methods inherited from class org.apache.commons.jexl3.parser.StringParser
buildRegex, buildString, buildTemplate, escapeIdentifier, escapeString, readString, unescapeIdentifier
-
Field Details
-
PRAGMA_OPTIONS
The name of the options pragma.- See Also:
-
PRAGMA_JEXLNS
The prefix of a namespace pragma.- See Also:
-
PRAGMA_MODULE
The prefix of a module pragma.- See Also:
-
PRAGMA_IMPORT
The import pragma.- See Also:
-
ASSIGN_NODES
The set of assignment operators as classes. -
featureController
The associated controller. -
info
The basic source info. -
source
The source being processed. -
scope
The map of named registers aka script parameters.Each parameter is associated to a register and is materialized as an offset in the registers array used during evaluation.
-
scopes
When parsing inner functions/lambda, need to stack the scope (sic). -
pragmas
The list of pragma declarations. -
namespaces
The known namespaces. -
loopCount
protected int loopCountThe number of nested loops. -
loopCounts
Stack of parsing loop counts. -
block
The current lexical block. -
blocks
Stack of lexical blocks. -
blockScopes
The map of lexical to functional blocks.
-
-
Constructor Details
-
JexlParser
public JexlParser()
-
-
Method Details
-
errorToken
Pick the most significant token for error reporting.- Parameters:
tokens- the tokens to choose from- Returns:
- the token
-
readSourceLine
Read a given source line.- Parameters:
src- the sourcelineno- the line number- Returns:
- the line
-
stringify
Utility function to create '.' separated string from a list of string.- Parameters:
lstr- the list of strings- Returns:
- the dotted version
-
allowRegisters
public void allowRegisters(boolean registers) Internal, for debug purpose only.- Parameters:
registers- whether register syntax is recognized by this parser
-
allowVariable
Whether a given variable name is allowed.- Parameters:
image- the name- Returns:
- true if allowed, false if reserved
-
checkLambda
Check fat vs thin arrow syntax feature.- Parameters:
token- the arrow token
-
checkVariable
Checks whether an identifier is a local variable or argument, ie a symbol, stored in a register.- Parameters:
identifier- the identifiername- the identifier name- Returns:
- the image
-
cleanup
Cleanup.- Parameters:
features- the feature set to restore if any
-
controlPragmaAnywhere
protected void controlPragmaAnywhere()Disables pragma feature if pragma-anywhere feature is disabled. -
declareFunction
Declares a local function.- Parameters:
variable- the identifier used to declaretoken- the variable name token
-
declareParameter
Declares a local parameter.This method creates an new entry in the symbol map.
- Parameters:
token- the parameter name tokenlexical- whether the parameter is lexical or notconstant- whether the parameter is constant or not
-
declarePragma
Adds a pragma declaration.- Parameters:
key- the pragma keyvalue- the pragma value
-
declareSymbol
private boolean declareSymbol(int symbol) Declares a symbol.- Parameters:
symbol- the symbol index- Returns:
- true if symbol can be declared in lexical scope, false (error) if it is already declared
-
declareVariable
Declares a local variable.This method creates an new entry in the symbol map.
- Parameters:
variable- the identifier used to declaretoken- the variable name toeknlexical- whether the symbol is lexicalconstant- whether the symbol is constant
-
getFeatures
- Returns:
- the current set of features active during parsing
-
getScope
Gets the frame used by this parser.Since local variables create new symbols, it is important to regain access after parsing to known which / how-many registers are needed.
- Returns:
- the named register map
-
getToken
Overridden in actual parser to access tokens stack.- Parameters:
index- 0 to get current token- Returns:
- the token on the stack
-
getUnit
Gets the lexical unit used by this parser.- Returns:
- the named register map
-
Identifier
Default implementation does nothing but is overridden by generated code.- Parameters:
top- whether the identifier is beginning an l/r value- Throws:
ParseException- subclasses may throw ParseException
-
isConstant
private boolean isConstant(int symbol) Checks whether a symbol has been declared as a const in the current stack of lexical units.- Parameters:
symbol- the symbol- Returns:
- true if constant, false otherwise
-
isNamespace
Checks whether a name is a declared namespace.- Parameters:
name- the namespace name- Returns:
- true if declared, false otherwise
-
isNamespaceFuncall
Semantic check identifying whether a list of 4 tokens forms a namespace function call.This is needed to disambiguate ternary operator, map entries and actual calls.
Note that this check is performed before syntactic check so the expected parameters need to be verified.
- Parameters:
ns- the namespace tokencolon- expected to be ":"fun- the function nameparen- expected to be "("- Returns:
- true if the name qualifies a namespace function call
-
isSymbolDeclared
Checks if a symbol is defined in lexical scopes.This works with parsed scripts in template resolution only.
- Parameters:
info- an info linked to a nodesymbol- the symbol number- Returns:
- true if symbol accessible in lexical scope
-
isVariable
Checks whether an identifier is a local variable or argument.- Parameters:
name- the variable name- Returns:
- true if a variable with that name was declared
-
jjtreeCloseNodeScope
Called by parser at end of node construction.Detects "Ambiguous statement" and 'non-left value assignment'.
- Parameters:
node- the node- Throws:
JexlException.Parsing- when parsing fails
-
jjtreeOpenNodeScope
Called by parser at beginning of node construction.- Parameters:
node- the node
-
popScope
protected void popScope()Pops back to previous local variable scope. -
popUnit
Restores the previous lexical unit.- Parameters:
unit- restores the previous lexical scope
-
pushScope
protected void pushScope()Create a new local variable scope and push it as current. -
pushUnit
Pushes a new lexical unit.- Parameters:
unit- the new lexical unit
-
setFeatures
Sets a new set of options.- Parameters:
features- the parser features
-
throwAmbiguousException
Throws Ambiguous exception.Seeks the end of the ambiguous statement to recover.
- Parameters:
node- the first token in ambiguous expression- Throws:
JexlException.Ambiguous- in all cases
-
throwFeatureException
Throws a feature exception.- Parameters:
feature- the feature codeinfo- the exception surroundings- Throws:
JexlException.Feature- in all cases
-
throwFeatureException
Throws a feature exception.- Parameters:
feature- the feature codetrigger- the token that triggered it- Throws:
JexlException.Parsing- if actual error token can not be foundJexlException.Feature- in all other cases
-
throwParsingException
Throws a parsing exception.- Parameters:
parsed- the token to report- Throws:
JexlException.Parsing- in all cases
-