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 copy({String text, Expectations expectations, int position,
bool isSuccess, bool isCommitted,
Object value: const Undefined()}) {
return new ParseResult(
(text != null) ? text : this.text,
(expectations != null) ? expectations : this.expectations,
(position != null) ? position : this.position,
(isSuccess != null) ? isSuccess : this.isSuccess,
(isCommitted != null) ? isCommitted : this.isCommitted,
(value != const Undefined()) ? 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) #
Creates a new Object instance.
Object instances have no meaningful state, and are only useful
through their identity. An Object instance is equal to itself
only.
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 bool isCommitted #
final bool isSuccess #
final A value #
null
if !isSuccess
final A value
Methods
ParseResult copy({String text, Expectations expectations, int position, bool isSuccess, bool isCommitted, Object value: const Undefined()}) #
ParseResult copy({String text, Expectations expectations, int position,
bool isSuccess, bool isCommitted,
Object value: const Undefined()}) {
return new ParseResult(
(text != null) ? text : this.text,
(expectations != null) ? expectations : this.expectations,
(position != null) ? position : this.position,
(isSuccess != null) ? isSuccess : this.isSuccess,
(isCommitted != null) ? isCommitted : this.isCommitted,
(value != const Undefined()) ? value : this.value);
}
dynamic toString() #
Returns a string representation of this object.
toString() {
final c = isCommitted ? '*' : '';
return isSuccess
? 'success$c: {value: $value, rest: "$_shortRest"}'
: 'failure$c: {message: $errorMessage, rest: "$_shortRest"}';
}