Skip to content

Instantly share code, notes, and snippets.

@pedrofurla
Created January 17, 2014 02:03
Show Gist options
  • Select an option

  • Save pedrofurla/8467264 to your computer and use it in GitHub Desktop.

Select an option

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
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