2 {-# OPTIONS -Wwarn -XNoMonomorphismRestriction #-}
3 -- The NoMonomorphismRestriction deals with a Happy infelicity
4 -- With OutsideIn's more conservativ monomorphism restriction
5 -- we aren't generalising
6 -- notHappyAtAll = error "urk"
7 -- which is terrible. Switching off the restriction allows
8 -- the generalisation. Better would be to make Happy generate
9 -- an appropriate signature.
11 -- The above warning supression flag is a temporary kludge.
12 -- While working on this module you are encouraged to remove it and fix
13 -- any warnings in the module. See
14 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
17 module HpcParser where
27 MODULE { ID "module" }
29 EXPRESSION { ID "expression" }
32 POSITION { ID "position" }
33 FUNCTION { ID "function" }
34 INSIDE { ID "inside" }
47 Spec : Ticks Modules { Spec ($1 []) ($2 []) }
49 Modules :: { L (ModuleName,[Tick]) }
50 Modules : Modules Module { $1 . ((:) $2) }
53 Module :: { (ModuleName,[Tick]) }
54 Module : MODULE string '{' TopTicks '}'
57 TopTicks :: { L Tick }
58 TopTicks : TopTicks TopTick { $1 . ((:) $2) }
62 TopTick : Tick { ExprTick $1 }
63 | TICK FUNCTION string optQual optCat ';'
64 { TickFunction $3 $4 $5 }
65 | INSIDE string '{' TopTicks '}'
66 { InsideFunction $2 ($4 []) }
68 Ticks :: { L ExprTick }
69 Ticks : Ticks Tick { $1 . ((:) $2) }
73 Tick : TICK optString optQual optCat ';'
74 { TickExpression False $2 $3 $4 }
76 optString :: { Maybe String }
77 optString : string { Just $1 }
80 optQual :: { Maybe Qualifier }
81 optQual : ON LINE int { Just (OnLine $3) }
82 | AT POSITION int ':' int '-' int ':' int
83 { Just (AtPosition $3 $5 $7 $9) }
85 optCat :: { Maybe String }
86 optCat : cat { Just $1 }
92 type ModuleName = String
95 = Spec [ExprTick] [(ModuleName,[Tick])]
99 = TickExpression Bool (Maybe String) (Maybe Qualifier) (Maybe String)
104 | TickFunction String (Maybe Qualifier) (Maybe String)
105 | InsideFunction String [Tick]
108 data Qualifier = OnLine Int
109 | AtPosition Int Int Int Int
114 hpcParser :: String -> IO Spec
115 hpcParser filename = do
116 txt <- readFile filename
117 let tokens = initLexer txt
118 return $ parser tokens
120 happyError e = error $ show (take 10 e)