Comparing version 0.6.16 to 0.7.0
@@ -16,2 +16,6 @@ # Changelog | ||
# 0.7.0 | ||
Upgrade `peerDependencies` to latest `fp-ts` (2.14.0), #60 | ||
# 0.6.16 | ||
@@ -18,0 +22,0 @@ |
@@ -6,3 +6,3 @@ import * as P from './Parser' | ||
*/ | ||
export declare type Char = string | ||
export type Char = string | ||
/** | ||
@@ -9,0 +9,0 @@ * The `char` parser constructor returns a parser which matches only the |
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { not } from 'fp-ts/es6/function'; | ||
import { monoidString } from 'fp-ts/es6/Monoid'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import { pipe } from 'fp-ts/es6/function'; | ||
import { not } from 'fp-ts/es6/Predicate'; | ||
import { Monoid } from 'fp-ts/es6/string'; | ||
import * as P from './Parser'; | ||
var maybe = P.maybe(monoidString); | ||
var maybe = P.maybe(Monoid); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -20,3 +20,3 @@ // constructors | ||
export var char = function (c) { | ||
return P.expected(P.sat(function (s) { return s === c; }), "\"" + c + "\""); | ||
return P.expected(P.sat(function (s) { return s === c; }), "\"".concat(c, "\"")); | ||
}; | ||
@@ -31,3 +31,3 @@ /** | ||
export var notChar = function (c) { | ||
return P.expected(P.sat(function (c1) { return c1 !== c; }), "anything but \"" + c + "\""); | ||
return P.expected(P.sat(function (c1) { return c1 !== c; }), "anything but \"".concat(c, "\"")); | ||
}; | ||
@@ -42,3 +42,3 @@ var isOneOf = function (s, c) { return s.indexOf(c) !== -1; }; | ||
export var oneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return isOneOf(s, c); }), "One of \"" + s + "\""); | ||
return P.expected(P.sat(function (c) { return isOneOf(s, c); }), "One of \"".concat(s, "\"")); | ||
}; | ||
@@ -52,3 +52,3 @@ /** | ||
export var notOneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of " + JSON.stringify(s)); | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of ".concat(JSON.stringify(s))); | ||
}; | ||
@@ -55,0 +55,0 @@ // ------------------------------------------------------------------------------------- |
@@ -1,4 +0,1 @@ | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { Either } from 'fp-ts/es6/Either' | ||
@@ -5,0 +2,0 @@ import { Char } from './char' |
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { codeFrameColumns } from '@babel/code-frame'; | ||
import { bimap } from 'fp-ts/es6/Either'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import { pipe } from 'fp-ts/es6/function'; | ||
import { stream } from './Stream'; | ||
var codeFrameColumns = require('@babel/code-frame').codeFrameColumns; | ||
var lineTerminatorRegex = /^\r\n$|^[\n\r]$/; | ||
@@ -9,0 +9,0 @@ var getLocation = function (source, cursor) { |
@@ -7,3 +7,4 @@ /** | ||
import { Applicative2 } from 'fp-ts/es6/Applicative' | ||
import { ChainRec2 } from 'fp-ts/ChainRec' | ||
import { ChainRec2 } from 'fp-ts/es6/ChainRec' | ||
import { Lazy } from 'fp-ts/es6/function' | ||
import { Functor2 } from 'fp-ts/es6/Functor' | ||
@@ -14,5 +15,6 @@ import { Monad2 } from 'fp-ts/es6/Monad' | ||
import * as O from 'fp-ts/es6/Option' | ||
import { Predicate } from 'fp-ts/es6/Predicate' | ||
import * as RNEA from 'fp-ts/es6/ReadonlyNonEmptyArray' | ||
import { Refinement } from 'fp-ts/es6/Refinement' | ||
import { Semigroup } from 'fp-ts/es6/Semigroup' | ||
import { Lazy, Predicate, Refinement } from 'fp-ts/es6/function' | ||
import { ParseResult } from './ParseResult' | ||
@@ -411,3 +413,3 @@ import { Stream } from './Stream' | ||
*/ | ||
export declare type URI = typeof URI | ||
export type URI = typeof URI | ||
declare module 'fp-ts/es6/HKT' { | ||
@@ -414,0 +416,0 @@ interface URItoKind2<E, A> { |
@@ -13,10 +13,10 @@ var __assign = (this && this.__assign) || function () { | ||
import * as A from 'fp-ts/es6/Array'; | ||
import { tailRec } from 'fp-ts/ChainRec'; | ||
import { tailRec } from 'fp-ts/es6/ChainRec'; | ||
import * as E from 'fp-ts/es6/Either'; | ||
import { identity, pipe } from 'fp-ts/es6/function'; | ||
import * as NEA from 'fp-ts/es6/NonEmptyArray'; | ||
import * as O from 'fp-ts/es6/Option'; | ||
import { not } from 'fp-ts/es6/Predicate'; | ||
import * as RA from 'fp-ts/es6/ReadonlyArray'; | ||
import * as RNEA from 'fp-ts/es6/ReadonlyNonEmptyArray'; | ||
import { identity, not } from 'fp-ts/es6/function'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import { error, escalate, extend, success, withExpected } from './ParseResult'; | ||
@@ -165,3 +165,3 @@ import { atEnd, getAndNext } from './Stream'; | ||
export var withStart = function (p) { return function (i) { | ||
return pipe(p(i), E.map(function (s) { return (__assign({}, s, { value: [s.value, i] })); })); | ||
return pipe(p(i), E.map(function (s) { return (__assign(__assign({}, s), { value: [s.value, i] })); })); | ||
}; }; | ||
@@ -199,3 +199,3 @@ /** | ||
export var many = function (p) { | ||
return pipe(many1(p), alt(function () { return of(A.empty); })); | ||
return pipe(many1(p), alt(function () { return of([]); })); | ||
}; | ||
@@ -213,3 +213,3 @@ /** | ||
return chainRec_(NEA.of(head), function (acc) { | ||
return pipe(parser, map(function (a) { return E.left(NEA.snoc(acc, a)); }), alt(function () { return of(E.right(acc)); })); | ||
return pipe(parser, map(function (a) { return E.left(A.append(a)(acc)); }), alt(function () { return of(E.right(acc)); })); | ||
}); | ||
@@ -227,3 +227,3 @@ })); | ||
export var sepBy = function (sep, p) { | ||
var nil = of(A.empty); | ||
var nil = of([]); | ||
return pipe(sepBy1(sep, p), alt(function () { return nil; })); | ||
@@ -241,3 +241,3 @@ }; | ||
return pipe(p, chain(function (head) { | ||
return pipe(many(pipe(sep, apSecond(p))), map(function (tail) { return NEA.cons(head, tail); })); | ||
return pipe(many(pipe(sep, apSecond(p))), map(function (tail) { return A.prepend(head)(tail); })); | ||
})); | ||
@@ -254,3 +254,3 @@ }; | ||
return pipe(p, chain(function (head) { | ||
return pipe(many(cutWith(sep, p)), map(function (tail) { return NEA.cons(head, tail); })); | ||
return pipe(many(cutWith(sep, p)), map(function (tail) { return A.prepend(head)(tail); })); | ||
})); | ||
@@ -284,5 +284,9 @@ }; | ||
*/ | ||
export var filter = function (predicate) { return function (p) { return function (i) { | ||
return pipe(p(i), E.chain(function (next) { return (predicate(next.value) ? E.right(next) : error(i)); })); | ||
}; }; }; | ||
export var filter = function (predicate) { | ||
return function (p) { | ||
return function (i) { | ||
return pipe(p(i), E.chain(function (next) { return (predicate(next.value) ? E.right(next) : error(i)); })); | ||
}; | ||
}; | ||
}; | ||
/** | ||
@@ -421,3 +425,3 @@ * Matches the provided parser `p` that occurs between the provided `left` and `right` parsers. | ||
return pipe(terminator, map(function () { return E.right(acc); }), alt(function () { | ||
return pipe(parser, map(function (a) { return E.left(RNEA.snoc(acc, a)); })); | ||
return pipe(parser, map(function (a) { return E.left(RA.append(a)(acc)); })); | ||
})); | ||
@@ -428,3 +432,3 @@ }); | ||
var map_ = function (ma, f) { return function (i) { | ||
return pipe(ma(i), E.map(function (s) { return (__assign({}, s, { value: f(s.value) })); })); | ||
return pipe(ma(i), E.map(function (s) { return (__assign(__assign({}, s), { value: f(s.value) })); })); | ||
}; }; | ||
@@ -434,7 +438,9 @@ var ap_ = function (mab, ma) { return chain_(mab, function (f) { return map_(ma, f); }); }; | ||
var chainRec_ = function (a, f) { | ||
var split = function (start) { return function (result) { | ||
return E.isLeft(result.value) | ||
? E.left({ value: result.value.left, stream: result.next }) | ||
: E.right(success(result.value.right, result.next, start)); | ||
}; }; | ||
var split = function (start) { | ||
return function (result) { | ||
return E.isLeft(result.value) | ||
? E.left({ value: result.value.left, stream: result.next }) | ||
: E.right(success(result.value.right, result.next, start)); | ||
}; | ||
}; | ||
return function (start) { | ||
@@ -503,3 +509,5 @@ return tailRec({ value: a, stream: start }, function (state) { | ||
*/ | ||
export var alt = function (that) { return function (fa) { return alt_(fa, that); }; }; | ||
export var alt = function (that) { return function (fa) { | ||
return alt_(fa, that); | ||
}; }; | ||
/** | ||
@@ -536,3 +544,3 @@ * @category Monad | ||
*/ | ||
export var getMonoid = function (M) { return (__assign({}, getSemigroup(M), { empty: succeed(M.empty) })); }; | ||
export var getMonoid = function (M) { return (__assign(__assign({}, getSemigroup(M)), { empty: succeed(M.empty) })); }; | ||
/** | ||
@@ -625,12 +633,16 @@ * @category instances | ||
*/ | ||
export var bindTo = function (name) { return function (fa) { | ||
return pipe(fa, map(function (a) { return bind_({}, name, a); })); | ||
}; }; | ||
export var bindTo = function (name) { | ||
return function (fa) { | ||
return pipe(fa, map(function (a) { return bind_({}, name, a); })); | ||
}; | ||
}; | ||
/** | ||
* @since 0.6.8 | ||
*/ | ||
export var bind = function (name, f) { return function (fa) { | ||
return pipe(fa, chain(function (a) { | ||
return pipe(f(a), map(function (b) { return bind_(a, name, b); })); | ||
})); | ||
}; }; | ||
export var bind = function (name, f) { | ||
return function (fa) { | ||
return pipe(fa, chain(function (a) { | ||
return pipe(f(a), map(function (b) { return bind_(a, name, b); })); | ||
})); | ||
}; | ||
}; |
@@ -25,3 +25,3 @@ import { Either } from 'fp-ts/es6/Either' | ||
*/ | ||
export declare type ParseResult<I, A> = Either<ParseError<I>, ParseSuccess<I, A>> | ||
export type ParseResult<I, A> = Either<ParseError<I>, ParseSuccess<I, A>> | ||
/** | ||
@@ -28,0 +28,0 @@ * @category constructors |
@@ -15,5 +15,5 @@ var __assign = (this && this.__assign) || function () { | ||
*/ | ||
import { empty, getMonoid } from 'fp-ts/es6/Array'; | ||
import { getMonoid } from 'fp-ts/es6/Array'; | ||
import { left, right } from 'fp-ts/es6/Either'; | ||
import { getFirstSemigroup, getLastSemigroup, getStructSemigroup } from 'fp-ts/es6/Semigroup'; | ||
import { first, last, struct } from 'fp-ts/es6/Semigroup'; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -38,3 +38,3 @@ // constructors | ||
export var error = function (input, expected, fatal) { | ||
if (expected === void 0) { expected = empty; } | ||
if (expected === void 0) { expected = []; } | ||
if (fatal === void 0) { fatal = false; } | ||
@@ -54,3 +54,3 @@ return left({ | ||
*/ | ||
export var withExpected = function (err, expected) { return (__assign({}, err, { expected: expected })); }; | ||
export var withExpected = function (err, expected) { return (__assign(__assign({}, err), { expected: expected })); }; | ||
/** | ||
@@ -60,3 +60,3 @@ * @category combinators | ||
*/ | ||
export var escalate = function (err) { return (__assign({}, err, { fatal: true })); }; | ||
export var escalate = function (err) { return (__assign(__assign({}, err), { fatal: true })); }; | ||
/** | ||
@@ -75,8 +75,8 @@ * @category combinators | ||
if (x.input.cursor < y.input.cursor) | ||
return getLastSemigroup().concat(x, y); | ||
return last().concat(x, y); | ||
if (x.input.cursor > y.input.cursor) | ||
return getFirstSemigroup().concat(x, y); | ||
return getStructSemigroup({ | ||
input: getFirstSemigroup(), | ||
fatal: getFirstSemigroup(), | ||
return first().concat(x, y); | ||
return struct({ | ||
input: first(), | ||
fatal: first(), | ||
expected: getMonoid() | ||
@@ -83,0 +83,0 @@ }).concat(x, y); |
@@ -30,5 +30,3 @@ import { Eq } from 'fp-ts/es6/Eq' | ||
*/ | ||
export declare const getAndNext: <A>( | ||
s: Stream<A> | ||
) => Option<{ | ||
export declare const getAndNext: <A>(s: Stream<A>) => Option<{ | ||
value: A | ||
@@ -35,0 +33,0 @@ next: Stream<A> |
@@ -6,4 +6,4 @@ /** | ||
import { fromEquals } from 'fp-ts/es6/Eq'; | ||
import { pipe } from 'fp-ts/es6/function'; | ||
import { map } from 'fp-ts/es6/Option'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -10,0 +10,0 @@ // constructors |
@@ -1,4 +0,1 @@ | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { Foldable, Foldable1 } from 'fp-ts/es6/Foldable' | ||
@@ -5,0 +2,0 @@ import { Functor, Functor1 } from 'fp-ts/es6/Functor' |
@@ -1,5 +0,9 @@ | ||
import * as E from 'fp-ts/Either'; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
import * as E from 'fp-ts/es6/Either'; | ||
import { pipe } from 'fp-ts/es6/function'; | ||
import * as M from 'fp-ts/es6/Monoid'; | ||
import * as O from 'fp-ts/es6/Option'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import { Monoid } from 'fp-ts/es6/string'; | ||
import * as C from './char'; | ||
@@ -38,3 +42,3 @@ import * as P from './Parser'; | ||
*/ | ||
export var fold = M.fold(P.getMonoid(M.monoidString)); | ||
export var fold = M.concatAll(P.getMonoid(Monoid)); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -47,3 +51,3 @@ // combinators | ||
*/ | ||
export var maybe = P.maybe(M.monoidString); | ||
export var maybe = P.maybe(Monoid); | ||
/** | ||
@@ -50,0 +54,0 @@ * Matches the given parser zero or more times, returning a string of the |
@@ -6,3 +6,3 @@ import * as P from './Parser' | ||
*/ | ||
export declare type Char = string | ||
export type Char = string | ||
/** | ||
@@ -9,0 +9,0 @@ * The `char` parser constructor returns a parser which matches only the |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.notLower = exports.notUpper = exports.notLetter = exports.notAlphanum = exports.notSpace = exports.notDigit = exports.lower = exports.upper = exports.unicodeLetter = exports.letter = exports.alphanum = exports.space = exports.digit = exports.many1 = exports.many = exports.notOneOf = exports.oneOf = exports.notChar = exports.char = void 0; | ||
/** | ||
@@ -14,6 +31,6 @@ * @since 0.6.0 | ||
var function_1 = require("fp-ts/lib/function"); | ||
var Monoid_1 = require("fp-ts/lib/Monoid"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var Predicate_1 = require("fp-ts/lib/Predicate"); | ||
var string_1 = require("fp-ts/lib/string"); | ||
var P = __importStar(require("./Parser")); | ||
var maybe = P.maybe(Monoid_1.monoidString); | ||
var maybe = P.maybe(string_1.Monoid); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -29,5 +46,6 @@ // constructors | ||
*/ | ||
exports.char = function (c) { | ||
return P.expected(P.sat(function (s) { return s === c; }), "\"" + c + "\""); | ||
var char = function (c) { | ||
return P.expected(P.sat(function (s) { return s === c; }), "\"".concat(c, "\"")); | ||
}; | ||
exports.char = char; | ||
/** | ||
@@ -40,5 +58,6 @@ * The `notChar` parser constructor makes a parser which will match any | ||
*/ | ||
exports.notChar = function (c) { | ||
return P.expected(P.sat(function (c1) { return c1 !== c; }), "anything but \"" + c + "\""); | ||
var notChar = function (c) { | ||
return P.expected(P.sat(function (c1) { return c1 !== c; }), "anything but \"".concat(c, "\"")); | ||
}; | ||
exports.notChar = notChar; | ||
var isOneOf = function (s, c) { return s.indexOf(c) !== -1; }; | ||
@@ -51,5 +70,6 @@ /** | ||
*/ | ||
exports.oneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return isOneOf(s, c); }), "One of \"" + s + "\""); | ||
var oneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return isOneOf(s, c); }), "One of \"".concat(s, "\"")); | ||
}; | ||
exports.oneOf = oneOf; | ||
/** | ||
@@ -61,5 +81,6 @@ * Matches a single character which isn't a character from the provided string. | ||
*/ | ||
exports.notOneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of " + JSON.stringify(s)); | ||
var notOneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of ".concat(JSON.stringify(s))); | ||
}; | ||
exports.notOneOf = notOneOf; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -75,3 +96,4 @@ // combinators | ||
*/ | ||
exports.many = function (parser) { return maybe(exports.many1(parser)); }; | ||
var many = function (parser) { return maybe((0, exports.many1)(parser)); }; | ||
exports.many = many; | ||
/** | ||
@@ -84,5 +106,6 @@ * Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
*/ | ||
exports.many1 = function (parser) { | ||
return pipeable_1.pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
var many1 = function (parser) { | ||
return (0, function_1.pipe)(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
}; | ||
exports.many1 = many1; | ||
var isDigit = function (c) { return '0123456789'.indexOf(c) !== -1; }; | ||
@@ -153,3 +176,3 @@ /** | ||
*/ | ||
exports.notDigit = P.expected(P.sat(function_1.not(isDigit)), 'a non-digit'); | ||
exports.notDigit = P.expected(P.sat((0, Predicate_1.not)(isDigit)), 'a non-digit'); | ||
/** | ||
@@ -161,3 +184,3 @@ * Matches a single character which isn't whitespace. | ||
*/ | ||
exports.notSpace = P.expected(P.sat(function_1.not(isSpace)), 'a non-whitespace character'); | ||
exports.notSpace = P.expected(P.sat((0, Predicate_1.not)(isSpace)), 'a non-whitespace character'); | ||
/** | ||
@@ -169,3 +192,3 @@ * Matches a single character which isn't a letter, digit or underscore. | ||
*/ | ||
exports.notAlphanum = P.expected(P.sat(function_1.not(isAlphanum)), 'a non-word character'); | ||
exports.notAlphanum = P.expected(P.sat((0, Predicate_1.not)(isAlphanum)), 'a non-word character'); | ||
/** | ||
@@ -177,3 +200,3 @@ * Matches a single character which isn't an ASCII letter. | ||
*/ | ||
exports.notLetter = P.expected(P.sat(function_1.not(isLetter)), 'a non-letter character'); | ||
exports.notLetter = P.expected(P.sat((0, Predicate_1.not)(isLetter)), 'a non-letter character'); | ||
/** | ||
@@ -185,3 +208,3 @@ * Matches a single character which isn't an upper case ASCII letter. | ||
*/ | ||
exports.notUpper = P.expected(P.sat(function_1.not(isUpper)), 'anything but an upper case letter'); | ||
exports.notUpper = P.expected(P.sat((0, Predicate_1.not)(isUpper)), 'anything but an upper case letter'); | ||
/** | ||
@@ -193,2 +216,2 @@ * Matches a single character which isn't a lower case ASCII letter. | ||
*/ | ||
exports.notLower = P.expected(P.sat(function_1.not(isLower)), 'anything but a lower case letter'); | ||
exports.notLower = P.expected(P.sat((0, Predicate_1.not)(isLower)), 'anything but a lower case letter'); |
@@ -1,4 +0,1 @@ | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { Either } from 'fp-ts/lib/Either' | ||
@@ -5,0 +2,0 @@ import { Char } from './char' |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.run = void 0; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
var code_frame_1 = require("@babel/code-frame"); | ||
var Either_1 = require("fp-ts/lib/Either"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var Stream_1 = require("./Stream"); | ||
var codeFrameColumns = require('@babel/code-frame').codeFrameColumns; | ||
var lineTerminatorRegex = /^\r\n$|^[\n\r]$/; | ||
@@ -38,5 +39,5 @@ var getLocation = function (source, cursor) { | ||
*/ | ||
exports.run = function (p, source) { | ||
return pipeable_1.pipe(p(Stream_1.stream(source.split(''))), Either_1.bimap(function (err) { | ||
return codeFrameColumns(source, getLocation(source, err.input.cursor), { | ||
var run = function (p, source) { | ||
return (0, function_1.pipe)(p((0, Stream_1.stream)(source.split(''))), (0, Either_1.bimap)(function (err) { | ||
return (0, code_frame_1.codeFrameColumns)(source, getLocation(source, err.input.cursor), { | ||
message: 'Expected: ' + err.expected.join(', ') | ||
@@ -46,1 +47,2 @@ }); | ||
}; | ||
exports.run = run; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.string = exports.stream = exports.parseResult = exports.parser = exports.char = void 0; | ||
/** | ||
@@ -11,0 +28,0 @@ * @since 0.6.0 |
@@ -7,3 +7,4 @@ /** | ||
import { Applicative2 } from 'fp-ts/lib/Applicative' | ||
import { ChainRec2 } from 'fp-ts/ChainRec' | ||
import { ChainRec2 } from 'fp-ts/lib/ChainRec' | ||
import { Lazy } from 'fp-ts/lib/function' | ||
import { Functor2 } from 'fp-ts/lib/Functor' | ||
@@ -14,5 +15,6 @@ import { Monad2 } from 'fp-ts/lib/Monad' | ||
import * as O from 'fp-ts/lib/Option' | ||
import { Predicate } from 'fp-ts/lib/Predicate' | ||
import * as RNEA from 'fp-ts/lib/ReadonlyNonEmptyArray' | ||
import { Refinement } from 'fp-ts/lib/Refinement' | ||
import { Semigroup } from 'fp-ts/lib/Semigroup' | ||
import { Lazy, Predicate, Refinement } from 'fp-ts/lib/function' | ||
import { ParseResult } from './ParseResult' | ||
@@ -411,3 +413,3 @@ import { Stream } from './Stream' | ||
*/ | ||
export declare type URI = typeof URI | ||
export type URI = typeof URI | ||
declare module 'fp-ts/lib/HKT' { | ||
@@ -414,0 +416,0 @@ interface URItoKind2<E, A> { |
@@ -13,19 +13,36 @@ "use strict"; | ||
}; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bind = exports.bindTo = exports.parser = exports.Alternative = exports.Alt = exports.ChainRec = exports.Monad = exports.Applicative = exports.Functor = exports.getMonoid = exports.getSemigroup = exports.URI = exports.zero = exports.flatten = exports.alt = exports.chainFirst = exports.chain = exports.of = exports.apSecond = exports.apFirst = exports.ap = exports.map = exports.many1Till = exports.manyTill = exports.optional = exports.takeUntil = exports.lookAhead = exports.surroundedBy = exports.between = exports.filter = exports.sepByCut = exports.sepBy1 = exports.sepBy = exports.many1 = exports.many = exports.eof = exports.maybe = exports.withStart = exports.either = exports.seq = exports.cutWith = exports.cut = exports.item = exports.expected = exports.sat = exports.failAt = exports.fail = exports.succeed = void 0; | ||
var A = __importStar(require("fp-ts/lib/Array")); | ||
var ChainRec_1 = require("fp-ts/ChainRec"); | ||
var ChainRec_1 = require("fp-ts/lib/ChainRec"); | ||
var E = __importStar(require("fp-ts/lib/Either")); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var NEA = __importStar(require("fp-ts/lib/NonEmptyArray")); | ||
var O = __importStar(require("fp-ts/lib/Option")); | ||
var Predicate_1 = require("fp-ts/lib/Predicate"); | ||
var RA = __importStar(require("fp-ts/lib/ReadonlyArray")); | ||
var RNEA = __importStar(require("fp-ts/lib/ReadonlyNonEmptyArray")); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var ParseResult_1 = require("./ParseResult"); | ||
@@ -45,3 +62,4 @@ var Stream_1 = require("./Stream"); | ||
*/ | ||
exports.succeed = function (a) { return function (i) { return ParseResult_1.success(a, i, i); }; }; | ||
var succeed = function (a) { return function (i) { return (0, ParseResult_1.success)(a, i, i); }; }; | ||
exports.succeed = succeed; | ||
/** | ||
@@ -53,3 +71,4 @@ * The `fail` parser will just fail immediately without consuming any input | ||
*/ | ||
exports.fail = function () { return function (i) { return ParseResult_1.error(i); }; }; | ||
var fail = function () { return function (i) { return (0, ParseResult_1.error)(i); }; }; | ||
exports.fail = fail; | ||
/** | ||
@@ -62,3 +81,4 @@ * The `failAt` parser will fail immediately without consuming any input, | ||
*/ | ||
exports.failAt = function (i) { return function () { return ParseResult_1.error(i); }; }; | ||
var failAt = function (i) { return function () { return (0, ParseResult_1.error)(i); }; }; | ||
exports.failAt = failAt; | ||
/** | ||
@@ -73,8 +93,9 @@ * The `sat` parser constructor takes a predicate function, and will consume | ||
*/ | ||
exports.sat = function (predicate) { | ||
return pipeable_1.pipe(exports.withStart(exports.item()), exports.chain(function (_a) { | ||
var sat = function (predicate) { | ||
return (0, function_1.pipe)((0, exports.withStart)((0, exports.item)()), (0, exports.chain)(function (_a) { | ||
var a = _a[0], start = _a[1]; | ||
return (predicate(a) ? exports.of(a) : exports.failAt(start)); | ||
return (predicate(a) ? (0, exports.of)(a) : (0, exports.failAt)(start)); | ||
})); | ||
}; | ||
exports.sat = sat; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -91,5 +112,6 @@ // combinators | ||
*/ | ||
exports.expected = function (p, message) { return function (i) { | ||
return pipeable_1.pipe(p(i), E.mapLeft(function (err) { return ParseResult_1.withExpected(err, [message]); })); | ||
var expected = function (p, message) { return function (i) { | ||
return (0, function_1.pipe)(p(i), E.mapLeft(function (err) { return (0, ParseResult_1.withExpected)(err, [message]); })); | ||
}; }; | ||
exports.expected = expected; | ||
/** | ||
@@ -102,8 +124,9 @@ * The `item` parser consumes a single value, regardless of what it is, | ||
*/ | ||
exports.item = function () { return function (i) { | ||
return pipeable_1.pipe(Stream_1.getAndNext(i), O.fold(function () { return ParseResult_1.error(i); }, function (_a) { | ||
var item = function () { return function (i) { | ||
return (0, function_1.pipe)((0, Stream_1.getAndNext)(i), O.fold(function () { return (0, ParseResult_1.error)(i); }, function (_a) { | ||
var value = _a.value, next = _a.next; | ||
return ParseResult_1.success(value, next, i); | ||
return (0, ParseResult_1.success)(value, next, i); | ||
})); | ||
}; }; | ||
exports.item = item; | ||
/** | ||
@@ -117,3 +140,4 @@ * The `cut` parser combinator takes a parser and produces a new parser for | ||
*/ | ||
exports.cut = function (p) { return function (i) { return pipeable_1.pipe(p(i), E.mapLeft(ParseResult_1.escalate)); }; }; | ||
var cut = function (p) { return function (i) { return (0, function_1.pipe)(p(i), E.mapLeft(ParseResult_1.escalate)); }; }; | ||
exports.cut = cut; | ||
/** | ||
@@ -127,5 +151,6 @@ * Takes two parsers `p1` and `p2`, returning a parser which will match | ||
*/ | ||
exports.cutWith = function (p1, p2) { | ||
return pipeable_1.pipe(p1, exports.apSecond(exports.cut(p2))); | ||
var cutWith = function (p1, p2) { | ||
return (0, function_1.pipe)(p1, (0, exports.apSecond)((0, exports.cut)(p2))); | ||
}; | ||
exports.cutWith = cutWith; | ||
/** | ||
@@ -143,7 +168,8 @@ * The `seq` combinator takes a parser, and a function which will receive | ||
*/ | ||
exports.seq = function (fa, f) { return function (i) { | ||
return pipeable_1.pipe(fa(i), E.chain(function (s) { | ||
return pipeable_1.pipe(f(s.value)(s.next), E.chain(function (next) { return ParseResult_1.success(next.value, next.next, i); })); | ||
var seq = function (fa, f) { return function (i) { | ||
return (0, function_1.pipe)(fa(i), E.chain(function (s) { | ||
return (0, function_1.pipe)(f(s.value)(s.next), E.chain(function (next) { return (0, ParseResult_1.success)(next.value, next.next, i); })); | ||
})); | ||
}; }; | ||
exports.seq = seq; | ||
/** | ||
@@ -162,3 +188,3 @@ * The `either` combinator takes two parsers, runs the first on the input | ||
*/ | ||
exports.either = function (p, f) { return function (i) { | ||
var either = function (p, f) { return function (i) { | ||
var e = p(i); | ||
@@ -171,4 +197,5 @@ if (E.isRight(e)) { | ||
} | ||
return pipeable_1.pipe(f()(i), E.mapLeft(function (err) { return ParseResult_1.extend(e.left, err); })); | ||
return (0, function_1.pipe)(f()(i), E.mapLeft(function (err) { return (0, ParseResult_1.extend)(e.left, err); })); | ||
}; }; | ||
exports.either = either; | ||
/** | ||
@@ -184,5 +211,6 @@ * Converts a parser into one which will return the point in the stream where | ||
*/ | ||
exports.withStart = function (p) { return function (i) { | ||
return pipeable_1.pipe(p(i), E.map(function (s) { return (__assign({}, s, { value: [s.value, i] })); })); | ||
var withStart = function (p) { return function (i) { | ||
return (0, function_1.pipe)(p(i), E.map(function (s) { return (__assign(__assign({}, s), { value: [s.value, i] })); })); | ||
}; }; | ||
exports.withStart = withStart; | ||
/** | ||
@@ -196,3 +224,4 @@ * The `maybe` parser combinator creates a parser which will run the provided | ||
*/ | ||
exports.maybe = function (M) { return exports.alt(function () { return exports.of(M.empty); }); }; | ||
var maybe = function (M) { return (0, exports.alt)(function () { return (0, exports.of)(M.empty); }); }; | ||
exports.maybe = maybe; | ||
/** | ||
@@ -204,5 +233,6 @@ * Matches the end of the stream. | ||
*/ | ||
exports.eof = function () { | ||
return exports.expected(function (i) { return (Stream_1.atEnd(i) ? ParseResult_1.success(undefined, i, i) : ParseResult_1.error(i)); }, 'end of file'); | ||
var eof = function () { | ||
return (0, exports.expected)(function (i) { return ((0, Stream_1.atEnd)(i) ? (0, ParseResult_1.success)(undefined, i, i) : (0, ParseResult_1.error)(i)); }, 'end of file'); | ||
}; | ||
exports.eof = eof; | ||
/** | ||
@@ -220,5 +250,6 @@ * The `many` combinator takes a parser, and returns a new parser which will | ||
*/ | ||
exports.many = function (p) { | ||
return pipeable_1.pipe(exports.many1(p), exports.alt(function () { return exports.of(A.empty); })); | ||
var many = function (p) { | ||
return (0, function_1.pipe)((0, exports.many1)(p), (0, exports.alt)(function () { return (0, exports.of)([]); })); | ||
}; | ||
exports.many = many; | ||
/** | ||
@@ -232,9 +263,10 @@ * The `many1` combinator is just like the `many` combinator, except it | ||
*/ | ||
exports.many1 = function (parser) { | ||
return pipeable_1.pipe(parser, exports.chain(function (head) { | ||
var many1 = function (parser) { | ||
return (0, function_1.pipe)(parser, (0, exports.chain)(function (head) { | ||
return chainRec_(NEA.of(head), function (acc) { | ||
return pipeable_1.pipe(parser, exports.map(function (a) { return E.left(NEA.snoc(acc, a)); }), exports.alt(function () { return exports.of(E.right(acc)); })); | ||
return (0, function_1.pipe)(parser, (0, exports.map)(function (a) { return E.left(A.append(a)(acc)); }), (0, exports.alt)(function () { return (0, exports.of)(E.right(acc)); })); | ||
}); | ||
})); | ||
}; | ||
exports.many1 = many1; | ||
/** | ||
@@ -248,6 +280,7 @@ * Matches the provided parser `p` zero or more times, but requires the | ||
*/ | ||
exports.sepBy = function (sep, p) { | ||
var nil = exports.of(A.empty); | ||
return pipeable_1.pipe(exports.sepBy1(sep, p), exports.alt(function () { return nil; })); | ||
var sepBy = function (sep, p) { | ||
var nil = (0, exports.of)([]); | ||
return (0, function_1.pipe)((0, exports.sepBy1)(sep, p), (0, exports.alt)(function () { return nil; })); | ||
}; | ||
exports.sepBy = sepBy; | ||
/** | ||
@@ -261,7 +294,8 @@ * Matches the provided parser `p` one or more times, but requires the | ||
*/ | ||
exports.sepBy1 = function (sep, p) { | ||
return pipeable_1.pipe(p, exports.chain(function (head) { | ||
return pipeable_1.pipe(exports.many(pipeable_1.pipe(sep, exports.apSecond(p))), exports.map(function (tail) { return NEA.cons(head, tail); })); | ||
var sepBy1 = function (sep, p) { | ||
return (0, function_1.pipe)(p, (0, exports.chain)(function (head) { | ||
return (0, function_1.pipe)((0, exports.many)((0, function_1.pipe)(sep, (0, exports.apSecond)(p))), (0, exports.map)(function (tail) { return A.prepend(head)(tail); })); | ||
})); | ||
}; | ||
exports.sepBy1 = sepBy1; | ||
/** | ||
@@ -274,7 +308,8 @@ * Like `sepBy1`, but cut on the separator, so that matching a `sep` not | ||
*/ | ||
exports.sepByCut = function (sep, p) { | ||
return pipeable_1.pipe(p, exports.chain(function (head) { | ||
return pipeable_1.pipe(exports.many(exports.cutWith(sep, p)), exports.map(function (tail) { return NEA.cons(head, tail); })); | ||
var sepByCut = function (sep, p) { | ||
return (0, function_1.pipe)(p, (0, exports.chain)(function (head) { | ||
return (0, function_1.pipe)((0, exports.many)((0, exports.cutWith)(sep, p)), (0, exports.map)(function (tail) { return A.prepend(head)(tail); })); | ||
})); | ||
}; | ||
exports.sepByCut = sepByCut; | ||
/** | ||
@@ -306,5 +341,10 @@ * Filters the result of a parser based upon a `Refinement` or a `Predicate`. | ||
*/ | ||
exports.filter = function (predicate) { return function (p) { return function (i) { | ||
return pipeable_1.pipe(p(i), E.chain(function (next) { return (predicate(next.value) ? E.right(next) : ParseResult_1.error(i)); })); | ||
}; }; }; | ||
var filter = function (predicate) { | ||
return function (p) { | ||
return function (i) { | ||
return (0, function_1.pipe)(p(i), E.chain(function (next) { return (predicate(next.value) ? E.right(next) : (0, ParseResult_1.error)(i)); })); | ||
}; | ||
}; | ||
}; | ||
exports.filter = filter; | ||
/** | ||
@@ -318,5 +358,6 @@ * Matches the provided parser `p` that occurs between the provided `left` and `right` parsers. | ||
*/ | ||
exports.between = function (left, right) { return function (p) { | ||
return pipeable_1.pipe(left, exports.chain(function () { return p; }), exports.chainFirst(function () { return right; })); | ||
var between = function (left, right) { return function (p) { | ||
return (0, function_1.pipe)(left, (0, exports.chain)(function () { return p; }), (0, exports.chainFirst)(function () { return right; })); | ||
}; }; | ||
exports.between = between; | ||
/** | ||
@@ -328,5 +369,6 @@ * Matches the provided parser `p` that is surrounded by the `bound` parser. Shortcut for `between(bound, bound)`. | ||
*/ | ||
exports.surroundedBy = function (bound) { | ||
return exports.between(bound, bound); | ||
var surroundedBy = function (bound) { | ||
return (0, exports.between)(bound, bound); | ||
}; | ||
exports.surroundedBy = surroundedBy; | ||
/** | ||
@@ -352,5 +394,6 @@ * Takes a `Parser` and tries to match it without consuming any input. | ||
*/ | ||
exports.lookAhead = function (p) { return function (i) { | ||
return pipeable_1.pipe(p(i), E.chain(function (next) { return ParseResult_1.success(next.value, i, i); })); | ||
var lookAhead = function (p) { return function (i) { | ||
return (0, function_1.pipe)(p(i), E.chain(function (next) { return (0, ParseResult_1.success)(next.value, i, i); })); | ||
}; }; | ||
exports.lookAhead = lookAhead; | ||
/** | ||
@@ -372,3 +415,4 @@ * Takes a `Predicate` and continues parsing until the given `Predicate` is satisfied. | ||
*/ | ||
exports.takeUntil = function (predicate) { return exports.many(exports.sat(function_1.not(predicate))); }; | ||
var takeUntil = function (predicate) { return (0, exports.many)((0, exports.sat)((0, Predicate_1.not)(predicate))); }; | ||
exports.takeUntil = takeUntil; | ||
/** | ||
@@ -394,5 +438,6 @@ * Returns `Some<A>` if the specified parser succeeds, otherwise returns `None`. | ||
*/ | ||
exports.optional = function (parser) { | ||
return pipeable_1.pipe(parser, exports.map(O.some), exports.alt(function () { return exports.succeed(O.none); })); | ||
var optional = function (parser) { | ||
return (0, function_1.pipe)(parser, (0, exports.map)(O.some), (0, exports.alt)(function () { return (0, exports.succeed)(O.none); })); | ||
}; | ||
exports.optional = optional; | ||
/** | ||
@@ -420,5 +465,6 @@ * The `manyTill` combinator takes a value `parser` and a `terminator` parser, and | ||
*/ | ||
exports.manyTill = function (parser, terminator) { | ||
return pipeable_1.pipe(terminator, exports.map(function () { return RA.empty; }), exports.alt(function () { return exports.many1Till(parser, terminator); })); | ||
var manyTill = function (parser, terminator) { | ||
return (0, function_1.pipe)(terminator, (0, exports.map)(function () { return RA.empty; }), (0, exports.alt)(function () { return (0, exports.many1Till)(parser, terminator); })); | ||
}; | ||
exports.manyTill = manyTill; | ||
/** | ||
@@ -445,7 +491,7 @@ * The `many1Till` combinator is just like the `manyTill` combinator, except it | ||
*/ | ||
exports.many1Till = function (parser, terminator) { | ||
return pipeable_1.pipe(parser, exports.chain(function (x) { | ||
var many1Till = function (parser, terminator) { | ||
return (0, function_1.pipe)(parser, (0, exports.chain)(function (x) { | ||
return chainRec_(RNEA.of(x), function (acc) { | ||
return pipeable_1.pipe(terminator, exports.map(function () { return E.right(acc); }), exports.alt(function () { | ||
return pipeable_1.pipe(parser, exports.map(function (a) { return E.left(RNEA.snoc(acc, a)); })); | ||
return (0, function_1.pipe)(terminator, (0, exports.map)(function () { return E.right(acc); }), (0, exports.alt)(function () { | ||
return (0, function_1.pipe)(parser, (0, exports.map)(function (a) { return E.left(RA.append(a)(acc)); })); | ||
})); | ||
@@ -455,18 +501,21 @@ }); | ||
}; | ||
exports.many1Till = many1Till; | ||
var map_ = function (ma, f) { return function (i) { | ||
return pipeable_1.pipe(ma(i), E.map(function (s) { return (__assign({}, s, { value: f(s.value) })); })); | ||
return (0, function_1.pipe)(ma(i), E.map(function (s) { return (__assign(__assign({}, s), { value: f(s.value) })); })); | ||
}; }; | ||
var ap_ = function (mab, ma) { return chain_(mab, function (f) { return map_(ma, f); }); }; | ||
var chain_ = function (ma, f) { return exports.seq(ma, f); }; | ||
var chain_ = function (ma, f) { return (0, exports.seq)(ma, f); }; | ||
var chainRec_ = function (a, f) { | ||
var split = function (start) { return function (result) { | ||
return E.isLeft(result.value) | ||
? E.left({ value: result.value.left, stream: result.next }) | ||
: E.right(ParseResult_1.success(result.value.right, result.next, start)); | ||
}; }; | ||
var split = function (start) { | ||
return function (result) { | ||
return E.isLeft(result.value) | ||
? E.left({ value: result.value.left, stream: result.next }) | ||
: E.right((0, ParseResult_1.success)(result.value.right, result.next, start)); | ||
}; | ||
}; | ||
return function (start) { | ||
return ChainRec_1.tailRec({ value: a, stream: start }, function (state) { | ||
return (0, ChainRec_1.tailRec)({ value: a, stream: start }, function (state) { | ||
var result = f(state.value)(state.stream); | ||
if (E.isLeft(result)) { | ||
return E.right(ParseResult_1.error(state.stream, result.left.expected, result.left.fatal)); | ||
return E.right((0, ParseResult_1.error)(state.stream, result.left.expected, result.left.fatal)); | ||
} | ||
@@ -477,3 +526,3 @@ return split(start)(result.right); | ||
}; | ||
var alt_ = function (fa, that) { return exports.either(fa, that); }; | ||
var alt_ = function (fa, that) { return (0, exports.either)(fa, that); }; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -486,3 +535,4 @@ // pipeables | ||
*/ | ||
exports.map = function (f) { return function (fa) { return map_(fa, f); }; }; | ||
var map = function (f) { return function (fa) { return map_(fa, f); }; }; | ||
exports.map = map; | ||
/** | ||
@@ -492,5 +542,6 @@ * @category Apply | ||
*/ | ||
exports.ap = function (fa) { return function (fab) { | ||
var ap = function (fa) { return function (fab) { | ||
return ap_(fab, fa); | ||
}; }; | ||
exports.ap = ap; | ||
/** | ||
@@ -500,5 +551,6 @@ * @category Apply | ||
*/ | ||
exports.apFirst = function (fb) { return function (fa) { | ||
var apFirst = function (fb) { return function (fa) { | ||
return ap_(map_(fa, function (a) { return function () { return a; }; }), fb); | ||
}; }; | ||
exports.apFirst = apFirst; | ||
/** | ||
@@ -508,5 +560,6 @@ * @category Apply | ||
*/ | ||
exports.apSecond = function (fb) { return function (fa) { | ||
var apSecond = function (fb) { return function (fa) { | ||
return ap_(map_(fa, function () { return function (b) { return b; }; }), fb); | ||
}; }; | ||
exports.apSecond = apSecond; | ||
/** | ||
@@ -521,5 +574,6 @@ * @category Applicative | ||
*/ | ||
exports.chain = function (f) { return function (ma) { | ||
var chain = function (f) { return function (ma) { | ||
return chain_(ma, f); | ||
}; }; | ||
exports.chain = chain; | ||
/** | ||
@@ -529,5 +583,6 @@ * @category Monad | ||
*/ | ||
exports.chainFirst = function (f) { return function (ma) { | ||
var chainFirst = function (f) { return function (ma) { | ||
return chain_(ma, function (a) { return map_(f(a), function () { return a; }); }); | ||
}; }; | ||
exports.chainFirst = chainFirst; | ||
/** | ||
@@ -537,3 +592,6 @@ * @category Alt | ||
*/ | ||
exports.alt = function (that) { return function (fa) { return alt_(fa, that); }; }; | ||
var alt = function (that) { return function (fa) { | ||
return alt_(fa, that); | ||
}; }; | ||
exports.alt = alt; | ||
/** | ||
@@ -543,3 +601,4 @@ * @category Monad | ||
*/ | ||
exports.flatten = function (mma) { return chain_(mma, function_1.identity); }; | ||
var flatten = function (mma) { return chain_(mma, function_1.identity); }; | ||
exports.flatten = flatten; | ||
/** | ||
@@ -562,3 +621,3 @@ * @category Alternative | ||
*/ | ||
exports.getSemigroup = function (S) { return ({ | ||
var getSemigroup = function (S) { return ({ | ||
concat: function (x, y) { | ||
@@ -568,2 +627,3 @@ return ap_(map_(x, function (x) { return function (y) { return S.concat(x, y); }; }), y); | ||
}); }; | ||
exports.getSemigroup = getSemigroup; | ||
/** | ||
@@ -573,3 +633,4 @@ * @category instances | ||
*/ | ||
exports.getMonoid = function (M) { return (__assign({}, exports.getSemigroup(M), { empty: exports.succeed(M.empty) })); }; | ||
var getMonoid = function (M) { return (__assign(__assign({}, (0, exports.getSemigroup)(M)), { empty: (0, exports.succeed)(M.empty) })); }; | ||
exports.getMonoid = getMonoid; | ||
/** | ||
@@ -662,12 +723,18 @@ * @category instances | ||
*/ | ||
exports.bindTo = function (name) { return function (fa) { | ||
return pipeable_1.pipe(fa, exports.map(function (a) { return bind_({}, name, a); })); | ||
}; }; | ||
var bindTo = function (name) { | ||
return function (fa) { | ||
return (0, function_1.pipe)(fa, (0, exports.map)(function (a) { return bind_({}, name, a); })); | ||
}; | ||
}; | ||
exports.bindTo = bindTo; | ||
/** | ||
* @since 0.6.8 | ||
*/ | ||
exports.bind = function (name, f) { return function (fa) { | ||
return pipeable_1.pipe(fa, exports.chain(function (a) { | ||
return pipeable_1.pipe(f(a), exports.map(function (b) { return bind_(a, name, b); })); | ||
})); | ||
}; }; | ||
var bind = function (name, f) { | ||
return function (fa) { | ||
return (0, function_1.pipe)(fa, (0, exports.chain)(function (a) { | ||
return (0, function_1.pipe)(f(a), (0, exports.map)(function (b) { return bind_(a, name, b); })); | ||
})); | ||
}; | ||
}; | ||
exports.bind = bind; |
@@ -25,3 +25,3 @@ import { Either } from 'fp-ts/lib/Either' | ||
*/ | ||
export declare type ParseResult<I, A> = Either<ParseError<I>, ParseSuccess<I, A>> | ||
export type ParseResult<I, A> = Either<ParseError<I>, ParseSuccess<I, A>> | ||
/** | ||
@@ -28,0 +28,0 @@ * @category constructors |
@@ -14,2 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extend = exports.escalate = exports.withExpected = exports.error = exports.success = void 0; | ||
/** | ||
@@ -28,4 +29,4 @@ * @since 0.6.0 | ||
*/ | ||
exports.success = function (value, next, start) { | ||
return Either_1.right({ | ||
var success = function (value, next, start) { | ||
return (0, Either_1.right)({ | ||
value: value, | ||
@@ -36,2 +37,3 @@ next: next, | ||
}; | ||
exports.success = success; | ||
/** | ||
@@ -41,6 +43,6 @@ * @category constructors | ||
*/ | ||
exports.error = function (input, expected, fatal) { | ||
if (expected === void 0) { expected = Array_1.empty; } | ||
var error = function (input, expected, fatal) { | ||
if (expected === void 0) { expected = []; } | ||
if (fatal === void 0) { fatal = false; } | ||
return Either_1.left({ | ||
return (0, Either_1.left)({ | ||
input: input, | ||
@@ -51,2 +53,3 @@ expected: expected, | ||
}; | ||
exports.error = error; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -59,3 +62,4 @@ // combinators | ||
*/ | ||
exports.withExpected = function (err, expected) { return (__assign({}, err, { expected: expected })); }; | ||
var withExpected = function (err, expected) { return (__assign(__assign({}, err), { expected: expected })); }; | ||
exports.withExpected = withExpected; | ||
/** | ||
@@ -65,3 +69,4 @@ * @category combinators | ||
*/ | ||
exports.escalate = function (err) { return (__assign({}, err, { fatal: true })); }; | ||
var escalate = function (err) { return (__assign(__assign({}, err), { fatal: true })); }; | ||
exports.escalate = escalate; | ||
/** | ||
@@ -71,5 +76,6 @@ * @category combinators | ||
*/ | ||
exports.extend = function (err1, err2) { | ||
var extend = function (err1, err2) { | ||
return getSemigroup().concat(err1, err2); | ||
}; | ||
exports.extend = extend; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -81,11 +87,11 @@ // instances | ||
if (x.input.cursor < y.input.cursor) | ||
return Semigroup_1.getLastSemigroup().concat(x, y); | ||
return (0, Semigroup_1.last)().concat(x, y); | ||
if (x.input.cursor > y.input.cursor) | ||
return Semigroup_1.getFirstSemigroup().concat(x, y); | ||
return Semigroup_1.getStructSemigroup({ | ||
input: Semigroup_1.getFirstSemigroup(), | ||
fatal: Semigroup_1.getFirstSemigroup(), | ||
expected: Array_1.getMonoid() | ||
return (0, Semigroup_1.first)().concat(x, y); | ||
return (0, Semigroup_1.struct)({ | ||
input: (0, Semigroup_1.first)(), | ||
fatal: (0, Semigroup_1.first)(), | ||
expected: (0, Array_1.getMonoid)() | ||
}).concat(x, y); | ||
} | ||
}); }; |
@@ -30,5 +30,3 @@ import { Eq } from 'fp-ts/lib/Eq' | ||
*/ | ||
export declare const getAndNext: <A>( | ||
s: Stream<A> | ||
) => Option<{ | ||
export declare const getAndNext: <A>(s: Stream<A>) => Option<{ | ||
value: A | ||
@@ -35,0 +33,0 @@ next: Stream<A> |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getEq = exports.getAndNext = exports.atEnd = exports.get = exports.stream = void 0; | ||
/** | ||
@@ -8,4 +9,4 @@ * @since 0.6.0 | ||
var Eq_1 = require("fp-ts/lib/Eq"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var Option_1 = require("fp-ts/lib/Option"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -18,3 +19,3 @@ // constructors | ||
*/ | ||
exports.stream = function (buffer, cursor) { | ||
var stream = function (buffer, cursor) { | ||
if (cursor === void 0) { cursor = 0; } | ||
@@ -26,2 +27,3 @@ return ({ | ||
}; | ||
exports.stream = stream; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -34,3 +36,4 @@ // destructors | ||
*/ | ||
exports.get = function (s) { return Array_1.lookup(s.cursor, s.buffer); }; | ||
var get = function (s) { return (0, Array_1.lookup)(s.cursor, s.buffer); }; | ||
exports.get = get; | ||
/** | ||
@@ -40,3 +43,4 @@ * @category destructors | ||
*/ | ||
exports.atEnd = function (s) { return s.cursor >= s.buffer.length; }; | ||
var atEnd = function (s) { return s.cursor >= s.buffer.length; }; | ||
exports.atEnd = atEnd; | ||
/** | ||
@@ -46,5 +50,6 @@ * @category destructors | ||
*/ | ||
exports.getAndNext = function (s) { | ||
return pipeable_1.pipe(exports.get(s), Option_1.map(function (a) { return ({ value: a, next: { buffer: s.buffer, cursor: s.cursor + 1 } }); })); | ||
var getAndNext = function (s) { | ||
return (0, function_1.pipe)((0, exports.get)(s), (0, Option_1.map)(function (a) { return ({ value: a, next: { buffer: s.buffer, cursor: s.cursor + 1 } }); })); | ||
}; | ||
exports.getAndNext = getAndNext; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -57,5 +62,6 @@ // instances | ||
*/ | ||
exports.getEq = function (E) { | ||
var EA = Array_1.getEq(E); | ||
return Eq_1.fromEquals(function (x, y) { return x.cursor === y.cursor && EA.equals(x.buffer, y.buffer); }); | ||
var getEq = function (E) { | ||
var EA = (0, Array_1.getEq)(E); | ||
return (0, Eq_1.fromEquals)(function (x, y) { return x.cursor === y.cursor && EA.equals(x.buffer, y.buffer); }); | ||
}; | ||
exports.getEq = getEq; |
@@ -1,4 +0,1 @@ | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { Foldable, Foldable1 } from 'fp-ts/lib/Foldable' | ||
@@ -5,0 +2,0 @@ import { Functor, Functor1 } from 'fp-ts/lib/Functor' |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var E = __importStar(require("fp-ts/Either")); | ||
exports.run = exports.doubleQuotedString = exports.float = exports.int = exports.notSpaces1 = exports.notSpaces = exports.spaces1 = exports.spaces = exports.many1 = exports.many = exports.maybe = exports.fold = exports.oneOf = exports.string = void 0; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
var E = __importStar(require("fp-ts/lib/Either")); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var M = __importStar(require("fp-ts/lib/Monoid")); | ||
var O = __importStar(require("fp-ts/lib/Option")); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var string_1 = require("fp-ts/lib/string"); | ||
var C = __importStar(require("./char")); | ||
@@ -26,13 +47,14 @@ var P = __importStar(require("./Parser")); | ||
*/ | ||
exports.string = function (s) { | ||
var string = function (s) { | ||
return P.expected(P.ChainRec.chainRec(s, function (acc) { | ||
return pipeable_1.pipe(charAt(0, acc), O.fold(function () { return P.of(E.right(s)); }, function (c) { | ||
return pipeable_1.pipe(C.char(c), P.chain(function () { return P.of(E.left(acc.slice(1))); })); | ||
return (0, function_1.pipe)(charAt(0, acc), O.fold(function () { return P.of(E.right(s)); }, function (c) { | ||
return (0, function_1.pipe)(C.char(c), P.chain(function () { return P.of(E.left(acc.slice(1))); })); | ||
})); | ||
}), JSON.stringify(s)); | ||
}; | ||
exports.string = string; | ||
function oneOf(F) { | ||
return function (ss) { | ||
return F.reduce(ss, P.fail(), function (p, s) { | ||
return pipeable_1.pipe(p, P.alt(function () { return exports.string(s); })); | ||
return (0, function_1.pipe)(p, P.alt(function () { return (0, exports.string)(s); })); | ||
}); | ||
@@ -49,3 +71,3 @@ }; | ||
*/ | ||
exports.fold = M.fold(P.getMonoid(M.monoidString)); | ||
exports.fold = M.concatAll(P.getMonoid(string_1.Monoid)); | ||
// ------------------------------------------------------------------------------------- | ||
@@ -58,3 +80,3 @@ // combinators | ||
*/ | ||
exports.maybe = P.maybe(M.monoidString); | ||
exports.maybe = P.maybe(string_1.Monoid); | ||
/** | ||
@@ -67,3 +89,4 @@ * Matches the given parser zero or more times, returning a string of the | ||
*/ | ||
exports.many = function (parser) { return exports.maybe(exports.many1(parser)); }; | ||
var many = function (parser) { return (0, exports.maybe)((0, exports.many1)(parser)); }; | ||
exports.many = many; | ||
/** | ||
@@ -76,5 +99,6 @@ * Matches the given parser one or more times, returning a string of the | ||
*/ | ||
exports.many1 = function (parser) { | ||
return pipeable_1.pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
var many1 = function (parser) { | ||
return (0, function_1.pipe)(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
}; | ||
exports.many1 = many1; | ||
var charAt = function (index, s) { | ||
@@ -119,3 +143,3 @@ return index >= 0 && index < s.length ? O.some(s.charAt(index)) : O.none; | ||
*/ | ||
exports.int = P.expected(pipeable_1.pipe(exports.fold([exports.maybe(C.char('-')), C.many1(C.digit)]), P.map(function (s) { return +s; })), 'an integer'); | ||
exports.int = P.expected((0, function_1.pipe)((0, exports.fold)([(0, exports.maybe)(C.char('-')), C.many1(C.digit)]), P.map(function (s) { return +s; })), 'an integer'); | ||
/** | ||
@@ -125,4 +149,4 @@ * @category combinators | ||
*/ | ||
exports.float = P.expected(pipeable_1.pipe(exports.fold([exports.maybe(C.char('-')), C.many(C.digit), exports.maybe(exports.fold([C.char('.'), C.many1(C.digit)]))]), P.chain(function (s) { | ||
return pipeable_1.pipe(fromString(s), O.fold(function () { return P.fail(); }, P.succeed)); | ||
exports.float = P.expected((0, function_1.pipe)((0, exports.fold)([(0, exports.maybe)(C.char('-')), C.many(C.digit), (0, exports.maybe)((0, exports.fold)([C.char('.'), C.many1(C.digit)]))]), P.chain(function (s) { | ||
return (0, function_1.pipe)(fromString(s), O.fold(function () { return P.fail(); }, P.succeed)); | ||
})), 'a float'); | ||
@@ -137,3 +161,3 @@ /** | ||
*/ | ||
exports.doubleQuotedString = P.surroundedBy(C.char('"'))(exports.many(P.either(exports.string('\\"'), function () { return C.notChar('"'); }))); | ||
exports.doubleQuotedString = P.surroundedBy(C.char('"'))((0, exports.many)(P.either((0, exports.string)('\\"'), function () { return C.notChar('"'); }))); | ||
/** | ||
@@ -140,0 +164,0 @@ * @summary |
{ | ||
"name": "parser-ts", | ||
"version": "0.6.16", | ||
"version": "0.7.0", | ||
"description": "String parser combinators for TypeScript", | ||
@@ -20,3 +20,3 @@ "main": "lib/index.js", | ||
"peerDependencies": { | ||
"fp-ts": "^2.0.0" | ||
"fp-ts": "^2.14.0" | ||
}, | ||
@@ -23,0 +23,0 @@ "tags": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131519
4148