combinator method

Combinator combinator ()

Combinators combine elements together, in a Selector.

Because the parser isn't white-space sensitive, special care has to be taken, when parsing the descendant combinator, , as it's an empty space. We have to check the previous character in the input, to see if it's a character. More info on how we deal with this in combinator.dart.

Implementation

Combinator combinator() {
  String c = parserInput.currentChar();

  if (c == '/') {
    parserInput.save();
    final String slashedCombinator =
        parserInput.$re(_combinatorRegExp1); //i-nsensitive
    if (slashedCombinator != null) {
      parserInput.forget();
      return Combinator(slashedCombinator);
    }
    parserInput.restore();
  }

  if (c == '>' || c == '+' || c == '~' || c == '|' || c == '^') {
    parserInput.i++;
    if (c == '^' && parserInput.currentChar() == '^') {
      c = '^^';
      parserInput.i++;
    }
    while (parserInput.isWhitespacePos()) {
      parserInput.i++;
    }
    return Combinator(c);
  } else if (parserInput.isWhitespacePrevPos()) {
    return Combinator(' ');
  } else {
    return Combinator(null);
  }

//2.2.0
//  combinator: function () {
//      var c = parserInput.currentChar();
//
//      if (c === '/') {
//          parserInput.save();
//          var slashedCombinator = parserInput.$re(/^\/[a-z]+\//i);
//          if (slashedCombinator) {
//              parserInput.forget();
//              return new(tree.Combinator)(slashedCombinator);
//          }
//          parserInput.restore();
//      }
//
//      if (c === '>' || c === '+' || c === '~' || c === '|' || c === '^') {
//          parserInput.i++;
//          if (c === '^' && parserInput.currentChar() === '^') {
//              c = '^^';
//              parserInput.i++;
//          }
//          while (parserInput.isWhitespace()) { parserInput.i++; }
//          return new(tree.Combinator)(c);
//      } else if (parserInput.isWhitespace(-1)) {
//          return new(tree.Combinator)(" ");
//      } else {
//          return new(tree.Combinator)(null);
//      }
//  }
}