Parsec.Token:operator
module Main where import Text.ParserCombinators.Parsec import Text.ParserCombinators.Parsec.Token import Text.ParserCombinators.Parsec.Language lexer :: TokenParser () lexer = makeTokenParser(javaStyle) 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 20081127_parsec00.hs Compiling Main ( 20081127_parsec00.hs, interpreted ) Ok, modules loaded: Main. *Main> :t operator operator :: forall st. TokenParser st -> CharParser st String *Main> run (operator lexer) "a" Loading package parsec ... linking ... done. parse error at (line 1, column 1): unexpected "a" expecting operator *Main> run (operator lexer) "+" "+"