addition method

Node addition ()

Search for:

multiplication operator multiplicationN
operator is + | -
multiplicationN is 0 | more multiplication

Example:

@a
@a + @b
@a + @b - 2

Implementation

Node addition() {
  Node a;
  Node m;
  String op;
  Operation operation;
  bool isSpaced;

  m = multiplication();
  if (m != null) {
    isSpaced = parserInput.isWhitespacePrevPos();
    while (true) {
      op = parserInput.$re(_additionRegExp1);
      if (op == null && !isSpaced) op = parserInput.$char('+');
      if (op == null && !isSpaced) op = parserInput.$char('-');
      if (op == null) break;

      a = multiplication();
      if (a == null) break;

      m.parensInOp = true;
      a.parensInOp = true;
      operation =
          Operation(op, <Node>[operation ?? m, a], isSpaced: isSpaced);
      isSpaced = parserInput.isWhitespacePrevPos();
    }
    return operation ?? m;
  }
  return null;

//2.2.0
//  addition: function () {
//      var m, a, op, operation, isSpaced;
//      m = this.multiplication();
//      if (m) {
//          isSpaced = parserInput.isWhitespace(-1);
//          while (true) {
//              op = parserInput.$re(/^[-+]\s+/) || (!isSpaced && (parserInput.$char('+') || parserInput.$char('-')));
//              if (!op) {
//                  break;
//              }
//              a = this.multiplication();
//              if (!a) {
//                  break;
//              }
//
//              m.parensInOp = true;
//              a.parensInOp = true;
//              operation = new(tree.Operation)(op, [operation || m, a], isSpaced);
//              isSpaced = parserInput.isWhitespace(-1);
//          }
//          return operation || m;
//      }
//  }
}