separatedBy method

Parser<List<T>> separatedBy(
  1. Parser other
)

Expects to see an infinite amounts of the pattern, separated by the other pattern.

Use this as a shortcut to parse arrays, parameter lists, etc.

Implementation

Parser<List<T>> separatedBy(Parser other) {
  var suffix = other.then(this).index(1).cast<T>();
  return this.then(suffix.star()).map((r) {
    var preceding =
        r.value.isEmpty ? [] : (r.value[0] == null ? [] : [r.value[0]]);
    var out = new List<T>.from(preceding);
    if (r.value[1] != null) out.addAll(r.value[1] as Iterable<T>);
    return out;
  });
}