Symbol.hs revision e9458b1a7a19a63aa4c179f9ab20f4d50681c168
4752N/A{-# LANGUAGE DeriveDataTypeable #-}
4752N/A{- |
4752N/AModule : ./CommonLogic/Symbol.hs
4752N/ADescription : Symbols of common logic
4752N/ACopyright : (c) Karl Luc, DFKI Bremen 2010, Eugen Kuksa, Uni Bremen 2011
4752N/ALicense : GPLv2 or higher, see LICENSE.txt
4752N/A
4752N/AMaintainer : eugenk@informatik.uni-bremen.de
4752N/AStability : experimental
4752N/APortability : portable
6982N/A
6982N/ADefinition of symbols for common logic
4752N/A-}
4752N/A
4752N/Amodule CommonLogic.Symbol (
4752N/A Symbol (..)
6982N/A , printSymbol
6982N/A , symOf
6982N/A , getSymbolMap
6982N/A , getSymbolName
4752N/A , symbolToRaw
4752N/A , idToRaw
4752N/A , matches
4752N/A , addSymbToSign
4752N/A , symKind
5821N/A )
4752N/A where
4752N/A
4752N/Aimport qualified Common.Id as Id
4752N/Aimport Common.Doc
4752N/Aimport Common.DocUtils
4752N/Aimport Common.Result
4752N/A
4752N/Aimport Data.Data
4752N/Aimport qualified Data.Set as Set
4752N/Aimport qualified Data.Map as Map
4752N/A
4752N/Aimport qualified CommonLogic.Sign as Sign
4752N/Aimport CommonLogic.Morphism as Morphism
4752N/A
4752N/Anewtype Symbol = Symbol {symName :: Id.Id}
4752N/A deriving (Show, Eq, Ord, Typeable)
4752N/A
4752N/Ainstance Id.GetRange Symbol where
4752N/A getRange = Id.getRange . symName
4752N/A
4752N/Ainstance Pretty Symbol where
4752N/A pretty = printSymbol
4752N/A
4752N/A-- | Pretty prints the symbol @x@
4752N/AprintSymbol :: Symbol -> Doc
4752N/AprintSymbol x = pretty $ symName x
4752N/A
4752N/A-- | Converts a signature to a set of symbols
4752N/AsymOf :: Sign.Sign -> Set.Set Symbol
4752N/AsymOf x = Set.fold (\ y -> Set.insert Symbol {symName = y}) Set.empty $
4752N/A Sign.allItems x
4752N/A
4752N/A-- | Determines the symbol map of a morhpism
4752N/AgetSymbolMap :: Morphism.Morphism -> Map.Map Symbol Symbol
4752N/AgetSymbolMap f =
4752N/A foldr (\ x -> Map.insert (Symbol x) (Symbol $ applyMap (propMap f) x))
4752N/A Map.empty $ Set.toList $ Sign.allItems $ source f
4752N/A
4752N/A-- | Determines the name of a symbol
4752N/AgetSymbolName :: Symbol -> Id.Id
4752N/AgetSymbolName = symName
4752N/A
4752N/AsymbolToRaw :: Symbol -> Symbol
4752N/AsymbolToRaw = id
4752N/A
4752N/AidToRaw :: Id.Id -> Symbol
4752N/AidToRaw mid = Symbol {symName = mid}
4752N/A
4752N/A-- | Checks two symbols on equality
4752N/Amatches :: Symbol -> Symbol -> Bool
4752N/Amatches s1 s2 = s1 == s2
4752N/A
4752N/A-- | Adds a symbol to a signature
4752N/AaddSymbToSign :: Sign.Sign -> Symbol -> Result Sign.Sign
4752N/AaddSymbToSign sig symb = Result [] $ Just $
4752N/A if Sign.isSeqMark $ symName symb
4752N/A then sig { Sign.sequenceMarkers =
4752N/A Set.insert (symName symb) $ Sign.sequenceMarkers sig
4752N/A }
4752N/A else sig { Sign.discourseNames =
4752N/A Set.insert (symName symb) $ Sign.discourseNames sig
4752N/A }
4752N/A
4752N/A-- | Returns a string classifying the symbol as name or sequence marker
4752N/AsymKind :: Symbol -> String
4752N/AsymKind s = if Sign.isSeqMark $ symName s then symKindSeqMark else symKindName
4752N/A
4752N/AsymKindName :: String
4752N/AsymKindName = "Name"
4752N/A
4752N/AsymKindSeqMark :: String
4752N/AsymKindSeqMark = "SequenceMarker"
4752N/A