AS_Annotation.der.hs revision 306014675f76e6e6986e94afda313fe8564ab2e2
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder{- |
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederModule : $Header$
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederCopyright : (c) Klaus L�ttich, Christian Maeder, and Uni Bremen 2002-2003
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederLicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederMaintainer : hets@tzi.de
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederStability : provisional
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederPortability : portable
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder These datastructures describe the Annotations of (Het)CASL.
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder There is also a paramterized data type for an 'Annoted' 'item'.
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-}
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maedermodule Common.AS_Annotation where
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maederimport Common.Id
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- DrIFT command
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder{-! global: UpPos !-}
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | start of an annote with its WORD or a comment
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederdata Annote_word = Annote_word String | Comment_start deriving (Show, Eq)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | line or group for 'Unparsed_anno'
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maederdata Annote_text = Line_anno String | Group_anno [String] deriving (Show, Eq)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | formats to be displayed (may be extended in the future).
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- Drop 3 from the show result to get the string for parsing and printing
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maederdata Display_format = DF_HTML | DF_LATEX | DF_RTF
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder deriving (Show, Eq, Ord)
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | swap a pair
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederswap :: (a, b) -> (b, a)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederswap (a, b) = (b, a)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | swap the entries of a lookup table
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederswapTable :: [(a, b)] -> [(b, a)]
ae464ac109d82566feab1acbc98eab3bf1f10bb3Christian MaederswapTable = map swap
ae464ac109d82566feab1acbc98eab3bf1f10bb3Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | drop the first 3 characters from the show result
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaedertoTable :: (Show a) => [a] -> [(a, String)]
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaedertoTable = map $ \a -> (a, drop 3 $ show a)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | a lookup table for the textual representation of display formats
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maederdisplay_format_table :: [(Display_format, String)]
ae464ac109d82566feab1acbc98eab3bf1f10bb3Christian Maederdisplay_format_table = toTable [ DF_HTML, DF_LATEX, DF_RTF ]
ae464ac109d82566feab1acbc98eab3bf1f10bb3Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | lookup the textual representation of a display format
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- in 'display_format_table'
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederlookupDisplayFormat :: Display_format -> String
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederlookupDisplayFormat df =
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder maybe (error "lookupDisplayFormat: unknown display format")
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder id $ lookup df display_format_table
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | precedence 'Lower' means less and 'BothDirections' means less and greater.
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- 'Higher' means greater but this is syntactically not allowed in 'Prec_anno'.
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- 'NoDirection' can also not be specified explicitly,
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- but covers those ids that are not mentionend in precedences.
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederdata PrecRel = Higher | Lower | BothDirections | NoDirection
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder deriving (Show, Eq)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | either left or right associative
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederdata AssocEither = ALeft | ARight deriving (Show,Eq)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | semantic (line) annotations without further information.
fe883661c9d1a5a8b42ac4e8673ec133d9dad354Christian Maeder-- Use the same drop-3-trick as for the 'Display_format'.
4e1eee47e914d754644cc396647b6997a28d3704Christian Maederdata Semantic_anno = SA_cons | SA_def | SA_implies | SA_mono | SA_implied
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder deriving (Show, Eq)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | a lookup table for the textual representation of semantic annos
4e1eee47e914d754644cc396647b6997a28d3704Christian Maedersemantic_anno_table :: [(Semantic_anno, String)]
4e1eee47e914d754644cc396647b6997a28d3704Christian Maedersemantic_anno_table = toTable [SA_cons, SA_def,
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder SA_implies, SA_mono, SA_implied]
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | lookup the textual representation of a semantic anno
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- in 'semantic_anno_table'
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederlookupSemanticAnno :: Semantic_anno -> String
4e1eee47e914d754644cc396647b6997a28d3704Christian MaederlookupSemanticAnno sa =
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder maybe (error "lookupSemanticAnno: no semantic anno")
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder id $ lookup sa semantic_anno_table
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | all possible annotations (without comment-outs)
4e1eee47e914d754644cc396647b6997a28d3704Christian Maederdata Annotation = -- | constructor for comments or unparsed annotes
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder Unparsed_anno Annote_word Annote_text [Pos]
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder -- | known annotes
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder | Display_anno Id [(Display_format, String)] [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- postion of anno start, keywords and anno end
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder | List_anno Id Id Id [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- postion of anno start, commas and anno end
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder | Number_anno Id [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- postion of anno start, commas and anno end
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder | Float_anno Id Id [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- postion of anno start, commas and anno end
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder | String_anno Id Id [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- postion of anno start, commas and anno end
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder | Prec_anno PrecRel [Id] [Id] [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- ^ positions: "{",commas,"}", RecRel, "{",commas,"}"
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder -- | Lower = "< " BothDirections = "<>"
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder | Assoc_anno AssocEither [Id] [Pos] -- position of commas
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder | Label [String] [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- postion of anno start and anno end
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- All annotations below are only as annote line allowed
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder | Semantic_anno Semantic_anno [Pos]
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- position information for annotations is provided
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder -- by every annotation
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder deriving (Show)
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maederinstance Eq Annotation where
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Unparsed_anno aw1 at1 _ == Unparsed_anno aw2 at2 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = (aw1,at1)==(aw2,at2)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Display_anno i1 x1 _ == Display_anno i2 x2 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = (i1,x1)==(i2,x2)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder List_anno i1 i2 i3 _ == List_anno i4 i5 i6 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = (i1,i2,i3)==(i4,i5,i6)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder Number_anno i1 _ == Number_anno i2 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = i1==i2
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Float_anno i1 i2 _ == Float_anno i3 i4 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = (i1,i2)==(i3,i4)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder String_anno i1 i2 _ == String_anno i3 i4 _
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder = (i1,i2)==(i3,i4)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder Prec_anno pr1 i1 i2 _ == Prec_anno pr2 i3 i4 _
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder = (pr1,i1,i2)==(pr2,i3,i4)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder Assoc_anno ae1 i1 _ == Assoc_anno ae2 i2 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = (ae1,i1) == (ae2,i2)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder Label str1 _ == Label str2 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = str1 == str2
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder Semantic_anno sa1 _ == Semantic_anno sa2 _
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder = sa1 == sa2
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder _ == _ = False
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- |
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- 'isLabel' tests if the given 'Annotation' is a label
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- (a 'Label' typically follows a formula)
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederisLabel :: Annotation -> Bool
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederisLabel a = case a of
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder Label _ _ -> True
c0467970183fa3dc894edea3caf9ca05d3a09fa8Christian Maeder _ -> False
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederisImplied :: Annotation -> Bool
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederisImplied a =
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder case a of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Semantic_anno SA_implied _ -> True
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder Semantic_anno _ _ -> False
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder _ -> False
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- |
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- 'isSemanticAnno' tests if the given 'Annotation' is a semantic one
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederisSemanticAnno :: Annotation -> Bool
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederisSemanticAnno a = case a of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Semantic_anno _ _ -> True
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder _ -> False
e05956d1da3c97e4d808926f97c6841c4a561991Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- |
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- 'isComment' tests if the given 'Annotation' is a comment line or a
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- comment group
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederisComment :: Annotation -> Bool
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederisComment c = case c of
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder Unparsed_anno Comment_start _ _ -> True
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder _ -> False
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- |
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- 'isAnnote' is the invers function to 'isComment'
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederisAnnote :: Annotation -> Bool
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederisAnnote = not . isComment
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- | an item wrapped in preceeding (left 'l_annos')
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- and following (right 'r_annos') annotations.
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder-- 'opt_pos' should carry the position of an optional semicolon
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- following a formula (but is currently unused).
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maederdata Annoted a = Annoted { item :: a
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder , opt_pos :: [Pos]
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder , l_annos :: [Annotation]
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder , r_annos :: [Annotation]}
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder deriving (Show, Eq)
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder-- | naming or labelling sentences
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maederdata Named s = NamedSen { senName :: String,
c0467970183fa3dc894edea3caf9ca05d3a09fa8Christian Maeder sentence :: s }
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder deriving (Eq, Show)
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | process all items and wrap matching annotations around the results
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaedermapAnM :: (Monad m) => (a -> m b) -> [Annoted a] -> m [Annoted b]
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaedermapAnM f al =
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder do il <- mapM (f . item) al
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder return $ zipWith ( \ a i -> a { item = i }) al il
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | replace the 'item'
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederreplaceAnnoted :: b -> Annoted a -> Annoted b
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederreplaceAnnoted x (Annoted _ o l r) = Annoted x o l r
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | add further following annotations
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaederappendAnno :: Annoted a -> [Annotation] -> Annoted a
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederappendAnno (Annoted x p l r) y = Annoted x p l (r++y)
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | put together preceding annotations and an item
aae7a026a323021c5364aef85a0e03d586e5a5c3Christian MaederaddLeftAnno :: [Annotation] -> a -> Annoted a
86c119e3e74ba4b1b4ca728531282e9100789939Christian MaederaddLeftAnno l i = Annoted i [] l []
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder-- | get the label following (or to the right of) an 'item'
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian MaedergetRLabel :: Annoted a -> String
4e1eee47e914d754644cc396647b6997a28d3704Christian MaedergetRLabel a = let ls = filter isLabel (r_annos a) in
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder if null ls then "" else
4e1eee47e914d754644cc396647b6997a28d3704Christian Maeder let Label l _ = head ls
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder in if null l then "" else head l
d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5Christian Maeder -- might be a multiline label
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder -- maybe remove white spaces
86c119e3e74ba4b1b4ca728531282e9100789939Christian Maeder