Created
January 17, 2014 02:03
-
-
Save pedrofurla/8467264 to your computer and use it in GitHub Desktop.
Not sure I am completely degenerating Parser.hs or providing improvement. I found a lot easier to work with these combinator
This file contains hidden or 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
| toParserList :: Parser a -> Parser (List a) | |
| toParserList = bindParser (\i -> valueParser (i:.Nil)) | |
| concatParser :: Parser (List t) -> Parser (List t) -> Parser (List t) | |
| concatParser (P p1) (P p2) = | |
| P(\i -> withResultInput (\i2 a2 -> withResultInput (\i3 a3 -> Result i3 $ a2 ++ a3) $ p2 i2 ) $ p1 i) | |
| (~~~) :: | |
| Parser t | |
| -> Parser t | |
| -> Parser (List t) | |
| l ~~~ r = concatParser (toParserList l) (toParserList r) | |
| (~~<) :: Parser t -> Parser (List t) -> Parser (List t) | |
| l ~~< r = concatParser (toParserList l) r | |
| (>~~) :: Parser (List t) -> Parser t -> Parser (List t) | |
| l >~~ r = concatParser l (toParserList r) | |
| (>~<) :: Parser (List t) -> Parser (List t) -> Parser (List t) | |
| (>~<) = concatParser | |
| -- Example | |
| -- /Surname: string that starts with a capital letter and is followed by 5 or more lower-case letters./ | |
| surnameParser = upper ~~< (thisMany 5 lower) >~< (list lower) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment