diff --git a/packages/combinator/lib/src/combinator/combinator.dart b/packages/combinator/lib/src/combinator/combinator.dart index e2ad9093..4c2f2ab4 100644 --- a/packages/combinator/lib/src/combinator/combinator.dart +++ b/packages/combinator/lib/src/combinator/combinator.dart @@ -190,11 +190,18 @@ abstract class Parser { Parser> separatedBy(Parser other) { var suffix = other.then(this).index(1).cast(); return this.then(suffix.star()).map((r) { - var preceding = - r.value!.isEmpty ? [] : (r.value![0] == null ? [] : [r.value![0]]); - var out = List.from(preceding); - if (r.value![1] != null) out.addAll(r.value![1] as List); - return out; + List? v = r.value; + if (v != null) { + var preceding = + v.isEmpty ? [] : (r.value?[0] == null ? [] : [r.value?[0]]); + var out = List.from(preceding); + if (r.value?[1] != null) { + out.addAll(r.value?[1] as List); + } + return out; + } else { + return List.empty(growable: true); + } }); }