aboutsummaryrefslogtreecommitdiff
path: root/src/parser/utils.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-01-08 18:14:59 +0530
committerAkshay Nair <phenax5@gmail.com>2022-01-08 18:16:48 +0530
commite8322ca988fc20baf7892915e6ccb069b11c608e (patch)
treeeaef108f21389268d42218eacde2256884a62f64 /src/parser/utils.ts
parente1092bfca260412ab716710d31c24c86d3a818e1 (diff)
downloadelxr-e8322ca988fc20baf7892915e6ccb069b11c608e.tar.gz
elxr-e8322ca988fc20baf7892915e6ccb069b11c608e.zip
feat(parser): implements or syntax
Diffstat (limited to '')
-rw-r--r--src/parser/utils.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/parser/utils.ts b/src/parser/utils.ts
index a06b6c9..debff22 100644
--- a/src/parser/utils.ts
+++ b/src/parser/utils.ts
@@ -78,7 +78,7 @@ export const delimited = <T>(
p: Parser<any>,
a: Parser<T>,
s: Parser<any>,
-): Parser<T> => suffixed(prefixed(p, a), s)
+): Parser<T> => recoverInput(suffixed(prefixed(p, a), s))
export const satifyChar =
(f: (c: char) => boolean): Parser<char> =>
@@ -150,13 +150,16 @@ export const optional = <T>(p: Parser<T>): Parser<Option<T>> =>
)
export const pair = <A, B>(a: Parser<A>, b: Parser<B>): Parser<[A, B]> =>
- pipe(
- a,
- andThen(ra => mapTo(b, rb => [ra, rb])),
+ recoverInput(
+ pipe(
+ a,
+ andThen(ra => mapTo(b, rb => [ra, rb])),
+ ),
)
export const tuple3 = <A, B, C>(
a: Parser<A>,
b: Parser<B>,
c: Parser<C>,
-): Parser<[A, B, C]> => mapTo(pair(pair(a, b), c), ([[a, b], c]) => [a, b, c])
+): Parser<[A, B, C]> =>
+ recoverInput(mapTo(pair(pair(a, b), c), ([[a, b], c]) => [a, b, c]))