T
- The type returned by parse()
EX
- The exception thrown by the abstract handlers (e.g. conditional(Object, Object, Object)
)public abstract class Parser<T,EX extends Throwable> extends AbstractParser<Scanner.TokenType>
s == "abc" && (c == 'b' || !b == true)Supported operators (in ascending priority) are:
a ? b : c
b
if a
, converted to boolean
, is true, otherwise
c
.
a || b
a
if a
, converted to boolean
, is true, otherwise
b
. (Equivalent to "a ? a : b
", except that a
is evaluated only once.)
a && b
b
if a
, converted to boolean
, is true, otherwise
false
. (Equivalent to "a ? b : false
".)
== != < <= > >=
a =* "*.c"
a =* "(*).c=$1.h"
Glob
).
The left-hand-side operand is the subject, the right-hand-side operand is the glob.
Iff the right-hand-side operand contains an equal sign ("=
"), as in the second example, then it
specifies a glob and the replacement.
null
iff the subject does not match the glob, otherwise,=*
" operator is only available if the Parser.Extension.OPERATOR_GLOB
parsing extension is
enabled (which is the default).
a =~ "A.*"
a =~ "(.*)abc(.*)=$1$2"
Pattern
).
The left-hand-side operand is the subject, the right-hand-side operand is the pattern.
Iff the right-hand-side operand contains an equal sign ("=
"), as in the second example, then it
specifies a pattern and the replacement.
null
iff the subject does not match the pattern, otherwise,=~
" operator is only available if the Parser.Extension.OPERATOR_REGEX
parsing extension is
enabled (which is the default).
+ -
* / %
a instanceof reference-type
a
is non-null and a subtype of reference-type
(...) ! -
Primaries are:
"abc"
123
123L 123l
1F 1.2E+3f
1D 1d 1. 1.1 1e-3
true false null
abc
Expression.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 Parser.Extension.NEW_CLASS_WITHOUT_PARENTHESES
)pkg.Clazz()
(Only with Parser.Extension.NEW_CLASS_WITHOUT_KEYWORD
)pkg.Clazz
(Only with Parser.Extension.NEW_CLASS_WITHOUT_KEYWORD
and Parser.Extension.NEW_CLASS_WITHOUT_PARENTHESES
)new pkg.Clazz()
"
new pkg.Clazz[x]
new pkg.Clazz[x][y][][]
new int[x]
new int[x][y][][]
new
keyword, as for class
instance creation)
pkg.Clazz[x]
pkg.Clazz[x][y][][]
int[x]
int[x][y][][]
x[y]
x.name
x.name
", or invokes "x.name()
" or "x.getName()
" (it is not possible to set an attribute this way)
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.Extension
Various extensions to the Java expression syntax.
|
static class |
Parser.UnaryOperator
Representation of all unary operators.
|
scanner
Constructor and Description |
---|
Parser(ProducerWhichThrows<? extends AbstractScanner.Token<Scanner.TokenType>,? extends ScanException> tokenProducer) |
Parser(Reader in) |
Parser(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(Class<?> targetType,
T operand) |
protected abstract T |
conditional(T lhs,
T mhs,
T rhs) |
void |
disableExtension(Parser.Extension extension)
Disables the given parsing extension.
|
void |
enableExtension(Parser.Extension extension)
Enables the given parsing extension.
|
protected abstract T |
fieldReference(T target,
String fieldName) |
ClassLoader |
getClassLoader() |
String[] |
getImports() |
protected abstract T |
instanceoF(T lhs,
Class<?> rhs) |
protected abstract T |
literal(Object value) |
protected abstract T |
methodInvocation(T target,
String methodName,
List<T> arguments) |
protected abstract T |
newArray(Class<?> clasS,
List<T> dimensions) |
protected abstract T |
newClass(Class<?> clasS,
List<T> arguments) |
protected abstract T |
parenthesized(T value) |
T |
parse() |
T |
parsePart() |
Parser<T,EX> |
setClassLoader(ClassLoader classLoader) |
void |
setExtensions(Collection<Parser.Extension> extensions)
Sets the given parsing extensions.
|
void |
setExtensions(EnumSet<Parser.Extension> extensions)
Sets the given parsing extensions.
|
Parser<T,EX> |
setImports(String[] imports)
By default, there is only one import: "java.lang".
|
protected abstract T |
staticFieldReference(Class<?> type,
String fieldName) |
protected abstract T |
staticMethodInvocation(Class<?> target,
String methodName,
List<T> arguments) |
protected abstract T |
unaryOperation(Parser.UnaryOperator operator,
T operand) |
protected abstract T |
variableReference(String variableName) |
public Parser(ProducerWhichThrows<? extends AbstractScanner.Token<Scanner.TokenType>,? extends ScanException> tokenProducer)
public Parser(Reader in)
public Parser(String expression)
public String[] getImports()
public Parser<T,EX> setImports(String[] imports)
public ClassLoader getClassLoader()
ClassLoader
public Parser<T,EX> setClassLoader(ClassLoader classLoader)
classLoader
- Used to load classes named in the expression; by default the class loader which loaded
the Parser
class.public void setExtensions(Collection<Parser.Extension> extensions)
Parser.Extension
public void setExtensions(EnumSet<Parser.Extension> extensions)
Parser.Extension
public void enableExtension(Parser.Extension extension)
Parser.Extension
public void disableExtension(Parser.Extension extension)
Parser.Extension
public T parse() throws ParseException, EX extends Throwable
ParseException
EX extends Throwable
public T parsePart() throws ParseException, EX extends Throwable
ParseException
EX extends Throwable
protected abstract T unaryOperation(Parser.UnaryOperator operator, T operand) throws EX extends Throwable
protected abstract T binaryOperation(T lhs, Parser.BinaryOperator operator, T rhs) throws EX extends Throwable
protected abstract T fieldReference(T target, String fieldName) throws EX extends Throwable
protected abstract T staticFieldReference(Class<?> type, String fieldName) throws EX extends Throwable
protected abstract T methodInvocation(T target, String methodName, List<T> arguments) throws EX extends Throwable
protected abstract T staticMethodInvocation(Class<?> target, String methodName, List<T> arguments) throws EX extends Throwable
protected abstract T variableReference(String variableName) throws EX extends Throwable, ParseException
EX extends Throwable
ParseException
protected abstract T newClass(Class<?> clasS, List<T> arguments) throws EX extends Throwable
protected abstract T newArray(Class<?> clasS, List<T> dimensions) throws EX extends Throwable
protected abstract T cast(Class<?> targetType, T operand) throws EX extends Throwable, ParseException
EX extends Throwable
ParseException
Copyright © 2018 Arno Unkrig. All rights reserved.