Interface Parser<T>
- Type Parameters:
T- The AST node this parser will be returning.
- All Known Implementing Classes:
LazyParser
public interface Parser<T>
Main interface of the parser library, used to implement custom parsers.
-
Method Summary
-
Method Details
-
parse
The core of the parsing logic. The context argument specifies where in the input string we are currently parsing. The responsibility of this function is to do one of:- Consume a part of the input and return a non-null value.
- Return null and keep the input context untouched. This can be achieved either by avoiding
the calls to
ParserContext.advance(int), or through the use of snapshotting (seeParserContext.snapshot()).
- Parameters:
context- Context of the parser containing the parsed string and the position in that string.- Returns:
- Null-value if this parser did not match anything. Non-null if it matched.
-
parse
Helper function to parse whole strings.- Parameters:
input- A string to parse.- Returns:
- A parsed out value (likely AST) or null, if it does not match.
-
map
Helper for converting a result of the parser into another type. More or less equivalent toStream.map(Function).- Type Parameters:
R- The return type of the new parser.- Parameters:
function- Function that should be used to map the result of the given parser.- Returns:
- A new parser which returns the expected type.
-