conditionAnd method

Condition conditionAnd (
  1. {bool needsParens: false}
)

Search for conditions such as:

(@a = white)
(@a = white) and (@b = black) and ...

Implementation

Condition conditionAnd({bool needsParens = false}) {
  // inside functions
  Condition insideCondition() {
    final cond = negatedCondition(needsParens: needsParens) ??
        parenthesisCondition(needsParens: needsParens);
    if (cond == null && !needsParens) {
      return atomicCondition(needsParens: needsParens);
    }
    return cond;
  }

  String and() => parserInput.$str('and');

  // code
  var result = insideCondition();
  if (result == null) return null;

  final logical = and();
  if (logical != null) {
    final next = conditionAnd(needsParens: needsParens);
    if (next != null) {
      result = Condition(logical, result, next);
    } else {
      return null;
    }
  }
  return result;

// 3.5.3 20180708
//  conditionAnd: function (needsParens) {
//      var result, logical, next, self = this;
//      function insideCondition() {
//          var cond = self.negatedCondition(needsParens) || self.parenthesisCondition(needsParens);
//          if (!cond && !needsParens) {
//              return self.atomicCondition(needsParens);
//          }
//          return cond;
//      }
//      function and() {
//          return parserInput.$str('and');
//      }
//
//      result = insideCondition();
//      if (!result) {
//          return ;
//      }
//      logical = and();
//      if (logical) {
//          next = this.conditionAnd(needsParens);
//          if (next) {
//              result = new(tree.Condition)(logical, result, next);
//          } else {
//              return ;
//          }
//      }
//      return result;
//  },
}