private static (State, ISyntax) ParseColon(ref CharacterReader r) { var identifier = r.ParseStyleClass(); if (identifier.IsEmpty) { throw new ExpressionParseException(r.Position, "Expected class name, is, nth-child or nth-last-child selector after ':'."); } const string IsKeyword = "is"; const string NotKeyword = "not"; const string NthChildKeyword = "nth-child"; const string NthLastChildKeyword = "nth-last-child"; if (identifier.SequenceEqual(IsKeyword.AsSpan()) && r.TakeIf('(')) { var syntax = ParseType(ref r, new IsSyntax()); Expect(ref r, ')'); return(State.CanHaveType, syntax); } if (identifier.SequenceEqual(NotKeyword.AsSpan()) && r.TakeIf('(')) { var argument = Parse(ref r, ')'); Expect(ref r, ')'); var syntax = new NotSyntax { Argument = argument }; return(State.Middle, syntax); } if (identifier.SequenceEqual(NthChildKeyword.AsSpan()) && r.TakeIf('(')) { var(step, offset) = ParseNthChildArguments(ref r); var syntax = new NthChildSyntax { Step = step, Offset = offset }; return(State.Middle, syntax); } if (identifier.SequenceEqual(NthLastChildKeyword.AsSpan()) && r.TakeIf('(')) { var(step, offset) = ParseNthChildArguments(ref r); var syntax = new NthLastChildSyntax { Step = step, Offset = offset }; return(State.Middle, syntax); } else { return( State.CanHaveType, new ClassSyntax { Class = ":" + identifier.ToString() }); } }
private static (State, ISyntax) ParseColon(ref CharacterReader r) { var identifier = r.ParseIdentifier(); if (identifier.IsEmpty) { throw new ExpressionParseException(r.Position, "Expected class name or is selector after ':'."); } const string IsKeyword = "is"; const string NotKeyword = "not"; if (identifier.SequenceEqual(IsKeyword.AsSpan()) && r.TakeIf('(')) { var syntax = ParseType(ref r, new IsSyntax()); Expect(ref r, ')'); return(State.CanHaveType, syntax); } if (identifier.SequenceEqual(NotKeyword.AsSpan()) && r.TakeIf('(')) { var argument = Parse(ref r, ')'); Expect(ref r, ')'); var syntax = new NotSyntax { Argument = argument }; return(State.Middle, syntax); } else { return( State.CanHaveType, new ClassSyntax { Class = ":" + identifier.ToString() }); } }