Parsec.Error:errorPos
Prelude> :m Text.ParserCombinators.Parsec Prelude Text.ParserCombinators.Parsec> :t errorPos errorPos :: ParseError -> SourcePos
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 (errorPos err) } Right x -> print x
で、
Prelude> :l 20090129_parsec00.hs [1 of 1] Compiling Main ( 20090129_parsec00.hs, interpreted ) Ok, modules loaded: Main. *Main> run (identifier lexer) "abc" Loading package parsec-2.0 ... linking ... done. "abc" *Main> run (identifier lexer) "123" parse error at (line 1, column 1) *Main> :l 20081127_parsec00.hs [1 of 1] Compiling Main ( 20081127_parsec00.hs, interpreted ) Ok, modules loaded: Main. *Main> run (identifier lexer) "123" parse error at (line 1, column 1): unexpected "1" expecting identifier