Skip to content

Instantly share code, notes, and snippets.

@blt
Created Jan 24, 2011
Embed
What would you like to do?
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (words)
import Control.Applicative hiding (many)
import Data.Attoparsec as P
import Data.Attoparsec.Char8 as P8
import Data.ByteString as B
import Data.Word
civil :: B.ByteString
civil = "That government is best which governs least"
space_w8 :: Parser Word8
space_w8 = P.satisfy P8.isSpace_w8 <?> "space"
skipSpaces :: Parser ()
skipSpaces = P.satisfy P8.isHorizontalSpace *>
P.skipWhile P8.isHorizontalSpace
words :: Parser [B.ByteString]
words = many $ skipSpaces *> P.takeTill P8.isSpace_w8 <* P8.char8 ' '
main :: IO ()
main = do
parseTest words civil
@blt

This comment has been minimized.

Copy link
Owner Author

@blt blt commented Jan 24, 2011

I'd like to parse civil into a list of words; instead I get

>>> parseTest words civil
Done "That government is best which governs least" []

Eh?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment