git.iko.soy/typeable/attoparsec
on 0.13.0.1 help sign in
31 lines 974 B history raw
1import Control.Applicative ((<|>), many)
2import Control.Monad (forM_)
3import System.Environment (getArgs)
4import qualified Data.Attoparsec.ByteString.Char8 as A
5import qualified Data.ByteString.Char8 as B
6import qualified Text.Parsec as P
7import qualified Text.Parsec.ByteString as P
9attoparsec = do
10 args <- getArgs
11 forM_ args $ \arg -> do
12 input <- B.readFile arg
13 case A.parse p input `A.feed` B.empty of
14 A.Done _ xs -> print (length xs)
15 what -> print what
16 where
17 slow = many (A.many1 A.letter_ascii <|> A.many1 A.digit)
18 fast = many (A.takeWhile1 isLetter <|> A.takeWhile1 isDigit)
19 isDigit c = c >= '0' && c <= '9'
20 isLetter c = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
21 p = fast
23parsec = do
24 args <- getArgs
25 forM_ args $ \arg -> do
26 input <- readFile arg
27 case P.parse (P.many (P.many1 P.letter P.<|> P.many1 P.digit)) "" input of
28 Left err -> print err
29 Right xs -> print (length xs)
31main = attoparsec