ToSExpr.hs revision ca0d4947f7b0fdcbf7eac627659e6cff6d3863ba
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederModule : $Header$
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederDescription : translate CASL to S-Expressions
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederCopyright : (c) C. Maeder, DFKI 2008
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederMaintainer : Christian.Maeder@dfki.de
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederStability : provisional
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederPortability : portable
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maedertranslation of CASL to S-Expressions
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maederimport qualified Data.Map as Map
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maederimport qualified Data.Set as Set
bb4d3b6e93db1495f02de46aff5076862e30517bChristian Maederimport qualified Data.List as List
21b18016469e574bd145ad07c7b0f02839677cc3Christian MaederpredToSSymbol :: Sign f e -> PRED_SYMB -> SExpr
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederpredToSSymbol sign p = case p of
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Pred_name _ -> error "predToSSymbol"
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Qual_pred_name i t _ -> predIdToSSymbol sign i $ toPredType t
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederpredIdToSSymbol :: Sign f e -> Id -> PredType -> SExpr
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederpredIdToSSymbol sign i t = case Map.lookup i $ predMap sign of
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Nothing -> error "predIdToSSymbol"
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Just s -> case List.elemIndex t $ Set.toList s of
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Nothing -> error "predIdToSSymbol2"
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Just n -> idToSSymbol (n + 1) i
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederopToSSymbol :: Sign f e -> OP_SYMB -> SExpr
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederopToSSymbol sign o = case o of
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Op_name _ -> error "opToSSymbol"
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Qual_op_name i t _ -> opIdToSSymbol sign i $ toOpType t
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederopIdToSSymbol :: Sign f e -> Id -> OpType -> SExpr
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaederopIdToSSymbol sign i (OpType _ args res) = case Map.lookup i $ opMap sign of
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Nothing -> error $ "opIdToSSymbol " ++ show i
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder (\ r -> opArgs r == args && opRes r == res) $ Set.toList s of
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Nothing -> error "opIdToSSymbol2"
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Just n -> idToSSymbol (n + 1) i
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaedersortToSSymbol :: Id -> SExpr
7862e8fb34d79382e93b45ce894acdd928da8a51Christian MaedersortToSSymbol = idToSSymbol 0
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaedervarToSSymbol :: Token -> SExpr
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaedervarToSSymbol = SSymbol . transToken
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaedervarDeclToSExpr :: (VAR, SORT) -> SExpr
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian MaedervarDeclToSExpr (v, s) =
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder SList [SSymbol "vardecl-indet", varToSSymbol v, sortToSSymbol s]
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maedersfail :: String -> Range -> a
7862e8fb34d79382e93b45ce894acdd928da8a51Christian Maedersfail s = error . show . Diag Error ("unexpected " ++ s)
bb4d3b6e93db1495f02de46aff5076862e30517bChristian MaedersRec :: GetRange f => Sign a e -> (f -> SExpr) -> Record f SExpr SExpr
bb4d3b6e93db1495f02de46aff5076862e30517bChristian MaedersRec sign mf = Record
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder { foldQuantification = \ _ q vs f _ ->
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder let s = SSymbol $ case q of
21b18016469e574bd145ad07c7b0f02839677cc3Christian Maeder Universal -> "all"
7862e8fb34d79382e93b45ce894acdd928da8a51Christian Maeder Existential -> "ex"
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder Unique_existential -> "ex1"
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder vl = SList $ map varDeclToSExpr $ flatVAR_DECLs vs
cf7e0d6750e408ddb47545d6b8349a70cf0b47afChristian Maeder in SList [s, vl, f]
: map sortToSSymbol (Set.toList $ sortSet sign))
, SList $ map sortToSSymbol $ predArgs t ]) $ Set.toList ts)
, sortToSSymbol $ opRes t ]) $ Set.toList ts)
(Map.toList sm)