2 module Parser ( parse ) where
15 '%module' { TKmodule }
17 '%newtype' { TKnewtype }
18 '%forall' { TKforall }
26 '%external' { TKexternal }
45 INTEGER { TKinteger $$ }
46 RATIONAL { TKrational $$ }
47 STRING { TKstring $$ }
50 %monad { P } { thenP } { returnP }
51 %lexer { lexer } { TKEOF }
56 : '%module' mname tdefs vdefgs
61 | tdef ';' tdefs {$1:$3}
64 : '%data' qcname tbinds '=' '{' cons1 '}'
66 | '%newtype' qcname tbinds trep
70 : {- empty -} {Nothing}
74 : name { ($1,Klifted) }
75 | '(' name '::' akind ')'
80 | tbind tbinds { $1:$2 }
84 : '(' name '::' ty')' { ($2,$4) }
88 | vbind vbinds { $1:$2 }
96 | bind binds1 { $1:$2 }
98 attbinds :: { [Tbind] }
107 | '(' kind ')' { $2 }
116 | con ';' cons1 { $1:$3 }
119 : qcname attbinds atys
134 | bty aty { Tapp $1 $2 }
140 | '%forall' tbinds '.' ty
141 { foldr Tforall $4 $2 }
143 vdefgs :: { [Vdefg] }
145 | vdefg ';' vdefgs {$1:$3 }
148 : '%rec' '{' vdefs1 '}'
154 | vdef ';' vdefs1 { $1:$3 }
157 : qname '::' ty '=' exp
167 : fexp aexp { App $1 $2 }
168 | fexp '@' aty { Appt $1 $3 }
173 | '\\' binds1 '->' exp
175 | '%let' vdefg '%in' exp
177 | '%case' '(' ty ')' aexp '%of' vbind '{' alts1 '}'
179 -- Note: ty, not aty! You can cast something to a forall type
180 -- Though now we have shift/reduce conflicts like woah
185 | '%external' STRING aty
190 | alt ';' alts1 { $1:$3 }
193 : qcname attbinds vbinds '->' exp
201 : '(' INTEGER '::' aty ')'
203 | '(' RATIONAL '::' aty ')'
205 | '(' CHAR '::' aty ')'
207 | '(' STRING '::' aty ')'
218 { let (parentNames, childName) = splitModuleName $3 in
219 ($1, parentNames, childName) }
224 -- TODO: Clean this up. Now hierarchical names are z-encoded.
226 -- note that a sequence of mnames is either:
227 -- empty, or a series of cnames separated by
228 -- dots, with a leading dot
229 -- See the definition of mnames: the "name" part
233 | '.' cname mnames {$2:$3}
235 -- it sucks to have to repeat the Maybe-checking twice,
236 -- but otherwise we get reduce/reduce conflicts
238 -- TODO: this is the ambiguity here. mname '.' name --
239 -- but by maximal-munch, in GHC.Base.Bool the entire
240 -- thing gets counted as the module name. What to do,
241 -- besides z-encoding the dots in the hierarchy again?
242 -- (Or using syntax other than a dot to separate the
243 -- module name from the variable name...)
244 qname :: { (Mname,Id) }
245 : name { (Nothing, $1) }
249 qcname :: { (Mname,Id) }
250 : cname { (Nothing, $1) }
258 happyError s l = failP (show l ++ ": Parse error\n") (take 100 s) l