Parse.hs revision 8468244da4da42d99833fd59dc1d00b09275158c
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederModule : $Header$
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederDescription : ADL syntax parser
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederCopyright : (c) Christian Maeder DFKI GmbH 2010
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederMaintainer : Christian.Maeder@dfki.de
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederStability : provisional
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederPortability : portable
30203b61afb4393c8e459470b3a16d1fe26acc7fChristian Maederkeywordstxt :: [String]
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder [ "CONTEXT", "ENDCONTEXT", "EXTENDS"
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder , "PATTERN", "ENDPATTERN"
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder , "SERVICE", "INITIAL", "SQLPLUG", "PHPPLUG"
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder , "POPULATION", "CONTAINS"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder , "UNI", "INJ", "SUR", "TOT", "SYM", "ASY", "TRN", "RFX", "PROP", "ALWAYS"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder , "RULE", "MAINTAINS", "SIGNALS", "SIGNAL", "ON"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder , "RELATION", "CONCEPT", "KEY"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder , "IMPORT", "GEN", "ISA", "I", "V", "S"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder , "PRAGMA", "EXPLANATION", "EXPLAIN", "IN", "REF", "ENGLISH", "DUTCH"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder , "ONE", "BIND", "TOPHP", "BINDING"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maederkeywordsops :: [String]
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder [ "-|", "|-", "-", "->", ">", "=", "~", "+", ";", "!", "*", "::", ":"
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder , "\\/", "/\\", "\\", "/", "<>" ]
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maederspecialchars :: String
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maederspecialchars = "()[].,{}"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maederskip :: CharParser st ()
e05956d1da3c97e4d808926f97c6841c4a561991Christian Maederskip = skipMany $ spaces <|> forget (nestComment <|> lineComment)
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaederpKey :: String -> CharParser st ()
64558a09e6f6b95d2689d02dd5251339f8ac505bChristian MaederpKey = forget . pKeyS
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaederpKeyS :: String -> CharParser st String
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederpKeyS s = try (string s << notFollowedBy letter) << skip
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaederpSym :: String -> CharParser st ()
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpSym = forget . pSymS
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederpSymS :: String -> CharParser st String
8a1f427564a5ae2db32332512237ef645289c34dChristian MaederpSymS s = tryString s << skip
613c474338a210f2aad9817376e5a3ce1fdde886Christian MaederpConid :: CharParser st String
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpConid = reserved keywordstxt (upper <:> many letter) << skip
6e5180855658f12f9059d9041f447bf0935de344Christian MaederpVarid :: CharParser st String
8a1f427564a5ae2db32332512237ef645289c34dChristian MaederpVarid = (lower <:> many letter) << skip
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaederpString :: CharParser st String
64558a09e6f6b95d2689d02dd5251339f8ac505bChristian MaederpString = stringLit <|> charLit
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpADLid :: CharParser st String
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederpADLid = pConid <|> pVarid <|> pString
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederpArchitecture :: CharParser st [PatElem]
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederpArchitecture = flat $ many1 pContext
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederpContext :: CharParser st [PatElem]
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder pKey "CONTEXT"
8a1f427564a5ae2db32332512237ef645289c34dChristian Maeder option () $ do
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder forget $ optionL $ do
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder pKey "BINDING"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder sepBy1 pBind $ pSym ","
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder pKey "EXTENDS"
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder sepBy1 pConid $ pSym ","
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder ps <- many pContextElement
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder pKey "ENDCONTEXT"
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder return $ concat ps
4be371b81d055e03a5946e4ec333613f313d689bChristian MaederpBind :: CharParser st String
4be371b81d055e03a5946e4ec333613f313d689bChristian MaederpBind = pKey "BIND" >> pDeclaration << pKey "TOPHP" >> (pConid <|> pString)
4be371b81d055e03a5946e4ec333613f313d689bChristian MaederpContextElement :: CharParser st [PatElem]
4be371b81d055e03a5946e4ec333613f313d689bChristian MaederpContextElement = pPattern <|> fmap (const [])
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder (pDeclaration <|> pConceptDef <|> pKeyDef
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder <|> pObjDef <|> pSqlplug <|> pPhpplug <|> pExplain
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder <|> (pKey "POPULATION" >> pMorphism << pKey "CONTAINS" >> pContent))
4be371b81d055e03a5946e4ec333613f313d689bChristian MaederpPattern :: CharParser st [PatElem]
4be371b81d055e03a5946e4ec333613f313d689bChristian MaederpPattern = pKey "PATTERN" >> (pConid <|> pString)
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder >> many pPatElem
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder << pKey "ENDPATTERN"
4be371b81d055e03a5946e4ec333613f313d689bChristian MaederpPatElem :: CharParser st PatElem
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederpPatElem = fmap Pr pRuleDef
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder <|> pGen <|> pDeclaration <|> fmap (const Ignored)
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder (pConceptDef <|> pKeyDef <|> pExplain)
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederpDeclaration :: CharParser st PatElem
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederpDeclaration = do
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder c1 <- pConcept
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder s <- pSymS "*" <|> pSymS "->"
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder let ps = if s == "->" then [Uni, Tot] else []
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder c2 <- pConcept
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder as <- optionL pProps
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder optionL pPragma
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian Maeder pKey "EXPLANATION"
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder return $ Pm (ps ++ as) $ Sgn n c1 c2