diff options
| author | Akshay Nair <phenax5@gmail.com> | 2022-01-08 21:12:20 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2022-01-08 21:12:20 +0530 |
| commit | e246f2341ee13926f4273c6d634cef4fe07f040e (patch) | |
| tree | 2dfcbdb24004b85c1a6ab2ed11c211621489c9a3 /src/parser/utils.ts | |
| parent | 61bb1f0c8b109c66d48e678a4d2cf7cb29cf7efb (diff) | |
| download | elxr-e246f2341ee13926f4273c6d634cef4fe07f040e.tar.gz elxr-e246f2341ee13926f4273c6d634cef4fe07f040e.zip | |
feat(parse): implements object property matching parser
Diffstat (limited to '')
| -rw-r--r-- | src/parser/utils.ts | 6 |
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) |
