AS_Annotation.der.hs revision faaa40307f4d95b3737ea714a1cf13bd79108a70
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterModule : $Header$
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterDescription : datastructures for annotations of (Het)CASL.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterCopyright : (c) Klaus Luettich, Christian Maeder, and Uni Bremen 2002-2006
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterLicense : GPLv2 or higher, see LICENSE.txt
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterMaintainer : Christian.Maeder@dfki.de
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterStability : provisional
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterPortability : portable
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterDatastructures for annotations of (Het)CASL.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster There is also a paramterized data type for an 'Annoted' 'item'.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster See also chapter II.5 of the CASL Reference Manual.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport qualified Data.Map as Map
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- DrIFT command
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{-! global: GetRange !-}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | start of an annote with its WORD or a comment
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbingsdata Annote_word = Annote_word String | Comment_start deriving (Show, Eq, Ord)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | line or group for 'Unparsed_anno'
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdata Annote_text = Line_anno String | Group_anno [String]
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings deriving (Show, Eq, Ord)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{- | formats to be displayed (may be extended in the future).
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterDrop 3 from the show result to get the string for parsing and printing -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdata Display_format = DF_HTML | DF_LATEX | DF_RTF deriving (Show, Eq, Ord)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | swap the entries of a lookup table
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterswapTable :: [(a, b)] -> [(b, a)]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterswapTable = map $ \ (a, b) -> (b, a)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | drop the first 3 characters from the show result
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FostertoTable :: (Show a) => [a] -> [(a, String)]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FostertoTable = map $ \ a -> (a, drop 3 $ show a)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | a lookup table for the textual representation of display formats
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdisplay_format_table :: [(Display_format, String)]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdisplay_format_table = toTable [ DF_HTML, DF_LATEX, DF_RTF ]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{- | lookup the textual representation of a display format
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterin 'display_format_table' -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterlookupDisplayFormat :: Display_format -> String
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterlookupDisplayFormat df =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster fromMaybe (error "lookupDisplayFormat: unknown display format")
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster $ lookup df display_format_table
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{- | precedence 'Lower' means less and 'BothDirections' means less and greater.
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings'Higher' means greater but this is syntactically not allowed in 'Prec_anno'.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster'NoDirection' can also not be specified explicitly,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterbut covers those ids that are not mentionend in precedences. -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdata PrecRel = Higher | Lower | BothDirections | NoDirection
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster deriving (Show, Eq, Ord)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | either left or right associative
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdata AssocEither = ALeft | ARight deriving (Show, Eq, Ord)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{- | semantic (line) annotations without further information.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterUse the same drop-3-trick as for the 'Display_format'. -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdata Semantic_anno = SA_cons | SA_def | SA_implies | SA_mono | SA_implied
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | SA_mcons | SA_ccons
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster deriving (Show, Eq, Ord)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | a lookup table for the textual representation of semantic annos
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostersemantic_anno_table :: [(Semantic_anno, String)]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostersemantic_anno_table =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster toTable [SA_cons, SA_def, SA_implies, SA_mono, SA_implied, SA_mcons, SA_ccons]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{- | lookup the textual representation of a semantic anno
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterin 'semantic_anno_table' -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterlookupSemanticAnno :: Semantic_anno -> String
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterlookupSemanticAnno sa =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster fromMaybe (error "lookupSemanticAnno: no semantic anno")
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster $ lookup sa semantic_anno_table
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster-- | all possible annotations (without comment-outs)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdata Annotation = -- | constructor for comments or unparsed annotes
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Unparsed_anno Annote_word Annote_text Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- | known annotes
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Display_anno Id [(Display_format, String)] Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- position of anno start, keywords and anno end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | List_anno Id Id Id Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- position of anno start, commas and anno end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Number_anno Id Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- position of anno start, commas and anno end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Float_anno Id Id Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- position of anno start, commas and anno end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | String_anno Id Id Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- position of anno start, commas and anno end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Prec_anno PrecRel [Id] [Id] Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {- positions: "{",commas,"}", RecRel, "{",commas,"}"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Lower = "< " BothDirections = "<>" -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Assoc_anno AssocEither [Id] Range -- position of commas
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Label [String] Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- position of anno start and anno end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Prefix_anno [(String, IRI)] Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- position of anno start and anno end
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster -- All annotations below are only as annote line allowed
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster | Semantic_anno Semantic_anno Range
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster {- position information for annotations is provided
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster by every annotation -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster deriving (Show, Eq, Ord)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{- | 'isLabel' tests if the given 'Annotation' is a label
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster(a 'Label' typically follows a formula) -}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterisLabel :: Annotation -> Bool
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterisLabel a = case a of
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster Label _ _ -> True
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken StubbingsisImplies :: Annotation -> Bool
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken StubbingsisImplies a = case a of
449854c2a07b50ea64d9d6a8b03d18d4afeeee43Ken Stubbings Semantic_anno SA_implies _ -> True
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterisImplied :: Annotation -> Bool
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan FosterisImplied a = case a of
partPrefixes :: [Annotation] -> (Map.Map String IRI, [Annotation])
_ -> (m, a : l)) (Map.empty, [])