module LearnParsers where import Text.Trifecta stop :: Parser a stop = unexpected "stop" -- read a single character '1' one = char '1' -- read a single character '1', then die one' = one >> stop -- equivalent to char '1' >> stop -- read two characters, '1', and '2' oneTwo = char '1' >> char '2' -- read two characters, -- '1' and '2', then die oneTwo' = oneTwo >> stop testParse :: Parser Char -> IO () testParse p = print $ parseString p mempty "123" pNL s = putStrLn ('\n' : s) oneTwoThree :: Parser String oneTwoThree = choice [ string "123" , string "12" , string "1" ] oneTwoThree' = oneTwoThree >> stop testParse' :: Parser String -> IO () testParse' p = print $ parseString p mempty "123" oneTwoThree'' :: Parser Char oneTwoThree'' = choice [ one , oneTwo , char '1' >> char '2' >> char '3' ]