Comparing version 0.6.6 to 0.6.7
@@ -16,2 +16,20 @@ # Changelog | ||
# 0.6.7 | ||
- **New Feature** | ||
- split "mega" parser instance into individual instances (@IMax153) | ||
- Add `Functor` instance (@IMax153) | ||
- Add `Applicative` instance (@IMax153) | ||
- Add `Monad` instance (@IMax153) | ||
- Add `Alt` instance (@IMax153) | ||
- Add `Alternative` instance (@IMax153) | ||
- **Bug Fix** | ||
- account for all common line terminators in `code-frame` (@IMax153) | ||
- **Polish** | ||
- standardize export declarations in all modules (@IMax153) | ||
- add `category` tags to module exports (@IMax153) | ||
- **Internal** | ||
- remove `pipeable` from `Parser` module (@IMax153) | ||
- make `Location` model `readonly` in `code-frame` (@IMax153) | ||
# 0.6.6 | ||
@@ -25,3 +43,3 @@ | ||
- **Polish** | ||
- Make `between` and `surroundedBy` polymorphic in return type, #23 (@YBogomolov) | ||
- make `between` and `surroundedBy` polymorphic in return type, #23 (@YBogomolov) | ||
@@ -28,0 +46,0 @@ # 0.6.4 |
import * as P from './Parser'; | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -7,38 +8,51 @@ */ | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* The `char` parser constructor returns a parser which matches only the | ||
* specified single character | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many(parser: P.Parser<Char, Char>): P.Parser<Char, string>; | ||
export declare const char: (c: Char) => P.Parser<Char, Char>; | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* The `notChar` parser constructor makes a parser which will match any | ||
* single character other than the one provided. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many1(parser: P.Parser<Char, Char>): P.Parser<Char, string>; | ||
export declare const notChar: (c: Char) => P.Parser<Char, Char>; | ||
/** | ||
* The `char` parser constructor returns a parser which matches only the | ||
* specified single character | ||
* Matches any one character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function char(c: Char): P.Parser<Char, Char>; | ||
export declare const oneOf: (s: string) => P.Parser<Char, Char>; | ||
/** | ||
* The `notChar` parser constructor makes a parser which will match any | ||
* single character other than the one provided. | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function notChar(c: Char): P.Parser<Char, Char>; | ||
export declare const notOneOf: (s: string) => P.Parser<Char, Char>; | ||
/** | ||
* Matches any one character from the provided string. | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function oneOf(s: string): P.Parser<Char, Char>; | ||
export declare const many: (parser: P.Parser<Char, Char>) => P.Parser<Char, string>; | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const many1: (parser: P.Parser<Char, Char>) => P.Parser<Char, string>; | ||
/** | ||
* Matches a single digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -50,2 +64,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -57,2 +72,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -70,2 +86,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -77,2 +94,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -82,10 +100,5 @@ */ | ||
/** | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export declare function notOneOf(s: string): P.Parser<Char, Char>; | ||
/** | ||
* Matches a single character which isn't a digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -97,2 +110,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -104,2 +118,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -111,2 +126,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -118,2 +134,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -125,4 +142,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const notLower: P.Parser<Char, Char>; |
117
es6/char.js
@@ -9,29 +9,15 @@ /** | ||
var maybe = P.maybe(monoidString); | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export function many(parser) { | ||
return maybe(many1(parser)); | ||
} | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export function many1(parser) { | ||
return pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
} | ||
/** | ||
* The `char` parser constructor returns a parser which matches only the | ||
* specified single character | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function char(c) { | ||
export var char = function (c) { | ||
return P.expected(P.sat(function (s) { return s === c; }), "\"" + c + "\""); | ||
} | ||
}; | ||
/** | ||
@@ -41,24 +27,53 @@ * The `notChar` parser constructor makes a parser which will match any | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function notChar(c) { | ||
export var notChar = function (c) { | ||
return P.expected(P.sat(function (c1) { return c1 !== c; }), "anything but \"" + c + "\""); | ||
} | ||
function isOneOf(s, c) { | ||
return s.indexOf(c) !== -1; | ||
} | ||
}; | ||
var isOneOf = function (s, c) { return s.indexOf(c) !== -1; }; | ||
/** | ||
* Matches any one character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function oneOf(s) { | ||
export var oneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return isOneOf(s, c); }), "One of \"" + s + "\""); | ||
} | ||
function isDigit(c) { | ||
return '0123456789'.indexOf(c) !== -1; | ||
} | ||
}; | ||
/** | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export var notOneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of " + JSON.stringify(s)); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var many = function (parser) { return maybe(many1(parser)); }; | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var many1 = function (parser) { | ||
return pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
}; | ||
var isDigit = function (c) { return '0123456789'.indexOf(c) !== -1; }; | ||
/** | ||
* Matches a single digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -68,23 +83,17 @@ */ | ||
var spaceRe = /^\s$/; | ||
function isSpace(c) { | ||
return spaceRe.test(c); | ||
} | ||
var isSpace = function (c) { return spaceRe.test(c); }; | ||
/** | ||
* Matches a single whitespace character. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var space = P.expected(P.sat(isSpace), 'a whitespace'); | ||
function isUnderscore(c) { | ||
return c === '_'; | ||
} | ||
function isLetter(c) { | ||
return /[a-z]/.test(c.toLowerCase()); | ||
} | ||
function isAlphanum(c) { | ||
return isLetter(c) || isDigit(c) || isUnderscore(c); | ||
} | ||
var isUnderscore = function (c) { return c === '_'; }; | ||
var isLetter = function (c) { return /[a-z]/.test(c.toLowerCase()); }; | ||
var isAlphanum = function (c) { return isLetter(c) || isDigit(c) || isUnderscore(c); }; | ||
/** | ||
* Matches a single letter, digit or underscore character. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -99,17 +108,15 @@ */ | ||
export var letter = P.expected(P.sat(isLetter), 'a letter'); | ||
function isUpper(c) { | ||
return isLetter(c) && c === c.toUpperCase(); | ||
} | ||
var isUpper = function (c) { return isLetter(c) && c === c.toUpperCase(); }; | ||
/** | ||
* Matches a single upper case ASCII letter. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var upper = P.expected(P.sat(isUpper), 'an upper case letter'); | ||
function isLower(c) { | ||
return isLetter(c) && c === c.toLowerCase(); | ||
} | ||
var isLower = function (c) { return isLetter(c) && c === c.toLowerCase(); }; | ||
/** | ||
* Matches a single lower case ASCII letter. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -119,12 +126,5 @@ */ | ||
/** | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export function notOneOf(s) { | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of " + JSON.stringify(s)); | ||
} | ||
/** | ||
* Matches a single character which isn't a digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -136,2 +136,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -143,2 +144,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -150,2 +152,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -157,2 +160,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -164,4 +168,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var notLower = P.expected(P.sat(not(isLower)), 'anything but a lower case letter'); |
@@ -12,2 +12,2 @@ /** | ||
*/ | ||
export declare function run<A>(p: Parser<Char, A>, source: string): Either<string, A>; | ||
export declare const run: <A>(p: Parser<Char, A>, source: string) => Either<string, A>; |
@@ -8,3 +8,4 @@ /** | ||
var codeFrameColumns = require('@babel/code-frame').codeFrameColumns; | ||
function getLocation(source, cursor) { | ||
var lineTerminatorRegex = /^\r\n$|^[\n\r]$/; | ||
var getLocation = function (source, cursor) { | ||
var line = 1; | ||
@@ -16,3 +17,3 @@ var column = 1; | ||
var c = source.charAt(i); | ||
if (c === '\n') { | ||
if (lineTerminatorRegex.test(c)) { | ||
line++; | ||
@@ -31,3 +32,3 @@ column = 1; | ||
}; | ||
} | ||
}; | ||
/** | ||
@@ -38,3 +39,3 @@ * Returns a pretty printed error message using `@babel/code-frame` | ||
*/ | ||
export function run(p, source) { | ||
export var run = function (p, source) { | ||
return pipe(p(stream(source.split(''))), bimap(function (err) { | ||
@@ -45,2 +46,2 @@ return codeFrameColumns(source, getLocation(source, err.input.cursor), { | ||
}, function (succ) { return succ.value; })); | ||
} | ||
}; |
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { Alt2 } from 'fp-ts/es6/Alt'; | ||
import { Alternative2 } from 'fp-ts/es6/Alternative'; | ||
import { Predicate } from 'fp-ts/es6/function'; | ||
import { Applicative2 } from 'fp-ts/es6/Applicative'; | ||
import { Functor2 } from 'fp-ts/es6/Functor'; | ||
import { Monad2 } from 'fp-ts/es6/Monad'; | ||
import { Monoid } from 'fp-ts/es6/Monoid'; | ||
import { NonEmptyArray } from 'fp-ts/es6/NonEmptyArray'; | ||
import * as NEA from 'fp-ts/es6/NonEmptyArray'; | ||
import { Semigroup } from 'fp-ts/es6/Semigroup'; | ||
import { Predicate, Lazy } from 'fp-ts/es6/function'; | ||
import { ParseResult } from './ParseResult'; | ||
import { Stream } from './Stream'; | ||
declare module 'fp-ts/es6/HKT' { | ||
interface URItoKind2<E, A> { | ||
Parser: Parser<E, A>; | ||
} | ||
} | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
*/ | ||
export declare const URI = "Parser"; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export declare type URI = typeof URI; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export interface Parser<I, A> { | ||
@@ -36,11 +28,13 @@ (i: Stream<I>): ParseResult<I, A>; | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function succeed<I, A>(a: A): Parser<I, A>; | ||
export declare const succeed: <I, A>(a: A) => Parser<I, A>; | ||
/** | ||
* The `fail` parser will just fail immediately without consuming any input | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function fail<I, A = never>(): Parser<I, A>; | ||
export declare const fail: <I, A = never>() => Parser<I, A>; | ||
/** | ||
@@ -50,6 +44,17 @@ * The `failAt` parser will fail immediately without consuming any input, | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function failAt<I, A = never>(i: Stream<I>): Parser<I, A>; | ||
export declare const failAt: <I, A = never>(i: Stream<I>) => Parser<I, A>; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare const sat: <I>(predicate: Predicate<I>) => Parser<I, I>; | ||
/** | ||
* A parser combinator which returns the provided parser unchanged, except | ||
@@ -59,5 +64,6 @@ * that if it fails, the provided error message will be returned in the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function expected<I, A>(p: Parser<I, A>, message: string): Parser<I, A>; | ||
export declare const expected: <I, A>(p: Parser<I, A>, message: string) => Parser<I, A>; | ||
/** | ||
@@ -67,5 +73,6 @@ * The `item` parser consumes a single value, regardless of what it is, | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function item<I>(): Parser<I, I>; | ||
export declare const item: <I>() => Parser<I, I>; | ||
/** | ||
@@ -76,5 +83,6 @@ * The `cut` parser combinator takes a parser and produces a new parser for | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function cut<I, A>(p: Parser<I, A>): Parser<I, A>; | ||
export declare const cut: <I, A>(p: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
@@ -85,5 +93,6 @@ * Takes two parsers `p1` and `p2`, returning a parser which will match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function cutWith<I, A, B>(p1: Parser<I, A>, p2: Parser<I, B>): Parser<I, B>; | ||
export declare const cutWith: <I, A, B>(p1: Parser<I, A>, p2: Parser<I, B>) => Parser<I, B>; | ||
/** | ||
@@ -98,5 +107,6 @@ * The `seq` combinator takes a parser, and a function which will receive | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function seq<I, A, B>(fa: Parser<I, A>, f: (a: A) => Parser<I, B>): Parser<I, B>; | ||
export declare const seq: <I, A, B>(fa: Parser<I, A>, f: (a: A) => Parser<I, B>) => Parser<I, B>; | ||
/** | ||
@@ -112,5 +122,6 @@ * The `either` combinator takes two parsers, runs the first on the input | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function either<I, A>(p: Parser<I, A>, f: () => Parser<I, A>): Parser<I, A>; | ||
export declare const either: <I, A>(p: Parser<I, A>, f: () => Parser<I, A>) => Parser<I, A>; | ||
/** | ||
@@ -123,15 +134,7 @@ * Converts a parser into one which will return the point in the stream where | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function withStart<I, A>(p: Parser<I, A>): Parser<I, [A, Stream<I>]>; | ||
export declare const withStart: <I, A>(p: Parser<I, A>) => Parser<I, [A, Stream<I>]>; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sat<I>(predicate: Predicate<I>): Parser<I, I>; | ||
/** | ||
* The `maybe` parser combinator creates a parser which will run the provided | ||
@@ -141,11 +144,13 @@ * parser on the input, and if it fails, it will returns the empty value (as | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function maybe<A>(M: Monoid<A>): <I>(p: Parser<I, A>) => Parser<I, A>; | ||
export declare const maybe: <A>(M: Monoid<A>) => <I>(p: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* Matches the end of the stream. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function eof<I>(): Parser<I, void>; | ||
export declare const eof: <I>() => Parser<I, void>; | ||
/** | ||
@@ -160,5 +165,6 @@ * The `many` combinator takes a parser, and returns a new parser which will | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many<I, A>(p: Parser<I, A>): Parser<I, Array<A>>; | ||
export declare const many: <I, A>(p: Parser<I, A>) => Parser<I, A[]>; | ||
/** | ||
@@ -169,5 +175,6 @@ * The `many1` combinator is just like the `many` combinator, except it | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many1<I, A>(p: Parser<I, A>): Parser<I, NonEmptyArray<A>>; | ||
export declare const many1: <I, A>(p: Parser<I, A>) => Parser<I, NEA.NonEmptyArray<A>>; | ||
/** | ||
@@ -178,5 +185,6 @@ * Matches the provided parser `p` zero or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sepBy<I, A, B>(sep: Parser<I, A>, p: Parser<I, B>): Parser<I, Array<B>>; | ||
export declare const sepBy: <I, A, B>(sep: Parser<I, A>, p: Parser<I, B>) => Parser<I, B[]>; | ||
/** | ||
@@ -187,11 +195,14 @@ * Matches the provided parser `p` one or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sepBy1<I, A, B>(sep: Parser<I, A>, p: Parser<I, B>): Parser<I, NonEmptyArray<B>>; | ||
export declare const sepBy1: <I, A, B>(sep: Parser<I, A>, p: Parser<I, B>) => Parser<I, NEA.NonEmptyArray<B>>; | ||
/** | ||
* Like `sepBy1`, but cut on the separator, so that matching a `sep` not | ||
* followed by a `p` will cause a fatal error. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sepByCut<I, A, B>(sep: Parser<I, A>, p: Parser<I, B>): Parser<I, NonEmptyArray<B>>; | ||
export declare const sepByCut: <I, A, B>(sep: Parser<I, A>, p: Parser<I, B>) => Parser<I, NEA.NonEmptyArray<B>>; | ||
/** | ||
@@ -202,11 +213,13 @@ * Matches the provided parser `p` that occurs between the provided `left` and `right` parsers. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
export declare function between<I, A>(left: Parser<I, A>, right: Parser<I, A>): <B>(p: Parser<I, B>) => Parser<I, B>; | ||
export declare const between: <I, A>(left: Parser<I, A>, right: Parser<I, A>) => <B>(p: Parser<I, B>) => Parser<I, B>; | ||
/** | ||
* Matches the provided parser `p` that is surrounded by the `bound` parser. Shortcut for `between(bound, bound)`. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
export declare function surroundedBy<I, A>(bound: Parser<I, A>): <B>(p: Parser<I, B>) => Parser<I, B>; | ||
export declare const surroundedBy: <I, A>(bound: Parser<I, A>) => <B>(p: Parser<I, B>) => Parser<I, B>; | ||
/** | ||
@@ -229,2 +242,3 @@ * Takes a `Parser` and tries to match it without consuming any input. | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
@@ -246,46 +260,110 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
*/ | ||
export declare const takeUntil: <I>(predicate: Predicate<I>) => Parser<I, I[]>; | ||
export declare const takeUntil: <I>(predicate: Predicate<I>) => Parser<I, Array<I>>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Functor | ||
* @since 0.6.7 | ||
*/ | ||
export declare function getMonoid<I, A>(M: Monoid<A>): Monoid<Parser<I, A>>; | ||
export declare const map: <A, B>(f: (a: A) => B) => <I>(fa: Parser<I, A>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
export declare const parser: Monad2<URI> & Alternative2<URI>; | ||
declare const alt: <E, A>(that: () => Parser<E, A>) => (fa: Parser<E, A>) => Parser<E, A>, ap: <E, A>(fa: Parser<E, A>) => <B>(fab: Parser<E, (a: A) => B>) => Parser<E, B>, apFirst: <E, B>(fb: Parser<E, B>) => <A>(fa: Parser<E, A>) => Parser<E, A>, apSecond: <e, B>(fb: Parser<e, B>) => <A>(fa: Parser<e, A>) => Parser<e, B>, chain: <E, A, B>(f: (a: A) => Parser<E, B>) => (ma: Parser<E, A>) => Parser<E, B>, chainFirst: <E, A, B>(f: (a: A) => Parser<E, B>) => (ma: Parser<E, A>) => Parser<E, A>, flatten: <E, A>(mma: Parser<E, Parser<E, A>>) => Parser<E, A>, map: <A, B>(f: (a: A) => B) => <E>(fa: Parser<E, A>) => Parser<E, B>; | ||
export { | ||
export declare const ap: <I, A>(fa: Parser<I, A>) => <B>(fab: Parser<I, (a: A) => B>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
alt, | ||
export declare const apFirst: <I, B>(fb: Parser<I, B>) => <A>(fa: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
ap, | ||
export declare const apSecond: <I, B>(fb: Parser<I, B>) => <A>(fa: Parser<I, A>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Applicative | ||
* @since 0.6.7 | ||
*/ | ||
apFirst, | ||
export declare const of: <I, A>(a: A) => Parser<I, A>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
apSecond, | ||
export declare const chain: <I, A, B>(f: (a: A) => Parser<I, B>) => (ma: Parser<I, A>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
chain, | ||
export declare const chainFirst: <I, A, B>(f: (a: A) => Parser<I, B>) => (ma: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* @category Alt | ||
* @since 0.6.7 | ||
*/ | ||
export declare const alt: <I, A>(that: Lazy<Parser<I, A>>) => (fa: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
export declare const flatten: <I, A>(mma: Parser<I, Parser<I, A>>) => Parser<I, A>; | ||
/** | ||
* @category Alternative | ||
* @since 0.6.7 | ||
*/ | ||
export declare const zero: <I, A>() => Parser<I, A>; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
chainFirst, | ||
export declare const URI = "Parser"; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
flatten, | ||
export declare type URI = typeof URI; | ||
declare module 'fp-ts/es6/HKT' { | ||
interface URItoKind2<E, A> { | ||
Parser: Parser<E, A>; | ||
} | ||
} | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const getSemigroup: <I, A>(S: Semigroup<A>) => Semigroup<Parser<I, A>>; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
map }; | ||
export declare const getMonoid: <I, A>(M: Monoid<A>) => Monoid<Parser<I, A>>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Functor: Functor2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Applicative: Applicative2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Monad: Monad2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Alt: Alt2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Alternative: Alternative2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const parser: Monad2<URI> & Alternative2<URI>; |
@@ -12,15 +12,14 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import { empty } from 'fp-ts/es6/Array'; | ||
import * as A from 'fp-ts/es6/Array'; | ||
import * as E from 'fp-ts/es6/Either'; | ||
import { not } from 'fp-ts/es6/function'; | ||
import { cons } from 'fp-ts/es6/NonEmptyArray'; | ||
import * as NEA from 'fp-ts/es6/NonEmptyArray'; | ||
import * as O from 'fp-ts/es6/Option'; | ||
import { pipe, pipeable } from 'fp-ts/es6/pipeable'; | ||
import { identity, not } from 'fp-ts/es6/function'; | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
import { error, escalate, extend, success, withExpected } from './ParseResult'; | ||
import { atEnd, getAndNext } from './Stream'; | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export var URI = 'Parser'; | ||
/** | ||
* The `succeed` parser constructor creates a parser which will simply | ||
@@ -31,15 +30,13 @@ * return the value provided as its argument, without consuming any input. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function succeed(a) { | ||
return function (i) { return success(a, i, i); }; | ||
} | ||
export var succeed = function (a) { return function (i) { return success(a, i, i); }; }; | ||
/** | ||
* The `fail` parser will just fail immediately without consuming any input | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function fail() { | ||
return function (i) { return error(i); }; | ||
} | ||
export var fail = function () { return function (i) { return error(i); }; }; | ||
/** | ||
@@ -49,8 +46,25 @@ * The `failAt` parser will fail immediately without consuming any input, | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function failAt(i) { | ||
return function () { return error(i); }; | ||
} | ||
export var failAt = function (i) { return function () { return error(i); }; }; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export var sat = function (predicate) { | ||
return pipe(withStart(item()), chain(function (_a) { | ||
var a = _a[0], start = _a[1]; | ||
return (predicate(a) ? of(a) : failAt(start)); | ||
})); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* A parser combinator which returns the provided parser unchanged, except | ||
@@ -60,9 +74,8 @@ * that if it fails, the provided error message will be returned in the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function expected(p, message) { | ||
return function (i) { | ||
return pipe(p(i), E.mapLeft(function (err) { return withExpected(err, [message]); })); | ||
}; | ||
} | ||
export var expected = function (p, message) { return function (i) { | ||
return pipe(p(i), E.mapLeft(function (err) { return withExpected(err, [message]); })); | ||
}; }; | ||
/** | ||
@@ -72,12 +85,11 @@ * The `item` parser consumes a single value, regardless of what it is, | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function item() { | ||
return function (i) { | ||
return pipe(getAndNext(i), O.fold(function () { return error(i); }, function (_a) { | ||
var value = _a.value, next = _a.next; | ||
return success(value, next, i); | ||
})); | ||
}; | ||
} | ||
export var item = function () { return function (i) { | ||
return pipe(getAndNext(i), O.fold(function () { return error(i); }, function (_a) { | ||
var value = _a.value, next = _a.next; | ||
return success(value, next, i); | ||
})); | ||
}; }; | ||
/** | ||
@@ -88,7 +100,6 @@ * The `cut` parser combinator takes a parser and produces a new parser for | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function cut(p) { | ||
return function (i) { return pipe(p(i), E.mapLeft(escalate)); }; | ||
} | ||
export var cut = function (p) { return function (i) { return pipe(p(i), E.mapLeft(escalate)); }; }; | ||
/** | ||
@@ -99,7 +110,8 @@ * Takes two parsers `p1` and `p2`, returning a parser which will match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function cutWith(p1, p2) { | ||
export var cutWith = function (p1, p2) { | ||
return pipe(p1, apSecond(cut(p2))); | ||
} | ||
}; | ||
/** | ||
@@ -114,7 +126,10 @@ * The `seq` combinator takes a parser, and a function which will receive | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function seq(fa, f) { | ||
return function (i) { return E.either.chain(fa(i), function (s) { return E.either.chain(f(s.value)(s.next), function (next) { return success(next.value, next.next, i); }); }); }; | ||
} | ||
export var seq = function (fa, f) { return function (i) { | ||
return pipe(fa(i), E.chain(function (s) { | ||
return pipe(f(s.value)(s.next), E.chain(function (next) { return success(next.value, next.next, i); })); | ||
})); | ||
}; }; | ||
/** | ||
@@ -130,16 +145,15 @@ * The `either` combinator takes two parsers, runs the first on the input | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function either(p, f) { | ||
return function (i) { | ||
var e = p(i); | ||
if (E.isRight(e)) { | ||
return e; | ||
} | ||
if (e.left.fatal) { | ||
return e; | ||
} | ||
return pipe(f()(i), E.mapLeft(function (err) { return extend(e.left, err); })); | ||
}; | ||
} | ||
export var either = function (p, f) { return function (i) { | ||
var e = p(i); | ||
if (E.isRight(e)) { | ||
return e; | ||
} | ||
if (e.left.fatal) { | ||
return e; | ||
} | ||
return pipe(f()(i), E.mapLeft(function (err) { return extend(e.left, err); })); | ||
}; }; | ||
/** | ||
@@ -152,24 +166,9 @@ * Converts a parser into one which will return the point in the stream where | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function withStart(p) { | ||
return function (i) { | ||
return pipe(p(i), E.map(function (s) { return (__assign({}, s, { value: [s.value, i] })); })); | ||
}; | ||
} | ||
export var withStart = function (p) { return function (i) { | ||
return pipe(p(i), E.map(function (s) { return (__assign({}, s, { value: [s.value, i] })); })); | ||
}; }; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export function sat(predicate) { | ||
return pipe(withStart(item()), chain(function (_a) { | ||
var a = _a[0], start = _a[1]; | ||
return (predicate(a) ? parser.of(a) : failAt(start)); | ||
})); | ||
} | ||
/** | ||
* The `maybe` parser combinator creates a parser which will run the provided | ||
@@ -179,15 +178,15 @@ * parser on the input, and if it fails, it will returns the empty value (as | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function maybe(M) { | ||
return alt(function () { return parser.of(M.empty); }); | ||
} | ||
export var maybe = function (M) { return alt(function () { return of(M.empty); }); }; | ||
/** | ||
* Matches the end of the stream. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function eof() { | ||
export var eof = function () { | ||
return expected(function (i) { return (atEnd(i) ? success(undefined, i, i) : error(i)); }, 'end of file'); | ||
} | ||
}; | ||
/** | ||
@@ -202,7 +201,8 @@ * The `many` combinator takes a parser, and returns a new parser which will | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function many(p) { | ||
return pipe(many1(p), alt(function () { return parser.of(empty); })); | ||
} | ||
export var many = function (p) { | ||
return pipe(many1(p), alt(function () { return of(A.empty); })); | ||
}; | ||
/** | ||
@@ -213,7 +213,10 @@ * The `many1` combinator is just like the `many` combinator, except it | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function many1(p) { | ||
return parser.chain(p, function (head) { return parser.map(many(p), function (tail) { return cons(head, tail); }); }); | ||
} | ||
export var many1 = function (p) { | ||
return pipe(p, chain(function (head) { | ||
return pipe(many(p), map(function (tail) { return NEA.cons(head, tail); })); | ||
})); | ||
}; | ||
/** | ||
@@ -224,8 +227,9 @@ * Matches the provided parser `p` zero or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function sepBy(sep, p) { | ||
var nil = parser.of(empty); | ||
export var sepBy = function (sep, p) { | ||
var nil = of(A.empty); | ||
return pipe(sepBy1(sep, p), alt(function () { return nil; })); | ||
} | ||
}; | ||
/** | ||
@@ -236,17 +240,22 @@ * Matches the provided parser `p` one or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function sepBy1(sep, p) { | ||
var bs = many(pipe(sep, apSecond(p))); | ||
return parser.chain(p, function (head) { return parser.map(bs, function (tail) { return cons(head, tail); }); }); | ||
} | ||
export var sepBy1 = function (sep, p) { | ||
return pipe(p, chain(function (head) { | ||
return pipe(many(pipe(sep, apSecond(p))), map(function (tail) { return NEA.cons(head, tail); })); | ||
})); | ||
}; | ||
/** | ||
* Like `sepBy1`, but cut on the separator, so that matching a `sep` not | ||
* followed by a `p` will cause a fatal error. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function sepByCut(sep, p) { | ||
var bs = many(cutWith(sep, p)); | ||
return parser.chain(p, function (head) { return parser.map(bs, function (tail) { return cons(head, tail); }); }); | ||
} | ||
export var sepByCut = function (sep, p) { | ||
return pipe(p, chain(function (head) { | ||
return pipe(many(cutWith(sep, p)), map(function (tail) { return NEA.cons(head, tail); })); | ||
})); | ||
}; | ||
/** | ||
@@ -257,17 +266,17 @@ * Matches the provided parser `p` that occurs between the provided `left` and `right` parsers. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
export function between(left, right) { | ||
return function (p) { | ||
return pipe(left, chain(function () { return p; }), chainFirst(function () { return right; })); | ||
}; | ||
} | ||
export var between = function (left, right) { return function (p) { | ||
return pipe(left, chain(function () { return p; }), chainFirst(function () { return right; })); | ||
}; }; | ||
/** | ||
* Matches the provided parser `p` that is surrounded by the `bound` parser. Shortcut for `between(bound, bound)`. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
export function surroundedBy(bound) { | ||
export var surroundedBy = function (bound) { | ||
return between(bound, bound); | ||
} | ||
}; | ||
/** | ||
@@ -290,6 +299,7 @@ * Takes a `Parser` and tries to match it without consuming any input. | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
*/ | ||
export var lookAhead = function (p) { return function (i) { | ||
return E.either.chain(p(i), function (next) { return success(next.value, i, i); }); | ||
return pipe(p(i), E.chain(function (next) { return success(next.value, i, i); })); | ||
}; }; | ||
@@ -309,61 +319,162 @@ /** | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
*/ | ||
export var takeUntil = function (predicate) { return many(sat(not(predicate))); }; | ||
// ------------------------------------------------------------------------------------- | ||
// non-pipeables | ||
// ------------------------------------------------------------------------------------- | ||
var map_ = function (ma, f) { return function (i) { | ||
return pipe(ma(i), E.map(function (s) { return (__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 seq(ma, f); }; | ||
var alt_ = function (fa, that) { return either(fa, that); }; | ||
// ------------------------------------------------------------------------------------- | ||
// pipeables | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @since 0.6.0 | ||
* @category Functor | ||
* @since 0.6.7 | ||
*/ | ||
export function getMonoid(M) { | ||
return { | ||
concat: function (x, y) { | ||
return parser.ap(parser.map(x, function (x) { return function (y) { return M.concat(x, y); }; }), y); | ||
}, | ||
empty: succeed(M.empty) | ||
}; | ||
} | ||
export var map = function (f) { return function (fa) { return map_(fa, f); }; }; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
export var parser = { | ||
URI: URI, | ||
map: function (fa, f) { return function (i) { return E.either.map(fa(i), function (s) { return (__assign({}, s, { value: f(s.value) })); }); }; }, | ||
of: succeed, | ||
ap: function (fab, fa) { return parser.chain(fab, function (f) { return parser.map(fa, f); }); }, | ||
chain: seq, | ||
alt: either, | ||
zero: fail | ||
}; | ||
var _a = pipeable(parser), alt = _a.alt, ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map; | ||
export { | ||
export var ap = function (fa) { return function (fab) { | ||
return ap_(fab, fa); | ||
}; }; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
alt, | ||
export var apFirst = function (fb) { return function (fa) { | ||
return ap_(map_(fa, function (a) { return function () { return a; }; }), fb); | ||
}; }; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
ap, | ||
export var apSecond = function (fb) { return function (fa) { | ||
return ap_(map_(fa, function () { return function (b) { return b; }; }), fb); | ||
}; }; | ||
/** | ||
* @since 0.6.0 | ||
* @category Applicative | ||
* @since 0.6.7 | ||
*/ | ||
apFirst, | ||
export var of = succeed; | ||
/** | ||
* @since 0.6.0 | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
apSecond, | ||
export var chain = function (f) { return function (ma) { | ||
return chain_(ma, f); | ||
}; }; | ||
/** | ||
* @since 0.6.0 | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
chain, | ||
export var chainFirst = function (f) { return function (ma) { | ||
return chain_(ma, function (a) { return map_(f(a), function () { return a; }); }); | ||
}; }; | ||
/** | ||
* @since 0.6.0 | ||
* @category Alt | ||
* @since 0.6.7 | ||
*/ | ||
chainFirst, | ||
export var alt = function (that) { return function (fa) { return alt_(fa, that); }; }; | ||
/** | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
export var flatten = function (mma) { return chain_(mma, identity); }; | ||
/** | ||
* @category Alternative | ||
* @since 0.6.7 | ||
*/ | ||
export var zero = fail; | ||
// ------------------------------------------------------------------------------------- | ||
// instances | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
flatten, | ||
export var URI = 'Parser'; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export var getSemigroup = function (S) { return ({ | ||
concat: function (x, y) { | ||
return ap_(map_(x, function (x) { return function (y) { return S.concat(x, y); }; }), y); | ||
} | ||
}); }; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
map }; | ||
export var getMonoid = function (M) { return (__assign({}, getSemigroup(M), { empty: succeed(M.empty) })); }; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export var Functor = { | ||
URI: URI, | ||
map: map_ | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export var Applicative = { | ||
URI: URI, | ||
map: map_, | ||
ap: ap_, | ||
of: of | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export var Monad = { | ||
URI: URI, | ||
map: map_, | ||
ap: ap_, | ||
of: of, | ||
chain: chain_ | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export var Alt = { | ||
URI: URI, | ||
map: map_, | ||
alt: alt_ | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export var Alternative = { | ||
URI: URI, | ||
map: map_, | ||
of: of, | ||
ap: ap_, | ||
alt: alt_, | ||
zero: fail | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export var parser = { | ||
URI: URI, | ||
map: map_, | ||
of: of, | ||
ap: ap_, | ||
chain: chain_, | ||
alt: alt_, | ||
zero: fail | ||
}; |
import { Either } from 'fp-ts/es6/Either'; | ||
import { Stream } from './Stream'; | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -12,2 +13,3 @@ */ | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -21,2 +23,3 @@ */ | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -26,20 +29,25 @@ */ | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function withExpected<I>(err: ParseError<I>, expected: Array<string>): ParseError<I>; | ||
export declare const success: <I, A>(value: A, next: Stream<I>, start: Stream<I>) => ParseResult<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function escalate<I>(err: ParseError<I>): ParseError<I>; | ||
export declare const error: <I, A = never>(input: Stream<I>, expected?: Array<string>, fatal?: boolean) => ParseResult<I, A>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function extend<I>(err1: ParseError<I>, err2: ParseError<I>): ParseError<I>; | ||
export declare const withExpected: <I>(err: ParseError<I>, expected: Array<string>) => ParseError<I>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function success<I, A>(value: A, next: Stream<I>, start: Stream<I>): ParseResult<I, A>; | ||
export declare const escalate: <I>(err: ParseError<I>) => ParseError<I>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function error<I, A = never>(input: Stream<I>, expected?: Array<string>, fatal?: boolean): ParseResult<I, A>; | ||
export declare const extend: <I>(err1: ParseError<I>, err2: ParseError<I>) => ParseError<I>; |
@@ -15,34 +15,13 @@ var __assign = (this && this.__assign) || function () { | ||
*/ | ||
import { empty } from 'fp-ts/es6/Array'; | ||
import { empty, getMonoid } from 'fp-ts/es6/Array'; | ||
import { left, right } from 'fp-ts/es6/Either'; | ||
import { getFirstSemigroup, getLastSemigroup, getStructSemigroup } from 'fp-ts/es6/Semigroup'; | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function withExpected(err, expected) { | ||
return __assign({}, err, { expected: expected }); | ||
} | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export function escalate(err) { | ||
return __assign({}, err, { fatal: true }); | ||
} | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export function extend(err1, err2) { | ||
if (err1.input.cursor < err2.input.cursor) { | ||
return err2; | ||
} | ||
else if (err1.input.cursor > err2.input.cursor) { | ||
return err1; | ||
} | ||
else { | ||
return __assign({}, err1, { expected: err1.expected.concat(err2.expected) }); | ||
} | ||
} | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export function success(value, next, start) { | ||
export var success = function (value, next, start) { | ||
return right({ | ||
@@ -53,7 +32,8 @@ value: value, | ||
}); | ||
} | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function error(input, expected, fatal) { | ||
export var error = function (input, expected, fatal) { | ||
if (expected === void 0) { expected = empty; } | ||
@@ -66,2 +46,38 @@ if (fatal === void 0) { fatal = false; } | ||
}); | ||
} | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var withExpected = function (err, expected) { return (__assign({}, err, { expected: expected })); }; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var escalate = function (err) { return (__assign({}, err, { fatal: true })); }; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var extend = function (err1, err2) { | ||
return getSemigroup().concat(err1, err2); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// instances | ||
// ------------------------------------------------------------------------------------- | ||
var getSemigroup = function () { return ({ | ||
concat: function (x, y) { | ||
if (x.input.cursor < y.input.cursor) | ||
return getLastSemigroup().concat(x, y); | ||
if (x.input.cursor > y.input.cursor) | ||
return getFirstSemigroup().concat(x, y); | ||
return getStructSemigroup({ | ||
input: getFirstSemigroup(), | ||
fatal: getFirstSemigroup(), | ||
expected: getMonoid() | ||
}).concat(x, y); | ||
} | ||
}); }; |
import { Eq } from 'fp-ts/es6/Eq'; | ||
import { Option } from 'fp-ts/es6/Option'; | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -11,17 +12,21 @@ */ | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function stream<A>(buffer: Array<A>, cursor?: number): Stream<A>; | ||
export declare const stream: <A>(buffer: Array<A>, cursor?: number) => Stream<A>; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function get<A>(s: Stream<A>): Option<A>; | ||
export declare const get: <A>(s: Stream<A>) => Option<A>; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function atEnd<A>(s: Stream<A>): boolean; | ||
export declare const atEnd: <A>(s: Stream<A>) => boolean; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function getAndNext<A>(s: Stream<A>): Option<{ | ||
export declare const getAndNext: <A>(s: Stream<A>) => Option<{ | ||
value: A; | ||
@@ -31,4 +36,5 @@ next: Stream<A>; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
export declare function getEq<A>(E: Eq<A>): Eq<Stream<A>>; | ||
export declare const getEq: <A>(E: Eq<A>) => Eq<Stream<A>>; |
@@ -8,33 +8,46 @@ /** | ||
import { pipe } from 'fp-ts/es6/pipeable'; | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export function stream(buffer, cursor) { | ||
export var stream = function (buffer, cursor) { | ||
if (cursor === void 0) { cursor = 0; } | ||
return { buffer: buffer, cursor: cursor }; | ||
} | ||
return ({ | ||
buffer: buffer, | ||
cursor: cursor | ||
}); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// destructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export function get(s) { | ||
return lookup(s.cursor, s.buffer); | ||
} | ||
export var get = function (s) { return lookup(s.cursor, s.buffer); }; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export function atEnd(s) { | ||
return s.cursor >= s.buffer.length; | ||
} | ||
export var atEnd = function (s) { return s.cursor >= s.buffer.length; }; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export function getAndNext(s) { | ||
export var getAndNext = function (s) { | ||
return pipe(get(s), map(function (a) { return ({ value: a, next: { buffer: s.buffer, cursor: s.cursor + 1 } }); })); | ||
} | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// instances | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
export function getEq(E) { | ||
export var getEq = function (E) { | ||
var EA = getArrayEq(E); | ||
return fromEquals(function (x, y) { return x.cursor === y.cursor && EA.equals(x.buffer, y.buffer); }); | ||
} | ||
}; |
@@ -10,35 +10,46 @@ /** | ||
/** | ||
* Matches the exact string provided. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare const maybe: <I>(p: P.Parser<I, string>) => P.Parser<I, string>; | ||
export declare const string: (s: string) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches the given parser zero or more times, returning a string of the | ||
* entire match | ||
* Matches one of a list of strings. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many(parser: P.Parser<C.Char, string>): P.Parser<C.Char, string>; | ||
export declare function oneOf<F extends URIS>(F: Functor1<F> & Foldable1<F>): (ss: Kind<F, string>) => P.Parser<C.Char, string>; | ||
export declare function oneOf<F>(F: Functor<F> & Foldable<F>): (ss: HKT<F, string>) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches the given parser one or more times, returning a string of the | ||
* entire match | ||
* | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many1(parser: P.Parser<C.Char, string>): P.Parser<C.Char, string>; | ||
export declare const fold: <I>(as: Array<P.Parser<I, string>>) => P.Parser<I, string>; | ||
/** | ||
* Matches the exact string provided. | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const maybe: <I>(p: P.Parser<I, string>) => P.Parser<I, string>; | ||
/** | ||
* Matches the given parser zero or more times, returning a string of the | ||
* entire match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function string(s: string): P.Parser<C.Char, string>; | ||
export declare const many: (parser: P.Parser<C.Char, string>) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches one of a list of strings. | ||
* Matches the given parser one or more times, returning a string of the | ||
* entire match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function oneOf<F extends URIS>(F: Functor1<F> & Foldable1<F>): (ss: Kind<F, string>) => P.Parser<C.Char, string>; | ||
export declare function oneOf<F>(F: Functor<F> & Foldable<F>): (ss: HKT<F, string>) => P.Parser<C.Char, string>; | ||
export declare const many1: (parser: P.Parser<C.Char, string>) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches zero or more whitespace characters. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -50,2 +61,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -57,2 +69,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -64,2 +77,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -69,10 +83,8 @@ */ | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const fold: <I>(as: Array<P.Parser<I, string>>) => P.Parser<I, string>; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export declare const int: P.Parser<C.Char, number>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -86,4 +98,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const doubleQuotedString: P.Parser<string, string>; | ||
export declare const doubleQuotedString: P.Parser<string, String>; |
@@ -6,5 +6,41 @@ import * as M from 'fp-ts/es6/Monoid'; | ||
import * as P from './Parser'; | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Matches the exact string provided. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export var string = function (s) { | ||
var _string = function (s2) { | ||
return pipe(charAt(0, s2), O.fold(function () { return P.succeed(''); }, function (c) { | ||
return pipe(C.char(c), P.chain(function () { return _string(s2.slice(1)); }), P.chain(function () { return P.succeed(s); })); | ||
})); | ||
}; | ||
return P.expected(_string(s), JSON.stringify(s)); | ||
}; | ||
export function oneOf(F) { | ||
return function (ss) { | ||
return F.reduce(ss, P.fail(), function (p, s) { | ||
return pipe(p, P.alt(function () { return string(s); })); | ||
}); | ||
}; | ||
} | ||
// ------------------------------------------------------------------------------------- | ||
// destructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export var fold = M.fold(P.getMonoid(M.monoidString)); | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var maybe = P.maybe(M.monoidString); | ||
@@ -15,7 +51,6 @@ /** | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function many(parser) { | ||
return maybe(many1(parser)); | ||
} | ||
export var many = function (parser) { return maybe(many1(parser)); }; | ||
/** | ||
@@ -25,33 +60,15 @@ * Matches the given parser one or more times, returning a string of the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export function many1(parser) { | ||
export var many1 = function (parser) { | ||
return pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
} | ||
function charAt(index, s) { | ||
}; | ||
var charAt = function (index, s) { | ||
return index >= 0 && index < s.length ? O.some(s.charAt(index)) : O.none; | ||
} | ||
}; | ||
/** | ||
* Matches the exact string provided. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export function string(s) { | ||
function _string(s2) { | ||
return pipe(charAt(0, s2), O.fold(function () { return P.succeed(''); }, function (c) { | ||
return pipe(C.char(c), P.chain(function () { return _string(s2.slice(1)); }), P.chain(function () { return P.succeed(s); })); | ||
})); | ||
} | ||
return P.expected(_string(s), JSON.stringify(s)); | ||
} | ||
export function oneOf(F) { | ||
return function (ss) { | ||
return F.reduce(ss, P.fail(), function (p, s) { | ||
return pipe(p, P.alt(function () { return string(s); })); | ||
}); | ||
}; | ||
} | ||
/** | ||
* Matches zero or more whitespace characters. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -63,2 +80,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -70,2 +88,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -77,14 +96,12 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var notSpaces1 = C.many1(C.notSpace); | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export var fold = M.fold(P.getMonoid(M.monoidString)); | ||
function fromString(s) { | ||
var fromString = function (s) { | ||
var n = +s; | ||
return isNaN(n) || s === '' ? O.none : O.some(n); | ||
} | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -94,2 +111,3 @@ */ | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -105,4 +123,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export var doubleQuotedString = P.surroundedBy(C.char('"'))(many(P.either(string('\\"'), function () { return C.notChar('"'); }))); |
import * as P from './Parser'; | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -7,38 +8,51 @@ */ | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* The `char` parser constructor returns a parser which matches only the | ||
* specified single character | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many(parser: P.Parser<Char, Char>): P.Parser<Char, string>; | ||
export declare const char: (c: Char) => P.Parser<Char, Char>; | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* The `notChar` parser constructor makes a parser which will match any | ||
* single character other than the one provided. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many1(parser: P.Parser<Char, Char>): P.Parser<Char, string>; | ||
export declare const notChar: (c: Char) => P.Parser<Char, Char>; | ||
/** | ||
* The `char` parser constructor returns a parser which matches only the | ||
* specified single character | ||
* Matches any one character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function char(c: Char): P.Parser<Char, Char>; | ||
export declare const oneOf: (s: string) => P.Parser<Char, Char>; | ||
/** | ||
* The `notChar` parser constructor makes a parser which will match any | ||
* single character other than the one provided. | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function notChar(c: Char): P.Parser<Char, Char>; | ||
export declare const notOneOf: (s: string) => P.Parser<Char, Char>; | ||
/** | ||
* Matches any one character from the provided string. | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function oneOf(s: string): P.Parser<Char, Char>; | ||
export declare const many: (parser: P.Parser<Char, Char>) => P.Parser<Char, string>; | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const many1: (parser: P.Parser<Char, Char>) => P.Parser<Char, string>; | ||
/** | ||
* Matches a single digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -50,2 +64,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -57,2 +72,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -70,2 +86,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -77,2 +94,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -82,10 +100,5 @@ */ | ||
/** | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export declare function notOneOf(s: string): P.Parser<Char, Char>; | ||
/** | ||
* Matches a single character which isn't a digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -97,2 +110,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -104,2 +118,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -111,2 +126,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -118,2 +134,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -125,4 +142,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const notLower: P.Parser<Char, Char>; |
123
lib/char.js
@@ -11,32 +11,15 @@ "use strict"; | ||
var maybe = P.maybe(Monoid_1.monoidString); | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
function many(parser) { | ||
return maybe(many1(parser)); | ||
} | ||
exports.many = many; | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
function many1(parser) { | ||
return pipeable_1.pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
} | ||
exports.many1 = many1; | ||
/** | ||
* The `char` parser constructor returns a parser which matches only the | ||
* specified single character | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function char(c) { | ||
exports.char = function (c) { | ||
return P.expected(P.sat(function (s) { return s === c; }), "\"" + c + "\""); | ||
} | ||
exports.char = char; | ||
}; | ||
/** | ||
@@ -46,26 +29,53 @@ * The `notChar` parser constructor makes a parser which will match any | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function notChar(c) { | ||
exports.notChar = function (c) { | ||
return P.expected(P.sat(function (c1) { return c1 !== c; }), "anything but \"" + c + "\""); | ||
} | ||
exports.notChar = notChar; | ||
function isOneOf(s, c) { | ||
return s.indexOf(c) !== -1; | ||
} | ||
}; | ||
var isOneOf = function (s, c) { return s.indexOf(c) !== -1; }; | ||
/** | ||
* Matches any one character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function oneOf(s) { | ||
exports.oneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return isOneOf(s, c); }), "One of \"" + s + "\""); | ||
} | ||
exports.oneOf = oneOf; | ||
function isDigit(c) { | ||
return '0123456789'.indexOf(c) !== -1; | ||
} | ||
}; | ||
/** | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
exports.notOneOf = function (s) { | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of " + JSON.stringify(s)); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it zero or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.many = function (parser) { return maybe(exports.many1(parser)); }; | ||
/** | ||
* Takes a `Parser<Char, string>` and matches it one or more times, returning | ||
* a `string` of what was matched. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.many1 = function (parser) { | ||
return pipeable_1.pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
}; | ||
var isDigit = function (c) { return '0123456789'.indexOf(c) !== -1; }; | ||
/** | ||
* Matches a single digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -75,23 +85,17 @@ */ | ||
var spaceRe = /^\s$/; | ||
function isSpace(c) { | ||
return spaceRe.test(c); | ||
} | ||
var isSpace = function (c) { return spaceRe.test(c); }; | ||
/** | ||
* Matches a single whitespace character. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.space = P.expected(P.sat(isSpace), 'a whitespace'); | ||
function isUnderscore(c) { | ||
return c === '_'; | ||
} | ||
function isLetter(c) { | ||
return /[a-z]/.test(c.toLowerCase()); | ||
} | ||
function isAlphanum(c) { | ||
return isLetter(c) || isDigit(c) || isUnderscore(c); | ||
} | ||
var isUnderscore = function (c) { return c === '_'; }; | ||
var isLetter = function (c) { return /[a-z]/.test(c.toLowerCase()); }; | ||
var isAlphanum = function (c) { return isLetter(c) || isDigit(c) || isUnderscore(c); }; | ||
/** | ||
* Matches a single letter, digit or underscore character. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -106,17 +110,15 @@ */ | ||
exports.letter = P.expected(P.sat(isLetter), 'a letter'); | ||
function isUpper(c) { | ||
return isLetter(c) && c === c.toUpperCase(); | ||
} | ||
var isUpper = function (c) { return isLetter(c) && c === c.toUpperCase(); }; | ||
/** | ||
* Matches a single upper case ASCII letter. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.upper = P.expected(P.sat(isUpper), 'an upper case letter'); | ||
function isLower(c) { | ||
return isLetter(c) && c === c.toLowerCase(); | ||
} | ||
var isLower = function (c) { return isLetter(c) && c === c.toLowerCase(); }; | ||
/** | ||
* Matches a single lower case ASCII letter. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -126,13 +128,5 @@ */ | ||
/** | ||
* Matches a single character which isn't a character from the provided string. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
function notOneOf(s) { | ||
return P.expected(P.sat(function (c) { return !isOneOf(s, c); }), "Not one of " + JSON.stringify(s)); | ||
} | ||
exports.notOneOf = notOneOf; | ||
/** | ||
* Matches a single character which isn't a digit. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -144,2 +138,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -151,2 +146,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -158,2 +154,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -165,2 +162,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -172,4 +170,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.notLower = P.expected(P.sat(function_1.not(isLower)), 'anything but a lower case letter'); |
@@ -12,2 +12,2 @@ /** | ||
*/ | ||
export declare function run<A>(p: Parser<Char, A>, source: string): Either<string, A>; | ||
export declare const run: <A>(p: Parser<Char, A>, source: string) => Either<string, A>; |
@@ -10,3 +10,4 @@ "use strict"; | ||
var codeFrameColumns = require('@babel/code-frame').codeFrameColumns; | ||
function getLocation(source, cursor) { | ||
var lineTerminatorRegex = /^\r\n$|^[\n\r]$/; | ||
var getLocation = function (source, cursor) { | ||
var line = 1; | ||
@@ -18,3 +19,3 @@ var column = 1; | ||
var c = source.charAt(i); | ||
if (c === '\n') { | ||
if (lineTerminatorRegex.test(c)) { | ||
line++; | ||
@@ -33,3 +34,3 @@ column = 1; | ||
}; | ||
} | ||
}; | ||
/** | ||
@@ -40,3 +41,3 @@ * Returns a pretty printed error message using `@babel/code-frame` | ||
*/ | ||
function run(p, source) { | ||
exports.run = function (p, source) { | ||
return pipeable_1.pipe(p(Stream_1.stream(source.split(''))), Either_1.bimap(function (err) { | ||
@@ -47,3 +48,2 @@ return codeFrameColumns(source, getLocation(source, err.input.cursor), { | ||
}, function (succ) { return succ.value; })); | ||
} | ||
exports.run = run; | ||
}; |
/** | ||
* @since 0.6.0 | ||
*/ | ||
import { Alt2 } from 'fp-ts/lib/Alt'; | ||
import { Alternative2 } from 'fp-ts/lib/Alternative'; | ||
import { Predicate } from 'fp-ts/lib/function'; | ||
import { Applicative2 } from 'fp-ts/lib/Applicative'; | ||
import { Functor2 } from 'fp-ts/lib/Functor'; | ||
import { Monad2 } from 'fp-ts/lib/Monad'; | ||
import { Monoid } from 'fp-ts/lib/Monoid'; | ||
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; | ||
import * as NEA from 'fp-ts/lib/NonEmptyArray'; | ||
import { Semigroup } from 'fp-ts/lib/Semigroup'; | ||
import { Predicate, Lazy } from 'fp-ts/lib/function'; | ||
import { ParseResult } from './ParseResult'; | ||
import { Stream } from './Stream'; | ||
declare module 'fp-ts/lib/HKT' { | ||
interface URItoKind2<E, A> { | ||
Parser: Parser<E, A>; | ||
} | ||
} | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
*/ | ||
export declare const URI = "Parser"; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export declare type URI = typeof URI; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export interface Parser<I, A> { | ||
@@ -36,11 +28,13 @@ (i: Stream<I>): ParseResult<I, A>; | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function succeed<I, A>(a: A): Parser<I, A>; | ||
export declare const succeed: <I, A>(a: A) => Parser<I, A>; | ||
/** | ||
* The `fail` parser will just fail immediately without consuming any input | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function fail<I, A = never>(): Parser<I, A>; | ||
export declare const fail: <I, A = never>() => Parser<I, A>; | ||
/** | ||
@@ -50,6 +44,17 @@ * The `failAt` parser will fail immediately without consuming any input, | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function failAt<I, A = never>(i: Stream<I>): Parser<I, A>; | ||
export declare const failAt: <I, A = never>(i: Stream<I>) => Parser<I, A>; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare const sat: <I>(predicate: Predicate<I>) => Parser<I, I>; | ||
/** | ||
* A parser combinator which returns the provided parser unchanged, except | ||
@@ -59,5 +64,6 @@ * that if it fails, the provided error message will be returned in the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function expected<I, A>(p: Parser<I, A>, message: string): Parser<I, A>; | ||
export declare const expected: <I, A>(p: Parser<I, A>, message: string) => Parser<I, A>; | ||
/** | ||
@@ -67,5 +73,6 @@ * The `item` parser consumes a single value, regardless of what it is, | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function item<I>(): Parser<I, I>; | ||
export declare const item: <I>() => Parser<I, I>; | ||
/** | ||
@@ -76,5 +83,6 @@ * The `cut` parser combinator takes a parser and produces a new parser for | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function cut<I, A>(p: Parser<I, A>): Parser<I, A>; | ||
export declare const cut: <I, A>(p: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
@@ -85,5 +93,6 @@ * Takes two parsers `p1` and `p2`, returning a parser which will match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function cutWith<I, A, B>(p1: Parser<I, A>, p2: Parser<I, B>): Parser<I, B>; | ||
export declare const cutWith: <I, A, B>(p1: Parser<I, A>, p2: Parser<I, B>) => Parser<I, B>; | ||
/** | ||
@@ -98,5 +107,6 @@ * The `seq` combinator takes a parser, and a function which will receive | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function seq<I, A, B>(fa: Parser<I, A>, f: (a: A) => Parser<I, B>): Parser<I, B>; | ||
export declare const seq: <I, A, B>(fa: Parser<I, A>, f: (a: A) => Parser<I, B>) => Parser<I, B>; | ||
/** | ||
@@ -112,5 +122,6 @@ * The `either` combinator takes two parsers, runs the first on the input | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function either<I, A>(p: Parser<I, A>, f: () => Parser<I, A>): Parser<I, A>; | ||
export declare const either: <I, A>(p: Parser<I, A>, f: () => Parser<I, A>) => Parser<I, A>; | ||
/** | ||
@@ -123,15 +134,7 @@ * Converts a parser into one which will return the point in the stream where | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function withStart<I, A>(p: Parser<I, A>): Parser<I, [A, Stream<I>]>; | ||
export declare const withStart: <I, A>(p: Parser<I, A>) => Parser<I, [A, Stream<I>]>; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sat<I>(predicate: Predicate<I>): Parser<I, I>; | ||
/** | ||
* The `maybe` parser combinator creates a parser which will run the provided | ||
@@ -141,11 +144,13 @@ * parser on the input, and if it fails, it will returns the empty value (as | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function maybe<A>(M: Monoid<A>): <I>(p: Parser<I, A>) => Parser<I, A>; | ||
export declare const maybe: <A>(M: Monoid<A>) => <I>(p: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* Matches the end of the stream. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function eof<I>(): Parser<I, void>; | ||
export declare const eof: <I>() => Parser<I, void>; | ||
/** | ||
@@ -160,5 +165,6 @@ * The `many` combinator takes a parser, and returns a new parser which will | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many<I, A>(p: Parser<I, A>): Parser<I, Array<A>>; | ||
export declare const many: <I, A>(p: Parser<I, A>) => Parser<I, A[]>; | ||
/** | ||
@@ -169,5 +175,6 @@ * The `many1` combinator is just like the `many` combinator, except it | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many1<I, A>(p: Parser<I, A>): Parser<I, NonEmptyArray<A>>; | ||
export declare const many1: <I, A>(p: Parser<I, A>) => Parser<I, NEA.NonEmptyArray<A>>; | ||
/** | ||
@@ -178,5 +185,6 @@ * Matches the provided parser `p` zero or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sepBy<I, A, B>(sep: Parser<I, A>, p: Parser<I, B>): Parser<I, Array<B>>; | ||
export declare const sepBy: <I, A, B>(sep: Parser<I, A>, p: Parser<I, B>) => Parser<I, B[]>; | ||
/** | ||
@@ -187,11 +195,14 @@ * Matches the provided parser `p` one or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sepBy1<I, A, B>(sep: Parser<I, A>, p: Parser<I, B>): Parser<I, NonEmptyArray<B>>; | ||
export declare const sepBy1: <I, A, B>(sep: Parser<I, A>, p: Parser<I, B>) => Parser<I, NEA.NonEmptyArray<B>>; | ||
/** | ||
* Like `sepBy1`, but cut on the separator, so that matching a `sep` not | ||
* followed by a `p` will cause a fatal error. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function sepByCut<I, A, B>(sep: Parser<I, A>, p: Parser<I, B>): Parser<I, NonEmptyArray<B>>; | ||
export declare const sepByCut: <I, A, B>(sep: Parser<I, A>, p: Parser<I, B>) => Parser<I, NEA.NonEmptyArray<B>>; | ||
/** | ||
@@ -202,11 +213,13 @@ * Matches the provided parser `p` that occurs between the provided `left` and `right` parsers. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
export declare function between<I, A>(left: Parser<I, A>, right: Parser<I, A>): <B>(p: Parser<I, B>) => Parser<I, B>; | ||
export declare const between: <I, A>(left: Parser<I, A>, right: Parser<I, A>) => <B>(p: Parser<I, B>) => Parser<I, B>; | ||
/** | ||
* Matches the provided parser `p` that is surrounded by the `bound` parser. Shortcut for `between(bound, bound)`. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
export declare function surroundedBy<I, A>(bound: Parser<I, A>): <B>(p: Parser<I, B>) => Parser<I, B>; | ||
export declare const surroundedBy: <I, A>(bound: Parser<I, A>) => <B>(p: Parser<I, B>) => Parser<I, B>; | ||
/** | ||
@@ -229,2 +242,3 @@ * Takes a `Parser` and tries to match it without consuming any input. | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
@@ -246,46 +260,110 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
*/ | ||
export declare const takeUntil: <I>(predicate: Predicate<I>) => Parser<I, I[]>; | ||
export declare const takeUntil: <I>(predicate: Predicate<I>) => Parser<I, Array<I>>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Functor | ||
* @since 0.6.7 | ||
*/ | ||
export declare function getMonoid<I, A>(M: Monoid<A>): Monoid<Parser<I, A>>; | ||
export declare const map: <A, B>(f: (a: A) => B) => <I>(fa: Parser<I, A>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
export declare const parser: Monad2<URI> & Alternative2<URI>; | ||
declare const alt: <E, A>(that: () => Parser<E, A>) => (fa: Parser<E, A>) => Parser<E, A>, ap: <E, A>(fa: Parser<E, A>) => <B>(fab: Parser<E, (a: A) => B>) => Parser<E, B>, apFirst: <E, B>(fb: Parser<E, B>) => <A>(fa: Parser<E, A>) => Parser<E, A>, apSecond: <e, B>(fb: Parser<e, B>) => <A>(fa: Parser<e, A>) => Parser<e, B>, chain: <E, A, B>(f: (a: A) => Parser<E, B>) => (ma: Parser<E, A>) => Parser<E, B>, chainFirst: <E, A, B>(f: (a: A) => Parser<E, B>) => (ma: Parser<E, A>) => Parser<E, A>, flatten: <E, A>(mma: Parser<E, Parser<E, A>>) => Parser<E, A>, map: <A, B>(f: (a: A) => B) => <E>(fa: Parser<E, A>) => Parser<E, B>; | ||
export { | ||
export declare const ap: <I, A>(fa: Parser<I, A>) => <B>(fab: Parser<I, (a: A) => B>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
alt, | ||
export declare const apFirst: <I, B>(fb: Parser<I, B>) => <A>(fa: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
ap, | ||
export declare const apSecond: <I, B>(fb: Parser<I, B>) => <A>(fa: Parser<I, A>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Applicative | ||
* @since 0.6.7 | ||
*/ | ||
apFirst, | ||
export declare const of: <I, A>(a: A) => Parser<I, A>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
apSecond, | ||
export declare const chain: <I, A, B>(f: (a: A) => Parser<I, B>) => (ma: Parser<I, A>) => Parser<I, B>; | ||
/** | ||
* @since 0.6.0 | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
chain, | ||
export declare const chainFirst: <I, A, B>(f: (a: A) => Parser<I, B>) => (ma: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* @category Alt | ||
* @since 0.6.7 | ||
*/ | ||
export declare const alt: <I, A>(that: Lazy<Parser<I, A>>) => (fa: Parser<I, A>) => Parser<I, A>; | ||
/** | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
export declare const flatten: <I, A>(mma: Parser<I, Parser<I, A>>) => Parser<I, A>; | ||
/** | ||
* @category Alternative | ||
* @since 0.6.7 | ||
*/ | ||
export declare const zero: <I, A>() => Parser<I, A>; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
chainFirst, | ||
export declare const URI = "Parser"; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
flatten, | ||
export declare type URI = typeof URI; | ||
declare module 'fp-ts/lib/HKT' { | ||
interface URItoKind2<E, A> { | ||
Parser: Parser<E, A>; | ||
} | ||
} | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const getSemigroup: <I, A>(S: Semigroup<A>) => Semigroup<Parser<I, A>>; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
map }; | ||
export declare const getMonoid: <I, A>(M: Monoid<A>) => Monoid<Parser<I, A>>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Functor: Functor2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Applicative: Applicative2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Monad: Monad2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Alt: Alt2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const Alternative: Alternative2<URI>; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
export declare const parser: Monad2<URI> & Alternative2<URI>; |
@@ -14,15 +14,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Array_1 = require("fp-ts/lib/Array"); | ||
var A = require("fp-ts/lib/Array"); | ||
var E = require("fp-ts/lib/Either"); | ||
var NEA = require("fp-ts/lib/NonEmptyArray"); | ||
var O = require("fp-ts/lib/Option"); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray"); | ||
var O = require("fp-ts/lib/Option"); | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
var ParseResult_1 = require("./ParseResult"); | ||
var Stream_1 = require("./Stream"); | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
exports.URI = 'Parser'; | ||
/** | ||
* The `succeed` parser constructor creates a parser which will simply | ||
@@ -33,17 +32,13 @@ * return the value provided as its argument, without consuming any input. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function succeed(a) { | ||
return function (i) { return ParseResult_1.success(a, i, i); }; | ||
} | ||
exports.succeed = succeed; | ||
exports.succeed = function (a) { return function (i) { return ParseResult_1.success(a, i, i); }; }; | ||
/** | ||
* The `fail` parser will just fail immediately without consuming any input | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function fail() { | ||
return function (i) { return ParseResult_1.error(i); }; | ||
} | ||
exports.fail = fail; | ||
exports.fail = function () { return function (i) { return ParseResult_1.error(i); }; }; | ||
/** | ||
@@ -53,9 +48,25 @@ * The `failAt` parser will fail immediately without consuming any input, | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function failAt(i) { | ||
return function () { return ParseResult_1.error(i); }; | ||
} | ||
exports.failAt = failAt; | ||
exports.failAt = function (i) { return function () { return ParseResult_1.error(i); }; }; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
exports.sat = function (predicate) { | ||
return pipeable_1.pipe(exports.withStart(exports.item()), exports.chain(function (_a) { | ||
var a = _a[0], start = _a[1]; | ||
return (predicate(a) ? exports.of(a) : exports.failAt(start)); | ||
})); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* A parser combinator which returns the provided parser unchanged, except | ||
@@ -65,10 +76,8 @@ * that if it fails, the provided error message will be returned in the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function expected(p, message) { | ||
return function (i) { | ||
return pipeable_1.pipe(p(i), E.mapLeft(function (err) { return ParseResult_1.withExpected(err, [message]); })); | ||
}; | ||
} | ||
exports.expected = expected; | ||
exports.expected = function (p, message) { return function (i) { | ||
return pipeable_1.pipe(p(i), E.mapLeft(function (err) { return ParseResult_1.withExpected(err, [message]); })); | ||
}; }; | ||
/** | ||
@@ -78,13 +87,11 @@ * The `item` parser consumes a single value, regardless of what it is, | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function item() { | ||
return function (i) { | ||
return pipeable_1.pipe(Stream_1.getAndNext(i), O.fold(function () { return ParseResult_1.error(i); }, function (_a) { | ||
var value = _a.value, next = _a.next; | ||
return ParseResult_1.success(value, next, i); | ||
})); | ||
}; | ||
} | ||
exports.item = item; | ||
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 value = _a.value, next = _a.next; | ||
return ParseResult_1.success(value, next, i); | ||
})); | ||
}; }; | ||
/** | ||
@@ -95,8 +102,6 @@ * The `cut` parser combinator takes a parser and produces a new parser for | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function cut(p) { | ||
return function (i) { return pipeable_1.pipe(p(i), E.mapLeft(ParseResult_1.escalate)); }; | ||
} | ||
exports.cut = cut; | ||
exports.cut = function (p) { return function (i) { return pipeable_1.pipe(p(i), E.mapLeft(ParseResult_1.escalate)); }; }; | ||
/** | ||
@@ -107,8 +112,8 @@ * Takes two parsers `p1` and `p2`, returning a parser which will match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function cutWith(p1, p2) { | ||
return pipeable_1.pipe(p1, apSecond(cut(p2))); | ||
} | ||
exports.cutWith = cutWith; | ||
exports.cutWith = function (p1, p2) { | ||
return pipeable_1.pipe(p1, exports.apSecond(exports.cut(p2))); | ||
}; | ||
/** | ||
@@ -123,8 +128,10 @@ * The `seq` combinator takes a parser, and a function which will receive | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function seq(fa, f) { | ||
return function (i) { return E.either.chain(fa(i), function (s) { return E.either.chain(f(s.value)(s.next), function (next) { return ParseResult_1.success(next.value, next.next, i); }); }); }; | ||
} | ||
exports.seq = seq; | ||
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); })); | ||
})); | ||
}; }; | ||
/** | ||
@@ -140,17 +147,15 @@ * The `either` combinator takes two parsers, runs the first on the input | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function either(p, f) { | ||
return function (i) { | ||
var e = p(i); | ||
if (E.isRight(e)) { | ||
return e; | ||
} | ||
if (e.left.fatal) { | ||
return e; | ||
} | ||
return pipeable_1.pipe(f()(i), E.mapLeft(function (err) { return ParseResult_1.extend(e.left, err); })); | ||
}; | ||
} | ||
exports.either = either; | ||
exports.either = function (p, f) { return function (i) { | ||
var e = p(i); | ||
if (E.isRight(e)) { | ||
return e; | ||
} | ||
if (e.left.fatal) { | ||
return e; | ||
} | ||
return pipeable_1.pipe(f()(i), E.mapLeft(function (err) { return ParseResult_1.extend(e.left, err); })); | ||
}; }; | ||
/** | ||
@@ -163,26 +168,9 @@ * Converts a parser into one which will return the point in the stream where | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function withStart(p) { | ||
return function (i) { | ||
return pipeable_1.pipe(p(i), E.map(function (s) { return (__assign({}, s, { value: [s.value, i] })); })); | ||
}; | ||
} | ||
exports.withStart = withStart; | ||
exports.withStart = function (p) { return function (i) { | ||
return pipeable_1.pipe(p(i), E.map(function (s) { return (__assign({}, s, { value: [s.value, i] })); })); | ||
}; }; | ||
/** | ||
* The `sat` parser constructor takes a predicate function, and will consume | ||
* a single character if calling that predicate function with the character | ||
* as its argument returns `true`. If it returns `false`, the parser will | ||
* fail. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
function sat(predicate) { | ||
return pipeable_1.pipe(withStart(item()), chain(function (_a) { | ||
var a = _a[0], start = _a[1]; | ||
return (predicate(a) ? exports.parser.of(a) : failAt(start)); | ||
})); | ||
} | ||
exports.sat = sat; | ||
/** | ||
* The `maybe` parser combinator creates a parser which will run the provided | ||
@@ -192,17 +180,15 @@ * parser on the input, and if it fails, it will returns the empty value (as | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function maybe(M) { | ||
return alt(function () { return exports.parser.of(M.empty); }); | ||
} | ||
exports.maybe = maybe; | ||
exports.maybe = function (M) { return exports.alt(function () { return exports.of(M.empty); }); }; | ||
/** | ||
* Matches the end of the stream. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function eof() { | ||
return expected(function (i) { return (Stream_1.atEnd(i) ? ParseResult_1.success(undefined, i, i) : ParseResult_1.error(i)); }, 'end of file'); | ||
} | ||
exports.eof = eof; | ||
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'); | ||
}; | ||
/** | ||
@@ -217,8 +203,8 @@ * The `many` combinator takes a parser, and returns a new parser which will | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function many(p) { | ||
return pipeable_1.pipe(many1(p), alt(function () { return exports.parser.of(Array_1.empty); })); | ||
} | ||
exports.many = many; | ||
exports.many = function (p) { | ||
return pipeable_1.pipe(exports.many1(p), exports.alt(function () { return exports.of(A.empty); })); | ||
}; | ||
/** | ||
@@ -229,8 +215,10 @@ * The `many1` combinator is just like the `many` combinator, except it | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function many1(p) { | ||
return exports.parser.chain(p, function (head) { return exports.parser.map(many(p), function (tail) { return NonEmptyArray_1.cons(head, tail); }); }); | ||
} | ||
exports.many1 = many1; | ||
exports.many1 = function (p) { | ||
return pipeable_1.pipe(p, exports.chain(function (head) { | ||
return pipeable_1.pipe(exports.many(p), exports.map(function (tail) { return NEA.cons(head, tail); })); | ||
})); | ||
}; | ||
/** | ||
@@ -241,9 +229,9 @@ * Matches the provided parser `p` zero or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function sepBy(sep, p) { | ||
var nil = exports.parser.of(Array_1.empty); | ||
return pipeable_1.pipe(sepBy1(sep, p), alt(function () { return nil; })); | ||
} | ||
exports.sepBy = sepBy; | ||
exports.sepBy = function (sep, p) { | ||
var nil = exports.of(A.empty); | ||
return pipeable_1.pipe(exports.sepBy1(sep, p), exports.alt(function () { return nil; })); | ||
}; | ||
/** | ||
@@ -254,19 +242,22 @@ * Matches the provided parser `p` one or more times, but requires the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function sepBy1(sep, p) { | ||
var bs = many(pipeable_1.pipe(sep, apSecond(p))); | ||
return exports.parser.chain(p, function (head) { return exports.parser.map(bs, function (tail) { return NonEmptyArray_1.cons(head, tail); }); }); | ||
} | ||
exports.sepBy1 = sepBy1; | ||
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); })); | ||
})); | ||
}; | ||
/** | ||
* Like `sepBy1`, but cut on the separator, so that matching a `sep` not | ||
* followed by a `p` will cause a fatal error. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function sepByCut(sep, p) { | ||
var bs = many(cutWith(sep, p)); | ||
return exports.parser.chain(p, function (head) { return exports.parser.map(bs, function (tail) { return NonEmptyArray_1.cons(head, tail); }); }); | ||
} | ||
exports.sepByCut = sepByCut; | ||
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); })); | ||
})); | ||
}; | ||
/** | ||
@@ -277,19 +268,17 @@ * Matches the provided parser `p` that occurs between the provided `left` and `right` parsers. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
function between(left, right) { | ||
return function (p) { | ||
return pipeable_1.pipe(left, chain(function () { return p; }), chainFirst(function () { return right; })); | ||
}; | ||
} | ||
exports.between = between; | ||
exports.between = function (left, right) { return function (p) { | ||
return pipeable_1.pipe(left, exports.chain(function () { return p; }), exports.chainFirst(function () { return right; })); | ||
}; }; | ||
/** | ||
* Matches the provided parser `p` that is surrounded by the `bound` parser. Shortcut for `between(bound, bound)`. | ||
* | ||
* @category combinators | ||
* @since 0.6.4 | ||
*/ | ||
function surroundedBy(bound) { | ||
return between(bound, bound); | ||
} | ||
exports.surroundedBy = surroundedBy; | ||
exports.surroundedBy = function (bound) { | ||
return exports.between(bound, bound); | ||
}; | ||
/** | ||
@@ -312,6 +301,7 @@ * Takes a `Parser` and tries to match it without consuming any input. | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
*/ | ||
exports.lookAhead = function (p) { return function (i) { | ||
return E.either.chain(p(i), function (next) { return ParseResult_1.success(next.value, i, i); }); | ||
return pipeable_1.pipe(p(i), E.chain(function (next) { return ParseResult_1.success(next.value, i, i); })); | ||
}; }; | ||
@@ -331,37 +321,162 @@ /** | ||
* | ||
* @category combinators | ||
* @since 0.6.6 | ||
*/ | ||
exports.takeUntil = function (predicate) { return many(sat(function_1.not(predicate))); }; | ||
exports.takeUntil = function (predicate) { return exports.many(exports.sat(function_1.not(predicate))); }; | ||
// ------------------------------------------------------------------------------------- | ||
// non-pipeables | ||
// ------------------------------------------------------------------------------------- | ||
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) })); })); | ||
}; }; | ||
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 alt_ = function (fa, that) { return exports.either(fa, that); }; | ||
// ------------------------------------------------------------------------------------- | ||
// pipeables | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category Functor | ||
* @since 0.6.7 | ||
*/ | ||
exports.map = function (f) { return function (fa) { return map_(fa, f); }; }; | ||
/** | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
exports.ap = function (fa) { return function (fab) { | ||
return ap_(fab, fa); | ||
}; }; | ||
/** | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
exports.apFirst = function (fb) { return function (fa) { | ||
return ap_(map_(fa, function (a) { return function () { return a; }; }), fb); | ||
}; }; | ||
/** | ||
* @category Apply | ||
* @since 0.6.7 | ||
*/ | ||
exports.apSecond = function (fb) { return function (fa) { | ||
return ap_(map_(fa, function () { return function (b) { return b; }; }), fb); | ||
}; }; | ||
/** | ||
* @category Applicative | ||
* @since 0.6.7 | ||
*/ | ||
exports.of = exports.succeed; | ||
/** | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
exports.chain = function (f) { return function (ma) { | ||
return chain_(ma, f); | ||
}; }; | ||
/** | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
exports.chainFirst = function (f) { return function (ma) { | ||
return chain_(ma, function (a) { return map_(f(a), function () { return a; }); }); | ||
}; }; | ||
/** | ||
* @category Alt | ||
* @since 0.6.7 | ||
*/ | ||
exports.alt = function (that) { return function (fa) { return alt_(fa, that); }; }; | ||
/** | ||
* @category Monad | ||
* @since 0.6.7 | ||
*/ | ||
exports.flatten = function (mma) { return chain_(mma, function_1.identity); }; | ||
/** | ||
* @category Alternative | ||
* @since 0.6.7 | ||
*/ | ||
exports.zero = exports.fail; | ||
// ------------------------------------------------------------------------------------- | ||
// instances | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
function getMonoid(M) { | ||
return { | ||
concat: function (x, y) { | ||
return exports.parser.ap(exports.parser.map(x, function (x) { return function (y) { return M.concat(x, y); }; }), y); | ||
}, | ||
empty: succeed(M.empty) | ||
}; | ||
} | ||
exports.getMonoid = getMonoid; | ||
exports.URI = 'Parser'; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
exports.getSemigroup = function (S) { return ({ | ||
concat: function (x, y) { | ||
return ap_(map_(x, function (x) { return function (y) { return S.concat(x, y); }; }), y); | ||
} | ||
}); }; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
exports.getMonoid = function (M) { return (__assign({}, exports.getSemigroup(M), { empty: exports.succeed(M.empty) })); }; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
exports.Functor = { | ||
URI: exports.URI, | ||
map: map_ | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
exports.Applicative = { | ||
URI: exports.URI, | ||
map: map_, | ||
ap: ap_, | ||
of: exports.of | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
exports.Monad = { | ||
URI: exports.URI, | ||
map: map_, | ||
ap: ap_, | ||
of: exports.of, | ||
chain: chain_ | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
exports.Alt = { | ||
URI: exports.URI, | ||
map: map_, | ||
alt: alt_ | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
exports.Alternative = { | ||
URI: exports.URI, | ||
map: map_, | ||
of: exports.of, | ||
ap: ap_, | ||
alt: alt_, | ||
zero: exports.fail | ||
}; | ||
/** | ||
* @category instances | ||
* @since 0.6.7 | ||
*/ | ||
exports.parser = { | ||
URI: exports.URI, | ||
map: function (fa, f) { return function (i) { return E.either.map(fa(i), function (s) { return (__assign({}, s, { value: f(s.value) })); }); }; }, | ||
of: succeed, | ||
ap: function (fab, fa) { return exports.parser.chain(fab, function (f) { return exports.parser.map(fa, f); }); }, | ||
chain: seq, | ||
alt: either, | ||
zero: fail | ||
map: map_, | ||
of: exports.of, | ||
ap: ap_, | ||
chain: chain_, | ||
alt: alt_, | ||
zero: exports.fail | ||
}; | ||
var _a = pipeable_1.pipeable(exports.parser), alt = _a.alt, ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map; | ||
exports.alt = alt; | ||
exports.ap = ap; | ||
exports.apFirst = apFirst; | ||
exports.apSecond = apSecond; | ||
exports.chain = chain; | ||
exports.chainFirst = chainFirst; | ||
exports.flatten = flatten; | ||
exports.map = map; |
import { Either } from 'fp-ts/lib/Either'; | ||
import { Stream } from './Stream'; | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -12,2 +13,3 @@ */ | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -21,2 +23,3 @@ */ | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -26,20 +29,25 @@ */ | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function withExpected<I>(err: ParseError<I>, expected: Array<string>): ParseError<I>; | ||
export declare const success: <I, A>(value: A, next: Stream<I>, start: Stream<I>) => ParseResult<I, A>; | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function escalate<I>(err: ParseError<I>): ParseError<I>; | ||
export declare const error: <I, A = never>(input: Stream<I>, expected?: Array<string>, fatal?: boolean) => ParseResult<I, A>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function extend<I>(err1: ParseError<I>, err2: ParseError<I>): ParseError<I>; | ||
export declare const withExpected: <I>(err: ParseError<I>, expected: Array<string>) => ParseError<I>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function success<I, A>(value: A, next: Stream<I>, start: Stream<I>): ParseResult<I, A>; | ||
export declare const escalate: <I>(err: ParseError<I>) => ParseError<I>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function error<I, A = never>(input: Stream<I>, expected?: Array<string>, fatal?: boolean): ParseResult<I, A>; | ||
export declare const extend: <I>(err1: ParseError<I>, err2: ParseError<I>) => ParseError<I>; |
@@ -19,35 +19,11 @@ "use strict"; | ||
var Either_1 = require("fp-ts/lib/Either"); | ||
var Semigroup_1 = require("fp-ts/lib/Semigroup"); | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function withExpected(err, expected) { | ||
return __assign({}, err, { expected: expected }); | ||
} | ||
exports.withExpected = withExpected; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
function escalate(err) { | ||
return __assign({}, err, { fatal: true }); | ||
} | ||
exports.escalate = escalate; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
function extend(err1, err2) { | ||
if (err1.input.cursor < err2.input.cursor) { | ||
return err2; | ||
} | ||
else if (err1.input.cursor > err2.input.cursor) { | ||
return err1; | ||
} | ||
else { | ||
return __assign({}, err1, { expected: err1.expected.concat(err2.expected) }); | ||
} | ||
} | ||
exports.extend = extend; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
function success(value, next, start) { | ||
exports.success = function (value, next, start) { | ||
return Either_1.right({ | ||
@@ -58,8 +34,8 @@ value: value, | ||
}); | ||
} | ||
exports.success = success; | ||
}; | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function error(input, expected, fatal) { | ||
exports.error = function (input, expected, fatal) { | ||
if (expected === void 0) { expected = Array_1.empty; } | ||
@@ -72,3 +48,38 @@ if (fatal === void 0) { fatal = false; } | ||
}); | ||
} | ||
exports.error = error; | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.withExpected = function (err, expected) { return (__assign({}, err, { expected: expected })); }; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.escalate = function (err) { return (__assign({}, err, { fatal: true })); }; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.extend = function (err1, err2) { | ||
return getSemigroup().concat(err1, err2); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// instances | ||
// ------------------------------------------------------------------------------------- | ||
var getSemigroup = function () { return ({ | ||
concat: function (x, y) { | ||
if (x.input.cursor < y.input.cursor) | ||
return Semigroup_1.getLastSemigroup().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() | ||
}).concat(x, y); | ||
} | ||
}); }; |
import { Eq } from 'fp-ts/lib/Eq'; | ||
import { Option } from 'fp-ts/lib/Option'; | ||
/** | ||
* @category model | ||
* @since 0.6.0 | ||
@@ -11,17 +12,21 @@ */ | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function stream<A>(buffer: Array<A>, cursor?: number): Stream<A>; | ||
export declare const stream: <A>(buffer: Array<A>, cursor?: number) => Stream<A>; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function get<A>(s: Stream<A>): Option<A>; | ||
export declare const get: <A>(s: Stream<A>) => Option<A>; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function atEnd<A>(s: Stream<A>): boolean; | ||
export declare const atEnd: <A>(s: Stream<A>) => boolean; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function getAndNext<A>(s: Stream<A>): Option<{ | ||
export declare const getAndNext: <A>(s: Stream<A>) => Option<{ | ||
value: A; | ||
@@ -31,4 +36,5 @@ next: Stream<A>; | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
export declare function getEq<A>(E: Eq<A>): Eq<Stream<A>>; | ||
export declare const getEq: <A>(E: Eq<A>) => Eq<Stream<A>>; |
@@ -10,38 +10,46 @@ "use strict"; | ||
var pipeable_1 = require("fp-ts/lib/pipeable"); | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
function stream(buffer, cursor) { | ||
exports.stream = function (buffer, cursor) { | ||
if (cursor === void 0) { cursor = 0; } | ||
return { buffer: buffer, cursor: cursor }; | ||
} | ||
exports.stream = stream; | ||
return ({ | ||
buffer: buffer, | ||
cursor: cursor | ||
}); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// destructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
function get(s) { | ||
return Array_1.lookup(s.cursor, s.buffer); | ||
} | ||
exports.get = get; | ||
exports.get = function (s) { return Array_1.lookup(s.cursor, s.buffer); }; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
function atEnd(s) { | ||
return s.cursor >= s.buffer.length; | ||
} | ||
exports.atEnd = atEnd; | ||
exports.atEnd = function (s) { return s.cursor >= s.buffer.length; }; | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
function getAndNext(s) { | ||
return pipeable_1.pipe(get(s), Option_1.map(function (a) { return ({ value: a, next: { buffer: s.buffer, cursor: s.cursor + 1 } }); })); | ||
} | ||
exports.getAndNext = getAndNext; | ||
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 } }); })); | ||
}; | ||
// ------------------------------------------------------------------------------------- | ||
// instances | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category instances | ||
* @since 0.6.0 | ||
*/ | ||
function getEq(E) { | ||
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); }); | ||
} | ||
exports.getEq = getEq; | ||
}; |
@@ -10,35 +10,46 @@ /** | ||
/** | ||
* Matches the exact string provided. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare const maybe: <I>(p: P.Parser<I, string>) => P.Parser<I, string>; | ||
export declare const string: (s: string) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches the given parser zero or more times, returning a string of the | ||
* entire match | ||
* Matches one of a list of strings. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many(parser: P.Parser<C.Char, string>): P.Parser<C.Char, string>; | ||
export declare function oneOf<F extends URIS>(F: Functor1<F> & Foldable1<F>): (ss: Kind<F, string>) => P.Parser<C.Char, string>; | ||
export declare function oneOf<F>(F: Functor<F> & Foldable<F>): (ss: HKT<F, string>) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches the given parser one or more times, returning a string of the | ||
* entire match | ||
* | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
export declare function many1(parser: P.Parser<C.Char, string>): P.Parser<C.Char, string>; | ||
export declare const fold: <I>(as: Array<P.Parser<I, string>>) => P.Parser<I, string>; | ||
/** | ||
* Matches the exact string provided. | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const maybe: <I>(p: P.Parser<I, string>) => P.Parser<I, string>; | ||
/** | ||
* Matches the given parser zero or more times, returning a string of the | ||
* entire match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function string(s: string): P.Parser<C.Char, string>; | ||
export declare const many: (parser: P.Parser<C.Char, string>) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches one of a list of strings. | ||
* Matches the given parser one or more times, returning a string of the | ||
* entire match | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare function oneOf<F extends URIS>(F: Functor1<F> & Foldable1<F>): (ss: Kind<F, string>) => P.Parser<C.Char, string>; | ||
export declare function oneOf<F>(F: Functor<F> & Foldable<F>): (ss: HKT<F, string>) => P.Parser<C.Char, string>; | ||
export declare const many1: (parser: P.Parser<C.Char, string>) => P.Parser<C.Char, string>; | ||
/** | ||
* Matches zero or more whitespace characters. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -50,2 +61,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -57,2 +69,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -64,2 +77,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -69,10 +83,8 @@ */ | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const fold: <I>(as: Array<P.Parser<I, string>>) => P.Parser<I, string>; | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
export declare const int: P.Parser<C.Char, number>; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -86,4 +98,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
export declare const doubleQuotedString: P.Parser<string, string>; | ||
export declare const doubleQuotedString: P.Parser<string, String>; |
@@ -8,5 +8,42 @@ "use strict"; | ||
var P = require("./Parser"); | ||
// ------------------------------------------------------------------------------------- | ||
// constructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* Matches the exact string provided. | ||
* | ||
* @category constructors | ||
* @since 0.6.0 | ||
*/ | ||
exports.string = function (s) { | ||
var _string = function (s2) { | ||
return pipeable_1.pipe(charAt(0, s2), O.fold(function () { return P.succeed(''); }, function (c) { | ||
return pipeable_1.pipe(C.char(c), P.chain(function () { return _string(s2.slice(1)); }), P.chain(function () { return P.succeed(s); })); | ||
})); | ||
}; | ||
return P.expected(_string(s), JSON.stringify(s)); | ||
}; | ||
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); })); | ||
}); | ||
}; | ||
} | ||
exports.oneOf = oneOf; | ||
// ------------------------------------------------------------------------------------- | ||
// destructors | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category destructors | ||
* @since 0.6.0 | ||
*/ | ||
exports.fold = M.fold(P.getMonoid(M.monoidString)); | ||
// ------------------------------------------------------------------------------------- | ||
// combinators | ||
// ------------------------------------------------------------------------------------- | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.maybe = P.maybe(M.monoidString); | ||
@@ -17,8 +54,6 @@ /** | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function many(parser) { | ||
return exports.maybe(many1(parser)); | ||
} | ||
exports.many = many; | ||
exports.many = function (parser) { return exports.maybe(exports.many1(parser)); }; | ||
/** | ||
@@ -28,36 +63,15 @@ * Matches the given parser one or more times, returning a string of the | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
function many1(parser) { | ||
exports.many1 = function (parser) { | ||
return pipeable_1.pipe(P.many1(parser), P.map(function (nea) { return nea.join(''); })); | ||
} | ||
exports.many1 = many1; | ||
function charAt(index, s) { | ||
}; | ||
var charAt = function (index, s) { | ||
return index >= 0 && index < s.length ? O.some(s.charAt(index)) : O.none; | ||
} | ||
}; | ||
/** | ||
* Matches the exact string provided. | ||
* | ||
* @since 0.6.0 | ||
*/ | ||
function string(s) { | ||
function _string(s2) { | ||
return pipeable_1.pipe(charAt(0, s2), O.fold(function () { return P.succeed(''); }, function (c) { | ||
return pipeable_1.pipe(C.char(c), P.chain(function () { return _string(s2.slice(1)); }), P.chain(function () { return P.succeed(s); })); | ||
})); | ||
} | ||
return P.expected(_string(s), 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 string(s); })); | ||
}); | ||
}; | ||
} | ||
exports.oneOf = oneOf; | ||
/** | ||
* Matches zero or more whitespace characters. | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -69,2 +83,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -76,2 +91,3 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -83,14 +99,12 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.notSpaces1 = C.many1(C.notSpace); | ||
/** | ||
* @since 0.6.0 | ||
*/ | ||
exports.fold = M.fold(P.getMonoid(M.monoidString)); | ||
function fromString(s) { | ||
var fromString = function (s) { | ||
var n = +s; | ||
return isNaN(n) || s === '' ? O.none : O.some(n); | ||
} | ||
}; | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -100,2 +114,3 @@ */ | ||
/** | ||
* @category combinators | ||
* @since 0.6.0 | ||
@@ -111,4 +126,5 @@ */ | ||
* | ||
* @category combinators | ||
* @since 0.6.0 | ||
*/ | ||
exports.doubleQuotedString = P.surroundedBy(C.char('"'))(many(P.either(string('\\"'), function () { return C.notChar('"'); }))); | ||
exports.doubleQuotedString = P.surroundedBy(C.char('"'))(exports.many(P.either(exports.string('\\"'), function () { return C.notChar('"'); }))); |
{ | ||
"name": "parser-ts", | ||
"version": "0.6.6", | ||
"version": "0.6.7", | ||
"description": "String parser combinators for TypeScript", | ||
@@ -5,0 +5,0 @@ "files": [ |
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
103228
3315