parseLineRangeChunk function

LineRange? parseLineRangeChunk(
  1. String sel
)

Parses a single N, N-M, N-, N+K, or ..-aliased (N..M, N..) chunk. Returns null when sel is not range-shaped; throws StateError on invalid bounds (omp's ToolError messages, verbatim).

Implementation

LineRange? parseLineRangeChunk(String sel) {
  final match = _lineRangeChunkRe.firstMatch(sel);
  if (match == null) return null;
  final rawStart = int.parse(match.group(1)!);
  if (rawStart < 1) {
    throw StateError(
      'Line selector 0 is invalid; lines are 1-indexed. Use :1.',
    );
  }
  // `..` is a forgiving alias for `-` (e.g. `2724..2727` == `2724-2727`).
  final sep = match.group(2) == '..' ? '-' : match.group(2);
  final rhsText = match.group(3);
  final rhs = rhsText != null ? int.parse(rhsText) : null;
  return LineRange(rawStart, _chunkEnd(rawStart, sep, rhs));
}