Package com.gengoai.parsing
Interface Expression
-
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
BaseExpression
,BinaryInfixOperatorExpression
,ListExpression
,TokenExpression
,UnaryOperatorExpression
,ValueExpression
public interface Expression extends Serializable
An expression encapsulates the result of parsing- Author:
- David B. Bracewell
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T extends Expression,O>
Oapply(Class<T> tClass, Function<T,O> function)
Applies the given function to this Expression treating it as an Expression of typeT
.default <T extends Expression>
Tas(Class<T> tClass)
Casts this Expression as the given Expression typeTag
getType()
Gets the tag associated with the Expressiondefault boolean
isInstance(Tag... tags)
Checks if this Expression's tag is an instance of any of the given tagsdefault boolean
isInstance(Class<? extends Expression> tClass)
Checks if this Expression is an instance of the given Expression typedefault boolean
isInstance(Class<? extends Expression> tClass, Tag type)
Checks if this Expression is an instance of the given Expression type and the given Tag typedefault <T extends Expression>
booleanwhen(Class<T> tClass, Consumer<T> consumer)
Applies the given consumer to the expression when it is an instance of the given expression typedefault <T extends Expression,O>
Optional<O>when(Class<T> tClass, Function<T,O> function)
Applies the given function to the expression when it is an instance of the given expression type
-
-
-
Method Detail
-
apply
default <T extends Expression,O> O apply(Class<T> tClass, Function<T,O> function)
Applies the given function to this Expression treating it as an Expression of typeT
.- Type Parameters:
T
- the expression type parameterO
- the output type parameter- Parameters:
tClass
- the class information of desired Expression typefunction
- the function to process the expression- Returns:
- the output of the function processing this expression
- Throws:
IllegalStateException
- if this Expression is not of typetClass
-
as
default <T extends Expression> T as(Class<T> tClass)
Casts this Expression as the given Expression type- Type Parameters:
T
- the expression type parameter- Parameters:
tClass
- the class information of desired expression type- Returns:
- the Expression as the given type
- Throws:
IllegalStateException
- if this Expression is not of typetClass
-
getType
Tag getType()
Gets the tag associated with the Expression- Returns:
- the type
-
isInstance
default boolean isInstance(Class<? extends Expression> tClass)
Checks if this Expression is an instance of the given Expression type- Parameters:
tClass
- the class information of desired expression type- Returns:
- True - if the expression is an instance of the given expression type, False otherwise
-
isInstance
default boolean isInstance(Class<? extends Expression> tClass, Tag type)
Checks if this Expression is an instance of the given Expression type and the given Tag type- Parameters:
tClass
- the class information of desired expression typetype
- the tag type- Returns:
- True - if the expression is an instance of the given expression type and tag type, False otherwise
-
isInstance
default boolean isInstance(Tag... tags)
Checks if this Expression's tag is an instance of any of the given tags- Parameters:
tags
- the tags to check- Returns:
- True - if the expression of any of the given tag , False otherwise
-
when
default <T extends Expression,O> Optional<O> when(Class<T> tClass, Function<T,O> function)
Applies the given function to the expression when it is an instance of the given expression type- Type Parameters:
T
- the expression type parameterO
- the output type parameter- Parameters:
tClass
- the class information of desired Expression typefunction
- the function to process the expression- Returns:
- the Optional output of the function.
-
when
default <T extends Expression> boolean when(Class<T> tClass, Consumer<T> consumer)
Applies the given consumer to the expression when it is an instance of the given expression type- Type Parameters:
T
- the expression type parameter- Parameters:
tClass
- the class information of desired Expression typeconsumer
- the consumer to process the expression- Returns:
- True if consumer is applied, False otherwise
-
-