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 beforeParser = before;
if (beforeParser != null) {
final beforeContext = beforeParser.parseOn(context);
if (beforeContext.isFailure) {
return beforeContext.failure(beforeContext.message);
}
context = beforeContext;
}
final resultContext = delegate.parseOn(context);
if (resultContext.isFailure) {
return resultContext;
}
context = resultContext;
final afterParser = after;
if (afterParser != null) {
final afterContext = afterParser.parseOn(context);
if (afterContext.isFailure) {
return afterContext.failure(afterContext.message);
}
context = afterContext;
}
return context.success(resultContext.value);
}