public static Selector Parse(string str) { Selector result = new Selector(); SelectorReader reader = new SelectorReader(str); SelectorCombinator combinator = null; SimpleSelectorChain simpleSelectors = new SimpleSelectorChain(); while (!reader.EndOfStream) { switch (reader.Status) { case SelectorReader.ReadStatus.Combinator: result.Add(combinator, simpleSelectors); combinator = reader.ReadCombinator(); simpleSelectors = new SimpleSelectorChain(); break; case SelectorReader.ReadStatus.SimpleSelector: SimpleSelector simpleSelector = reader.ReadSimpleSelector(); if (simpleSelector.Type == SelectorType.PseudoElement) { result.PseudoElementSelector = simpleSelector; } simpleSelectors.Add(simpleSelector); break; } } result.Add(combinator, simpleSelectors); return result; }
public void Add(SelectorCombinator combinator, SimpleSelectorChain selector) { if (Chain.Count > 0 && combinator == null) throw new ArgumentNullException("Combinator could not be null if selector is not in first node of chain."); Chain.Add(new Tuple<SelectorCombinator, SimpleSelectorChain>(combinator, selector)); }