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<String> parseOn(Context context) {
final buffer = context.buffer;
final start = context.position;
final end = buffer.length;
var position = start;
var count = 0;
while (count < min) {
if (position >= end || !predicate.test(buffer.codeUnitAt(position))) {
return context.failure(message, position);
}
position++;
count++;
}
while (position < end && count < max) {
if (!predicate.test(buffer.codeUnitAt(position))) {
break;
}
position++;
count++;
}
return context.success(buffer.substring(start, position), position);
}