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 '}'
178 -- Note: ty, not aty! You can cast something to a forall type
179 -- Though now we have shift/reduce conflicts like woah
184 | '%external' STRING aty
189 | alt ';' alts1 { $1:$3 }
192 : qcname attbinds vbinds '->' exp
200 : '(' INTEGER '::' aty ')'
202 | '(' RATIONAL '::' aty ')'
204 | '(' CHAR '::' aty ')'
206 | '(' STRING '::' aty ')'
217 { let (parentNames, childName) = splitModuleName $3 in
218 ($1, parentNames, childName) }
223 -- TODO: Clean this up. Now hierarchical names are z-encoded.
225 -- note that a sequence of mnames is either:
226 -- empty, or a series of cnames separated by
227 -- dots, with a leading dot
228 -- See the definition of mnames: the "name" part
232 | '.' cname mnames {$2:$3}
234 -- it sucks to have to repeat the Maybe-checking twice,
235 -- but otherwise we get reduce/reduce conflicts
237 -- TODO: this is the ambiguity here. mname '.' name --
238 -- but by maximal-munch, in GHC.Base.Bool the entire
239 -- thing gets counted as the module name. What to do,
240 -- besides z-encoding the dots in the hierarchy again?
241 -- (Or using syntax other than a dot to separate the
242 -- module name from the variable name...)
243 qname :: { (Mname,Id) }
244 : name { (Nothing, $1) }
248 qcname :: { (Mname,Id) }
249 : cname { (Nothing, $1) }
257 happyError s l = failP (show l ++ ": Parse error\n") (take 100 s) l