CharacterParser, DelegateParser, EpsilonParser, FailureParser, ListParser, StringParserpublic abstract class Parser extends Object
| Constructor | Description |
|---|---|
Parser() |
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
accept(String input) |
Tests if the
input can be successfully parsed. |
Parser |
and() |
Returns a parser (logical and-predicate) that succeeds whenever the receiver does, but never
consumes input.
|
Parser |
callCC(ContinuationParser.ContinuationHandler handler) |
Returns a parser that is called with its current continuation.
|
abstract Parser |
copy() |
Returns a shallow copy of the receiver.
|
Parser |
delimitedBy(Parser separator) |
Returns a new parser that parses the receiver one or more times, separated
and possibly ended by a
separator." |
Parser |
end() |
Returns a parser that succeeds only if the receiver consumes the complete input.
|
Parser |
end(String message) |
Returns a parser that succeeds only if the receiver consumes the complete input, otherwise
return a failure with the
message. |
Parser |
flatten() |
Returns a parser that discards the result of the receiver, and returns a sub-string of the
consumed range in the string/list being parsed.
|
List<Parser> |
getChildren() |
Returns a list of directly referring parsers.
|
protected boolean |
hasEqualChildren(Parser other,
Set<Parser> seen) |
Compares the children of two parsers.
|
protected boolean |
hasEqualProperties(Parser other) |
Compares the properties of two parsers.
|
boolean |
isEqualTo(Parser other) |
Recursively tests for structural similarity of two parsers.
|
protected boolean |
isEqualTo(Parser other,
Set<Parser> seen) |
Recursively tests for structural similarity of two parsers.
|
<A,B> Parser |
map(Function<A,B> function) |
Returns a parser that evaluates a
function as the production action on success of the
receiver. |
<T> List<T> |
matches(String input) |
Returns a list of all successful overlapping parses of the
input. |
<T> List<T> |
matchesSkipping(String input) |
Returns a list of all successful non-overlapping parses of the
input. |
Parser |
neg() |
Returns a parser that consumes any input token (character), but the receiver.
|
Parser |
neg(String message) |
Returns a parser that consumes any input token (character), but the receiver.
|
Parser |
not() |
Returns a parser (logical not-predicate) that succeeds whenever the receiver fails, but never
consumes input.
|
Parser |
not(String message) |
Returns a parser (logical not-predicate) that succeeds whenever the receiver fails, but never
consumes input.
|
Parser |
optional() |
Returns new parser that accepts the receiver, if possible.
|
Parser |
optional(Object otherwise) |
Returns new parser that accepts the receiver, if possible.
|
ChoiceParser |
or(Parser... others) |
Returns a parser that accepts the receiver or
other. |
Result |
parse(String input) |
Returns the parse result of the
input. |
abstract Result |
parseOn(Context context) |
Primitive method doing the actual parsing.
|
Parser |
permute(int... indexes) |
Returns a parser that transforms a successful parse result by returning the permuted elements
at
indexes of a list. |
Parser |
pick(int index) |
Returns a parser that transform a successful parse result by returning the element at
index of a list. |
Parser |
plus() |
Returns a parser that accepts the receiver one or more times.
|
Parser |
plusGreedy(Parser limit) |
Returns a parser that parses the receiver one or more times until it reaches
limit. |
Parser |
plusLazy(Parser limit) |
Returns a parser that parses the receiver one or more times until it reaches a
limit. |
Parser |
repeat(int min,
int max) |
Returns a parser that accepts the receiver between
min and max times. |
Parser |
repeatGreedy(Parser limit,
int min,
int max) |
Returns a parser that parses the receiver at least
min and at most max times
until it reaches a limit. |
Parser |
repeatLazy(Parser limit,
int min,
int max) |
Returns a parser that parses the receiver at least
min and at most max times
until it reaches a limit. |
void |
replace(Parser source,
Parser target) |
Replaces the referring parser
source with target. |
Parser |
separatedBy(Parser separator) |
Returns a new parser that parses the receiver one or more times, separated
by a
separator. |
SequenceParser |
seq(Parser... others) |
Returns a parser that accepts the receiver followed by
others. |
SettableParser |
settable() |
Returns a parser that points to the receiver, but can be changed to point to something else at
a later point in time.
|
Parser |
star() |
Returns a parser that accepts the receiver zero or more times.
|
Parser |
starGreedy(Parser limit) |
Returns a parser that parses the receiver zero or more times until it reaches a
limit. |
Parser |
starLazy(Parser limit) |
Returns a parser that parses the receiver zero or more times until it reaches a
limit. |
Parser |
times(int count) |
Returns a parser that accepts the receiver exactly
count times. |
Parser |
token() |
Returns a parser that returns a
Token. |
String |
toString() |
Returns a human readable string identifying this parser.
|
Parser |
trim() |
Returns a parser that consumes whitespace before and after the receiver.
|
Parser |
trim(Parser both) |
Returns a parser that consumes input on
both sides of the receiver. |
Parser |
trim(Parser before,
Parser after) |
Returns a parser that consumes input
before and after the receiver. |
public boolean accept(String input)
input can be successfully parsed.public <T> List<T> matches(String input)
input.public <T> List<T> matchesSkipping(String input)
input.public Parser optional()
null if not applicable.public Parser optional(Object otherwise)
otherwise.public Parser star()
public Parser starGreedy(Parser limit)
limit.
This is a greedy non-blind implementation of the star() operator. The
limit is not consumed.public Parser starLazy(Parser limit)
limit.
This is a lazy non-blind implementation of the star() operator. The
limit is not consumed.public Parser plus()
public Parser plusGreedy(Parser limit)
limit.
This is a greedy non-blind implementation of the plus() operator. The
limit is not consumed.public Parser plusLazy(Parser limit)
limit.
This is a lazy non-blind implementation of the plus() operator. The
limit is not consumed.public Parser repeat(int min, int max)
min and max times. The
resulting parser returns a list of the parse results of the receiver.
This is a greedy and blind implementation that tries to consume as much input as possible and
that does not consider what comes afterwards.public Parser repeatGreedy(Parser limit, int min, int max)
min and at most max times
until it reaches a limit. This is a greedy non-blind implementation of the repeat(int, int) operator. The limit is not consumed.public Parser repeatLazy(Parser limit, int min, int max)
min and at most max times
until it reaches a limit. This is a lazy non-blind implementation of the repeat(int, int) operator. The limit is not consumed.public Parser times(int count)
count times. The resulting parser
returns a list of the parse results of the receiver.public SequenceParser seq(Parser... others)
others. The resulting parser
returns a list of the parse result of the receiver followed by the parse result of
others. Calling this method on an existing sequence code not nest this sequence into a new one,
but instead augments the existing sequence with others.public ChoiceParser or(Parser... others)
other. The resulting parser returns the
parse result of the receiver, if the receiver fails it returns the parse result of
other (exclusive ordered choice).public Parser and()
public Parser callCC(ContinuationParser.ContinuationHandler handler)
public Parser not()
public Parser not(String message)
public Parser neg()
public Parser neg(String message)
public Parser flatten()
public Parser token()
Token. The token carries the parsed value of the
receiver Token.getValue(), as well as the consumed input Token.getInput() from
Token.getStart() to Token.getStop() of the input being parsed.public Parser trim()
public Parser trim(Parser both)
both sides of the receiver.public Parser trim(Parser before, Parser after)
before and after the receiver.public Parser end()
public Parser end(String message)
message.public SettableParser settable()
public <A,B> Parser map(Function<A,B> function)
function as the production action on success of the
receiver.public Parser pick(int index)
index of a list. A negative index can be used to access the elements from the back of the
list.public Parser permute(int... indexes)
indexes of a list. Negative indexes can be used to access the elements from the back
of the list.public Parser separatedBy(Parser separator)
separator.public Parser delimitedBy(Parser separator)
separator."public abstract Parser copy()
public boolean isEqualTo(Parser other)
protected boolean isEqualTo(Parser other, Set<Parser> seen)
protected boolean hasEqualProperties(Parser other)
protected boolean hasEqualChildren(Parser other, Set<Parser> seen)
getChildren().public void replace(Parser source, Parser target)
source with target. Does nothing if the parser
does not exist.Copyright © 2018 PetitParser. All rights reserved.