Skip to content

Map<A, B> final

finalclassMap<A, B>extendsParser<B>

Inheritance

Object → Parser0<A>Parser<A>Map<A, B>

Constructors

Map()

Map(Parser0<A>parser,BFunction(A)f)
Implementation
dart
Map(this.parser, this.f);

Properties

backtrack no setter inherited

Parser<B>getbacktrack

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 Parser.

Implementation
dart
@override
Parser<A> get backtrack => Parsers.backtrack(this);

f final

finalBFunction(A)f
Implementation
dart
final Function1<A, B> f;

hashCode no setter inherited

intgethashCode

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
dart
external int get hashCode;

not no setter inherited

Parser0<Unit>getnot

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
dart
Parser0<Unit> get not => Parsers.not(this);

opt no setter inherited

Parser0<Option<B>>getopt

Succeeds with Some of the parsed value, or None if this parser fails without consuming input.

Inherited from Parser0.

Implementation
dart
Parser0<Option<A>> get opt =>
    Parsers.oneOf0(ilist([Parsers.map0(this, (a) => a.some), Parsers.pure(none<A>())]));

parser final

finalParser0<A>parser
Implementation
dart
final Parser0<A> parser;

peek no setter inherited

Parser0<Unit>getpeek

Succeeds when this parser would succeed at the current position but consumes no input.

Inherited from Parser0.

Implementation
dart
Parser0<Unit> get peek => Parsers.peek(this);

runtimeType no setter inherited

TypegetruntimeType

A representation of the runtime type of the object.

Inherited from Object.

Implementation
dart
external Type get runtimeType;

soft no setter inherited

Soft<B>getsoft

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 Parser.

Implementation
dart
@override
Soft<A> get soft => Soft(this);

string no setter inherited

Parser<String>getstring

Returns a parser that succeeds with the substring of the input matched by this parser, instead of its original return value.

Inherited from Parser.

Implementation
dart
@override
Parser<String> get string => Parsers.stringP(this);

voided no setter inherited

Parser<Unit>getvoided

Returns a parser that runs this parser and discards the result, producing Unit.

Inherited from Parser.

Implementation
dart
@override
Parser<Unit> get voided => Parsers.voided(this);

with1 no setter inherited

With1<B>getwith1

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
dart
With1<A> get with1 => With1(this);

withString no setter inherited

Parser<Record>getwithString

Returns a parser that produces both the parsed value and the substring of input that was consumed.

Inherited from Parser.

Implementation
dart
@override
Parser<(A, String)> get withString => Parsers.withString(this);

Methods

andThen()

Parser<C>andThen<C>(CFunction(B)g)
Implementation
dart
Parser<C> andThen<C>(Function1<B, C> g) => Map(parser, (A x) => g(f(x)));

as() inherited

Parser<B>as<B>(Bb)

Returns a parser that succeeds with b whenever this parser succeeds, discarding the matched value.

Inherited from Parser.

Implementation
dart
@override
Parser<B> as<B>(B b) => Parsers.as(this, b);

between() inherited

Parser<B>between(Parser0<dynamic>b,Parser0<dynamic>c)

Matches b, then this parser, then c, returning only the result of this parser.

Inherited from Parser.

Implementation
dart
@override
Parser<A> between(Parser0<dynamic> b, Parser0<dynamic> c) =>
    b.voided.with1.product(product(c.voided)).map((tuple) => tuple.$2.$1);

eitherOr() inherited

Parser<Either<B,B>>eitherOr<B>(Parser<B>pb)

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 Parser.

Implementation
dart
@override
Parser<Either<B, A>> eitherOr<B>(Parser<B> pb) => Parsers.eitherOr(this, pb);

filter() inherited

Parser<B>filter(boolFunction(B)p)

Succeeds with the parsed value only when p returns true; fails (without consuming) otherwise.

Inherited from Parser.

Implementation
dart
@override
Parser<A> filter(Function1<A, bool> p) {
  return Parsers.select<Unit, A>(
    map((a) => p(a) ? Right(a) : Left(Unit())),
    Parsers.fail(),
  );
}

flatMap() inherited

Parser<B>flatMap<B>(Parser0<B>Function(B)f)

Sequences this parser with a function that chooses the next parser based on the parsed value.

Inherited from Parser.

Implementation
dart
@override
Parser<B> flatMap<B>(Function1<A, Parser0<B>> f) => Parsers.flatMap10(this, f);

map() inherited

Parser<C>map<B>(BFunction(B)f)

Transforms the parsed value with f.

Inherited from Parser.

Implementation
dart
@override
Parser<B> map<B>(Function1<A, B> f) => Parsers.map(this, f);

mapFilter() inherited

Parser<B>mapFilter<B>(Option<B>Function(B)f)

Applies f to the parsed value; succeeds with the Some result or fails (without consuming) when f returns None.

Inherited from Parser.

Implementation
dart
@override
Parser<B> mapFilter<B>(Function1<A, Option<B>> f) {
  return Parsers.select<Unit, B>(
    map((a) {
      return f(a).fold(
        () => Left(Unit()),
        (b) => Right(b),
      );
    }),
    Parsers.fail(),
  );
}

noSuchMethod() inherited

dynamicnoSuchMethod(Invocationinvocation)

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:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This 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:

dart
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
dart
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);

orElse() inherited

Parser<B>orElse(Parser<B>that)

Tries this parser, then that if this one fails without consuming input.

Inherited from Parser.

Implementation
dart
@override
Parser<A> orElse(Parser<A> that) => Parsers.oneOf(ilist([this, that]));

parse() inherited

Either<ParseError,Record>parse(Stringstr)

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
dart
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

Either<ParseError,B>parseAll(Stringstr)

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
dart
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

Parser<Record>product<B>(Parser0<B>that)

Runs this parser followed by that, returning both results as a tuple.

Inherited from Parser.

Implementation
dart
@override
Parser<(A, B)> product<B>(Parser0<B> that) => Parsers.product10(this, that);

productL() inherited

Parser<B>productL<B>(Parser0<B>that)

Runs this parser followed by that, discarding the result of that.

Inherited from Parser.

Implementation
dart
@override
Parser<A> productL<B>(Parser0<B> that) => product(that.voided).map((t) => t.$1);

productR() inherited

Parser<B>productR<B>(Parser0<B>that)

Runs this parser followed by that, discarding the result of this parser.

Inherited from Parser.

Implementation
dart
@override
Parser<B> productR<B>(Parser0<B> that) => voided.product(that).map((t) => t.$2);

rep() inherited

Parser<NonEmptyIList<B>>rep({int?min,int?max})

Repeats this parser one or more times, collecting results into a NonEmptyIList. Pass min (default 1) or max to control the count.

Inherited from Parser.

Implementation
dart
Parser<NonEmptyIList<A>> rep({int? min, int? max}) =>
    repAs(Accumulator.nel(), min: min, max: max);

rep0() inherited

Parser0<IList<B>>rep0({int?min,int?max})

Repeats this parser zero or more times, collecting results into an IList. Pass min to require at least that many matches; pass max to cap the number of matches.

Inherited from Parser.

Implementation
dart
Parser0<IList<A>> rep0({int? min, int? max}) {
  if (min == null || min == 0) {
    return repAs0(Accumulator0.ilist(), max: max);
  } else {
    return repAs(Accumulator0.ilist(), min: min, max: max);
  }
}

repAs() inherited

Parser<B>repAs<B>(Accumulator<B,B>acc, {int?min,int?max,});

Repeats this parser one or more times (or at least min times), accumulating results with acc. Pass max to cap repetitions.

Inherited from Parser.

Implementation
dart
Parser<B> repAs<B>(Accumulator<A, B> acc, {int? min, int? max}) =>
    Parsers.repAs(this, acc, min ?? 1, max: max);

repAs0() inherited

Parser0<B>repAs0<B>(Accumulator0<B,B>acc, {int?max})

Repeats this parser zero or more times, accumulating results with acc. Pass max to cap the number of repetitions.

Inherited from Parser.

Implementation
dart
Parser0<B> repAs0<B>(Accumulator0<A, B> acc, {int? max}) => Parsers.repAs0(this, acc, max: max);

repExactlyAs() inherited

Parser<B>repExactlyAs<B>(inttimes,Accumulator<B,B>acc)

Repeats this parser exactly times times, accumulating with acc.

Inherited from Parser.

Implementation
dart
Parser<B> repExactlyAs<B>(int times, Accumulator<A, B> acc) =>
    Parsers.repExactlyAs(this, times, acc);

repSep() inherited

Parser<NonEmptyIList<B>>repSep(Parser0<dynamic>sep, {int?min,int?max,});

Repeats this parser one or more times with sep between each element, collecting results into a NonEmptyIList. Pass min/max to control count.

Inherited from Parser.

Implementation
dart
Parser<NonEmptyIList<A>> repSep(Parser0<dynamic> sep, {int? min, int? max}) =>
    Parsers.repSep(this, sep, min: min ?? 1, max: max);

repSep0() inherited

Parser0<IList<B>>repSep0(Parser0<dynamic>sep, {int?min,int?max,});

Repeats this parser zero or more times with sep between each element, collecting results into an IList. Pass min/max to control count.

Inherited from Parser.

Implementation
dart
Parser0<IList<A>> repSep0(Parser0<dynamic> sep, {int? min, int? max}) =>
    Parsers.repSep0(this, sep, min: min ?? 0, max: max);

repUntil() inherited

Parser<NonEmptyIList<B>>repUntil(Parser0<dynamic>sep)

Repeats this parser one or more times, stopping when sep matches at the current position.

Inherited from Parser.

Implementation
dart
Parser<NonEmptyIList<A>> repUntil(Parser0<dynamic> sep) => Parsers.repUntil(this, sep);

repUntil0() inherited

Parser0<IList<B>>repUntil0(Parser0<dynamic>sep)

Repeats this parser zero or more times, stopping when sep matches at the current position.

Inherited from Parser.

Implementation
dart
Parser0<IList<A>> repUntil0(Parser0<dynamic> sep) => Parsers.repUntil0(this, sep);

repUntilAs() inherited

Parser<B>repUntilAs<B>(Parser0<dynamic>end,Accumulator<B,B>acc,);

Repeats this parser one or more times until end matches, accumulating with acc.

Inherited from Parser.

Implementation
dart
Parser<B> repUntilAs<B>(Parser0<dynamic> end, Accumulator<A, B> acc) =>
    Parsers.repUntilAs(this, end, acc);

repUntilAs0() inherited

Parser0<B>repUntilAs0<B>(Parser0<dynamic>end,Accumulator0<B,B>acc,);

Repeats this parser zero or more times until end matches, accumulating with acc.

Inherited from Parser.

Implementation
dart
Parser0<B> repUntilAs0<B>(Parser0<dynamic> end, Accumulator0<A, B> acc) =>
    Parsers.repUntilAs0(this, end, acc);

surroundedBy() inherited

Parser0<B>surroundedBy(Parser<dynamic>b)

Matches b, then this parser, then b again, returning only the result of this parser.

Inherited from Parser.

Implementation
dart
@override
Parser0<A> surroundedBy(Parser<dynamic> b) => between(b, b);

toString() inherited

StringtoString()

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
dart
external String toString();

withContext() inherited

Parser<B>withContext(Stringstr)

Attaches a human-readable context label str to any error produced by this parser, making failure messages easier to diagnose.

Inherited from Parser.

Implementation
dart
@override
Parser<A> withContext(String str) => Parsers.withContext(this, str);

Operators

operator ==() inherited

booloperator ==(Objectother)

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 == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must 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
dart
external bool operator ==(Object other);

operator |() inherited

Parser<B>operator |(Parser<B>that)

Tries this parser, falling back to that if this one fails without consuming input. Alias for orElse.

Inherited from Parser.

Implementation
dart
@override
Parser<A> operator |(Parser<A> that) => orElse(that);