2 {-# LANGUAGE BangPatterns #-} -- required for versions of Happy before 1.18.6
3 {-# OPTIONS -Wwarn -XNoMonomorphismRestriction #-}
4 -- The NoMonomorphismRestriction deals with a Happy infelicity
5 -- With OutsideIn's more conservativ monomorphism restriction
6 -- we aren't generalising
7 -- notHappyAtAll = error "urk"
8 -- which is terrible. Switching off the restriction allows
9 -- the generalisation. Better would be to make Happy generate
10 -- an appropriate signature.
12 -- The above warning supression flag is a temporary kludge.
13 -- While working on this module you are encouraged to remove it and fix
14 -- any warnings in the module. See
15 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
18 module HpcParser where
28 MODULE { ID "module" }
30 EXPRESSION { ID "expression" }
33 POSITION { ID "position" }
34 FUNCTION { ID "function" }
35 INSIDE { ID "inside" }
48 Spec : Ticks Modules { Spec ($1 []) ($2 []) }
50 Modules :: { L (ModuleName,[Tick]) }
51 Modules : Modules Module { $1 . ((:) $2) }
54 Module :: { (ModuleName,[Tick]) }
55 Module : MODULE string '{' TopTicks '}'
58 TopTicks :: { L Tick }
59 TopTicks : TopTicks TopTick { $1 . ((:) $2) }
63 TopTick : Tick { ExprTick $1 }
64 | TICK FUNCTION string optQual optCat ';'
65 { TickFunction $3 $4 $5 }
66 | INSIDE string '{' TopTicks '}'
67 { InsideFunction $2 ($4 []) }
69 Ticks :: { L ExprTick }
70 Ticks : Ticks Tick { $1 . ((:) $2) }
74 Tick : TICK optString optQual optCat ';'
75 { TickExpression False $2 $3 $4 }
77 optString :: { Maybe String }
78 optString : string { Just $1 }
81 optQual :: { Maybe Qualifier }
82 optQual : ON LINE int { Just (OnLine $3) }
83 | AT POSITION int ':' int '-' int ':' int
84 { Just (AtPosition $3 $5 $7 $9) }
86 optCat :: { Maybe String }
87 optCat : cat { Just $1 }
93 type ModuleName = String
96 = Spec [ExprTick] [(ModuleName,[Tick])]
100 = TickExpression Bool (Maybe String) (Maybe Qualifier) (Maybe String)
105 | TickFunction String (Maybe Qualifier) (Maybe String)
106 | InsideFunction String [Tick]
109 data Qualifier = OnLine Int
110 | AtPosition Int Int Int Int
115 hpcParser :: String -> IO Spec
116 hpcParser filename = do
117 txt <- readFile filename
118 let tokens = initLexer txt
119 return $ parser tokens
121 happyError e = error $ show (take 10 e)