diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-11 17:13:57 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-11 17:13:57 +0530 |
| commit | 952256ae8bf5514a246db8f33bef207f5747b138 (patch) | |
| tree | 750bbdedd1e98e50a8e5d0c3ae0017d45e2bf953 /src/utils/parser-comb.ts | |
| parent | 67748db74f73343b054ee0af1763e376a5470416 (diff) | |
| download | css-everything-952256ae8bf5514a246db8f33bef207f5747b138.tar.gz css-everything-952256ae8bf5514a246db8f33bef207f5747b138.zip | |
feat: adds parser for literal numbers
Diffstat (limited to '')
| -rw-r--r-- | src/utils/parser-comb.ts | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/utils/parser-comb.ts b/src/utils/parser-comb.ts index e0665f6..f682068 100644 --- a/src/utils/parser-comb.ts +++ b/src/utils/parser-comb.ts @@ -73,3 +73,11 @@ export const sepBy = <A>(parser: Parser<A>, sepP: Parser<any>): Parser<Array<A>> Err: _ => Result.Ok({ value: [], input: originalInput }), }) +export const optional = <A>(parser: Parser<A>): Parser<undefined | A> => input => { + const result = parser(input) + return match(result, { + Ok: _ => result, + Err: _ => Result.Ok({ value: undefined, input }) + }) +} + |
