conditions method

Node conditions ()

Function to be passed to ParserInput.expect().

Search for conditions like:

(@a = white) in when (@a = white) { } or
when (@b = 1), (@c = 2) ... { }

Implementation

Node conditions() {
  Node a;
  Node b;
  Condition condition;
  final int index = parserInput.i;

  a = this.condition(needsParens: true);
  if (a != null) {
    while (true) {
      if (!parserInput.peek(_reConditions) ||
          (parserInput.$char(',') == null)) {
        break;
      }
      b = this.condition(needsParens: true);
      if (b == null) break;

      condition = Condition('or', condition ?? a, b, index: index);
    }
    return condition ?? a;
  }

  return null;

// 3.5.3 20180708
//  conditions: function () {
//      var a, b, index = parserInput.i, condition;
//
//      a = this.condition(true);
//      if (a) {
//          while (true) {
//              if (!parserInput.peek(/^,\s*(not\s*)?\(/) || !parserInput.$char(',')) {
//                  break;
//              }
//              b = this.condition(true);
//              if (!b) {
//                  break;
//              }
//              condition = new(tree.Condition)('or', condition || a, b, index);
//          }
//          return condition || a;
//      }
//  },
}