atomicCondition method

Condition atomicCondition ({bool needsParens: false })

The simplest condition, such as

@a > @b

More complex conditions have atomic conditions inside:

((@a = true) and (@b = true))

Syntax:

LeftValue operator RightValue
Value is addition | keyword | quoted
operator is  >= | <= | => |  =< | > | < | =

also:

Value
Example: @a  is the same as @a = true

Implementation

Condition atomicCondition({bool needsParens = false}) {
  Node a;
  Node b;
  Condition c;
  final int index = parserInput.i;
  String op;

  // function definition
  Node cond() =>
      addition() ??
      entities.keyword() ??
      entities.quoted() ??
      entities.mixinLookup();

  a = cond();

  if (a != null) {
    if (parserInput.$char('>') != null) {
      if (parserInput.$char('=') != null) {
        op = '>=';
      } else {
        op = '>';
      }
    } else if (parserInput.$char('<') != null) {
      if (parserInput.$char('=') != null) {
        op = '<=';
      } else {
        op = '<';
      }
    } else if (parserInput.$char('=') != null) {
      if (parserInput.$char('>') != null) {
        op = '=>';
      } else if (parserInput.$char('<') != null) {
        op = '=<';
      } else {
        op = '=';
      }
    }

    if (op != null) {
      b = cond();

      if (b != null) {
        c = Condition(op, a, b, index: index);
      } else {
        parserInput.error('expected expression');
      }
    } else {
      c = Condition('=', a, Keyword.True(), index: index);
    }
    return c;
  }
  return null;

// 3.5.3 20180708
//  atomicCondition: function (needsParens) {
//      var entities = this.entities, index = parserInput.i, a, b, c, op;
//
//      function cond() {
//          return this.addition() || entities.keyword() || entities.quoted() || entities.mixinLookup();
//      }
//      cond = cond.bind(this);
//
//      a = cond();
//      if (a) {
//          if (parserInput.$char('>')) {
//              if (parserInput.$char('=')) {
//                  op = '>=';
//              } else {
//                  op = '>';
//              }
//          } else
//          if (parserInput.$char('<')) {
//              if (parserInput.$char('=')) {
//                  op = '<=';
//              } else {
//                  op = '<';
//              }
//          } else
//          if (parserInput.$char('=')) {
//              if (parserInput.$char('>')) {
//                  op = '=>';
//              } else if (parserInput.$char('<')) {
//                  op = '=<';
//              } else {
//                  op = '=';
//              }
//          }
//          if (op) {
//              b = cond();
//              if (b) {
//                  c = new(tree.Condition)(op, a, b, index, false);
//              } else {
//                  error('expected expression');
//              }
//          } else {
//              c = new(tree.Condition)('=', a, new(tree.Keyword)('true'), index, false);
//          }
//          return c;
//      }
//  },
}