T - The type returned by parse()E - The exception thrown by the abstract handlers (e.g. conditional(Object, Object, Object))public abstract class Parser<T,E extends java.lang.Exception> extends AbstractParser<Scanner.TokenType>
s == "abc" && (c == 'b' || !b == true)Supported operators (in ascending priority) are:
a ? b : cb if a, converted to boolean, is true, otherwise
c.
a || ba if a, converted to boolean, is true, otherwise
b. (Equivalent to 'a ? a : b', except that a is evaluated only once.)
a && bb if a, converted to boolean, is true, otherwise
false. (Equivalent to 'a ? b : false'.)
== != < <= > >=a =* "*.c"a =* "(*).c=$1.h"Glob). Evaluates to the replacement, or, iff no replacement is given,
to the match, or, iff the subject does not match the glob, to null.
(Only with extension OPERATOR_GLOB)
a =~ "A.*"a =~ "(.*)abc(.*)=$1$2"Pattern). Evaluates to the replacement, or, iff no replacement is given,
to the match, or, iff the subject does not match the glob, to null.
(Only with extension OPERATOR_REGEX)
+ -* / %a instanceof reference-typetrue iff a is non-null and a subtype of reference-type(...) ! -"abc"123123L 123l1F 1.2E+3f1D 1d 1.1 1.1e-3true false nullabcExpression.evaluate(de.unkrig.commons.lang.protocol.Mapping)new pkg.Clazz(arg1, arg2)new RootPackageClazz(arg1, arg2)new ImportedClazz(arg1,
arg2)
new pkg.Clazz#
(Only with extensions NEW_CLASS_WITHOUT_PARENTHESES and NEW_CLASS_WITHOUT_KEYWORD)
pkg.Clazz
(Only with extension NEW_CLASS_WITHOUT_KEYWORD)
pkg.Clazz()
new pkg.Clazz()new pkg.Clazz[x]new pkg.Clazz[x][y][][]new int[x]new int[x][y][][]
pkg.Clazz[x]pkg.Clazz[x][y][][]int[x]int[x][y][][]x[y]x.namename", or invokes "name()" or "getName()"x.meth(a, b, c)Null operands are handled leniently, e.g. "7 == null" is false, "null == null" is true.
To implement your parser, derive from this class and implement the abstract methods.
| Modifier and Type | Class and Description |
|---|---|
static class |
Parser.BinaryOperator
Representation of all binary operators.
|
static class |
Parser.UnaryOperator
Representation of all unary operators.
|
scanner| Constructor and Description |
|---|
Parser(ProducerWhichThrows<? extends AbstractScanner.Token<Scanner.TokenType>,? extends ScanException> tokenProducer) |
Parser(java.io.Reader in) |
Parser(java.lang.String expression) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract T |
arrayAccess(T lhs,
T rhs) |
protected abstract T |
binaryOperation(T lhs,
Parser.BinaryOperator operator,
T rhs) |
protected abstract T |
cast(java.lang.Class<?> targetType,
T operand) |
protected abstract T |
conditional(T lhs,
T mhs,
T rhs) |
void |
disableExtension(de.unkrig.commons.text.expression.Parser.Extension extension)
Disable one of the parser extensions listed in
Parser.Extension. |
void |
enableExtension(de.unkrig.commons.text.expression.Parser.Extension extension)
Enable one of the parser extensions listed in
Parser.Extension. |
protected abstract T |
fieldReference(T target,
java.lang.String fieldName) |
java.lang.ClassLoader |
getClassLoader() |
java.lang.String[] |
getImports() |
protected abstract T |
instanceoF(T lhs,
java.lang.Class<?> rhs) |
protected abstract T |
literal(java.lang.Object value) |
protected abstract T |
methodInvocation(T target,
java.lang.String methodName,
java.util.List<T> arguments) |
protected abstract T |
newArray(java.lang.Class<?> clasS,
java.util.List<T> dimensions) |
protected abstract T |
newClass(java.lang.Class<?> clasS,
java.util.List<T> arguments) |
protected abstract T |
parenthesized(T value) |
T |
parse() |
Parser<T,E> |
setClassLoader(java.lang.ClassLoader classLoader) |
Parser<T,E> |
setImports(java.lang.String[] imports)
By default, there is only one import: "java.lang".
|
protected abstract T |
staticFieldReference(java.lang.Class<?> type,
java.lang.String fieldName) |
protected abstract T |
staticMethodInvocation(java.lang.Class<?> target,
java.lang.String methodName,
java.util.List<T> arguments) |
protected abstract T |
unaryOperation(Parser.UnaryOperator operator,
T operand) |
protected abstract T |
variableReference(java.lang.String variableName) |
public Parser(ProducerWhichThrows<? extends AbstractScanner.Token<Scanner.TokenType>,? extends ScanException> tokenProducer)
public Parser(java.io.Reader in)
public Parser(java.lang.String expression)
public java.lang.String[] getImports()
public Parser<T,E> setImports(java.lang.String[] imports)
public java.lang.ClassLoader getClassLoader()
ClassLoaderpublic Parser<T,E> setClassLoader(java.lang.ClassLoader classLoader)
classLoader - Used to load classes named in the expression; by default the class loader which loaded
the Parser class.public void enableExtension(de.unkrig.commons.text.expression.Parser.Extension extension)
Parser.Extension. By default, all extensions are enabled.public void disableExtension(de.unkrig.commons.text.expression.Parser.Extension extension)
Parser.Extension. By default, all extensions are enabled.public T parse() throws ParseException, E extends java.lang.Exception
ParseExceptionE extends java.lang.Exceptionprotected abstract T conditional(T lhs, T mhs, T rhs) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T unaryOperation(Parser.UnaryOperator operator, T operand) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T binaryOperation(T lhs, Parser.BinaryOperator operator, T rhs) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T fieldReference(T target, java.lang.String fieldName) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T staticFieldReference(java.lang.Class<?> type, java.lang.String fieldName) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T methodInvocation(T target, java.lang.String methodName, java.util.List<T> arguments) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T staticMethodInvocation(java.lang.Class<?> target, java.lang.String methodName, java.util.List<T> arguments) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T variableReference(java.lang.String variableName) throws E extends java.lang.Exception, ParseException
E extends java.lang.ExceptionParseExceptionprotected abstract T literal(@Nullable java.lang.Object value) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T parenthesized(T value) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T instanceoF(T lhs, java.lang.Class<?> rhs) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T newClass(java.lang.Class<?> clasS, java.util.List<T> arguments) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T newArray(java.lang.Class<?> clasS, java.util.List<T> dimensions) throws E extends java.lang.Exception
E extends java.lang.Exceptionprotected abstract T cast(java.lang.Class<?> targetType, T operand) throws E extends java.lang.Exception, ParseException
E extends java.lang.ExceptionParseException