mapWithPosition<R> method
Parser<R>
mapWithPosition<
R>( - R mapper(
- T value,
- int start,
- int end
)
)
Implementation
Parser<R> mapWithPosition<R>(R Function(T value, int start, int end) mapper) {
return (position() & flatten()).map((values) {
final start = values[0] as int;
final text = values[1] as String;
final end = start + text.length;
// Parse the inner parser again to get the value
final innerResult = parse(text);
if (innerResult is Success) {
return mapper(innerResult.value, start, end);
}
else {
throw innerResult;
}
});
}