private static Expression ParseOperand(TokensQueue tokens) { tokens.SkipWhiteAndComments(); var token = tokens.Read(); switch (token.Type) { case TokenType.Number: return ParseNumber(ref token, tokens); case TokenType.Literal: return ParseLiteral(ref token, tokens); case TokenType.Hash: return ParseHashColor(ref token, tokens); case TokenType.Minus: return new NegateExpression(ParseOperand(tokens)); case TokenType.OpenParenthesis: var inner = Parse(tokens); tokens.Read(TokenType.CloseParenthesis); return inner; default: throw new TokenException("unexpected token " + token.StringValue, token); } }
private static SelectorExpression ParseOperand(TokensQueue tokens, SelectorExpression parent = null) { tokens.SkipWhiteAndComments(); var token = tokens.Read(); switch (token.Type) { case TokenType.Literal: return ParseTypeSelector(token, tokens); case TokenType.Dot: return ParseClassSelector(token, tokens); case TokenType.Hash: return ParseIdSelector(token, tokens); case TokenType.Colon: return ParsePseudoSelector(token, tokens); case TokenType.OpenSquareBracket: return ParseAttributeSelector(token, tokens); case TokenType.Ampersand: return new ParentSelector(parent); default: throw new TokenException("unexpected token " + token.StringValue, token); } }