Created
December 14, 2020 05:40
-
-
Save pfgray/750f5526b436415b235f9ce2a616e2a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Parser, parser } from "parser-ts/lib/Parser" | |
import { Do } from 'fp-ts-contrib/lib/Do' | |
import { char, digit, letter, space } from "parser-ts/lib/char" | |
import { many1 } from "parser-ts/lib/string" | |
import { stream } from "parser-ts/lib/Stream" | |
type PasswordEntry = { | |
min: number | |
max: number | |
l: string | |
pw: string | |
} | |
const parsePE: Parser<string, PasswordEntry> = | |
Do(parser) | |
.bind('min', many1(digit)) | |
.do(char('-')) | |
.bind.do(space)('max', many1(digit)) | |
.do(space) | |
.bind('l', letter) | |
.do(char(':')) | |
.do(space) | |
.bind('pw', many1(letter)) | |
.return(({min, max, l, pw}) => ({ | |
min: parseInt(min, 10), | |
max: parseInt(max, 10), | |
l, | |
pw | |
})) | |
console.log( | |
parsePE(stream("9-10 x: pxcbpxxwkqjttx".split(''))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment