StartParser final
Inheritance
Object → Parser0<A> → StartParser
Constructors
StartParser()
Properties
backtrack no setter inherited
Wraps this parser so that it always restores the input offset on failure, enabling the failure to be caught by orElse even after partial input has been consumed.
Inherited from Parser0.
Implementation
Parser0<A> get backtrack => Parsers.backtrack0(this);hashCode no setter inherited
The hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
external int get hashCode;not no setter inherited
A parser that succeeds (consuming no input) only when this parser would fail at the current position, and fails when this parser would succeed.
Inherited from Parser0.
Implementation
Parser0<Unit> get not => Parsers.not(this);opt no setter inherited
Succeeds with Some of the parsed value, or None if this parser fails without consuming input.
Inherited from Parser0.
Implementation
Parser0<Option<A>> get opt =>
Parsers.oneOf0(ilist([Parsers.map0(this, (a) => a.some), Parsers.pure(none<A>())]));peek no setter inherited
Succeeds when this parser would succeed at the current position but consumes no input.
Inherited from Parser0.
Implementation
Parser0<Unit> get peek => Parsers.peek(this);runtimeType no setter inherited
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;soft no setter inherited
Returns a Soft0 view that uses soft (backtracking) product combinators.
In a soft product a.soft.product(b), a failure in b backtracks to before a ran, allowing the failure to be caught by orElse.
Inherited from Parser0.
Implementation
Soft0<A> get soft => Soft0(this);string no setter inherited
Returns a parser that succeeds with the substring of the input matched by this parser, instead of its original return value.
Inherited from Parser0.
Implementation
Parser0<String> get string => Parsers.stringP0(this);voided no setter inherited
Returns a parser that runs this parser and discards the result, producing Unit.
Inherited from Parser0.
Implementation
Parser0<Unit> get voided => Parsers.voided0(this);with1 no setter inherited
Promotes this Parser0 so it can be sequenced with a Parser to produce a Parser result.
All combinators on With1 return Parser instead of Parser0, which is useful when at least one side of a product is known to consume input.
Inherited from Parser0.
Implementation
With1<A> get with1 => With1(this);withString no setter inherited
Returns a parser that produces both the parsed value and the substring of input that was consumed.
Inherited from Parser0.
Implementation
Parser0<(A, String)> get withString => Parsers.withString0(this);Methods
as() inherited
Returns a parser that succeeds with b whenever this parser succeeds, discarding the matched value.
Inherited from Parser0.
Implementation
Parser0<B> as<B>(B b) => Parsers.as0(this, b);between() inherited
Matches b, then this parser, then c, returning only the result of this parser.
Inherited from Parser0.
Implementation
Parser0<A> between(Parser0<dynamic> b, Parser0<dynamic> c) =>
b.voided.product(product(c.voided)).map((tuple) => tuple.$2.$1);eitherOr() inherited
Returns a parser that tries pb first; on success wraps its result in Left, otherwise tries this parser and wraps its result in Right.
Inherited from Parser0.
Implementation
Parser0<Either<B, A>> eitherOr<B>(covariant Parser0<B> pb) => Parsers.eitherOr0(this, pb);filter() inherited
Succeeds with the parsed value only when p returns true; fails (without consuming) otherwise.
Inherited from Parser0.
Implementation
Parser0<A> filter(Function1<A, bool> p) {
return Parsers.select0<Unit, A>(
map((a) => p(a) ? Right(a) : Left(Unit())),
Parsers.fail(),
);
}flatMap() inherited
Sequences this parser with a function that chooses the next parser based on the parsed value.
Inherited from Parser0.
Implementation
Parser0<B> flatMap<B>(Function1<A, Parser0<B>> f) => Parsers.flatMap0(this, f);map() inherited
Transforms the parsed value with f.
Inherited from Parser0.
Implementation
Parser0<B> map<B>(Function1<A, B> f) => Parsers.map0(this, f);mapFilter() inherited
Applies f to the parsed value; succeeds with the Some result or fails (without consuming) when f returns None.
Inherited from Parser0.
Implementation
Parser0<B> mapFilter<B>(Function1<A, Option<B>> f) {
return Parsers.select0<Unit, B>(
map((a) {
return f(a).fold(
() => Left(Unit()),
(b) => Right(b),
);
}),
Parsers.fail(),
);
}noSuchMethod() inherited
Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time errorThis invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.
If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);orElse() inherited
Tries this parser, then that if this one fails without consuming input.
Inherited from Parser0.
Implementation
Parser0<A> orElse(covariant Parser0<A> that) => Parsers.oneOf0(ilist([this, that]));parse() inherited
Runs this parser on str and returns the remaining unparsed input paired with the parsed value, or a ParseError on failure.
Unlike parseAll, trailing input after a successful match is allowed.
Inherited from Parser0.
Implementation
Either<ParseError, (String, A)> parse(String str) {
final state = State(str);
final result = _parseMut(state);
final err = state.error;
final offset = state.offset;
if (err == null) {
return Right((str.substring(offset), result!));
} else {
return Left(
ParseError(
Some(str),
offset,
Expectation.unify(NonEmptyIList.unsafe(err.value.toIList())),
),
);
}
}parseAll() inherited
Runs this parser on str and requires the entire input to be consumed.
Returns the parsed value on success, or a ParseError if the parser fails or if any input remains after a successful match.
Inherited from Parser0.
Implementation
Either<ParseError, A> parseAll(String str) {
final state = State(str);
final result = _parseMut(state);
final err = state.error;
final offset = state.offset;
if (err == null) {
if (result != null && offset == str.length) {
return Right(result);
} else {
return Left(
ParseError(
Some(str),
offset,
NonEmptyIList(Expectation.endOfString(offset, str.length)),
),
);
}
} else {
return Left(
ParseError(
Some(str),
offset,
Expectation.unify(NonEmptyIList.unsafe(err.value.toIList())),
),
);
}
}product() inherited
Runs this parser followed by that, returning both results as a tuple.
Inherited from Parser0.
Implementation
Parser0<(A, B)> product<B>(Parser0<B> that) => Parsers.product0(this, that);productL() inherited
Runs this parser followed by that, discarding the result of that.
Inherited from Parser0.
Implementation
Parser0<A> productL<B>(Parser0<B> that) => product(that.voided).map((t) => t.$1);productR() inherited
Runs this parser followed by that, discarding the result of this parser.
Inherited from Parser0.
Implementation
Parser0<B> productR<B>(Parser0<B> that) => voided.product(that).map((t) => t.$2);surroundedBy() inherited
Matches b, then this parser, then b again, returning only the result of this parser.
Inherited from Parser0.
Implementation
Parser0<A> surroundedBy(Parser<dynamic> b) => between(b, b);toString() inherited
A string representation of this object.
Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.
Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.
Inherited from Object.
Implementation
external String toString();withContext() inherited
Attaches a human-readable context label str to any error produced by this parser, making failure messages easier to diagnose.
Inherited from Parser0.
Implementation
Parser0<A> withContext(String str) => Parsers.withContext0(this, str);Operators
operator ==() inherited
The equality operator.
The default behavior for all Objects is to return true if and only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false.Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
external bool operator ==(Object other);operator |() inherited
Tries this parser, falling back to that if this one fails without consuming input. Alias for orElse.
Inherited from Parser0.
Implementation
Parser0<A> operator |(covariant Parser0<A> that) => orElse(that);