Put "%expect 0" directives in the .y files
[ghc-hetmet.git] / utils / hpc / HpcParser.y
1
2 {-# OPTIONS -Wwarn #-}
3 -- The above warning supression flag is a temporary kludge.
4 -- While working on this module you are encouraged to remove it and fix
5 -- any warnings in the module. See
6 --     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
7 -- for details
8
9 module HpcParser where
10
11 import HpcLexer
12 }
13
14 %name parser
15 %expect 0
16 %tokentype { Token }
17
18 %token
19         MODULE          { ID "module" }
20         TICK            { ID "tick" }
21         EXPRESSION      { ID "expression" }
22         ON              { ID "on" }
23         LINE            { ID "line" }
24         POSITION        { ID "position" }
25         FUNCTION        { ID "function" }
26         INSIDE          { ID "inside" }
27         AT              { ID "at" }
28         ':'             { SYM ':' }
29         '-'             { SYM '-' }
30         ';'             { SYM ';' }
31         '{'             { SYM '{' }
32         '}'             { SYM '}' }
33         int             { INT $$ }
34         string          { STR $$ }
35         cat             { CAT $$ }
36 %%
37
38 Spec    :: { Spec }
39 Spec    : Ticks Modules         { Spec ($1 []) ($2 []) }
40
41 Modules :: { L (ModuleName,[Tick]) }
42 Modules : Modules Module        { $1 . ((:) $2) }
43         |                       { id }
44         
45 Module :: { (ModuleName,[Tick]) }
46 Module  : MODULE string '{' TopTicks '}'
47                                 { ($2,$4 []) }
48
49 TopTicks :: { L Tick }
50 TopTicks : TopTicks TopTick     { $1 . ((:) $2) }
51          |                      { id }
52         
53 TopTick :: { Tick }
54 TopTick : Tick                  { ExprTick $1 }
55         | TICK FUNCTION string optQual optCat ';'
56                                 { TickFunction $3 $4 $5 }
57         | INSIDE string '{' TopTicks '}'
58                                 { InsideFunction $2 ($4 []) }
59                                  
60 Ticks   :: { L ExprTick }
61 Ticks   : Ticks  Tick           { $1 . ((:) $2) }
62         |                       { id } 
63         
64 Tick   :: { ExprTick }
65 Tick    : TICK optString optQual optCat ';'
66                                 { TickExpression False $2 $3 $4 }
67
68 optString :: { Maybe String }
69 optString : string              { Just $1 }
70           |                     { Nothing }
71         
72 optQual :: { Maybe Qualifier }
73 optQual : ON LINE int           { Just (OnLine $3) }
74         | AT POSITION int ':' int '-' int ':' int
75                                 { Just (AtPosition $3 $5 $7 $9) }
76         |                       { Nothing }
77 optCat  :: { Maybe String }
78 optCat  : cat                   { Just $1 }
79         |                       { Nothing }
80
81 {
82 type L a = [a] -> [a]
83         
84 type ModuleName = String
85
86 data Spec 
87   = Spec [ExprTick] [(ModuleName,[Tick])]
88    deriving (Show)
89
90 data ExprTick
91   = TickExpression Bool (Maybe String) (Maybe Qualifier) (Maybe String)
92    deriving (Show)
93
94 data Tick
95   = ExprTick ExprTick
96   | TickFunction   String (Maybe Qualifier) (Maybe String)
97   | InsideFunction String [Tick]
98    deriving (Show)
99
100 data Qualifier = OnLine Int
101                | AtPosition Int Int Int Int
102    deriving (Show)             
103
104
105
106 hpcParser :: String -> IO Spec
107 hpcParser filename = do
108   txt <- readFile filename
109   let tokens = initLexer txt
110   return $ parser tokens        
111
112 happyError e = error $ show (take 10 e)
113 }