"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _parsimmon = _interopRequireDefault(require("parsimmon"));

var _binaryOperator = _interopRequireDefault(require("../abstract/binaryOperator"));

var _unaryOperator = _interopRequireDefault(require("./unaryOperator"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var processBoolean2 = function processBoolean2(x) {
  return x + '=';
};

var processBoolean3 = function processBoolean3(x) {
  return x === 'or' ? '||' : x === 'and' ? '&&' : x;
};

var operatorPrecedenceTable = [['unary', _unaryOperator.default], ['multiplicative', _parsimmon.default.regexp(/[*/%]/)], ['additive', _parsimmon.default.regexp(/[+-]/)], ['boolean1', _parsimmon.default.regexp(/[<>]=?/)], ['boolean2', _parsimmon.default.regexp(/[=!]=/).map(processBoolean2)], ['boolean3', _parsimmon.default.regexp(/(\|\||&&|or|and)/).map(processBoolean3)]];

var _default = operatorPrecedenceTable.slice(1).reduce(function (ParentParser, _ref) {
  var _ref2 = _slicedToArray(_ref, 2),
      parserDecription = _ref2[0],
      Parser = _ref2[1];

  return (0, _binaryOperator.default)(ParentParser, Parser, parserDecription);
}, operatorPrecedenceTable[0][1]);

exports.default = _default;