From ab2d8ae3f38fc6ebedb58ad0068c29a55b642fe8 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 28 Jul 2016 17:40:52 -0700 Subject: [PATCH] unify complex --- lib/src/extender.dart | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/src/extender.dart b/lib/src/extender.dart index 6f761eec..4f4fdafa 100644 --- a/lib/src/extender.dart +++ b/lib/src/extender.dart @@ -186,8 +186,8 @@ class Extender { var unified = _unifyComplex(group1, group2); if (unified == null) return null; - if (unified.members.length > 1) return null; - return unified.members.first.members; + if (unified.length > 1) return null; + return unified.first; }); var choices = [[initialCombinator]]; @@ -519,6 +519,24 @@ class Extender { return result; } + List _unifyComplex( + List complex1, List complex2) { + var base1 = complex1.members.last; + var base2 = complex2.members.last; + if (base1 is CompoundSelector && base2 is CompoundSelector) { + var unified = _unifyCompound(base2.components, base1.components); + if (unified == null) return null; + + return weave([ + base1.components.take(base1.components.length - 1).toList(), + base2.components.take(base2.components.length - 1).toList() + ..add(unified) + ]); + } else { + return null; + } + } + CompoundSelector _unifyCompound(List compound1, List compound2) { var result = compound2;