Parser takes as input a
CharSequence source and parses it when the parse(CharSequence) method is called.
A value of type T will be returned if parsing succeeds, or a ParserException
is thrown to indicate parsing error. For example: Parser<String> scanner = Scanners.IDENTIFIER;
assertEquals("foo", scanner.parse("foo"));
Parsers run either on character level to scan the source, or on token level to parse
a list of Token objects returned from another parser. This other parser that returns the
list of tokens for token level parsing is hooked up via the from(Parser, Parser)
or from(Parser) method.
The following are important naming conventions used throughout the library:
Token is called a lexer.
index parameters are 0-based indexes in the original source.
Mode#DEBUG mode to
parse(CharSequence, Mode) and inspect the result in
ParserException#getParseTree(). All labeled parsers will generate a node
in the exception's parse tree, with matched indices in the source.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | Parser.
Defines the mode that a parser should be run in. |
| public static class | |
| private static class |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract boolean | |
| private static <T> T | |
| private static <T> T | |
| private static <T> T | |
| private static <T> T | |
| pack-priv final Parser | asDelimiter()
As a delimiter, the parser's error is considered lenient and will only be reported if no other meaningful error is encountered. |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final <R> Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | followedBy(Parser<?> parser)
A |
| public final Parser | |
| public final Parser | |
| pack-priv final T | |
| public final <R> Parser | |
| public final <R> Parser | |
| public final Parser | infixl(Parser<? extends BiFunction<? super T, ? super T, ? extends T>> operator)
A |
| public final Parser | infixn(Parser<? extends BiFunction<? super T, ? super T, ? extends T>> op)
A |
| public final Parser | infixr(Parser<? extends BiFunction<? super T, ? super T, ? extends T>> op)
A |
| public Parser | |
| public Parser | |
| public final Parser | |
| public final Parser | |
| public final <R> Parser | |
| public static <T> Parser. | |
| public final <R> Parser | |
| public final <To> Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | notFollowedBy(Parser<?> parser)
A |
| public final Parser | optional()
Deprecated
since 3.0. Use
optional(null) or asOptional instead.
|
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final T | |
| public final T | |
| public final T | |
| public final T | Returns: the resultthe source string source, String the name of the module, this name appears in error message moduleName)
Deprecated
Please use
parse(CharSequence) instead.
Parses |
| public final T | Returns: the resultwhere the source is read from readable, String the name of the module, this name appears in error message moduleName)
Deprecated
Please use
parse(Readable) instead.
Parses source read from |
| public final ParseTree | parseTree(CharSequence source)
Parses |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| pack-priv static StringBuilder | |
| public final Parser | reluctantBetween(Parser<?> before, Parser<?> after)
Deprecated
This method probably only works in the simplest cases. And it's a character-level
parser only. Use it at your own risk. It may be deleted later when we find a better way.
A |
| public final <R> Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | skipAtLeast(int min)
A |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser | |
| public final Parser |