Parsec.Token:reserved

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 reserved
reserved :: forall st. TokenParser st -> String -> CharParser st ()
*Main> run (reserved lexer "abc") "abc"
Loading package parsec ... linking ... done.
()
*Main> run (reserved lexer "abc") "def"
parse error at (line 1, column 1):
unexpected "d"
expecting "abc"
*Main> run (reserved lexer "") "def"
parse error at (line 1, column 1):
unexpected "d"
expecting end of ""