Created
January 22, 2012 08:13
-
-
Save deepakjois/1656230 to your computer and use it in GitHub Desktop.
Simple sentence parser
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
word :: Parser String | |
word = do{ c <- letter | |
; do{ cs <- word | |
; return (c:cs) | |
} | |
<|> return [c] | |
} | |
sentence :: Parser [String] | |
sentence = do{ words <- sepBy1 word separator | |
; oneOf ".?!" | |
; return words | |
} | |
separator :: Parser () | |
separator = skipMany1 (space <|> char ',') | |
-- P.parse sentence "unknown" "a b c." | |
-- => Right ["a","b","c"] | |
-- P.parse sentence "unknown" "a b c ." | |
-- => unexpected "." | |
-- => expecting space, "," or letter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment