/// <summary> /// TODO: Added quick fix for multipule mixins, but need to add mixins with variables which will changes things a bit /// </summary> /// <param name="node"></param> /// <param name="element"></param> // private void OldMixin(PegNode node, Element element) // { // var root = element.GetRoot(); // foreach (var el in Selectors(node.child_, els => els)) // root = root.Descend(el.Selector, el); // if (root.Rules != null) element.Rules.AddRange(root.Rules); // } private void Mixin(PegNode node, Element element) { var root = element.GetRoot(); var rules = new List<INode>(); var selectors = Selectors(node.child_, els => els); if (selectors.Count() > 1) { foreach (var el in selectors) root = root.Descend(el.Selector, el); if (root.Rules != null) element.Rules.AddRange(root.Rules); } else { var el = selectors.First(); foreach (var mixinElement in root.Nearests(el.Name)) { if (mixinElement.Rules != null) rules.AddRange(mixinElement.Rules); } element.Rules.AddRange(rules); } }
/// <summary> /// ruleset: selectors [{] ws prsimary ws [}] ws / ws selectors ';' ws; /// </summary> /// <param name="node"></param> /// <param name="element"></param> private void RuleSet(PegNode node, Element element) { if (node.id_.ToEnLess() == EnLess.standard_ruleset) { node = node.child_; var elements = Selectors(node, element, els => StandardSelectors(element, els)); foreach (var el in elements) Primary(node.next_, el); } else if (node.id_.ToEnLess() == EnLess.mixin_ruleset) { node = node.child_; var elements = Selectors(node, element, els => els); foreach (var el in elements){ var root = element.GetRoot(); var rules = root.Descend(el.Selector, el).Rules; element.Rules.AddRange(rules); } } }