Fixed null safety

This commit is contained in:
thomashii 2021-03-21 08:44:06 +08:00
parent 3dadedaf20
commit 9c2f0cfa28

View file

@ -190,11 +190,18 @@ abstract class Parser<T> {
Parser<List<T>> separatedBy(Parser other) { Parser<List<T>> separatedBy(Parser other) {
var suffix = other.then(this).index(1).cast<T>(); var suffix = other.then(this).index(1).cast<T>();
return this.then(suffix.star()).map((r) { return this.then(suffix.star()).map((r) {
List<dynamic>? v = r.value;
if (v != null) {
var preceding = var preceding =
r.value!.isEmpty ? [] : (r.value![0] == null ? [] : [r.value![0]]); v.isEmpty ? [] : (r.value?[0] == null ? [] : [r.value?[0]]);
var out = List<T>.from(preceding); var out = List<T>.from(preceding);
if (r.value![1] != null) out.addAll(r.value![1] as List<T>); if (r.value?[1] != null) {
out.addAll(r.value?[1] as List<T>);
}
return out; return out;
} else {
return List<T>.empty(growable: true);
}
}); });
} }