Parsec.Token
module Main where import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Token import Text.ParserCombinators.Parsec.Language lexer :: TokenParser () lexer = makeTokenParser( LanguageDef { commentStart = "" , commentEnd = "" , commentLine = "" , nestedComments = True , identStart = letter <|> char '_' , identLetter = alphaNum <|> oneOf "_'" , opStart = opLetter emptyDef , opLetter = oneOf ":!#$%&*+./<=>?@\\^|-~" , reservedOpNames= [] , reservedNames = [] , caseSensitive = True } ) 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 20081126_parsec00.hs Compiling Main ( 20081126_parsec00.hs, interpreted ) Ok, modules loaded: Main. *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"