ad0291a73b15455002c5dc7cb51f77cbe7ba6146
[packages/parsec.git] / test / Bugs / Bug9.hs
1
2 module Bugs.Bug9 ( main ) where
3
4 import Control.Applicative ((<*), (<$>), (<$))
5 import Text.Parsec
6 import Text.Parsec.Language (haskellStyle)
7 import Text.Parsec.String (Parser)
8 import Text.Parsec.Error ( errorMessages, messageString )
9 import Text.Parsec.Expr
10 import qualified Text.Parsec.Token as P
11
12 import Test.HUnit hiding ( Test )
13 import Test.Framework
14 import Test.Framework.Providers.HUnit
15
16 data Expr = Const Integer | Op Expr Expr
17 deriving Show
18
19 main :: Test
20 main =
21 testCase "Tracing of current position in error message (#9)"
22 $ result @?= ["unexpected '>'","expecting operator or end of input"]
23
24 where
25 result :: [String]
26 result =
27 case parse parseTopLevel "" "4 >> 5" of
28 Left err ->
29 drop 1 $ lines $ show err
30 Right{} -> []
31
32 -- Syntax analaysis
33
34 parseTopLevel :: Parser Expr
35 parseTopLevel = parseExpr <* eof
36
37 parseExpr :: Parser Expr
38 parseExpr = buildExpressionParser table (Const <$> integer)
39 where
40 table = [[ Infix (Op <$ reserved ">>>") AssocLeft ]]
41
42 -- Lexical analysis
43
44 lexer = P.makeTokenParser haskellStyle { P.reservedOpNames = [">>>"] }
45
46 integer = P.integer lexer
47 reserved = P.reserved lexer
48 reservedOp = P.reservedOp lexer
49