Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parser-ts

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parser-ts - npm Package Compare versions

Comparing version 0.6.10 to 0.6.11

6

CHANGELOG.md

@@ -16,2 +16,8 @@ # Changelog

# 0.6.11
- **New Feature**
- add `ChainRec` instance for `Parser` (@IMax153)
- add `manyTill` and `many1Till` to `Parser` module (@IMax153)
# 0.6.10

@@ -18,0 +24,0 @@

@@ -7,2 +7,3 @@ /**

import { Applicative2 } from 'fp-ts/es6/Applicative'
import { ChainRec2 } from 'fp-ts/ChainRec'
import { Functor2 } from 'fp-ts/es6/Functor'

@@ -13,2 +14,3 @@ import { Monad2 } from 'fp-ts/es6/Monad'

import * as O from 'fp-ts/es6/Option'
import * as RNEA from 'fp-ts/es6/ReadonlyNonEmptyArray'
import { Semigroup } from 'fp-ts/es6/Semigroup'

@@ -303,2 +305,50 @@ import { Lazy, Predicate, Refinement } from 'fp-ts/es6/function'

/**
* The `manyTill` combinator takes a value `parser` and a `terminator` parser, and
* returns a new parser that will run the value `parser` repeatedly on the input
* stream, returning a list of the result values of each parse operation as its
* result, or the empty list if the parser never succeeded.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.manyTill(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Right', right: [] }
*
* @category combinators
* @since 0.6.11
*/
export declare const manyTill: <I, A, B>(parser: Parser<I, A>, terminator: Parser<I, B>) => Parser<I, readonly A[]>
/**
* The `many1Till` combinator is just like the `manyTill` combinator, except it
* requires the value `parser` to match at least once before the `terminator`
* parser. The resulting list is thus guaranteed to contain at least one value.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.many1Till(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Left', left: '> 1 | -\n | ^ Expected: a letter' }
*
* @category combinators
* @since 0.6.11
*/
export declare const many1Till: <I, A, B>(
parser: Parser<I, A>,
terminator: Parser<I, B>
) => Parser<I, RNEA.ReadonlyNonEmptyArray<A>>
/**
* @category Functor

@@ -395,2 +445,7 @@ * @since 0.6.7

* @category instances
* @since 0.6.11
*/
export declare const ChainRec: ChainRec2<URI>
/**
* @category instances
* @since 0.6.7

@@ -397,0 +452,0 @@ */

88

es6/Parser.js

@@ -13,5 +13,8 @@ var __assign = (this && this.__assign) || function () {

import * as A from 'fp-ts/es6/Array';
import { tailRec } from 'fp-ts/ChainRec';
import * as E from 'fp-ts/es6/Either';
import * as NEA from 'fp-ts/es6/NonEmptyArray';
import * as O from 'fp-ts/es6/Option';
import * as RA from 'fp-ts/es6/ReadonlyArray';
import * as RNEA from 'fp-ts/es6/ReadonlyNonEmptyArray';
import { identity, not } from 'fp-ts/es6/function';

@@ -359,5 +362,57 @@ import { pipe } from 'fp-ts/es6/pipeable';

};
// -------------------------------------------------------------------------------------
// non-pipeables
// -------------------------------------------------------------------------------------
/**
* The `manyTill` combinator takes a value `parser` and a `terminator` parser, and
* returns a new parser that will run the value `parser` repeatedly on the input
* stream, returning a list of the result values of each parse operation as its
* result, or the empty list if the parser never succeeded.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.manyTill(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Right', right: [] }
*
* @category combinators
* @since 0.6.11
*/
export var manyTill = function (parser, terminator) {
return pipe(terminator, map(function () { return RA.empty; }), alt(function () { return many1Till(parser, terminator); }));
};
/**
* The `many1Till` combinator is just like the `manyTill` combinator, except it
* requires the value `parser` to match at least once before the `terminator`
* parser. The resulting list is thus guaranteed to contain at least one value.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.many1Till(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Left', left: '> 1 | -\n | ^ Expected: a letter' }
*
* @category combinators
* @since 0.6.11
*/
export var many1Till = function (parser, terminator) {
return pipe(parser, chain(function (x) {
return chainRec_(RNEA.of(x), function (acc) {
return pipe(terminator, map(function () { return E.right(acc); }), alt(function () {
return pipe(parser, map(function (a) { return E.left(RNEA.snoc(acc, a)); }));
}));
});
}));
};
var map_ = function (ma, f) { return function (i) {

@@ -368,2 +423,18 @@ return pipe(ma(i), E.map(function (s) { return (__assign({}, s, { value: f(s.value) })); }));

var chain_ = function (ma, f) { return seq(ma, f); };
var chainRec_ = function (a, f) {
var split = function (result) {
return E.isLeft(result.value)
? E.left({ value: result.value.left, stream: result.next })
: E.right(success(result.value.right, result.next, result.start));
};
return function (i) {
return tailRec({ value: a, stream: i }, function (state) {
var result = f(state.value)(state.stream);
if (E.isLeft(result)) {
return E.right(error(state.stream, result.left.expected, result.left.fatal));
}
return split(result.right);
});
};
};
var alt_ = function (fa, that) { return either(fa, that); };

@@ -486,2 +557,13 @@ // -------------------------------------------------------------------------------------

* @category instances
* @since 0.6.11
*/
export var ChainRec = {
URI: URI,
map: map_,
ap: ap_,
chain: chain_,
chainRec: chainRec_
};
/**
* @category instances
* @since 0.6.7

@@ -488,0 +570,0 @@ */

@@ -7,2 +7,3 @@ /**

import { Applicative2 } from 'fp-ts/lib/Applicative'
import { ChainRec2 } from 'fp-ts/ChainRec'
import { Functor2 } from 'fp-ts/lib/Functor'

@@ -13,2 +14,3 @@ import { Monad2 } from 'fp-ts/lib/Monad'

import * as O from 'fp-ts/lib/Option'
import * as RNEA from 'fp-ts/lib/ReadonlyNonEmptyArray'
import { Semigroup } from 'fp-ts/lib/Semigroup'

@@ -303,2 +305,50 @@ import { Lazy, Predicate, Refinement } from 'fp-ts/lib/function'

/**
* The `manyTill` combinator takes a value `parser` and a `terminator` parser, and
* returns a new parser that will run the value `parser` repeatedly on the input
* stream, returning a list of the result values of each parse operation as its
* result, or the empty list if the parser never succeeded.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.manyTill(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Right', right: [] }
*
* @category combinators
* @since 0.6.11
*/
export declare const manyTill: <I, A, B>(parser: Parser<I, A>, terminator: Parser<I, B>) => Parser<I, readonly A[]>
/**
* The `many1Till` combinator is just like the `manyTill` combinator, except it
* requires the value `parser` to match at least once before the `terminator`
* parser. The resulting list is thus guaranteed to contain at least one value.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.many1Till(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Left', left: '> 1 | -\n | ^ Expected: a letter' }
*
* @category combinators
* @since 0.6.11
*/
export declare const many1Till: <I, A, B>(
parser: Parser<I, A>,
terminator: Parser<I, B>
) => Parser<I, RNEA.ReadonlyNonEmptyArray<A>>
/**
* @category Functor

@@ -395,2 +445,7 @@ * @since 0.6.7

* @category instances
* @since 0.6.11
*/
export declare const ChainRec: ChainRec2<URI>
/**
* @category instances
* @since 0.6.7

@@ -397,0 +452,0 @@ */

@@ -22,5 +22,8 @@ "use strict";

var A = __importStar(require("fp-ts/lib/Array"));
var ChainRec_1 = require("fp-ts/ChainRec");
var E = __importStar(require("fp-ts/lib/Either"));
var NEA = __importStar(require("fp-ts/lib/NonEmptyArray"));
var O = __importStar(require("fp-ts/lib/Option"));
var RA = __importStar(require("fp-ts/lib/ReadonlyArray"));
var RNEA = __importStar(require("fp-ts/lib/ReadonlyNonEmptyArray"));
var function_1 = require("fp-ts/lib/function");

@@ -368,5 +371,57 @@ var pipeable_1 = require("fp-ts/lib/pipeable");

};
// -------------------------------------------------------------------------------------
// non-pipeables
// -------------------------------------------------------------------------------------
/**
* The `manyTill` combinator takes a value `parser` and a `terminator` parser, and
* returns a new parser that will run the value `parser` repeatedly on the input
* stream, returning a list of the result values of each parse operation as its
* result, or the empty list if the parser never succeeded.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.manyTill(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Right', right: [] }
*
* @category combinators
* @since 0.6.11
*/
exports.manyTill = function (parser, terminator) {
return pipeable_1.pipe(terminator, exports.map(function () { return RA.empty; }), exports.alt(function () { return exports.many1Till(parser, terminator); }));
};
/**
* The `many1Till` combinator is just like the `manyTill` combinator, except it
* requires the value `parser` to match at least once before the `terminator`
* parser. The resulting list is thus guaranteed to contain at least one value.
*
* @example
* import * as C from 'parser-ts/char'
* import { run } from 'parser-ts/code-frame'
* import * as P from 'parser-ts/Parser'
*
* const parser = P.many1Till(C.letter, C.char('-'))
*
* run(parser, 'abc-')
* // { _tag: 'Right', right: [ 'a', 'b', 'c' ] }
*
* run(parser, '-')
* // { _tag: 'Left', left: '> 1 | -\n | ^ Expected: a letter' }
*
* @category combinators
* @since 0.6.11
*/
exports.many1Till = function (parser, terminator) {
return pipeable_1.pipe(parser, exports.chain(function (x) {
return chainRec_(RNEA.of(x), function (acc) {
return pipeable_1.pipe(terminator, exports.map(function () { return E.right(acc); }), exports.alt(function () {
return pipeable_1.pipe(parser, exports.map(function (a) { return E.left(RNEA.snoc(acc, a)); }));
}));
});
}));
};
var map_ = function (ma, f) { return function (i) {

@@ -377,2 +432,18 @@ return pipeable_1.pipe(ma(i), E.map(function (s) { return (__assign({}, s, { value: f(s.value) })); }));

var chain_ = function (ma, f) { return exports.seq(ma, f); };
var chainRec_ = function (a, f) {
var split = function (result) {
return E.isLeft(result.value)
? E.left({ value: result.value.left, stream: result.next })
: E.right(ParseResult_1.success(result.value.right, result.next, result.start));
};
return function (i) {
return ChainRec_1.tailRec({ value: a, stream: i }, function (state) {
var result = f(state.value)(state.stream);
if (E.isLeft(result)) {
return E.right(ParseResult_1.error(state.stream, result.left.expected, result.left.fatal));
}
return split(result.right);
});
};
};
var alt_ = function (fa, that) { return exports.either(fa, that); };

@@ -495,2 +566,13 @@ // -------------------------------------------------------------------------------------

* @category instances
* @since 0.6.11
*/
exports.ChainRec = {
URI: exports.URI,
map: map_,
ap: ap_,
chain: chain_,
chainRec: chainRec_
};
/**
* @category instances
* @since 0.6.7

@@ -497,0 +579,0 @@ */

2

package.json
{
"name": "parser-ts",
"version": "0.6.10",
"version": "0.6.11",
"description": "String parser combinators for TypeScript",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc