Comparing version 0.0.1 to 0.0.2
@@ -15,4 +15,9 @@ # Changelog | ||
# 0.0.2 | ||
- **Bug Fix** | ||
- fix `sepBy1`, https://github.com/gcanti/parser-ts/pull/1 (@sledorze) | ||
# 0.0.1 | ||
Initial release |
@@ -0,1 +1,2 @@ | ||
import { identity } from 'fp-ts/lib/function'; | ||
import { left, right } from 'fp-ts/lib/Either'; | ||
@@ -203,4 +204,15 @@ import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray'; | ||
export function sepBy(sep, parser) { | ||
return alt(sepBy1(sep, parser).map(function (a) { return a.toArray(); }), of([])); | ||
return alt(sepBy1(sep, parser).map(function (a) { return a.toArray(); }), alt(parser.map(function (a) { return [a]; }), of([]))); | ||
} | ||
// to remove when lending in fp-ts | ||
function applySecond(apply) { | ||
return function (fa, fb) { return apply.ap(apply.map(function () { return identity; }, fa), fb); }; | ||
} | ||
/** Matches both parsers and return the value of the second | ||
*/ | ||
function second(pa, pb) { | ||
return new Parser(function (s) { | ||
return applySecond({ URI: URI, map: map, ap: ap })(pa, pb).run(s); | ||
}); | ||
} | ||
/** Matches the provided parser `p` one or more times, but requires the | ||
@@ -211,3 +223,3 @@ * parser `sep` to match once in between each match of `p`. In other words, | ||
export function sepBy1(sep, parser) { | ||
return parser.chain(function (head) { return sepBy(sep, parser).chain(function (tail) { return of(new NonEmptyArray(head, tail)); }); }); | ||
return parser.chain(function (head) { return alt(many(second(sep, parser)), of([])).chain(function (tail) { return of(new NonEmptyArray(head, tail)); }); }); | ||
} | ||
@@ -214,0 +226,0 @@ // tslint:disable-next-line no-unused-expression |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var function_1 = require("fp-ts/lib/function"); | ||
var Either_1 = require("fp-ts/lib/Either"); | ||
@@ -226,5 +227,16 @@ var NonEmptyArray_1 = require("fp-ts/lib/NonEmptyArray"); | ||
function sepBy(sep, parser) { | ||
return alt(sepBy1(sep, parser).map(function (a) { return a.toArray(); }), of([])); | ||
return alt(sepBy1(sep, parser).map(function (a) { return a.toArray(); }), alt(parser.map(function (a) { return [a]; }), of([]))); | ||
} | ||
exports.sepBy = sepBy; | ||
// to remove when lending in fp-ts | ||
function applySecond(apply) { | ||
return function (fa, fb) { return apply.ap(apply.map(function () { return function_1.identity; }, fa), fb); }; | ||
} | ||
/** Matches both parsers and return the value of the second | ||
*/ | ||
function second(pa, pb) { | ||
return new Parser(function (s) { | ||
return applySecond({ URI: exports.URI, map: map, ap: ap })(pa, pb).run(s); | ||
}); | ||
} | ||
/** Matches the provided parser `p` one or more times, but requires the | ||
@@ -235,3 +247,3 @@ * parser `sep` to match once in between each match of `p`. In other words, | ||
function sepBy1(sep, parser) { | ||
return parser.chain(function (head) { return sepBy(sep, parser).chain(function (tail) { return of(new NonEmptyArray_1.NonEmptyArray(head, tail)); }); }); | ||
return parser.chain(function (head) { return alt(many(second(sep, parser)), of([])).chain(function (tail) { return of(new NonEmptyArray_1.NonEmptyArray(head, tail)); }); }); | ||
} | ||
@@ -238,0 +250,0 @@ exports.sepBy1 = sepBy1; |
{ | ||
"name": "parser-ts", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "String parser combinators for TypeScript", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
81261
1215