Parse_AS_DFOL.hs revision 211c5fb252e0a776baad9a4857ab198659289a4a
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaederModule : $Header$
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettDescription : AParser for first-order logic with dependent types (DFOL)
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaederCopyright : (c) Kristina Sojakova, Jacobs University 2009
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachMaintainer : k.sojakova@ijacobs-university.de
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaederStability : experimental
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus RoggenbachPortability : portable
78718c37b1a50086a27e0f031db4cf82bea934aeChristian Maeder basicSpec -- parser for DFOL specifications
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , symbItems -- parser for symbol lists
a79fe3aad8743ea57e473ea5f66a723244cb9c0eMarkus Roggenbach , symbMapItems -- parser for symbol map lists
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maederimport qualified Common.Lexer as Lexer
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maederimport Common.Token (casl_structured_reserved_words)
5cc369fbceee1b13bd0f06e43620c46541d1d4f8Christian Maederimport qualified Common.Keywords as Keywords
dfc58f5ec6492d1a9b9babd9cdcdbb15baa6e657Christian Maederimport qualified Common.AnnoState as AnnoState
842ae753ab848a8508c4832ab64296b929167a97Christian Maeder-- keywords which cannot appear as identifiers in a signature
1538a6e8d77301d6de757616ffc69ee61f1482e4Andy Gimblettreserved :: [String]
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly "Pi"] ++ casl_structured_reserved_words
1538a6e8d77301d6de757616ffc69ee61f1482e4Andy Gimblett-- parser for basic spec
3b48e17c1da54ee669e70b626d9fbc32ce495b2cChristian MaederbasicSpec :: AnnoState.AParser st BASIC_SPEC
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillybasicSpec = fmap Basic_spec (AnnoState.trailingAnnosParser basicItemP)
842ae753ab848a8508c4832ab64296b929167a97Christian Maeder (Lexer.oBraceT >> Lexer.cBraceT >> return (Basic_spec []))
842ae753ab848a8508c4832ab64296b929167a97Christian Maeder-- parser for basic items
842ae753ab848a8508c4832ab64296b929167a97Christian MaederbasicItemP :: AnnoState.AParser st BASIC_ITEM
bcd914850de931848b86d7728192a149f9c0108bChristian Maeder f <- formulaP
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder return $ Axiom_item f
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder do ns <- namesP
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder return $ Decl_item (ns, t)
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder-- parser for all types
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder return $ Pi vs t
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder do t <- type1P
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder (ts, _) <- type1P `Lexer.separatedBy`
bcd914850de931848b86d7728192a149f9c0108bChristian Maeder let xs = t:ts
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder return $ Func (init xs) (last xs)
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian Maeder-- parser for basic types and types enclosed in parentheses
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian Maedertype1P = do AnnoState.asKey "Sort"
fbc0c2baf563fe5b664f0152674a8d3acecca58cAndy Gimblett return $ Univ t
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett do t <- termP
e771539425f4a0abef9f94cf4b63690f3603f682Andy Gimblett return $ Univ t
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder-- parser for terms
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimbletttermP = do f <- nameP
4314e26a12954cb1c9be4dea10aa8103edac5bbbChristian Maeder (as, _) <- termP `Lexer.separatedBy` AnnoState.anComma
842ae753ab848a8508c4832ab64296b929167a97Christian Maeder return $ Appl (Identifier f) as
842ae753ab848a8508c4832ab64296b929167a97Christian Maeder do return $ Identifier f)
842ae753ab848a8508c4832ab64296b929167a97Christian Maeder-- parsers for names
842ae753ab848a8508c4832ab64296b929167a97Christian MaedernameP = Lexer.pToken $ Lexer.reserved reserved Lexer.scanAnyWords
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy GimblettnamesP :: AnnoState.AParser st [NAME]
bb83db66bd9b3b4ce67be66419daf29886175276Andy GimblettnamesP = fmap fst $ nameP `Lexer.separatedBy` AnnoState.anComma
bb83db66bd9b3b4ce67be66419daf29886175276Andy Gimblett-- parser for variable declarations
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian MaedervarP :: AnnoState.AParser st ([NAME], TYPE)
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian MaedervarP = do ns <- namesP
dfc58f5ec6492d1a9b9babd9cdcdbb15baa6e657Christian Maeder return (ns, t)
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'ReillyvarsP :: AnnoState.AParser st [([NAME], TYPE)]
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'ReillyvarsP = do (vs, _) <- varP `Lexer.separatedBy` AnnoState.asKey ";"
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian Maeder-- parser for all formulas
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaederformulaP :: AnnoState.AParser st FORMULA
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian MaederformulaP = forallP
e54c5af823b9775dd2c058185ea5bdf7593950faAndy Gimblett{- parser for equivalences, implications, conjunctions, disjunctions,
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly negations, equalities, atomic formulas, and formulas in parentheses -}
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblettformula1P :: AnnoState.AParser st FORMULA
d326dac41dadbe2b84bb7021cbfd91f4dd4a19bcAndy Gimblettformula1P = do f <- formula2P
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett (-- equivalences
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly g <- formula2P
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly return $ Equivalence f g
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly -- implications
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly g <- formula2P
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly return $ Implication f g
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly -- all other cases
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder{- parser for conjunctions, disjunctions, negations, equalities,
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly atomic formulas, and formulas in parentheses -}
f4a5178450076ee54f3a9adb4f91e241aea3ba75Christian Maederformula2P :: AnnoState.AParser st FORMULA
f4a5178450076ee54f3a9adb4f91e241aea3ba75Christian Maederformula2P = do f <- formula3P
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett (-- conjunctions
d297a45fc73aa6c4a1f9d073c3170611415f324bAndy Gimblett (fs, _) <- formula3P `Lexer.separatedBy`
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder return $ Conjunction (f:fs)
0b8146e4f675518993a34eb2255ad7ddd7bf82a4Christian Maeder -- disjunctions
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly (fs, _) <- formula3P `Lexer.separatedBy`
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly return $ Disjunction (f:fs)
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'Reilly -- all other cases
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'Reilly{- parser for negations, equalities, atomic formulas,
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly and formulas in parentheses -}
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reillyformula3P :: AnnoState.AParser st FORMULA
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reillyformula3P = parenFormulaP
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly-- parser for equalities and predicate formulas
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maederformula4P :: AnnoState.AParser st FORMULA
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maederformula4P = do x <- termP
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder (-- equalities
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly return $ Equality x y
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly -- predicates
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly return (Pred x))
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly-- parser for formulas enclosed in parentheses
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillyparenFormulaP :: AnnoState.AParser st FORMULA
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'ReillyparenFormulaP = do Lexer.oParenT
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly f <- formulaP
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian Maeder-- parser for forall formulas
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian MaederforallP :: AnnoState.AParser st FORMULA
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian MaederforallP = do AnnoState.asKey Keywords.forallS
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder f <- formulaP
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder return $ Forall vs f
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly-- parser for exists formulas
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillyexistsP :: AnnoState.AParser st FORMULA
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly f <- formulaP
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly return $ Exists vs f
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly-- parser for negations
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'ReillynegP :: AnnoState.AParser st FORMULA
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillynegP = do AnnoState.asKey Keywords.negS <|> AnnoState.asKey Keywords.notS
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'Reilly f <- formula3P
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder return $ Negation f
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder-- parser for true
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaedertrueP :: AnnoState.AParser st FORMULA
ad872d5e07383c8fec42bddf02a13d1fbcac52b2Christian Maeder-- parser for false
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'ReillyfalseP :: AnnoState.AParser st FORMULA
7e7d791d2f643ffd82843b78e424b6f9f68c24eeChristian Maeder-- parser for symbol items
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaedersymbItems :: AnnoState.AParser st SYMB_ITEMS
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaedersymbItems = fmap Symb_items namesP
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder-- parser for symbol map items
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian MaedersymbMapItems :: AnnoState.AParser st SYMB_MAP_ITEMS
bcd914850de931848b86d7728192a149f9c0108bChristian MaedersymbMapItems = do (xs, _) <- symbOrMap `Lexer.separatedBy` AnnoState.anComma
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'Reilly return $ Symb_map_items xs
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder-- parser for symbols or symbol maps
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillysymbOrMap :: AnnoState.AParser st SYMB_OR_MAP
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'ReillysymbOrMap = do s <- nameP
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder return $ Symb_map s t
7f24d24e63854a9a2539c2dac55198f746ad57dbChristian Maeder return (Symb s))