2 module Parser ( parse ) where
14 '%module' { TKmodule }
16 '%newtype' { TKnewtype }
17 '%forall' { TKforall }
25 '%external' { TKexternal }
44 INTEGER { TKinteger $$ }
45 RATIONAL { TKrational $$ }
46 STRING { TKstring $$ }
49 %monad { P } { thenP } { returnP }
50 %lexer { lexer } { TKEOF }
55 : '%module' mname tdefs vdefgs
60 | tdef ';' tdefs {$1:$3}
63 : '%data' qcname tbinds '=' '{' cons1 '}'
65 | '%newtype' qcname tbinds trep
69 : {- empty -} {Nothing}
73 : name { ($1,Klifted) }
74 | '(' name '::' akind ')'
79 | tbind tbinds { $1:$2 }
83 : '(' name '::' ty')' { ($2,$4) }
87 | vbind vbinds { $1:$2 }
95 | bind binds1 { $1:$2 }
97 attbinds :: { [Tbind] }
106 | '(' kind ')' { $2 }
115 | con ';' cons1 { $1:$3 }
118 : qcname attbinds atys
133 | bty aty { Tapp $1 $2 }
139 | '%forall' tbinds '.' ty
140 { foldr Tforall $4 $2 }
142 vdefgs :: { [Vdefg] }
144 | vdefg ';' vdefgs {$1:$3 }
147 : '%rec' '{' vdefs1 '}'
153 | vdef ';' vdefs1 { $1:$3 }
156 : qname '::' ty '=' exp
166 : fexp aexp { App $1 $2 }
167 | fexp '@' aty { Appt $1 $3 }
172 | '\\' binds1 '->' exp
174 | '%let' vdefg '%in' exp
176 | '%case' '(' ty ')' aexp '%of' vbind '{' alts1 '}'
182 | '%external' STRING aty
187 | alt ';' alts1 { $1:$3 }
190 : qcname attbinds vbinds '->' exp
198 : '(' INTEGER '::' aty ')'
200 | '(' RATIONAL '::' aty ')'
202 | '(' CHAR '::' aty ')'
204 | '(' STRING '::' aty ')'
215 { let (parentNames, childName) = splitModuleName $3 in
216 ($1, parentNames, childName) }
221 -- TODO: Clean this up. Now hierarchical names are z-encoded.
223 -- note that a sequence of mnames is either:
224 -- empty, or a series of cnames separated by
225 -- dots, with a leading dot
226 -- See the definition of mnames: the "name" part
230 | '.' cname mnames {$2:$3}
232 -- it sucks to have to repeat the Maybe-checking twice,
233 -- but otherwise we get reduce/reduce conflicts
235 qname :: { (Mname,Id) }
236 : name { (Nothing, $1) }
240 qcname :: { (Mname,Id) }
241 : cname { (Nothing, $1) }
249 happyError s l = failP (show l ++ ": Parse error\n") (take 100 s) l