ContinuationParser<T> class

Continuation parser that when activated captures a continuation function and passes it together with the current context into the handler.

Handlers are not required to call the continuation, but can completely ignore it, call it multiple times, and/or store it away for later use. Similarly handlers can modify the current context and/or modify the returned result.

The following example shows a simple wrapper. Messages are printed before and after the digit() parser is activated:

final wrapped = digit();
final parser = new ContinuationParser(wrapped, (continuation, context) {
  print('Parser will be activated, the context is $context.');
  final result = continuation(context);
  print('Parser was activated, the result is $result.');
  return result;
});

See profile, progress, and trace for more elaborate examples.

Inheritance

Constructors

ContinuationParser(Parser<T> delegate, ContinuationHandler<T> handler)

Properties

handler ContinuationHandler<T>
final
children → List<Parser>
Returns a list of directly referenced parsers. [...]
read-only, inherited
delegate Parser
read / write, inherited
hashCode → int
The hash code for this object.
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

copy() ContinuationParser<T>
Returns a shallow copy of the receiver. [...]
override
hasEqualProperties(covariant ContinuationParser<T> other) → bool
Compare the properties of two parsers. Normally this method should not be called directly, instead use Parser#equals. [...]
override
parseOn(Context context) Result<T>
Primitive method doing the actual parsing. [...]
override
accept(String input) → bool
Tests if the input can be successfully parsed. [...]
inherited
allMatches(String string, [ int start = 0 ]) → Iterable<Match>
Matches this parser against string repeatedly. [...]
inherited
and() Parser<T>
Returns a parser (logical and-predicate) that succeeds whenever the receiver does, but never consumes input. [...]
inherited
cast<R>() Parser<R>
Returns a parser that casts itself to Parser<R>.
inherited
castList<R>() Parser<List<R>>
Returns a parser that casts itself to Parser<List<R>>. Assumes this parser to be of type Parser<List>.
inherited
end([String message = 'end of input expected' ]) Parser<T>
Returns a parser that succeeds only if the receiver consumes the complete input, otherwise return a failure with the optional message. [...]
inherited
fastParseOn(String buffer, int position) → int
Primitive method doing the actual parsing. [...]
inherited
flatten([String message ]) Parser<String>
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. [...]
inherited
hasEqualChildren(Parser other, Set<Parser> seen) → bool
Compare the children of two parsers. Normally this method should not be called directly, instead use Parser#equals. [...]
inherited
isEqualTo(Parser other, [ Set<Parser> seen ]) → bool
Recursively tests for structural equality of two parsers. [...]
inherited
map<R>(ActionCallback<T, R> callback, { bool hasSideEffects: false }) Parser<R>
Returns a parser that evaluates a callback as the production action on success of the receiver. [...]
inherited
matchAsPrefix(String string, [ int start = 0 ]) → Match
Match this pattern against the start of string. [...]
inherited
matches(String input) → List<T>
Returns a list of all successful overlapping parses of the input. [...]
inherited
matchesSkipping(String input) → List<T>
Returns a list of all successful non-overlapping parses of the input. [...]
inherited
neg([String message = 'input not expected' ]) Parser<String>
Returns a parser that consumes any input token (character), but the receiver. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
not([String message = 'success not expected' ]) Parser<void>
Returns a parser (logical not-predicate) that succeeds whenever the receiver fails, but never consumes input. [...]
inherited
optional([T otherwise ]) Parser<T>
Returns new parser that accepts the receiver, if possible. The resulting parser returns the result of the receiver, or null if not applicable. The returned value can be provided as an optional argument otherwise. [...]
inherited
or(Parser other) Parser
Returns a parser that accepts the receiver or 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). [...]
inherited
parse(String input) Result<T>
Returns the parse result of the input. [...]
inherited
permute<R>(List<int> indexes) Parser<List<R>>
Returns a parser that transforms a successful parse result by returning the permuted elements at indexes of a list. Negative indexes can be used to access the elements from the back of the list. Assumes this parser to be of type Parser<List<R>>. [...]
inherited
pick<R>(int index) Parser<R>
Returns a parser that transform a successful parse result by returning the element at index of a list. A negative index can be used to access the elements from the back of the list. Assumes this parser to be of type Parser<List<R>>. [...]
inherited
plus() Parser<List<T>>
Returns a parser that accepts the receiver one or more times. The resulting parser returns a list of the parse results of the receiver. [...]
inherited
plusGreedy(Parser limit) Parser<List<T>>
Returns a parser that parses the receiver one or more times until it reaches limit. This is a greedy non-blind implementation of the Parser.plus operator. The limit is not consumed.
inherited
plusLazy(Parser limit) Parser<List<T>>
Returns a parser that parses the receiver one or more times until it reaches a limit. This is a lazy non-blind implementation of the Parser.plus operator. The limit is not consumed.
inherited
repeat(int min, [ int max ]) Parser<List<T>>
Returns a parser that accepts the receiver between min and max times. The resulting parser returns a list of the parse results of the receiver. [...]
inherited
repeatGreedy(Parser limit, int min, int max) Parser<List<T>>
Returns a parser that parses the receiver at least min and at most max times until it reaches a limit. This is a greedy non-blind implementation of the Parser.repeat operator. The limit is not consumed.
inherited
repeatLazy(Parser limit, int min, int max) Parser<List<T>>
Returns a parser that parses the receiver at least min and at most max times until it reaches a limit. This is a lazy non-blind implementation of the Parser.repeat operator. The limit is not consumed.
inherited
replace(Parser source, Parser target) → void
Changes the receiver by replacing source with target. Does nothing if source does not exist in Parser.children. [...]
inherited
separatedBy<R>(Parser separator, { bool includeSeparators: true, bool optionalSeparatorAtEnd: false }) Parser<List<R>>
Returns a parser that consumes the receiver one or more times separated by the separator parser. The resulting parser returns a flat list of the parse results of the receiver interleaved with the parse result of the separator parser. The type parameter R defines the type of the returned list. [...]
inherited
seq(Parser other) Parser<List>
Returns a parser that accepts the receiver followed by other. The resulting parser returns a list of the parse result of the receiver followed by the parse result of other. Calling this method on an existing sequence code not nest this sequence into a new one, but instead augments the existing sequence with other. [...]
inherited
settable() SettableParser<T>
Returns a parser that points to the receiver, but can be changed to point to something else at a later point in time. [...]
inherited
star() Parser<List<T>>
Returns a parser that accepts the receiver zero or more times. The resulting parser returns a list of the parse results of the receiver. [...]
inherited
starGreedy(Parser limit) Parser<List<T>>
Returns a parser that parses the receiver zero or more times until it reaches a limit. This is a greedy non-blind implementation of the Parser.star operator. The limit is not consumed.
inherited
starLazy(Parser limit) Parser<List<T>>
Returns a parser that parses the receiver zero or more times until it reaches a limit. This is a lazy non-blind implementation of the Parser.star operator. The limit is not consumed.
inherited
times(int count) Parser
Returns a parser that accepts the receiver exactly count times. The resulting parser returns a list of the parse results of the receiver. [...]
inherited
token() Parser<Token<T>>
Returns a parser that returns a Token. The token carries the parsed value of the receiver Token.value, as well as the consumed input Token.input from Token.start to Token.stop of the input being parsed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited
trim([Parser left, Parser right ]) Parser<T>
Returns a parser that consumes input before and after the receiver, discards the excess input and only returns returns the result of the receiver. The optional argument is a parser that consumes the excess input. By default whitespace() is used. Up to two arguments can be provided to have different parsers on the left and right side. [...]
inherited

Operators

operator &(Parser other) Parser<List>
Convenience operator returning a parser that accepts the receiver followed by other. See Parser.seq for details.
inherited
operator ==(dynamic other) → bool
The equality operator.
inherited
operator |(Parser other) Parser
Convenience operator returning a parser that accepts the receiver or other. See Parser.or for details.
inherited