mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #49906 parsimmon: sepBy1 should return a non-empty array by @Nathan-Fenner
This commit is contained in:
6
types/parsimmon/index.d.ts
vendored
6
types/parsimmon/index.d.ts
vendored
@@ -250,9 +250,9 @@ declare namespace Parsimmon {
|
||||
/**
|
||||
* Equivalent to Parsimmon.sepBy(parser, separator).
|
||||
*
|
||||
* Expects one or more matches for parser, separated by the parser separator, yielding an array.
|
||||
* Expects one or more matches for parser, separated by the parser separator, yielding a non-empty array.
|
||||
*/
|
||||
sepBy1<U>(separator: Parser<U>): Parser<T[]>;
|
||||
sepBy1<U>(separator: Parser<U>): Parser<[T, ...T[]]>;
|
||||
/**
|
||||
* Equivalent to Parsimmon.of(result).
|
||||
*/
|
||||
@@ -472,7 +472,7 @@ declare namespace Parsimmon {
|
||||
/**
|
||||
* This is the same as Parsimmon.sepBy, but matches the content parser at least once.
|
||||
*/
|
||||
function sepBy1<T, U>(content: Parser<T>, separator: Parser<U>): Parser<T[]>;
|
||||
function sepBy1<T, U>(content: Parser<T>, separator: Parser<U>): Parser<[T, ...T[]]>;
|
||||
|
||||
/**
|
||||
* accepts a function that returns a parser, which is evaluated the first time the parser is used.
|
||||
|
||||
@@ -39,7 +39,9 @@ let fooOrBarPar: Parser<Foo | Bar>;
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
let strArrPar: Parser<string[]>;
|
||||
let str1ArrPar: Parser<[string, ...string[]]>;
|
||||
let fooArrPar: Parser<Foo[]>;
|
||||
let foo1ArrPar: Parser<[Foo, ...Foo[]]>;
|
||||
|
||||
// -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
|
||||
@@ -284,6 +286,9 @@ strPar = P.seqMap(
|
||||
|
||||
strArrPar = P.sepBy(P.string('foo'), P.string('bar'));
|
||||
strArrPar = P.sepBy1(P.string('foo'), P.string('bar'));
|
||||
str1ArrPar = P.sepBy1(P.string('foo'), P.string('bar'));
|
||||
function flattenMultiple(first: string, ...rest: string[]): number { return rest.length; }
|
||||
numPar = str1ArrPar.map(arr => flattenMultiple(...arr));
|
||||
|
||||
strPar = P.test((a: string) => false);
|
||||
|
||||
@@ -324,6 +329,7 @@ numPar = P.digit
|
||||
|
||||
fooArrPar = fooPar.sepBy(barPar);
|
||||
fooArrPar = fooPar.sepBy1(barPar);
|
||||
foo1ArrPar = fooPar.sepBy1(barPar);
|
||||
|
||||
fooPar = barPar.of(foo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user