aboutsummaryrefslogtreecommitdiff
path: root/src/parser/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/utils.ts')
-rw-r--r--src/parser/utils.ts6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/parser/utils.ts b/src/parser/utils.ts
index debff22..9e05286 100644
--- a/src/parser/utils.ts
+++ b/src/parser/utils.ts
@@ -40,14 +40,14 @@ export const many0 = <T>(parser: Parser<T>): Parser<Array<T>> =>
)
export const many1 = <T>(parser: Parser<T>): Parser<Array<T>> =>
- flow(
+ recoverInput(flow(
many0(parser),
chain(([res, inp]) =>
res.length > 0
? right([res, inp])
: left([`many1 failed to parse at ${inp}`, inp]),
),
- )
+ ))
const recoverInput =
<T>(p: Parser<T>): Parser<T> =>
@@ -123,6 +123,8 @@ export const matchString =
? right([s, input.slice(s.length)])
: left([`Expected ${s} but got ${input.slice(0, 1)}`, input])
+export const oneOf = (xs: string[]): Parser<string> => or(xs.map(matchString))
+
export const symbol = (s: string): Parser<string> =>
delimited(whitespaces0, matchString(s), whitespaces0)