Parser of common logic interchange format
Ref. Common Logic
ISO/IEC IS 24707:2007(E)
cltext :: CharParser st TEXT_MRS
namedtext :: CharParser st TEXT
return $ Named_text n t nullRange
return $ Named_text n (Text [] nullRange) nullRange
text :: CharParser st TEXT
phr <- many1 phrase --was many1 (not as in standard)
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
try (oParenT >> clModuleKey)
try (oParenT >> clImportsKey)
try (oParenT >> clCommentKey)
c <- quotedstring <|> enclosedname
t <- comment_txt <?> "comment: 3"
return $ Comment_text (Comment c nullRange) t nullRange
comment_txt :: CharParser st TEXT
return $ Text [] nullRange
pModule :: CharParser st MODULE
[] -> return $ Mod t txt nullRange
_ -> return $ Mod_ex t exs txt nullRange
pModExcl :: CharParser st ([NAME], TEXT)
try (oParenT >> clExcludesKey)
importation :: CharParser st IMPORTATION
-- | parser for sentences
sentence :: CharParser st SENTENCE
c <- quotedstring <|> enclosedname
return $ Comment_sent (Comment c $ Range $ rangeSpan c) s
$ Range $ joinRanges [rangeSpan ck, rangeSpan c, rangeSpan s]
return $ rolesetSentence t0 nts
at <- atom <?> "predicate"
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,
return $ Bool_sent (Negation s) $ Range $ joinRanges [rangeSpan c,
c <- try iffKey -- with try? yes.
return $ Bool_sent (Biconditional s1 s2) $ Range $ joinRanges [rangeSpan c,
rangeSpan s1, rangeSpan s1]
return $ Bool_sent (Implication s1 s2) $ Range $ joinRanges [rangeSpan c,
rangeSpan s1, rangeSpan s1]
quantsent1 :: Bool -> Token -> CharParser st SENTENCE
g <- identifier -- according to grammar in standard there may be a name
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)
True -> -- TODO: check whether indvC_sen is the right function to get free names
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]
return $ Left $ (nos,t) -- TODO: check what to do with the term @t@
intNameOrSeqMark :: CharParser st NAME_OR_SEQMARK
s <- seqmark -- fix seqmark parser for one
atom :: CharParser st ATOM
term :: CharParser st TERM
term_fun_cmt :: CharParser st TERM
c <- quotedstring <|> enclosedname
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
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
{- old unfinished function - TODO: remove as soon as the new one works
-- | collect all the names and sequence markers
symbItems :: GenParser Char st NAME
return (Token "x" nullRange)
-- | Parse a list of comma separated symbols.
symbItems :: GenParser Char st SYMB_ITEMS
return (Symb_items is $ catRange ps)
-- | parse a comma separated list of symbols
symbs :: GenParser Char st ([NAME_OR_SEQMARK], [Token])
do c <- commaT `followedWith` intNameOrSeqMark
-- | parse a list of symbol mappings
symbMapItems :: GenParser Char st SYMB_MAP_ITEMS
return (Symb_map_items is $ catRange ps)
-- | parse a comma separated list of symbol mappings
symbMaps :: GenParser Char st ([SYMB_OR_MAP], [Token])
do c <- commaT `followedWith` intNameOrSeqMark
-- | parsing one symbol or a mapping of one to a second symbol
symbMap :: GenParser Char st SYMB_OR_MAP
symbMapS :: GenParser Char st SYMB_OR_MAP
do f <- pToken $ toKey mapsTo
return (Symb_mapS s t $ tokPos f)
<|> return (Symb $ SeqMark s)
symbMapN :: GenParser Char st SYMB_OR_MAP
do f <- pToken $ toKey mapsTo
return (Symb_mapN s t $ tokPos f)
<|> return (Symb $ Name s)