Parser of common logic interchange format
Ref. Common Logic
ISO/IEC IS 24707:2007(E)
import
Common.Lexer as Lexer hiding (oParenT, cParenT, pToken)
cltext :: CharParser st TEXT_META
cltext = many white >> (do
try $ oParenT >> clTextKey
where tm :: TEXT -> TEXT_META
, metarelation = metarelations t
, nondiscourseNames = Nothing
namedtext :: CharParser st TEXT
n <- name <?> "name after \"cl-text\""
return $ Named_text n t nullRange
n <- name <?> "name after \"cl-text\""
return $ Named_text n (Text [] nullRange) nullRange
text :: CharParser st TEXT
return $ Text phr nullRange
-- keys set here to prevent try in more complex parser to get the right
-- error message in ex. the following text
phrase :: CharParser st PHRASE
phrase = many white >> (do
try (oParenT >> clModuleKey)
try (oParenT >> clImportsKey)
try (oParenT >> clCommentKey)
c <- quotedstring <|> enclosedname <?> "comment after \"cl-comment\""
t <- comment_txt <?> "text after \"cl-comment <comment>\""
return $ Comment_text (Comment c nullRange) t nullRange
s <- sentence <?> "sentence"
comment_txt :: CharParser st TEXT
return $ Text [] nullRange
pModule :: CharParser st MODULE
t <- identifier <?> "module name after \"cl-module\""
(exs,txt) <- pModExcl <?> "text in module"
[] -> return $ Mod t txt nullRange
_ -> return $ Mod_ex t exs txt nullRange
pModExcl :: CharParser st ([NAME], TEXT)
pModExcl = many white >> (do
try (oParenT >> clExcludesKey)
exs <- many identifier <?> "only names in module-exclusion list"
importation :: CharParser st IMPORTATION
n <- identifier <?> "importation name after \"cl-imports\""
-- | parser for sentences
sentence :: CharParser st SENTENCE
c <- quotedstring <|> enclosedname <?> "comment after \"cl-comment\""
s <- sentence <?> "sentence after \"cl-comment <comment>\""
return $ Comment_sent (Comment c $ Range $ rangeSpan c) s
$ Range $ joinRanges [rangeSpan ck, rangeSpan c, rangeSpan s]
return $ rolesetSentence t0 nts
return $ Atom_sent at $ Range $ rangeSpan at
s <- many sentence -- joinRanges with s = []?
return $ Bool_sent (Conjunction s) $ Range $ joinRanges [rangeSpan c,
return $ Bool_sent (Disjunction s) $ Range $ joinRanges [rangeSpan c,
s <- sentence <?> "sentence after \"not\""
return $ Bool_sent (Negation s) $ Range $ joinRanges [rangeSpan c,
s1 <- sentence <?> "sentence after \"iff\""
s2 <- sentence <?> "second sentence after \"iff\""
return $ Bool_sent (Biconditional s1 s2) $ Range $ joinRanges [rangeSpan c,
rangeSpan s1, rangeSpan s1]
s1 <- sentence <?> "sentence after \"if\""
s2 <- sentence <?> "second sentence after \"if\""
return $ Bool_sent (Implication s1 s2) $ Range $ joinRanges [rangeSpan c,
rangeSpan s1, rangeSpan s1]
quantsent1 :: Bool -> Token -> CharParser st SENTENCE
g <- identifier <?> "predicate after quantifier"
quantsent2 t c $ Just g -- Quant_sent using syntactic sugar
quantsent2 t c Nothing -- normal Quant_sent
quantsent2 :: Bool -> Token -> Maybe NAME -> CharParser st SENTENCE
return $ quantsent3 t mg (rights bl) (lefts bl) s
$ Range $ joinRanges [rangeSpan c, rangeSpan s]
quantsent3 :: Bool -> Maybe NAME -> [NAME_OR_SEQMARK]
-> [(NAME_OR_SEQMARK, TERM)] -> SENTENCE -> Range -> SENTENCE
quantsent3 t mg bs ((n,trm):nts) s rn = -- Quant_sent using syntactic sugar
Name nm -> Atom (Funct_term trm [Term_seq $ Name_term nm] nullRange) []
SeqMark sqm -> Atom (Funct_term trm [Seq_marks sqm] nullRange) []
True -> Quant_sent (Universal [n] $ quantsent3 t mg bs nts (
Bool_sent (Implication (Atom_sent functerm rn) s) rn
False -> Quant_sent (Universal [n] $ quantsent3 t mg bs nts (
Bool_sent (Conjunction [Atom_sent functerm rn, s]) rn
quantsent3 t mg bs [] s rn =
let quantType = if t then Universal else Existential
Nothing -> Quant_sent (quantType bs s) rn -- normal Quant_sent
Just g -> -- Quant_sent using syntactic sugar
let functerm = Atom (Funct_term (Name_term g) (map (Term_seq . Name_term)
Quant_sent (Universal bs (Bool_sent (Implication
(Atom_sent functerm nullRange) s) rn)) rn
Quant_sent (Existential bs (Bool_sent (Conjunction
[Atom_sent functerm nullRange, s]) rn)) rn
boundlist :: CharParser st [Either (NAME_OR_SEQMARK, TERM) NAME_OR_SEQMARK]
atom :: CharParser st ATOM
t1 <- term <?> "term after \"=\""
t2 <- term <?> "second term after \"=\""
term :: CharParser st TERM
term_fun_cmt :: CharParser st TERM
term_fun_cmt = parens (do
c <- quotedstring <|> enclosedname <?> "comment after \"cl-comment\""
t <- term <?> "term after \"cl-comment <comment>\""
return $ Comment_term t (Comment c $ Range $ rangeSpan c)
$ Range $ joinRanges [rangeSpan ck, rangeSpan c, rangeSpan t]
ts <- many1 termseq -- many1? yes, because it's a functional term
return $ Funct_term t ts $ Range $ joinRanges [rangeSpan t, rangeSpan ts]
termseq :: CharParser st TERM_SEQ
<?> "term or sequence marker in term sequence"
rolesetTerm :: CharParser st TERM
rolesetNT :: CharParser st (NAME, TERM)
rolesetSentence :: TERM -> [(NAME, TERM)] -> SENTENCE
let x = rolesetFreeName t0 nts
in Quant_sent (Existential [Name x] (Bool_sent (Conjunction $
(rolesetAddToTerm x t0) : map (rolesetMixTerm x) nts
) nullRange)) $ Range $ rangeSpan t0
rolesetFreeName :: TERM -> [(NAME, TERM)] -> NAME
rolesetFreeName trm nts =
rolesetAddToTerm :: NAME -> TERM -> SENTENCE
rolesetAddToTerm x trm = Atom_sent (Atom trm [Term_seq $ Name_term x]) nullRange
rolesetMixTerm :: NAME -> (NAME, TERM) -> SENTENCE
rolesetMixTerm x (n, t) =
Atom_sent (Atom (Name_term n) [Term_seq $ Name_term x, Term_seq t]) nullRange
-- | Toplevel parser for basic specs
return $ Basic_spec $ [bi]
-- function to parse different syntaxes
-- parsing: axiom items with dots, clif sentences, clif text
-- first getting only the sentences
parseBasicItems = try parseSentences
return $ Axiom_items (textToAn [tx])
-- | parser for Axiom_items
-- | Toplevel parser for formulae
-- | Toplevel parser for formulae