@masala/parser
Version:
106 lines (92 loc) • 3.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.isTuple = isTuple;
exports.tuple = tuple;
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/*
* Parsec
* https://github.com/d-plaindoux/parsec
*
* Copyright (c) 2015-2016 Didier Plaindoux
* Licensed under the LGPL2 license.
*/
var NEUTRAL = exports.NEUTRAL = Symbol('MASALA_NEUTRAL');
var Tuple = exports.Tuple = function () {
function Tuple(array) {
_classCallCheck(this, Tuple);
if (array === undefined) {
array = [];
}
this.value = array;
}
_createClass(Tuple, [{
key: 'at',
value: function at(index) {
return this.value[index];
}
}, {
key: 'array',
value: function array() {
return [].concat(_toConsumableArray(this.value));
}
}, {
key: 'single',
value: function single() {
return this.value[0];
}
}, {
key: 'first',
value: function first() {
return this.value[0];
}
}, {
key: 'last',
value: function last() {
return this.value[this.size() - 1];
}
}, {
key: 'join',
value: function join() {
var j = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
return this.value.join(j);
}
}, {
key: 'append',
value: function append(element) {
if (element === NEUTRAL) {
return new Tuple([].concat(_toConsumableArray(this.value)));
}
if (isTuple(element)) {
return new Tuple([].concat(_toConsumableArray(this.value), _toConsumableArray(element.value)));
}
// single element
return new Tuple([].concat(_toConsumableArray(this.value), [element]));
}
}, {
key: 'isEmpty',
value: function isEmpty() {
return this.size() === 0;
}
}, {
key: 'size',
value: function size() {
return this.value.length;
}
}]);
return Tuple;
}();
function isTuple(object) {
return object instanceof Tuple;
}
function tuple(array) {
if (array === undefined) {
return new Tuple([]);
} else {
return new Tuple(array);
}
}
//# sourceMappingURL=tuple.js.map