Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@blt
Created January 24, 2011 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blt/793501 to your computer and use it in GitHub Desktop.
Save blt/793501 to your computer and use it in GitHub Desktop.
{-# 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
Copy link
Author

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