Parsec.Token
module Main where import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Token import Text.ParserCombinators.Parsec.Language lexer :: TokenParser () lexer = makeTokenParser(emptyDef) run :: Show a => Parser a -> String -> IO () run p input = case (parse p "" input) of Left err -> do{ putStr "parse error at " ; print err } Right x -> print x
で、
Prelude> :l 20081124_parsec00.hs Compiling Main ( 20081124_parsec00.hs, interpreted ) Ok, modules loaded: Main. *Main> :t symbol symbol :: forall st. TokenParser st -> String -> CharParser st String *Main> :t lexer lexer :: TokenParser () *Main> :t run run :: forall a. (Show a) => Parser a -> String -> IO () *Main> :t (symbol lexer) (symbol lexer) :: String -> CharParser () String *Main> :t ((symbol lexer) "a") ((symbol lexer) "a") :: CharParser () String *Main> run ((symbol lexer) "a") "abc" Loading package parsec ... linking ... done. "a" *Main> run ((symbol lexer) "a") "b" parse error at (line 1, column 1): unexpected "b" expecting "a"