attoparsec icon indicating copy to clipboard operation
attoparsec copied to clipboard

takeWhile1 doesn't stop on end of string

Open varosi opened this issue 10 years ago • 4 comments

I have this code:

parseClass :: Parser Text
parseClass = do
    string "Class" <|> string "class"
    skipSpace
    takeWhile1 isAlpha

When I call it in GHCi I got this results:

*Lib> maybeResult . parse parseClass' $ (pack "Class Test ")
Just "Test"
*Lib> maybeResult . parse parseClass' $ (pack "Class Test")
Nothing

varosi avatar Nov 07 '15 09:11 varosi

What if you place a endOfInput at the end?

basvandijk avatar Nov 08 '15 11:11 basvandijk

I would like to match "parseClass" parser no matter if it is in the middle or at the end of input.

varosi avatar Nov 08 '15 21:11 varosi

@varosi maybeResult converts Partial values to Nothings - this is intended behaviour. You need to feed it an empty input (empty string) in order for the Partial to turn into a Done so that maybeResult will return a Just.

googleson78 avatar Dec 12 '18 13:12 googleson78

Thanks! На ср, 12.12.2018 г., 15:25 ч. Georgi Lyubenov [email protected] написа:

@varosi https://github.com/varosi maybeResult converts Partial values to Nothings - this is intended behaviour. You need to feed it an empty input (empty string) in order for the Partial to turn into a Done so that maybeResult will return a Just.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bos/attoparsec/issues/111#issuecomment-446587019, or mute the thread https://github.com/notifications/unsubscribe-auth/AFxXht47g-DDK56qwrUGHWYCjpMDn8Opks5u4QPTgaJpZM4Gd666 .

varosi avatar Dec 16 '18 09:12 varosi