UNPKG

parser-combinator

Version:
73 lines (56 loc) 5.77 kB
'use strict'; 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; }; }(); /* * Parsec * https://github.com/d-plaindoux/parsec * * Copyright (c) 2016 Didier Plaindoux * Licensed under the LGPL2 license. */ var _try = require('../data/try'); var _try2 = _interopRequireDefault(_try); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var Stream = function () { function Stream() { _classCallCheck(this, Stream); } // Stream 'a => number -> number _createClass(Stream, [{ key: 'location', value: function location(index) { return index; } // Stream 'a => number -> Try 'a }, { key: 'get', value: function get(index) { try { if (this.endOfStream(index)) { return _try2.default.failure(new Error('End of stream reached')); } else { return _try2.default.success(this.unsafeGet(index)); } } catch (e) { return _try2.default.failure(e); } } // Stream 'a => [Comparable 'a] -> number -> boolean }, { key: 'subStreamAt', value: function subStreamAt(s, index) { for (var i = 0; i < s.length; i++) { var value = this.get(i + index); if (!value.isSuccess() || value.success() !== s[i]) { return false; } } return true; } }]); return Stream; }(); exports.default = Stream; //# sourceMappingURL=stream.js.map