Package redempt.redlex.parser
Interface ParserComponent
public interface ParserComponent
Represents a parser able to process a single, specific token type
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ParserComponent
coerce
(ParserComponent.ComponentType type, String name, Function<T, Object> func) getName()
getType()
static ParserComponent
mapChildren
(String name, Function<Object[], Object> func) Creates a ParserComponent that operates on the parsed Objects of its child tokensstatic ParserComponent
Creates a ParserComponent that operates on the String value of a tokenstatic ParserComponent
Creates a ParserComponent that operates directly on a tokenParses an Object
-
Method Details
-
mapString
Creates a ParserComponent that operates on the String value of a token- Parameters:
name
- The name of the token type to targetfunc
- The function to parse the String value- Returns:
- A ParserComponent
-
mapChildren
Creates a ParserComponent that operates on the parsed Objects of its child tokens- Parameters:
name
- The name of the token type to targetfunc
- The function to parse the result from the parsed Objects of child tokens- Returns:
- A ParserComponent
-
mapToken
Creates a ParserComponent that operates directly on a token- Parameters:
name
- The name of the token type to targetfunc
- The function to parse the result from the Token object- Returns:
- A ParserComponent
-
coerce
static <T> ParserComponent coerce(ParserComponent.ComponentType type, String name, Function<T, Object> func) -
parse
Parses an Object- Parameters:
context
- The context Object, depends on the type of the ParserComponent- Returns:
- The parsed Object
-
getType
ParserComponent.ComponentType getType()- Returns:
- The type of the ParserComponent, which determines what context will be passed to it
-
getName
String getName()- Returns:
- The name of the token type targeted by this ParserComponent
-