mapWithPosition<R> method

Parser<R> mapWithPosition<R>(
  1. R mapper(
    1. T value,
    2. int start,
    3. 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;
    }
  });
}