Definition of abstract syntax for common logic
import qualified
Data.Set as Set (empty)
emptyTextMeta :: TEXT_META
emptyTextMeta = Text_meta { getText = Text [] nullRange
, nondiscourseNames = Nothing }
data TEXT_META = Text_meta { getText :: TEXT
, metarelation :: Set METARELATION
, nondiscourseNames :: Maybe (Set NAME)
} deriving (Show, Ord, Eq)
-- TODO: check static analysis and other features on discourse names, as soon as parsers of segregated dialects are implemented
data PHRASE = Module MODULE
| Importation IMPORTATION
data IMPORTATION = Imp_name NAME
data SENTENCE = Quant_sent QUANT_SENT
Id.Range | Comment_sent COMMENT SENTENCE
Id.Rangedata QUANT_SENT = Universal [NAME_OR_SEQMARK] SENTENCE
| Existential [NAME_OR_SEQMARK] SENTENCE
data BOOL_SENT = Conjunction [SENTENCE]
| Implication SENTENCE SENTENCE
| Biconditional SENTENCE SENTENCE
data ATOM = Equation TERM TERM
data TERM = Name_term NAME
data TERM_SEQ = Term_seq TERM
data NAME_OR_SEQMARK = Name NAME
data SYMB_MAP_ITEMS = Symb_map_items [SYMB_OR_MAP]
Id.Rangedata SYMB_OR_MAP = Symb NAME_OR_SEQMARK
data SYMB_ITEMS = Symb_items [NAME_OR_SEQMARK]
Id.Range -- pos: SYMB_KIND, commas
data METARELATION = RelativeInterprets NAME NAME [SYMB_MAP_ITEMS]
-- pos: delta, t2 - (this_text + delta entails t2)
| DefinablyInterprets NAME [SYMB_MAP_ITEMS]
-- pos: t2 - (this_text definably interprets t2)
| FaithfullyInterprets NAME NAME [SYMB_MAP_ITEMS]
-- pos: delta, t2 - (forall sigma. not (this_text + delta entails sigma) => not (t2 entails sigma))
| DefinablyEquivalent NAME [SYMB_MAP_ITEMS]
-- pos: t2 - (this_text ist definably equivalent to t2)
| NonconservativeExtends NAME [SYMB_MAP_ITEMS]
-- pos: t2 - (forall sigma. this_text entails sigma => t2 entails sigma)
| ConservativeExtends NAME [SYMB_MAP_ITEMS]
-- pos: t2 (this_text conservatively extends t2)
-- include the Libraries in the DevGraph
-- pretty printing using CLIF
instance Pretty BASIC_SPEC where
instance Pretty BASIC_ITEMS where
instance Pretty TEXT_META where
instance Pretty METARELATION where
pretty = printMetarelation
instance Pretty TEXT where
instance Pretty PHRASE where
instance Pretty MODULE where
instance Pretty IMPORTATION where
pretty = printImportation
instance Pretty SENTENCE where
instance Pretty BOOL_SENT where
instance Pretty QUANT_SENT where
instance Pretty ATOM where
instance Pretty TERM where
instance Pretty TERM_SEQ where
instance Pretty COMMENT where
instance Pretty NAME_OR_SEQMARK where
pretty = printNameOrSeqMark
instance Pretty SYMB_OR_MAP where
instance Pretty SYMB_MAP_ITEMS where
pretty = printSymbMapItems
instance Pretty SYMB_ITEMS where
printBasicSpec :: BASIC_SPEC -> Doc
printBasicSpec (Basic_spec xs) = vcat $ map pretty xs
printBasicItems :: BASIC_ITEMS -> Doc
printBasicItems (Axiom_items xs) = vcat $ map pretty xs
printTextMeta :: TEXT_META -> Doc
printTextMeta tm = pretty $ getText tm
printMetarelation :: METARELATION -> Doc
printMetarelation _ = empty
-- print basic spec as pure clif-texts, without any annotations
exportBasicSpec :: BASIC_SPEC -> Doc
exportBasicSpec (Basic_spec xs) = vsep $ map (exportBasicItems .
AS_Anno.item) xs
exportBasicItems :: BASIC_ITEMS -> Doc
exportBasicItems (Axiom_items xs) = vsep $ map (exportTextMeta .
AS_Anno.item) xs
exportTextMeta :: TEXT_META -> Doc
exportTextMeta = pretty . getText
-- using pure clif syntax from here
Text x _ -> fsep $ map pretty x
Named_text x y _ -> parens $ text clTextS <+> text x <+> pretty y
printPhrase :: PHRASE -> Doc
printPhrase s = case s of
Module x -> parens $ text clModuleS <+> pretty x
Importation x -> parens $ text clImportS <+> pretty x
Comment_text x y _ -> parens $ text clCommentS <+> quotes (pretty x) <+> pretty y
printModule :: MODULE -> Doc
printModule (Mod x z _) = pretty x <+> pretty z
printModule (Mod_ex x y z _) =
pretty x <+> parens (text clExcludeS <+> fsep (map pretty y)) <+> pretty z
printImportation :: IMPORTATION -> Doc
printImportation (Imp_name x) = pretty x
printSentence :: SENTENCE -> Doc
printSentence s = case s of
Quant_sent xs _ -> parens $ pretty xs
Bool_sent xs _ -> parens $ pretty xs
Atom_sent xs _ -> pretty xs
Comment_sent x y _ -> parens $ text clCommentS <+> quotes (pretty x) <+> pretty y
Irregular_sent xs _ -> parens $ pretty xs
printComment :: COMMENT -> Doc
printComment s = case s of
printQuantSent :: QUANT_SENT -> Doc
printQuantSent s = case s of
Universal x y -> text forallS <+> parens (sep $ map pretty x) <+> pretty y
Existential x y -> text existsS <+> parens (sep $ map pretty x) <+> pretty y
printBoolSent :: BOOL_SENT -> Doc
printBoolSent s = case s of
Conjunction xs -> text andS <+> (fsep $ map pretty xs)
Disjunction xs -> text orS <+> (fsep $ map pretty xs)
Negation xs -> text notS <+> pretty xs
Implication x y -> text ifS <+> pretty x <+> pretty y
Biconditional x y -> text iffS <+> pretty x <+> pretty y
Equation a b -> parens $ equals <+> pretty a <+> pretty b
Atom t ts -> parens $ pretty t <+> (sep $ map pretty ts)
Funct_term t ts _ -> parens $ pretty t <+> (fsep $ map pretty ts)
Comment_term t c _ -> parens $ text clCommentS <+> quotes (pretty c) <+> pretty t
printTermSeq :: TERM_SEQ -> Doc
printTermSeq s = case s of
printNameOrSeqMark :: NAME_OR_SEQMARK -> Doc
printNameOrSeqMark s = case s of
-- Alt x y -> pretty x <+> pretty y
printSymbOrMap :: SYMB_OR_MAP -> Doc
printSymbOrMap (Symb nos) = pretty nos
printSymbOrMap (Symb_mapN source dest _) =
pretty source <+> mapsto <+> pretty dest <> space
printSymbOrMap (Symb_mapS source dest _) =
pretty source <+> mapsto <+> pretty dest <> space -- space needed. without space the comma (from printSymbMapItems) would be part of the name @dest@
printSymbMapItems :: SYMB_MAP_ITEMS -> Doc
printSymbMapItems (Symb_map_items xs _) = ppWithCommas xs
printSymbItems :: SYMB_ITEMS -> Doc
printSymbItems (Symb_items xs _) = fsep $ map pretty xs
-- keywords, reservednames in CLIF
clCommentS = "cl-comment"
clExcludeS = "cl-excludes"