element method

Element element ()

A Selector Element

div
+ h1
#socks
input[type="text"]

Elements are the building blocks for Selectors, they are made out of a Combinator (see combinator rule), and an element name, such as a tag a class, or *.

Implementation

Element element() {
  Combinator c;
  dynamic e; //String or Node
  final int index = parserInput.i;
  Selector v;

  c = combinator();

  e = parserInput.$re(_elementRegExp1) ??
      parserInput.$re(_elementRegExp2) ??
      parserInput.$char('*') ??
      parserInput.$char('&') ??
      attribute() ??
      parserInput.$re(_elementRegExp3) ??
      parserInput.$re(_elementRegExp4) ??
      entities.variableCurly();

  if (e == null) {
    parserInput.save();
    if (parserInput.$char('(') != null) {
      if ((v = selector(isLess: false)) != null &&
          parserInput.$char(')') != null) {
        e = Paren(v);
        parserInput.forget();
      } else {
        parserInput.restore("Missing closing ')'");
      }
    } else {
      parserInput.forget();
    }
  }

  return (e != null)
      ? Element(c, e,
          isVariable: e is Variable, index: index, currentFileInfo: fileInfo)
      : null;

// 3.5.0.beta 20180625
//  element: function () {
//      var e, c, v, index = parserInput.i;
//
//      c = this.combinator();
//
//      e = parserInput.$re(/^(?:\d+\.\d+|\d+)%/) ||
//          parserInput.$re(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) ||
//          parserInput.$char('*') || parserInput.$char('&') || this.attribute() ||
//          parserInput.$re(/^\([^&()@]+\)/) ||  parserInput.$re(/^[\.#:](?=@)/) ||
//          this.entities.variableCurly();
//
//      if (!e) {
//          parserInput.save();
//          if (parserInput.$char('(')) {
//              if ((v = this.selector(false)) && parserInput.$char(')')) {
//                  e = new(tree.Paren)(v);
//                  parserInput.forget();
//              } else {
//                  parserInput.restore('Missing closing \')\'');
//              }
//          } else {
//              parserInput.forget();
//          }
//      }
//
//      if (e) { return new(tree.Element)(c, e, e instanceof tree.Variable, index, fileInfo); }
//  },
}