parseOn method
Primitive method doing the actual parsing.
The method is overridden in concrete subclasses to implement the
parser specific logic. The methods takes a parse context
and
returns the resulting context, which is either a Success or
Failure context.
Implementation
@override
Result<R> parseOn(Context context) {
final buffer = context.buffer;
// Trim the left part:
final before = _trim(left, buffer, context.position);
if (before != context.position) {
context = Context(buffer, before);
}
// Consume the delegate:
final result = delegate.parseOn(context);
if (result.isFailure) {
return result;
}
// Trim the right part:
final after = _trim(right, buffer, result.position);
return after == result.position
? result
: result.success(result.value, after);
}