public virtual void VisitSimpleSelector(CssSimpleSelector selector) { switch (selector?.SimpleSelectorType) { case CssSimpleSelectorType.TypeSelector: VisitTypeSelector(selector); break; case CssSimpleSelectorType.UniversalSelector: VisitUniversalSelector(selector); break; case CssSimpleSelectorType.ClassSelector: VisitClassSelector(selector); break; case CssSimpleSelectorType.IdSelector: VisitIdSelector(selector); break; case null: DefaultVisit(null); break; default: throw new ArgumentOutOfRangeException(nameof(selector), $"Unknown simple selector type '{selector.SimpleSelectorType}'"); } DefaultVisitList(selector?.AttributeSelectors); }
private static bool TryParseSimpleSelector(CssStringStreamReader reader, out CssSimpleSelector selector) { selector = null; reader.SkipWhitespaceAndComments(); switch (reader.CurrentChar) { case '#': reader.Advance(); return (reader.TryReadIdentifier(out var id) && TryParseSimpleSelector(reader, CssSimpleSelectorType.IdSelector, new CssQualifiedName(id), out selector)); case '.': reader.Advance(); return (reader.TryReadIdentifier(out var className) && TryParseSimpleSelector(reader, CssSimpleSelectorType.ClassSelector, new CssQualifiedName(className), out selector)); case '*': reader.Advance(); return(TryParseUniversalSelector(reader, out selector)); case '[': case ':': return(TryParseUniversalSelector(reader, out selector)); default: return (reader.TryReadQualifiedName(out var typeName) && TryParseSimpleSelector(reader, CssSimpleSelectorType.TypeSelector, typeName, out selector)); } }
private static bool TryParseSimpleSelector(CssStringStreamReader reader, CssSimpleSelectorType simpleSelectorType, CssQualifiedName name, out CssSimpleSelector selector) { var attributeSelectors = ParseAttributeSelectors(reader); var pseudoClasses = ParsePseudoClasses(reader); if (attributeSelectors == null || pseudoClasses == null) { selector = null; return(false); } selector = new CssSimpleSelector(simpleSelectorType, name, attributeSelectors, pseudoClasses); return(true); }
public virtual void VisitUniversalSelector(CssSimpleSelector selector) => DefaultVisit(selector);
public virtual void VisitTypeSelector(CssSimpleSelector selector) => DefaultVisit(selector);
private static bool TryParseUniversalSelector(CssStringStreamReader reader, out CssSimpleSelector selector) => TryParseSimpleSelector(reader, CssSimpleSelectorType.UniversalSelector, new CssQualifiedName("*"), out selector);