{-% DrIFT (Automatic class derivations for Haskell) %-} {-% version 1.8 for Strafunski %-} -- | Base PXSL data types. -- -- CVS: $Id: PxsltParserTerms.ds,v 1.2 2003/06/01 21:00:46 thor Exp $ -- -- Copyright (C) 2003 Tom Moertel -- Licensed under the terms of the GNU General Public License. -- See the LICENSE file in the project distribution for details. module PxsltParserTerms where import DataGenerics import Data.Dynamic import XmlString type Line = Int type Column = Int type SourceContext = (Line, Column) type Attribute = ( String, [Statement] ) data Statement = Element { context :: SourceContext , name :: String , posnAttrs :: [[Statement]] , namedAttrs :: [Attribute] , children :: [Statement] } | Literal { context :: SourceContext , xstr :: XmlString } | Comment { context :: SourceContext , text :: String } | MacroDef{ context :: SourceContext , name :: String , parms :: [String] , body :: [Statement] } | MacroApp{ context :: SourceContext , name :: String , posnArgs :: [[Statement]] , namedArgs :: [(String, [Statement])] , children :: [Statement] } | Eval { context :: SourceContext , children :: [Statement] } | Error { context :: SourceContext , text :: String } | Empty -- ^ blank line deriving (Eq, Read) instance Show Statement where showsPrec _ l@Literal{} = ("XML: " ++) . xsToXmlS (xstr l) showsPrec _ c@Comment{} = ("Comment: " ++) . (text c ++) showsPrec _ Empty = ("Empty" ++) showsPrec p e@Element{} = ("Element: " ++) . (name e ++) . (' ':) . attrs . foldr (.) id (map show1 (children e)) where attrs = showsPrec p (posnAttrs e) . (' ':) . showsPrec p (namedAttrs e) show1 child = (concatMap ("\n "++) (lines (show child)) ++) showsPrec p md@MacroDef{} = ("MacroDef: " ++) . (name md ++) . (' ':) . showsPrec p (parms md) . (" =" ++) . foldr (.) id (map show1 (body md)) where show1 child = (concatMap ("\n "++) (lines (show child)) ++) showsPrec p e@MacroApp{} = ("MacroApp: " ++) . (name e ++) . (' ':) . attrs . foldr (.) id (map show1 (children e)) where attrs = showsPrec p (posnArgs e) . (' ':) . showsPrec p (namedArgs e) show1 child = (concatMap ("\n "++) (lines (show child)) ++) showsPrec p e@Eval{} = ("Eval: " ++) . foldr (.) id (map show1 (children e)) where show1 child = (concatMap ("\n "++) (lines (show child)) ++) showsPrec p (Error ctx text) = ("Error: "++) . showsPrec p ctx . (": "++) . (text++) {-* Generated by DrIFT-Strafunksi 1.8 : Look, but Don't Touch. *-} _tc_StatementTc = mkTyCon "Statement" instance Typeable Statement where typeOf x = mkAppTy _tc_StatementTc [ ] -- Imported from other files :- {-% DrIFT (Automatic class derivations for Haskell) %-} {-% version 1.8 for Strafunski %-} {-* Generated by DrIFT-Strafunksi 1.8 : Look, but Don't Touch. *-} instance Data Statement where gfoldl f z (Element aa ab ac ad ae) = z Element `f` aa `f` ab `f` ac `f` ad `f` ae gfoldl f z (Literal aa ab) = z Literal `f` aa `f` ab gfoldl f z (Comment aa ab) = z Comment `f` aa `f` ab gfoldl f z (MacroDef aa ab ac ad) = z MacroDef `f` aa `f` ab `f` ac `f` ad gfoldl f z (MacroApp aa ab ac ad ae) = z MacroApp `f` aa `f` ab `f` ac `f` ad `f` ae gfoldl f z (Eval aa ab) = z Eval `f` aa `f` ab gfoldl f z (Error aa ab) = z Error `f` aa `f` ab gfoldl f z Empty = z Empty gunfold f z c | conString c == "Element" = f (f (f (f (f (z Element))))) gunfold f z c | conString c == "Literal" = f (f (z Literal)) gunfold f z c | conString c == "Comment" = f (f (z Comment)) gunfold f z c | conString c == "MacroDef" = f (f (f (f (z MacroDef)))) gunfold f z c | conString c == "MacroApp" = f (f (f (f (f (z MacroApp))))) gunfold f z c | conString c == "Eval" = f (f (z Eval)) gunfold f z c | conString c == "Error" = f (f (z Error)) gunfold f z c | conString c == "Empty" = z Empty conOf (Element aa ab ac ad ae) = Constr{ conString = "Element" } conOf (Literal aa ab) = Constr{ conString = "Literal" } conOf (Comment aa ab) = Constr{ conString = "Comment" } conOf (MacroDef aa ab ac ad) = Constr{ conString = "MacroDef" } conOf (MacroApp aa ab ac ad ae) = Constr{ conString = "MacroApp" } conOf (Eval aa ab) = Constr{ conString = "Eval" } conOf (Error aa ab) = Constr{ conString = "Error" } conOf Empty = Constr{ conString = "Empty" } consOf _ = [ Constr{ conString = "Element" } , Constr{ conString = "Literal" } , Constr{ conString = "Comment" } , Constr{ conString = "MacroDef" } , Constr{ conString = "MacroApp" } , Constr{ conString = "Eval" } , Constr{ conString = "Error" } , Constr{ conString = "Empty" } ] -- Imported from other files :-