simpleSelector method

SimpleSelector? simpleSelector()

Simple selector grammar:

simple_selector_sequence
   : [ type_selector | universal ]
     [ HASH | class | attrib | pseudo | negation ]*
   | [ HASH | class | attrib | pseudo | negation ]+
type_selector
   : [ namespace_prefix ]? element_name
namespace_prefix
   : [ IDENT | '*' ]? '|'
element_name
   : IDENT
universal
   : [ namespace_prefix ]? '*'
class
   : '.' IDENT

Implementation

SimpleSelector? simpleSelector() {
  // TODO(terry): Natalie makes a good point parsing of namespace and element
  //              are essentially the same (asterisk or identifier) other
  //              than the error message for element.  Should consolidate the
  //              code.
  // TODO(terry): Need to handle attribute namespace too.
  dynamic first;
  switch (_peek()) {
    case TokenKind.ASTERISK:
      // Mark as universal namespace.
      _next();
      first = Wildcard();
      break;
    case TokenKind.IDENTIFIER:
      first = identifier();
      break;
    default:
      // Expecting simple selector.
      // TODO(terry): Could be a synthesized token like value, etc.
      if (TokenKind.isKindIdentifier(_peek())) {
        first = identifier();
      } else if (_peekKind(TokenKind.SEMICOLON)) {
        // Can't be a selector if we found a semi-colon.
        return null;
      }
      break;
  }

  if (_maybeEat(TokenKind.NAMESPACE)) {
    _next();
    return null;
  } else if (first != null) {
    return ElementSelector(first);
  } else {
    // Check for HASH | class | attrib | pseudo | negation
    return simpleSelectorTail();
  }
}