Changeset 6238

Show
Ignore:
Timestamp:
08/14/05 14:22:51 (3 years ago)
Author:
autrijus
svk:copy_cache_prev:
8452
Message:

* Haskell2Xml instances.

Location:
src/Pugs
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/CodeGen.hs

    r6230 r6238  
    1717import Pugs.CodeGen.PIR (genPIR) 
    1818import Pugs.CodeGen.Perl5 (genPerl5) 
     19import Pugs.CodeGen.XML (genXML) 
    1920import Pugs.Compile.Pugs (genPugs) 
    2021import Pugs.Compile.Haskell (genGHC) 
     
    3233    , ("Perl5",       genPerl5) 
    3334    , ("Pugs",        genPugs) 
     35    , ("Xml",         genXML) 
    3436    ] 
    3537 
  • src/Pugs/PIL1.hs

    r6237 r6238  
    22 
    33module Pugs.PIL1 where 
    4 import Pugs.AST 
     4import Pugs.AST hiding (Prim) 
    55import Pugs.Internals 
    66import Pugs.Types 
    77import Emit.PIR 
    88import DrIFT.Perl5 
    9  
    10 {-! global : Perl5 !-} 
    11  
    12 instance Perl5 Scope 
    13 instance Perl5 SubType 
     9import Text.XML.HaXml.Haskell2Xml 
     10 
     11{-! global : Perl5, Haskell2Xml !-} 
     12 
    1413instance Perl5 VInt where  
    1514    showPerl5 = show 
     
    2625    showPerl5 _ = "(undef)" 
    2726 
     27instance (Typeable a) => Haskell2Xml (TVar a) where 
     28    toHType   _    = Prim "TVar" "tvar" 
     29    toContents _   = [CElem (Elem "tvar" [] [])] 
     30 
     31instance Haskell2Xml Exp where 
     32    toHType   _    = Prim "Exp" "exp" 
     33    toContents _   = [CElem (Elem "exp" [] [])] 
     34    fromContents _ = (Noop, []) 
     35 
     36instance Haskell2Xml VRat where 
     37    toHType   _    = Prim "Rational" "rational" 
     38    toContents i   = [CElem (Elem "rational" [mkAttr "value" (show i)] [])] 
     39        where 
     40        mkAttr :: String -> String -> Attribute 
     41        mkAttr n v = (n, AttValue [Left v]) 
     42    fromContents (CElem (Elem "rational" [("value",(AttValue [Left s]))] []):cs) 
     43                   = (read s, cs) 
     44    fromContents (_:cs) = fromContents cs 
     45 
    2846{-| 
    2947    The plan here is to first compile the environment (subroutines, 
     
    3149    Language) using the 'compile' function and 'Compile' class. 
    3250-} 
     51 
     52data PIL_Environment = PIL_Environment 
     53    { pilMain :: [PIL_Decl] 
     54    , pilGlob :: PIL_Stmts 
     55    } 
     56    deriving (Show, Eq, Ord, Typeable) 
    3357 
    3458data PIL_Stmts = PNil 
     
    112136 
    113137------------------------------------------------------------------------ 
    114 {- Previously generated by DrIFT : Look, but Don't Touch. -} 
    115  
    116 instance Perl5 TParam where 
    117     showPerl5 (MkTParam aa ab) = showP5HashObj "MkTParam" 
    118               [("tpParam", showPerl5 aa) , ("tpDefault", showPerl5 ab)] 
    119  
    120 instance Perl5 TCxt where 
    121     showPerl5 (TCxtVoid) = showP5Class "TCxtVoid" 
    122     showPerl5 (TCxtLValue aa) = showP5ArrayObj "TCxtLValue" 
    123               [showPerl5 aa] 
    124     showPerl5 (TCxtItem aa) = showP5ArrayObj "TCxtItem" [showPerl5 aa] 
    125     showPerl5 (TCxtSlurpy aa) = showP5ArrayObj "TCxtSlurpy" 
    126               [showPerl5 aa] 
    127     showPerl5 (TTailCall aa) = showP5ArrayObj "TTailCall" 
    128               [showPerl5 aa] 
    129  
    130 instance Perl5 TEnv where 
    131     showPerl5 (MkTEnv aa ab ac ad ae) = showP5HashObj "MkTEnv" 
    132               [("tLexDepth", showPerl5 aa) , ("tTokDepth", showPerl5 ab) , 
    133                ("tCxt", showPerl5 ac) , ("tReg", showPerl5 ad) , 
    134                ("tLabel", showPerl5 ae)] 
    135  
    136 instance Perl5 Val where 
    137     showPerl5 (VUndef) = showP5Class "VUndef" 
    138     showPerl5 (VBool aa) = showP5ArrayObj "VBool" [showPerl5 aa] 
    139     showPerl5 (VInt aa) = showP5ArrayObj "VInt" [showPerl5 aa] 
    140     showPerl5 (VRat aa) = showP5ArrayObj "VRat" [showPerl5 aa] 
    141     showPerl5 (VNum aa) = showP5ArrayObj "VNum" [showPerl5 aa] 
    142     showPerl5 (VStr aa) = showP5ArrayObj "VStr" [showPerl5 aa] 
    143     showPerl5 (VList aa) = showP5ArrayObj "VList" [showPerl5 aa] 
    144     showPerl5 (VType aa) = showP5ArrayObj "VType" [showPerl5 aa] 
    145     showPerl5 _ = "(warn '<val>')" 
    146  
    147 instance Perl5 Cxt where 
    148     showPerl5 (CxtVoid) = showP5Class "CxtVoid" 
    149     showPerl5 (CxtItem aa) = showP5ArrayObj "CxtItem" [showPerl5 aa] 
    150     showPerl5 (CxtSlurpy aa) = showP5ArrayObj "CxtSlurpy" 
    151               [showPerl5 aa] 
    152  
    153 instance Perl5 Type where 
    154     showPerl5 (MkType aa) = showP5ArrayObj "MkType" [showPerl5 aa] 
    155     showPerl5 (TypeOr aa ab) = showP5ArrayObj "TypeOr" 
    156               [showPerl5 aa , showPerl5 ab] 
    157     showPerl5 (TypeAnd aa ab) = showP5ArrayObj "TypeAnd" 
    158               [showPerl5 aa , showPerl5 ab] 
    159  
    160 instance Perl5 Param where 
    161     showPerl5 (MkParam aa ab ac ad ae af ag ah ai) = 
    162               showP5HashObj "MkParam" 
    163               [("isInvocant", showPerl5 aa) , ("isOptional", showPerl5 ab) , 
    164                ("isNamed", showPerl5 ac) , ("isLValue", showPerl5 ad) , 
    165                ("isWritable", showPerl5 ae) , ("isLazy", showPerl5 af) , 
    166                ("paramName", showPerl5 ag) , ("paramContext", showPerl5 ah) , 
    167                ("paramDefault", showPerl5 ai)] 
    168  
    169 instance Perl5 Pos where 
    170     showPerl5 (MkPos aa ab ac ad ae) = showP5HashObj "MkPos" 
    171               [("posName", showPerl5 aa) , ("posBeginLine", showPerl5 ab) , 
    172                ("posBeginColumn", showPerl5 ac) , ("posEndLine", showPerl5 ad) , 
    173                ("posEndColumn", showPerl5 ae)] 
    174  
    175138{- 
     139 
     140data Scope = SState  -- ^ Persistent across calls 
     141           | SMy     -- ^ Lexical 
     142           | SOur    -- ^ Package 
     143           | SLet    -- ^ Hypotheticalised (reverted upon failure) 
     144           | STemp   -- ^ Temporary (reverted at scope exit) 
     145           | SGlobal -- ^ Global 
     146 
     147data SubType = SubMethod    -- ^ Method 
     148             | SubCoroutine -- ^ Coroutine 
     149             | SubMacro     -- ^ Macro 
     150             | SubRoutine   -- ^ Regular subroutine 
     151             | SubBlock     -- ^ Bare block 
     152             | SubPointy    -- ^ Pointy sub 
     153             | SubPrim      -- ^ Built-in primitive operator (see "Pugs.Prim") 
     154 
     155 
    176156data Val 
    177157    = VUndef                 -- ^ Undefined value 
     
    212192    , posEndColumn      :: !Int 
    213193    } 
     194 
    214195-} 
     196 
    215197{-* Generated by DrIFT : Look, but Don't Touch. *-} 
     198instance Perl5 PIL_Environment where 
     199    showPerl5 (PIL_Environment aa ab) = 
     200              showP5HashObj "PIL::Environment" 
     201              [("pilMain", showPerl5 aa) , ("pilGlob", showPerl5 ab)] 
     202 
     203instance Haskell2Xml PIL_Environment where 
     204    toHType v = 
     205        Defined "PIL_Environment" [] 
     206                [Constr "PIL_Environment" [] [toHType aa,toHType ab]] 
     207      where 
     208        (PIL_Environment aa ab) = v 
     209    fromContents (CElem (Elem constr [] cs):etc) 
     210        | "PIL_Environment" `isPrefixOf` constr = 
     211            (\(aa,cs00)-> (\(ab,_)-> (PIL_Environment aa ab, etc)) 
     212                          (fromContents cs00)) 
     213            (fromContents cs) 
     214    toContents v@(PIL_Environment aa ab) = 
     215        [mkElemC (showConstr 0 (toHType v)) (concat [toContents aa, 
     216                                                     toContents ab])] 
     217 
    216218instance Perl5 PIL_Stmts where 
    217219    showPerl5 (PNil) = showP5Class "PNil" 
     
    222224               ("pStmts", showPerl5 ac)] 
    223225 
     226instance Haskell2Xml PIL_Stmts where 
     227    toHType v = 
     228        Defined "PIL_Stmts" [] 
     229                [Constr "PNil" [] [],Constr "PStmts" [] [toHType aa,toHType ab], 
     230                 Constr "PPad" [] [toHType ac,toHType ad,toHType ae]] 
     231      where 
     232        (PStmts aa ab) = v 
     233        (PPad ac ad ae) = v 
     234    fromContents (CElem (Elem constr [] cs):etc) 
     235        | "PStmts" `isPrefixOf` constr = 
     236            (\(aa,cs00)-> (\(ab,_)-> (PStmts aa ab, etc)) (fromContents cs00)) 
     237            (fromContents cs) 
     238        | "PPad" `isPrefixOf` constr = 
     239            (\(ac,cs00)-> (\(ad,cs01)-> (\(ae,_)-> (PPad ac ad ae, etc)) 
     240                                        (fromContents cs01)) 
     241                          (fromContents cs00)) 
     242            (fromContents cs) 
     243        | "PNil" `isPrefixOf` constr = 
     244            (PNil,etc) 
     245    toContents v@PNil = 
     246        [mkElemC (showConstr 0 (toHType v)) []] 
     247    toContents v@(PStmts aa ab) = 
     248        [mkElemC (showConstr 1 (toHType v)) (concat [toContents aa, 
     249                                                     toContents ab])] 
     250    toContents v@(PPad ac ad ae) = 
     251        [mkElemC (showConstr 2 (toHType v)) (concat [toContents ac, 
     252                                                     toContents ad,toContents ae])] 
     253 
    224254instance Perl5 PIL_Stmt where 
    225255    showPerl5 (PNoop) = showP5Class "PNoop" 
     
    229259              [("pPos", showPerl5 aa) , ("pExp", showPerl5 ab) , 
    230260               ("pNode", showPerl5 ac)] 
     261 
     262instance Haskell2Xml PIL_Stmt where 
     263    toHType v = 
     264        Defined "PIL_Stmt" [] 
     265                [Constr "PNoop" [] [],Constr "PStmt" [] [toHType aa], 
     266                 Constr "PPos" [] [toHType ab,toHType ac,toHType ad]] 
     267      where 
     268        (PStmt aa) = v 
     269        (PPos ab ac ad) = v 
     270    fromContents (CElem (Elem constr [] cs):etc) 
     271        | "PStmt" `isPrefixOf` constr = 
     272            (\(aa,_)-> (PStmt aa, etc)) (fromContents cs) 
     273        | "PPos" `isPrefixOf` constr = 
     274            (\(ab,cs00)-> (\(ac,cs01)-> (\(ad,_)-> (PPos ab ac ad, etc)) 
     275                                        (fromContents cs01)) 
     276                          (fromContents cs00)) 
     277            (fromContents cs) 
     278        | "PNoop" `isPrefixOf` constr = 
     279            (PNoop,etc) 
     280    toContents v@PNoop = 
     281        [mkElemC (showConstr 0 (toHType v)) []] 
     282    toContents v@(PStmt aa) = 
     283        [mkElemC (showConstr 1 (toHType v)) (toContents aa)] 
     284    toContents v@(PPos ab ac ad) = 
     285        [mkElemC (showConstr 2 (toHType v)) (concat [toContents ab, 
     286                                                     toContents ac,toContents ad])] 
    231287 
    232288instance Perl5 PIL_Expr where 
     
    241297               ("pBody", showPerl5 ac)] 
    242298 
     299instance Haskell2Xml PIL_Expr where 
     300    toHType v = 
     301        Defined "PIL_Expr" [] 
     302                [Constr "PRawName" [] [toHType aa],Constr "PExp" [] [toHType ab], 
     303                 Constr "PLit" [] [toHType ac],Constr "PThunk" [] [toHType ad], 
     304                 Constr "PCode" [] [toHType ae,toHType af,toHType ag]] 
     305      where 
     306        (PRawName aa) = v 
     307        (PExp ab) = v 
     308        (PLit ac) = v 
     309        (PThunk ad) = v 
     310        (PCode ae af ag) = v 
     311    fromContents (CElem (Elem constr [] cs):etc) 
     312        | "PThunk" `isPrefixOf` constr = 
     313            (\(ad,_)-> (PThunk ad, etc)) (fromContents cs) 
     314        | "PRawName" `isPrefixOf` constr = 
     315            (\(aa,_)-> (PRawName aa, etc)) (fromContents cs) 
     316        | "PLit" `isPrefixOf` constr = 
     317            (\(ac,_)-> (PLit ac, etc)) (fromContents cs) 
     318        | "PExp" `isPrefixOf` constr = 
     319            (\(ab,_)-> (PExp ab, etc)) (fromContents cs) 
     320        | "PCode" `isPrefixOf` constr = 
     321            (\(ae,cs00)-> (\(af,cs01)-> (\(ag,_)-> (PCode ae af ag, etc)) 
     322                                        (fromContents cs01)) 
     323                          (fromContents cs00)) 
     324            (fromContents cs) 
     325    toContents v@(PRawName aa) = 
     326        [mkElemC (showConstr 0 (toHType v)) (toContents aa)] 
     327    toContents v@(PExp ab) = 
     328        [mkElemC (showConstr 1 (toHType v)) (toContents ab)] 
     329    toContents v@(PLit ac) = 
     330        [mkElemC (showConstr 2 (toHType v)) (toContents ac)] 
     331    toContents v@(PThunk ad) = 
     332        [mkElemC (showConstr 3 (toHType v)) (toContents ad)] 
     333    toContents v@(PCode ae af ag) = 
     334        [mkElemC (showConstr 4 (toHType v)) (concat [toContents ae, 
     335                                                     toContents af,toContents ag])] 
     336 
    243337instance Perl5 PIL_Decl where 
    244338    showPerl5 (PSub aa ab ac ad) = showP5HashObj "PSub" 
     
    246340               ("pSubParams", showPerl5 ac) , ("pSubBody", showPerl5 ad)] 
    247341 
     342instance Haskell2Xml PIL_Decl where 
     343    toHType v = 
     344        Defined "PIL_Decl" [] 
     345                [Constr "PSub" [] [toHType aa,toHType ab,toHType ac,toHType ad]] 
     346      where 
     347        (PSub aa ab ac ad) = v 
     348    fromContents (CElem (Elem constr [] cs):etc) 
     349        | "PSub" `isPrefixOf` constr = 
     350            (\(aa,cs00)-> (\(ab,cs01)-> (\(ac,cs02)-> (\(ad, 
     351                                                         _)-> (PSub aa ab ac ad, etc)) 
     352                                                      (fromContents cs02)) 
     353                                        (fromContents cs01)) 
     354                          (fromContents cs00)) 
     355            (fromContents cs) 
     356    toContents v@(PSub aa ab ac ad) = 
     357        [mkElemC (showConstr 0 (toHType v)) (concat [toContents aa, 
     358                                                     toContents ab,toContents ac,toContents ad])] 
     359 
    248360instance Perl5 PIL_Literal where 
    249361    showPerl5 (PVal aa) = showP5HashObj "PVal" [("pVal", showPerl5 aa)] 
     362 
     363instance Haskell2Xml PIL_Literal where 
     364    toHType v = 
     365        Defined "PIL_Literal" [] [Constr "PVal" [] [toHType aa]] 
     366      where 
     367        (PVal aa) = v 
     368    fromContents (CElem (Elem constr [] cs):etc) 
     369        | "PVal" `isPrefixOf` constr = 
     370            (\(aa,_)-> (PVal aa, etc)) (fromContents cs) 
     371    toContents v@(PVal aa) = 
     372        [mkElemC (showConstr 0 (toHType v)) (toContents aa)] 
    250373 
    251374instance Perl5 PIL_LValue where 
     
    260383              [("pLHS", showPerl5 aa) , ("pRHS", showPerl5 ab)] 
    261384 
     385instance Haskell2Xml PIL_LValue where 
     386    toHType v = 
     387        Defined "PIL_LValue" [] 
     388                [Constr "PVar" [] [toHType aa], 
     389                 Constr "PApp" [] [toHType ab,toHType ac,toHType ad,toHType ae], 
     390                 Constr "PAssign" [] [toHType af,toHType ag], 
     391                 Constr "PBind" [] [toHType ah,toHType ai]] 
     392      where 
     393        (PVar aa) = v 
     394        (PApp ab ac ad ae) = v 
     395        (PAssign af ag) = v 
     396        (PBind ah ai) = v 
     397    fromContents (CElem (Elem constr [] cs):etc) 
     398        | "PVar" `isPrefixOf` constr = 
     399            (\(aa,_)-> (PVar aa, etc)) (fromContents cs) 
     400        | "PBind" `isPrefixOf` constr = 
     401            (\(ah,cs00)-> (\(ai,_)-> (PBind ah ai, etc)) (fromContents cs00)) 
     402            (fromContents cs) 
     403        | "PAssign" `isPrefixOf` constr = 
     404            (\(af,cs00)-> (\(ag,_)-> (PAssign af ag, etc)) (fromContents cs00)) 
     405            (fromContents cs) 
     406        | "PApp" `isPrefixOf` constr = 
     407            (\(ab,cs00)-> (\(ac,cs01)-> (\(ad,cs02)-> (\(ae, 
     408                                                         _)-> (PApp ab ac ad ae, etc)) 
     409                                                      (fromContents cs02)) 
     410                                        (fromContents cs01)) 
     411                          (fromContents cs00)) 
     412            (fromContents cs) 
     413    toContents v@(PVar aa) = 
     414        [mkElemC (showConstr 0 (toHType v)) (toContents aa)] 
     415    toContents v@(PApp ab ac ad ae) = 
     416        [mkElemC (showConstr 1 (toHType v)) (concat [toContents ab, 
     417                                                     toContents ac,toContents ad,toContents ae])] 
     418    toContents v@(PAssign af ag) = 
     419        [mkElemC (showConstr 2 (toHType v)) (concat [toContents af, 
     420                                                     toContents ag])] 
     421    toContents v@(PBind ah ai) = 
     422        [mkElemC (showConstr 3 (toHType v)) (concat [toContents ah, 
     423                                                     toContents ai])] 
     424 
     425instance Perl5 TParam where 
     426    showPerl5 (MkTParam aa ab) = showP5HashObj "MkTParam" 
     427              [("tpParam", showPerl5 aa) , ("tpDefault", showPerl5 ab)] 
     428 
     429instance Haskell2Xml TParam where 
     430    toHType v = 
     431        Defined "TParam" [] [Constr "MkTParam" [] [toHType aa,toHType ab]] 
     432      where 
     433        (MkTParam aa ab) = v 
     434    fromContents (CElem (Elem constr [] cs):etc) 
     435        | "MkTParam" `isPrefixOf` constr = 
     436            (\(aa,cs00)-> (\(ab,_)-> (MkTParam aa ab, etc)) 
     437                          (fromContents cs00)) 
     438            (fromContents cs) 
     439    toContents v@(MkTParam aa ab) = 
     440        [mkElemC (showConstr 0 (toHType v)) (concat [toContents aa, 
     441                                                     toContents ab])] 
     442 
     443instance Perl5 TCxt where 
     444    showPerl5 (TCxtVoid) = showP5Class "TCxtVoid" 
     445    showPerl5 (TCxtLValue aa) = showP5ArrayObj "TCxtLValue" 
     446              [showPerl5 aa] 
     447    showPerl5 (TCxtItem aa) = showP5ArrayObj "TCxtItem" [showPerl5 aa] 
     448    showPerl5 (TCxtSlurpy aa) = showP5ArrayObj "TCxtSlurpy" 
     449              [showPerl5 aa] 
     450    showPerl5 (TTailCall aa) = showP5ArrayObj "TTailCall" 
     451              [showPerl5 aa] 
     452 
     453instance Haskell2Xml TCxt where 
     454    toHType v = 
     455        Defined "TCxt" [] 
     456                [Constr "TCxtVoid" [] [],Constr "TCxtLValue" [] [toHType aa], 
     457                 Constr "TCxtItem" [] [toHType ab], 
     458                 Constr "TCxtSlurpy" [] [toHType ac], 
     459                 Constr "TTailCall" [] [toHType ad]] 
     460      where 
     461        (TCxtLValue aa) = v 
     462        (TCxtItem ab) = v 
     463        (TCxtSlurpy ac) = v 
     464        (TTailCall ad) = v 
     465    fromContents (CElem (Elem constr [] cs):etc) 
     466        | "TTailCall" `isPrefixOf` constr = 
     467            (\(ad,_)-> (TTailCall ad, etc)) (fromContents cs) 
     468        | "TCxtVoid" `isPrefixOf` constr = 
     469            (TCxtVoid,etc) 
     470        | "TCxtSlurpy" `isPrefixOf` constr = 
     471            (\(ac,_)-> (TCxtSlurpy ac, etc)) (fromContents cs) 
     472        | "TCxtLValue" `isPrefixOf` constr = 
     473            (\(aa,_)-> (TCxtLValue aa, etc)) (fromContents cs) 
     474        | "TCxtItem" `isPrefixOf` constr = 
     475            (\(ab,_)-> (TCxtItem ab, etc)) (fromContents cs) 
     476    toContents v@TCxtVoid = 
     477        [mkElemC (showConstr 0 (toHType v)) []] 
     478    toContents v@(TCxtLValue aa) = 
     479        [mkElemC (showConstr 1 (toHType v)) (toContents aa)] 
     480    toContents v@(TCxtItem ab) = 
     481        [mkElemC (showConstr 2 (toHType v)) (toContents ab)] 
     482    toContents v@(TCxtSlurpy ac) = 
     483        [mkElemC (showConstr 3 (toHType v)) (toContents ac)] 
     484    toContents v@(TTailCall ad) = 
     485        [mkElemC (showConstr 4 (toHType v)) (toContents ad)] 
     486 
     487instance Perl5 TEnv where 
     488    showPerl5 (MkTEnv aa ab ac ad ae) = showP5HashObj "MkTEnv" 
     489              [("tLexDepth", showPerl5 aa) , ("tTokDepth", showPerl5 ab) , 
     490               ("tCxt", showPerl5 ac) , ("tReg", showPerl5 ad) , 
     491               ("tLabel", showPerl5 ae)] 
     492 
     493instance Haskell2Xml TEnv where 
     494    toHType v = 
     495        Defined "TEnv" [] 
     496                [Constr "MkTEnv" [] 
     497                        [toHType aa,toHType ab,toHType ac,toHType ad,toHType ae]] 
     498      where 
     499        (MkTEnv aa ab ac ad ae) = v 
     500    fromContents (CElem (Elem constr [] cs):etc) 
     501        | "MkTEnv" `isPrefixOf` constr = 
     502            (\(aa,cs00)-> (\(ab,cs01)-> (\(ac,cs02)-> (\(ad,cs03)-> (\(ae, 
     503                                                                       _)-> (MkTEnv aa ab ac ad ae, etc)) 
     504                                                                    (fromContents cs03)) 
     505                                                      (fromContents cs02)) 
     506                                        (fromContents cs01)) 
     507                          (fromContents cs00)) 
     508            (fromContents cs) 
     509    toContents v@(MkTEnv aa ab ac ad ae) = 
     510        [mkElemC (showConstr 0 (toHType v)) (concat [toContents aa, 
     511                                                     toContents ab,toContents ac,toContents ad, 
     512                                                     toContents ae])] 
     513 
     514instance Perl5 Scope where 
     515    showPerl5 (SState) = showP5Class "SState" 
     516    showPerl5 (SMy) = showP5Class "SMy" 
     517    showPerl5 (SOur) = showP5Class "SOur" 
     518    showPerl5 (SLet) = showP5Class "SLet" 
     519    showPerl5 (STemp) = showP5Class "STemp" 
     520    showPerl5 (SGlobal) = showP5Class "SGlobal" 
     521 
     522instance Haskell2Xml Scope where 
     523    toHType v = 
     524        Defined "Scope" [] 
     525                [Constr "SState" [] [],Constr "SMy" [] [],Constr "SOur" [] [], 
     526                 Constr "SLet" [] [],Constr "STemp" [] [],Constr "SGlobal" [] []] 
     527    fromContents (CElem (Elem constr [] cs):etc) 
     528        | "STemp" `isPrefixOf` constr = 
     529            (STemp,etc) 
     530        | "SState" `isPrefixOf` constr = 
     531            (SState,etc) 
     532        | "SOur" `isPrefixOf` constr = 
     533            (SOur,etc) 
     534        | "SMy" `isPrefixOf` constr = 
     535            (SMy,etc) 
     536        | "SLet" `isPrefixOf` constr = 
     537            (SLet,etc) 
     538        | "SGlobal" `isPrefixOf` constr = 
     539            (SGlobal,etc) 
     540    toContents v@SState = 
     541        [mkElemC (showConstr 0 (toHType v)) []] 
     542    toContents v@SMy = 
     543        [mkElemC (showConstr 1 (toHType v)) []] 
     544    toContents v@SOur = 
     545        [mkElemC (showConstr 2 (toHType v)) []] 
     546    toContents v@SLet = 
     547        [mkElemC (showConstr 3 (toHType v)) []] 
     548    toContents v@STemp = 
     549        [mkElemC (showConstr 4 (toHType v)) []] 
     550    toContents v@SGlobal = 
     551        [mkElemC (showConstr 5 (toHType v)) []] 
     552 
     553instance Perl5 SubType where 
     554    showPerl5 (SubMethod) = showP5Class "SubMethod" 
     555    showPerl5 (SubCoroutine) = showP5Class "SubCoroutine" 
     556    showPerl5 (SubMacro) = showP5Class "SubMacro" 
     557    showPerl5 (SubRoutine) = showP5Class "SubRoutine" 
     558    showPerl5 (SubBlock) = showP5Class "SubBlock" 
     559    showPerl5 (SubPointy) = showP5Class "SubPointy" 
     560    showPerl5 (SubPrim) = showP5Class "SubPrim" 
     561 
     562instance Haskell2Xml SubType where 
     563    toHType v = 
     564        Defined "SubType" [] 
     565                [Constr "SubMethod" [] [],Constr "SubCoroutine" [] [], 
     566                 Constr "SubMacro" [] [],Constr "SubRoutine" [] [], 
     567                 Constr "SubBlock" [] [],Constr "SubPointy" [] [], 
     568                 Constr "SubPrim" [] []] 
     569    fromContents (CElem (Elem constr [] cs):etc) 
     570        | "SubRoutine" `isPrefixOf` constr = 
     571            (SubRoutine,etc) 
     572        | "SubPrim" `isPrefixOf` constr = 
     573            (SubPrim,etc) 
     574        | "SubPointy" `isPrefixOf` constr = 
     575            (SubPointy,etc) 
     576        | "SubMethod" `isPrefixOf` constr = 
     577            (SubMethod,etc) 
     578        | "SubMacro" `isPrefixOf` constr = 
     579            (SubMacro,etc) 
     580        | "SubCoroutine" `isPrefixOf` constr = 
     581            (SubCoroutine,etc) 
     582        | "SubBlock" `isPrefixOf` constr = 
     583            (SubBlock,etc) 
     584    toContents v@SubMethod = 
     585        [mkElemC (showConstr 0 (toHType v)) []] 
     586    toContents v@SubCoroutine = 
     587        [mkElemC (showConstr 1 (toHType v)) []] 
     588    toContents v@SubMacro = 
     589        [mkElemC (showConstr 2 (toHType v)) []] 
     590    toContents v@SubRoutine = 
     591        [mkElemC (showConstr 3 (toHType v)) []] 
     592    toContents v@SubBlock = 
     593        [mkElemC (showConstr 4 (toHType v)) []] 
     594    toContents v@SubPointy = 
     595        [mkElemC (showConstr 5 (toHType v)) []] 
     596    toContents v@SubPrim = 
     597        [mkElemC (showConstr 6 (toHType v)) []] 
     598 
     599instance Perl5 Val where 
     600    showPerl5 (VUndef) = showP5Class "VUndef" 
     601    showPerl5 (VBool aa) = showP5ArrayObj "VBool" [showPerl5 aa] 
     602    showPerl5 (VInt aa) = showP5ArrayObj "VInt" [showPerl5 aa] 
     603    showPerl5 (VRat aa) = showP5ArrayObj "VRat" [showPerl5 aa] 
     604    showPerl5 (VNum aa) = showP5ArrayObj "VNum" [showPerl5 aa] 
     605    showPerl5 (VStr aa) = showP5ArrayObj "VStr" [showPerl5 aa] 
     606    showPerl5 (VList aa) = showP5ArrayObj "VList" [showPerl5 aa] 
     607    showPerl5 (VType aa) = showP5ArrayObj "VType" [showPerl5 aa] 
     608 
     609instance Haskell2Xml Val where 
     610    toHType v = 
     611        Defined "Val" [] 
     612                [Constr "VUndef" [] [],Constr "VBool" [] [toHType aa], 
     613                 Constr "VInt" [] [toHType ab],Constr "VRat" [] [toHType ac], 
     614                 Constr "VNum" [] [toHType ad],Constr "VStr" [] [toHType ae], 
     615                 Constr "VList" [] [toHType af],Constr "VType" [] [toHType ag]] 
     616      where 
     617        (VBool aa) = v 
     618        (VInt ab) = v 
     619        (VRat ac) = v 
     620        (VNum ad) = v 
     621        (VStr ae) = v 
     622        (VList af) = v 
     623        (VType ag) = v 
     624    fromContents (CElem (Elem constr [] cs):etc) 
     625        | "VUndef" `isPrefixOf` constr = 
     626            (VUndef,etc) 
     627        | "VType" `isPrefixOf` constr = 
     628            (\(ag,_)-> (VType ag, etc)) (fromContents cs) 
     629        | "VStr" `isPrefixOf` constr = 
     630            (\(ae,_)-> (VStr ae, etc)) (fromContents cs) 
     631        | "VRat" `isPrefixOf` constr = 
     632            (\(ac,_)-> (VRat ac, etc)) (fromContents cs) 
     633        | "VNum" `isPrefixOf` constr = 
     634            (\(ad,_)-> (VNum ad, etc)) (fromContents cs) 
     635        | "VList" `isPrefixOf` constr = 
     636            (\(af,_)-> (VList af, etc)) (fromContents cs) 
     637        | "VInt" `isPrefixOf` constr = 
     638            (\(ab,_)-> (VInt ab, etc)) (fromContents cs) 
     639        | "VBool" `isPrefixOf` constr = 
     640            (\(aa,_)-> (VBool aa, etc)) (fromContents cs) 
     641    toContents v@VUndef = 
     642        [mkElemC (showConstr 0 (toHType v)) []] 
     643    toContents v@(VBool aa) = 
     644        [mkElemC (showConstr 1 (toHType v)) (toContents aa)] 
     645    toContents v@(VInt ab) = 
     646        [mkElemC (showConstr 2 (toHType v)) (toContents ab)] 
     647    toContents v@(VRat ac) = 
     648        [mkElemC (showConstr 3 (toHType v)) (toContents ac)] 
     649    toContents v@(VNum ad) = 
     650        [mkElemC (showConstr 4 (toHType v)) (toContents ad)] 
     651    toContents v@(VStr ae) = 
     652        [mkElemC (showConstr 5 (toHType v)) (toContents ae)] 
     653    toContents v@(VList af) = 
     654        [mkElemC (showConstr 6 (toHType v)) (toContents af)] 
     655    toContents v@(VType ag) = 
     656        [mkElemC (showConstr 7 (toHType v)) (toContents ag)] 
     657 
     658instance Perl5 Cxt where 
     659    showPerl5 (CxtVoid) = showP5Class "CxtVoid" 
     660    showPerl5 (CxtItem aa) = showP5ArrayObj "CxtItem" [showPerl5 aa] 
     661    showPerl5 (CxtSlurpy aa) = showP5ArrayObj "CxtSlurpy" 
     662              [showPerl5 aa] 
     663 
     664instance Haskell2Xml Cxt where 
     665    toHType v = 
     666        Defined "Cxt" [] 
     667                [Constr "CxtVoid" [] [],Constr "CxtItem" [] [toHType aa], 
     668                 Constr "CxtSlurpy" [] [toHType ab]] 
     669      where 
     670        (CxtItem aa) = v 
     671        (CxtSlurpy ab) = v 
     672    fromContents (CElem (Elem constr [] cs):etc) 
     673        | "CxtVoid" `isPrefixOf` constr = 
     674            (CxtVoid,etc) 
     675        | "CxtSlurpy" `isPrefixOf` constr = 
     676            (\(ab,_)-> (CxtSlurpy ab, etc)) (fromContents cs) 
     677        | "CxtItem" `isPrefixOf` constr = 
     678            (\(aa,_)-> (CxtItem aa, etc)) (fromContents cs) 
     679    toContents v@CxtVoid = 
     680        [mkElemC (showConstr 0 (toHType v)) []] 
     681    toContents v@(CxtItem aa) = 
     682        [mkElemC (showConstr 1 (toHType v)) (toContents aa)] 
     683    toContents v@(CxtSlurpy ab) = 
     684        [mkElemC (showConstr 2 (toHType v)) (toContents ab)] 
     685 
     686instance Perl5 Type where 
     687    showPerl5 (MkType aa) = showP5ArrayObj "MkType" [showPerl5 aa] 
     688    showPerl5 (TypeOr aa ab) = showP5ArrayObj "TypeOr" 
     689              [showPerl5 aa , showPerl5 ab] 
     690    showPerl5 (TypeAnd aa ab) = showP5ArrayObj "TypeAnd" 
     691              [showPerl5 aa , showPerl5 ab] 
     692 
     693instance Haskell2Xml Type where 
     694    toHType v = 
     695        Defined "Type" [] 
     696                [Constr "MkType" [] [toHType aa], 
     697                 Constr "TypeOr" [] [toHType ab,toHType ac], 
     698                 Constr "TypeAnd" [] [toHType ad,toHType ae]] 
     699      where 
     700        (MkType aa) = v 
     701        (TypeOr ab ac) = v 
     702        (TypeAnd ad ae) = v 
     703    fromContents (CElem (Elem constr [] cs):etc) 
     704        | "TypeOr" `isPrefixOf` constr = 
     705            (\(ab,cs00)-> (\(ac,_)-> (TypeOr ab ac, etc)) (fromContents cs00)) 
     706            (fromContents cs) 
     707        | "TypeAnd" `isPrefixOf` constr = 
     708            (\(ad,cs00)-> (\(ae,_)-> (TypeAnd ad ae, etc)) (fromContents cs00)) 
     709            (fromContents cs) 
     710        | "MkType" `isPrefixOf` constr = 
     711            (\(aa,_)-> (MkType aa, etc)) (fromContents cs) 
     712    toContents v@(MkType aa) = 
     713        [mkElemC (showConstr 0 (toHType v)) (toContents aa)] 
     714    toContents v@(TypeOr ab ac) = 
     715        [mkElemC (showConstr 1 (toHType v)) (concat [toContents ab, 
     716                                                     toContents ac])] 
     717    toContents v@(TypeAnd ad ae) = 
     718        [mkElemC (showConstr 2 (toHType v)) (concat [toContents ad, 
     719                                                     toContents ae])] 
     720 
     721instance Perl5 Param where 
     722    showPerl5 (MkParam aa ab ac ad ae af ag ah ai) = 
     723              showP5HashObj "MkParam" 
     724              [("isInvocant", showPerl5 aa) , ("isOptional", showPerl5 ab) , 
     725               ("isNamed", showPerl5 ac) , ("isLValue", showPerl5 ad) , 
     726               ("isWritable", showPerl5 ae) , ("isLazy", showPerl5 af) , 
     727               ("paramName", showPerl5 ag) , ("paramContext", showPerl5 ah) , 
     728               ("paramDefault", showPerl5 ai)] 
     729 
     730instance Haskell2Xml Param where 
     731    toHType v = 
     732        Defined "Param" [] 
     733                [Constr "MkParam" [] 
     734                        [toHType aa,toHType ab,toHType ac,toHType ad,toHType ae,toHType af, 
     735                         toHType ag,toHType ah,toHType ai]] 
     736      where 
     737        (MkParam aa ab ac ad ae af ag ah ai) = v 
     738