simpleSelectorSequence method

SimpleSelectorSequence? simpleSelectorSequence(
  1. bool forceCombinatorNone
)

Implementation

SimpleSelectorSequence? simpleSelectorSequence(bool forceCombinatorNone) {
  var combinatorType = TokenKind.COMBINATOR_NONE;
  var thisOperator = false;

  switch (_peek()) {
    case TokenKind.PLUS:
      _eat(TokenKind.PLUS);
      combinatorType = TokenKind.COMBINATOR_PLUS;
      break;
    case TokenKind.GREATER:
      _eat(TokenKind.GREATER);
      combinatorType = TokenKind.COMBINATOR_GREATER;
      break;
    case TokenKind.TILDE:
      _eat(TokenKind.TILDE);
      combinatorType = TokenKind.COMBINATOR_TILDE;
      break;
    case TokenKind.AMPERSAND:
      _eat(TokenKind.AMPERSAND);
      thisOperator = true;
      break;
  }

  // Check if WHITESPACE existed between tokens if so we're descendent.
  if (combinatorType == TokenKind.COMBINATOR_NONE && !forceCombinatorNone) {
    if (_previousToken != null && _previousToken!.end != _peekToken.start) {
      combinatorType = TokenKind.COMBINATOR_DESCENDANT;
    }
  }

  var simpleSel = thisOperator
      ? ElementSelector(
          ThisOperator(),
        )
      : simpleSelector();
  if (simpleSel == null &&
      (combinatorType == TokenKind.COMBINATOR_PLUS ||
          combinatorType == TokenKind.COMBINATOR_GREATER ||
          combinatorType == TokenKind.COMBINATOR_TILDE)) {
    // For "+ &", "~ &" or "> &" a selector sequence with no name is needed
    // so that the & will have a combinator too.  This is needed to
    // disambiguate selector expressions:
    //    .foo&:hover     combinator before & is NONE
    //    .foo &          combinator before & is DESCDENDANT
    //    .foo > &        combinator before & is GREATER
    simpleSel = ElementSelector(Identifier(''));
  }
  if (simpleSel != null) {
    return SimpleSelectorSequence(simpleSel, combinatorType);
  }
  return null;
}