[project @ 2000-06-09 15:15:25 by simonmar]
[ghc-hetmet.git] / ghc / compiler / parser / ParseUtil.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1999
3 %
4 \section[ParseUtil]{Parser Utilities}
5
6 \begin{code}
7 module ParseUtil (
8           parseError            -- String -> Pa
9         , cbot                  -- a
10         , splitForConApp        -- RdrNameHsType -> [RdrNameBangType]
11                                 --     -> P (RdrName, [RdrNameBangType])
12
13         , mkRecConstrOrUpdate   -- HsExp -> [HsFieldUpdate] -> P HsExp
14         , groupBindings
15         
16         , mkExtName             -- Maybe ExtName -> RdrName -> ExtName
17
18         , checkPrec             -- String -> P String
19         , checkContext          -- HsType -> P HsContext
20         , checkInstType         -- HsType -> P HsType
21         , checkDataHeader       -- HsQualType -> P (HsContext,HsName,[HsName])
22         , checkSimple           -- HsType -> [HsName] -> P ((HsName,[HsName]))
23         , checkPattern          -- HsExp -> P HsPat
24         , checkPatterns         -- [HsExp] -> P [HsPat]
25         -- , checkExpr          -- HsExp -> P HsExp
26         , checkValDef           -- (SrcLoc, HsExp, HsRhs, [HsDecl]) -> P HsDecl
27         , checkValSig           -- (SrcLoc, HsExp, HsRhs, [HsDecl]) -> P HsDecl
28
29         
30         -- some built-in names (all :: RdrName)
31         , unitCon_RDR, unitTyCon_RDR, nilCon_RDR, listTyCon_RDR
32         , tupleCon_RDR, tupleTyCon_RDR, ubxTupleCon_RDR, ubxTupleTyCon_RDR
33         , funTyCon_RDR
34
35         -- pseudo-keywords, in var and tyvar forms (all :: RdrName)
36         , as_var_RDR, hiding_var_RDR, qualified_var_RDR, forall_var_RDR
37         , export_var_RDR, label_var_RDR, dynamic_var_RDR, unsafe_var_RDR
38         , stdcall_var_RDR, ccall_var_RDR
39
40         , as_tyvar_RDR, hiding_tyvar_RDR, qualified_tyvar_RDR
41         , export_tyvar_RDR, label_tyvar_RDR, dynamic_tyvar_RDR
42         , unsafe_tyvar_RDR, stdcall_tyvar_RDR, ccall_tyvar_RDR
43
44         , minus_RDR, pling_RDR, dot_RDR
45
46  ) where
47
48 #include "HsVersions.h"
49
50 import Lex
51 import HsSyn
52 import SrcLoc
53 import RdrHsSyn
54 import RdrName
55 import CallConv
56 import PrelNames        ( pRELUDE_Name, mkTupNameStr )
57 import OccName          ( dataName, tcName, varName, tvName, setOccNameSpace, occNameUserString )
58 import CmdLineOpts      ( opt_NoImplicitPrelude )
59 import StringBuffer     ( lexemeToString )
60 import FastString       ( unpackFS )
61 import BasicTypes       ( Boxity(..) )
62 import ErrUtils
63 import UniqFM           ( UniqFM, listToUFM, lookupUFM )
64 import Outputable
65
66 -----------------------------------------------------------------------------
67 -- Misc utils
68
69 parseError :: String -> P a
70 parseError s = 
71   getSrcLocP `thenP` \ loc ->
72   failMsgP (hcat [ppr loc, text ": ", text s])
73
74 cbot = panic "CCall:result_ty"
75
76 -----------------------------------------------------------------------------
77 -- splitForConApp
78
79 -- When parsing data declarations, we sometimes inadvertently parse
80 -- a constructor application as a type (eg. in data T a b = C a b `D` E a b)
81 -- This function splits up the type application, adds any pending
82 -- arguments, and converts the type constructor back into a data constructor.
83
84 splitForConApp :: RdrNameHsType -> [RdrNameBangType]
85         -> P (RdrName, [RdrNameBangType])
86
87 splitForConApp  t ts = split t ts
88  where
89         split (HsAppTy t u) ts = split t (Unbanged u : ts)
90
91         split (HsTyVar t)   ts  = returnP (con, ts)
92            where t_occ = rdrNameOcc t
93                  con   = setRdrNameOcc t (setOccNameSpace t_occ dataName)
94
95         split _ _ = parseError "Illegal data/newtype declaration"
96
97 ----------------------------------------------------------------------------
98 -- Various Syntactic Checks
99
100 callConvFM :: UniqFM CallConv
101 callConvFM = listToUFM $
102       map (\ (x,y) -> (_PK_ x,y))
103      [  ("stdcall",  stdCallConv),
104         ("ccall",    cCallConv)
105 --      ("pascal",   pascalCallConv),
106 --      ("fastcall", fastCallConv)
107      ]
108
109 checkCallConv :: FAST_STRING -> P CallConv
110 checkCallConv s = 
111   case lookupUFM callConvFM s of
112         Nothing -> parseError ("unknown calling convention: `"
113                                  ++ unpackFS s ++ "'")
114         Just conv -> returnP conv
115
116 checkInstType :: RdrNameHsType -> P RdrNameHsType
117 checkInstType t 
118   = case t of
119         HsForAllTy tvs ctxt ty ->
120                 checkDictTy ty [] `thenP` \ dict_ty ->
121                 returnP (HsForAllTy tvs ctxt dict_ty)
122
123         ty ->   checkDictTy ty [] `thenP` \ dict_ty->
124                 returnP (HsForAllTy Nothing [] dict_ty)
125
126 checkContext :: RdrNameHsType -> P RdrNameContext
127 checkContext (HsTupleTy _ ts) 
128   = mapP (\t -> checkPred t []) ts `thenP` \ps ->
129     returnP ps
130 checkContext (HsTyVar t) -- empty contexts are allowed
131   | t == unitTyCon_RDR = returnP []
132 checkContext t 
133   = checkPred t [] `thenP` \p ->
134     returnP [p]
135
136 checkPred :: RdrNameHsType -> [RdrNameHsType] 
137         -> P (HsPred RdrName)
138 checkPred (HsTyVar t) args@(_:_) | not (isRdrTyVar t) 
139         = returnP (HsPClass t args)
140 checkPred (HsAppTy l r) args = checkPred l (r:args)
141 checkPred (HsPredTy (HsPIParam n ty)) [] = returnP (HsPIParam n ty)
142 checkPred _ _ = parseError "Illegal class assertion"
143
144 checkDictTy :: RdrNameHsType -> [RdrNameHsType] -> P RdrNameHsType
145 checkDictTy (HsTyVar t) args@(_:_) | not (isRdrTyVar t) 
146         = returnP (mkHsDictTy t args)
147 checkDictTy (HsAppTy l r) args = checkDictTy l (r:args)
148 checkDictTy _ _ = parseError "Illegal class assertion"
149
150 checkDataHeader :: RdrNameHsType 
151         -> P (RdrNameContext, RdrName, [RdrNameHsTyVar])
152 checkDataHeader (HsForAllTy Nothing cs t) =
153    checkSimple t []          `thenP` \(c,ts) ->
154    returnP (cs,c,map UserTyVar ts)
155 checkDataHeader t =
156    checkSimple t []          `thenP` \(c,ts) ->
157    returnP ([],c,map UserTyVar ts)
158
159 checkSimple :: RdrNameHsType -> [RdrName] -> P ((RdrName,[RdrName]))
160 checkSimple (HsAppTy l (HsTyVar a)) xs | isRdrTyVar a 
161    = checkSimple l (a:xs)
162 checkSimple (HsTyVar t) xs | not (isRdrTyVar t) = returnP (t,xs)
163 checkSimple t _ = trace (showSDoc (ppr t)) $ parseError "Illegal data/newtype declaration"
164
165 ---------------------------------------------------------------------------
166 -- Checking Patterns.
167
168 -- We parse patterns as expressions and check for valid patterns below,
169 -- nverting the expression into a pattern at the same time.
170
171 checkPattern :: RdrNameHsExpr -> P RdrNamePat
172 checkPattern e = checkPat e []
173
174 checkPatterns :: [RdrNameHsExpr] -> P [RdrNamePat]
175 checkPatterns es = mapP checkPattern es
176
177 checkPat :: RdrNameHsExpr -> [RdrNamePat] -> P RdrNamePat
178 checkPat (HsVar c) args | isRdrDataCon c = returnP (ConPatIn c args)
179 checkPat (HsApp f x) args = 
180         checkPat x [] `thenP` \x ->
181         checkPat f (x:args)
182 checkPat e [] = case e of
183         EWildPat           -> returnP WildPatIn
184         HsVar x            -> returnP (VarPatIn x)
185         HsLit l            -> returnP (LitPatIn l)
186         ELazyPat e         -> checkPat e [] `thenP` (returnP . LazyPatIn)
187         EAsPat n e         -> checkPat e [] `thenP` (returnP . AsPatIn n)
188         ExprWithTySig e t  -> checkPat e [] `thenP` \e ->
189                               -- pattern signatures are parsed as sigtypes,
190                               -- but they aren't explicit forall points.  Hence
191                               -- we have to remove the implicit forall here.
192                               let t' = case t of 
193                                           HsForAllTy Nothing [] ty -> ty
194                                           other -> other
195                               in
196                               returnP (SigPatIn e t')
197
198         OpApp (HsVar n) (HsVar plus) _ (HsLit k@(HsInt _)) | plus == plus_RDR
199                            -> returnP (NPlusKPatIn n k)
200
201         OpApp l op fix r   -> checkPat l [] `thenP` \l ->
202                               checkPat r [] `thenP` \r ->
203                               case op of
204                                  HsVar c -> returnP (ConOpPatIn l c fix r)
205                                  _ -> patFail
206
207         NegApp l r         -> checkPat l [] `thenP` (returnP . NegPatIn)
208         HsPar e            -> checkPat e [] `thenP` (returnP . ParPatIn)
209         ExplicitList es    -> mapP (\e -> checkPat e []) es `thenP` \ps ->
210                               returnP (ListPatIn ps)
211         ExplicitTuple es b -> mapP (\e -> checkPat e []) es `thenP` \ps ->
212                               returnP (TuplePatIn ps b)
213         RecordCon c fs     -> mapP checkPatField fs `thenP` \fs ->
214                               returnP (RecPatIn c fs)
215         _ -> patFail
216
217 checkPat _ _ = patFail
218
219 checkPatField :: (RdrName, RdrNameHsExpr, Bool) 
220         -> P (RdrName, RdrNamePat, Bool)
221 checkPatField (n,e,b) =
222         checkPat e [] `thenP` \p ->
223         returnP (n,p,b)
224
225 patFail = parseError "Parse error in pattern"
226
227 ---------------------------------------------------------------------------
228 -- Check Expression Syntax
229
230 {-
231 We can get away without checkExpr if the renamer generates errors for
232 pattern syntax used in expressions (wildcards, as patterns and lazy 
233 patterns).
234
235 checkExpr :: RdrNameHsExpr -> P RdrNameHsExpr
236 checkExpr e = case e of
237         HsVar _                   -> returnP e
238         HsIPVar _                 -> returnP e
239         HsLit _                   -> returnP e
240         HsLam match               -> checkMatch match `thenP` (returnP.HsLam)
241         HsApp e1 e2               -> check2Exprs e1 e2 HsApp
242         OpApp e1 e2 fix e3        -> checkExpr e1 `thenP` \e1 ->
243                                      checkExpr e2 `thenP` \e2 ->
244                                      checkExpr e3 `thenP` \e3 ->
245                                      returnP (OpApp e1 e2 fix e3)
246         NegApp e neg              -> checkExpr e `thenP` \e ->
247                                      returnP (NegApp e neg)
248         HsPar e                   -> check1Expr e HsPar
249         SectionL e1 e2            -> check2Exprs e1 e2 SectionL
250         SectionR e1 e2            -> check2Exprs e1 e2 SectionR
251         HsCase e alts             -> mapP checkMatch alts `thenP` \alts ->
252                                      checkExpr e `thenP` \e ->
253                                      returnP (HsCase e alts)
254         HsIf e1 e2 e3             -> check3Exprs e1 e2 e3 HsIf
255
256         HsLet bs e                -> check1Expr e (HsLet bs)
257         HsDo stmts                -> mapP checkStmt stmts `thenP` (returnP . HsDo)
258         HsTuple es                -> checkManyExprs es HsTuple
259         HsList es                 -> checkManyExprs es HsList
260         HsRecConstr c fields      -> mapP checkField fields `thenP` \fields ->
261                                      returnP (HsRecConstr c fields)
262         HsRecUpdate e fields      -> mapP checkField fields `thenP` \fields ->
263                                      checkExpr e `thenP` \e ->
264                                      returnP (HsRecUpdate e fields)
265         HsEnumFrom e              -> check1Expr e HsEnumFrom
266         HsEnumFromTo e1 e2        -> check2Exprs e1 e2 HsEnumFromTo
267         HsEnumFromThen e1 e2      -> check2Exprs e1 e2 HsEnumFromThen
268         HsEnumFromThenTo e1 e2 e3 -> check3Exprs e1 e2 e3 HsEnumFromThenTo
269         HsListComp e stmts        -> mapP checkStmt stmts `thenP` \stmts ->
270                                      checkExpr e `thenP` \e ->
271                                      returnP (HsListComp e stmts)
272         RdrNameHsExprTypeSig loc e ty     -> checkExpr e `thenP` \e ->
273                                      returnP (RdrNameHsExprTypeSig loc e ty)
274         _                         -> parseError "parse error in expression"
275
276 -- type signature for polymorphic recursion!!
277 check1Expr :: RdrNameHsExpr -> (RdrNameHsExpr -> a) -> P a
278 check1Expr e f = checkExpr e `thenP` (returnP . f)
279
280 check2Exprs :: RdrNameHsExpr -> RdrNameHsExpr -> (RdrNameHsExpr -> RdrNameHsExpr -> a) -> P a
281 check2Exprs e1 e2 f = 
282         checkExpr e1 `thenP` \e1 ->
283         checkExpr e2 `thenP` \e2 ->
284         returnP (f e1 e2)
285
286 check3Exprs :: RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr -> (RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr -> a) -> P a
287 check3Exprs e1 e2 e3 f = 
288         checkExpr e1 `thenP` \e1 ->
289         checkExpr e2 `thenP` \e2 ->
290         checkExpr e3 `thenP` \e3 ->
291         returnP (f e1 e2 e3)
292
293 checkManyExprs es f =
294         mapP checkExpr es `thenP` \es ->
295         returnP (f es) 
296
297 checkAlt (HsAlt loc p galts bs) 
298         = checkGAlts galts `thenP` \galts -> returnP (HsAlt loc p galts bs)
299
300 checkGAlts (HsUnGuardedAlt e) = check1Expr e HsUnGuardedAlt
301 checkGAlts (HsGuardedAlts galts) 
302     = mapP checkGAlt galts `thenP` (returnP . HsGuardedAlts)
303
304 checkGAlt (HsGuardedAlt loc e1 e2) = check2Exprs e1 e2 (HsGuardedAlt loc)
305
306 checkStmt (HsGenerator p e) = check1Expr e (HsGenerator p)
307 checkStmt (HsQualifier e)   = check1Expr e HsQualifier
308 checkStmt s@(HsLetStmt bs)  = returnP s
309
310 checkField (HsFieldUpdate n e) = check1Expr e (HsFieldUpdate n)
311 checkField e = returnP e
312 -}
313 ---------------------------------------------------------------------------
314 -- Check Equation Syntax
315
316 checkValDef 
317         :: RdrNameHsExpr
318         -> Maybe RdrNameHsType
319         -> RdrNameGRHSs
320         -> SrcLoc
321         -> P RdrBinding
322
323 checkValDef lhs opt_sig grhss loc
324  = case isFunLhs lhs [] of
325            Just (f,inf,es) -> 
326                 checkPatterns es `thenP` \ps ->
327                 returnP (RdrValBinding (FunMonoBind f inf [Match [] ps opt_sig grhss] loc))
328
329            Nothing ->
330                 checkPattern lhs `thenP` \lhs ->
331                 returnP (RdrValBinding (PatMonoBind lhs grhss loc))
332
333 checkValSig
334         :: RdrNameHsExpr
335         -> RdrNameHsType
336         -> SrcLoc
337         -> P RdrBinding
338 checkValSig (HsVar v) ty loc = returnP (RdrSig (Sig v ty loc))
339 checkValSig other     ty loc = parseError "Type signature given for an expression"
340
341
342 -- A variable binding is parsed as an RdrNameFunMonoBind.
343 -- See comments with HsBinds.MonoBinds
344
345 isFunLhs (OpApp l (HsVar op) fix r) es  | not (isRdrDataCon op)
346                                 = Just (op, True, (l:r:es))
347 isFunLhs (HsVar f) es | not (isRdrDataCon f)
348                                 = Just (f,False,es)
349 isFunLhs (HsApp f e) es         = isFunLhs f (e:es)
350 isFunLhs (HsPar e)   es         = isFunLhs e es
351 isFunLhs _ _                    = Nothing
352
353 ---------------------------------------------------------------------------
354 -- Miscellaneous utilities
355
356 checkPrec :: Integer -> P ()
357 checkPrec i | 0 <= i && i <= 9 = returnP ()
358             | otherwise        = parseError "precedence out of range"
359
360 mkRecConstrOrUpdate 
361         :: RdrNameHsExpr 
362         -> RdrNameHsRecordBinds
363         -> P RdrNameHsExpr
364
365 mkRecConstrOrUpdate (HsVar c) fs | isRdrDataCon c
366   = returnP (RecordCon c fs)
367 mkRecConstrOrUpdate exp fs@(_:_) 
368   = returnP (RecordUpd exp fs)
369 mkRecConstrOrUpdate _ _
370   = parseError "Empty record update"
371
372 -- Supplying the ext_name in a foreign decl is optional ; if it
373 -- isn't there, the Haskell name is assumed. Note that no transformation
374 -- of the Haskell name is then performed, so if you foreign export (++),
375 -- it's external name will be "++". Too bad; it's important because we don't
376 -- want z-encoding (e.g. names with z's in them shouldn't be doubled)
377 -- (This is why we use occNameUserString.)
378 mkExtName :: Maybe ExtName -> RdrName -> ExtName
379 mkExtName Nothing rdrNm = ExtName (_PK_ (occNameUserString (rdrNameOcc rdrNm)))
380                                   Nothing
381 mkExtName (Just x) _    = x
382
383 -----------------------------------------------------------------------------
384 -- group function bindings into equation groups
385
386 -- we assume the bindings are coming in reverse order, so we take the srcloc
387 -- from the *last* binding in the group as the srcloc for the whole group.
388
389 groupBindings :: [RdrBinding] -> RdrBinding
390 groupBindings binds = group Nothing binds
391   where group :: Maybe RdrNameMonoBinds -> [RdrBinding] -> RdrBinding
392         group (Just bind) [] = RdrValBinding bind
393         group Nothing [] = RdrNullBind
394
395                 -- don't group together FunMonoBinds if they have
396                 -- no arguments.  This is necessary now that variable bindings
397                 -- with no arguments are now treated as FunMonoBinds rather
398                 -- than pattern bindings (tests/rename/should_fail/rnfail002).
399         group (Just (FunMonoBind f inf1 mtchs ignore_srcloc))
400                     (RdrValBinding (FunMonoBind f' _ 
401                                         [mtch@(Match _ (_:_) _ _)] loc)
402                         : binds)
403             | f == f' = group (Just (FunMonoBind f inf1 (mtch:mtchs) loc)) binds
404
405         group (Just so_far) binds
406             = RdrValBinding so_far `RdrAndBindings` group Nothing binds
407         group Nothing (bind:binds)
408             = case bind of
409                 RdrValBinding b@(FunMonoBind _ _ _ _) -> group (Just b) binds
410                 other -> bind `RdrAndBindings` group Nothing binds
411
412 -----------------------------------------------------------------------------
413 -- Built-in names
414
415 unitCon_RDR, unitTyCon_RDR, nilCon_RDR, listTyCon_RDR :: RdrName
416 tupleCon_RDR, tupleTyCon_RDR            :: Int -> RdrName
417 ubxTupleCon_RDR, ubxTupleTyCon_RDR      :: Int -> RdrName
418
419 unitCon_RDR
420         | opt_NoImplicitPrelude = mkSrcUnqual   dataName unitName
421         | otherwise             = mkPreludeQual dataName pRELUDE_Name unitName
422
423 unitTyCon_RDR
424         | opt_NoImplicitPrelude = mkSrcUnqual   tcName unitName
425         | otherwise             = mkPreludeQual tcName pRELUDE_Name unitName
426
427 nilCon_RDR
428         | opt_NoImplicitPrelude = mkSrcUnqual   dataName listName
429         | otherwise             = mkPreludeQual dataName pRELUDE_Name listName
430
431 listTyCon_RDR
432         | opt_NoImplicitPrelude = mkSrcUnqual   tcName listName
433         | otherwise             = mkPreludeQual tcName pRELUDE_Name listName
434
435 funTyCon_RDR
436         | opt_NoImplicitPrelude = mkSrcUnqual   tcName funName
437         | otherwise             = mkPreludeQual tcName pRELUDE_Name funName
438
439 tupleCon_RDR arity
440   | opt_NoImplicitPrelude = mkSrcUnqual   dataName (snd (mkTupNameStr Boxed arity))
441   | otherwise             = mkPreludeQual dataName pRELUDE_Name
442                                 (snd (mkTupNameStr Boxed arity))
443
444 tupleTyCon_RDR arity
445   | opt_NoImplicitPrelude = mkSrcUnqual   tcName (snd (mkTupNameStr Boxed arity))
446   | otherwise             = mkPreludeQual tcName pRELUDE_Name
447                                 (snd (mkTupNameStr Boxed arity))
448
449
450 ubxTupleCon_RDR arity
451   | opt_NoImplicitPrelude = mkSrcUnqual   dataName (snd (mkTupNameStr Unboxed arity))
452   | otherwise             = mkPreludeQual dataName pRELUDE_Name 
453                                 (snd (mkTupNameStr Unboxed arity))
454
455 ubxTupleTyCon_RDR arity
456   | opt_NoImplicitPrelude = mkSrcUnqual   tcName (snd (mkTupNameStr Unboxed arity))
457   | otherwise             = mkPreludeQual tcName pRELUDE_Name 
458                                 (snd (mkTupNameStr Unboxed arity))
459
460 unitName = SLIT("()")
461 funName  = SLIT("(->)")
462 listName = SLIT("[]")
463
464 asName              = SLIT("as")
465 hidingName          = SLIT("hiding")
466 qualifiedName       = SLIT("qualified")
467 forallName          = SLIT("forall")
468 exportName          = SLIT("export")
469 labelName           = SLIT("label")
470 dynamicName         = SLIT("dynamic")
471 unsafeName          = SLIT("unsafe")
472 stdcallName         = SLIT("stdcall")
473 ccallName           = SLIT("ccall")
474
475 as_var_RDR          = mkSrcUnqual varName asName
476 hiding_var_RDR      = mkSrcUnqual varName hidingName
477 qualified_var_RDR   = mkSrcUnqual varName qualifiedName
478 forall_var_RDR      = mkSrcUnqual varName forallName
479 export_var_RDR      = mkSrcUnqual varName exportName
480 label_var_RDR       = mkSrcUnqual varName labelName
481 dynamic_var_RDR     = mkSrcUnqual varName dynamicName
482 unsafe_var_RDR      = mkSrcUnqual varName unsafeName
483 stdcall_var_RDR     = mkSrcUnqual varName stdcallName
484 ccall_var_RDR       = mkSrcUnqual varName ccallName
485
486 as_tyvar_RDR        = mkSrcUnqual tvName asName
487 hiding_tyvar_RDR    = mkSrcUnqual tvName hidingName
488 qualified_tyvar_RDR = mkSrcUnqual tvName qualifiedName
489 export_tyvar_RDR    = mkSrcUnqual tvName exportName
490 label_tyvar_RDR     = mkSrcUnqual tvName labelName
491 dynamic_tyvar_RDR   = mkSrcUnqual tvName dynamicName
492 unsafe_tyvar_RDR    = mkSrcUnqual tvName unsafeName
493 stdcall_tyvar_RDR   = mkSrcUnqual tvName stdcallName
494 ccall_tyvar_RDR     = mkSrcUnqual tvName ccallName
495
496 minus_RDR           = mkSrcUnqual varName SLIT("-")
497 pling_RDR           = mkSrcUnqual varName SLIT("!")
498 dot_RDR             = mkSrcUnqual varName SLIT(".")
499
500 plus_RDR            = mkSrcUnqual varName SLIT("+")
501 \end{code}