Dart DocumentationparsersParseResult<A>

ParseResult<A> class

class ParseResult<A> {
 final bool isSuccess;
 final bool isCommitted;
 /// [:null:] if [:!isSuccess:]
 final A value;
 final String text;
 final Position position;
 final Expectations expectations;

 String get errorMessage {
   final pos = expectations.position;
   final maxSeenChar = (pos.offset < text.length)
       ? "'${text[pos.offset]}'"
       : 'eof';
   final prelude =
       'line ${pos.line}, character ${pos.character}:';
   final expected = expectations.expected;
   if (expected.isEmpty) {
     return '$prelude unexpected $maxSeenChar.';
   } else {
     final or = _humanOr(new List.from(expected));
     return "$prelude expected $or, got $maxSeenChar.";
   }
 }

 ParseResult(this.text, this.expectations, this.position, this.isSuccess,
             this.isCommitted, this.value);

 ParseResult with({String text, Expectations expectations, int position,
                   bool isSuccess, bool isCommitted, Object value}) {
   return new ParseResult(
       ?text         ? text         : this.text,
       ?expectations ? expectations : this.expectations,
       ?position     ? position     : this.position,
       ?isSuccess    ? isSuccess    : this.isSuccess,
       ?isCommitted  ? isCommitted  : this.isCommitted,
       ?value        ? value        : this.value);
 }

 String get _rest => text.substring(position.offset);
 get _shortRest => _rest.length < 10 ? _rest : '${_rest.substring(0, 10)}...';

 toString() {
   final c = isCommitted ? '*' : '';
   return isSuccess
       ? 'success$c: {value: $value, rest: "$_shortRest"}'
       : 'failure$c: {message: $errorMessage, rest: "$_shortRest"}';
 }
}

Constructors

new ParseResult(String text, Expectations expectations, Position position, bool isSuccess, bool isCommitted, A value) #

ParseResult(this.text, this.expectations, this.position, this.isSuccess,
           this.isCommitted, this.value);

Properties

final String errorMessage #

String get errorMessage {
 final pos = expectations.position;
 final maxSeenChar = (pos.offset < text.length)
     ? "'${text[pos.offset]}'"
     : 'eof';
 final prelude =
     'line ${pos.line}, character ${pos.character}:';
 final expected = expectations.expected;
 if (expected.isEmpty) {
   return '$prelude unexpected $maxSeenChar.';
 } else {
   final or = _humanOr(new List.from(expected));
   return "$prelude expected $or, got $maxSeenChar.";
 }
}

final Expectations expectations #

final Expectations expectations;

final bool isCommitted #

final bool isCommitted;

final bool isSuccess #

final bool isSuccess;

final Position position #

final Position position;

final String text #

final String text;

final A value #

null if !isSuccess

final A value;

Methods

toString() #

Returns a string representation of this object.

docs inherited from Object
toString() {
 final c = isCommitted ? '*' : '';
 return isSuccess
     ? 'success$c: {value: $value, rest: "$_shortRest"}'
     : 'failure$c: {message: $errorMessage, rest: "$_shortRest"}';
}

ParseResult with({String text, Expectations expectations, int position, bool isSuccess, bool isCommitted, Object value}) #

ParseResult with({String text, Expectations expectations, int position,
                 bool isSuccess, bool isCommitted, Object value}) {
 return new ParseResult(
     ?text         ? text         : this.text,
     ?expectations ? expectations : this.expectations,
     ?position     ? position     : this.position,
     ?isSuccess    ? isSuccess    : this.isSuccess,
     ?isCommitted  ? isCommitted  : this.isCommitted,
     ?value        ? value        : this.value);
}