Skip to content

Commit 98068b7

Browse files
committed
Add parser.lookaheadNot combinator
1 parent c9afa3e commit 98068b7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/parsing/combinators.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ export const lazy =
3737
input =>
3838
parser()(input)
3939

40+
export const lookaheadNot =
41+
<Output>(
42+
parser: Parser<Output>,
43+
notFollowedBy: Parser<unknown>,
44+
followedByName: string,
45+
): Parser<Output> =>
46+
input =>
47+
either.flatMap(parser(input), success =>
48+
either.match(notFollowedBy(success.remainingInput), {
49+
left: _ => either.makeRight(success),
50+
right: _ =>
51+
either.makeLeft({
52+
input,
53+
message: `input was unexpectedly followed by ${followedByName}`,
54+
}),
55+
}),
56+
)
57+
4058
export const map =
4159
<Output, NewOutput>(
4260
parser: Parser<Output>,

0 commit comments

Comments
 (0)