1690N/ADescription : ADL syntax parser
1690N/ACopyright : (c) Stef Joosten, Christian Maeder DFKI GmbH 2010
1690N/AMaintainer : Christian.Maeder@dfki.de
1690N/A [ "CONTEXT", "ENDCONTEXT", "EXTENDS"
1690N/A , "SERVICE", "INITIAL", "SQLPLUG", "PHPPLUG"
1690N/A , "UNI", "INJ", "SUR", "TOT", "SYM", "ASY", "TRN", "RFX", "PROP", "ALWAYS"
1690N/A , "RULE", "MAINTAINS", "SIGNALS", "SIGNAL", "ON"
1690N/A , "RELATION", "CONCEPT", "KEY"
1690N/A , "IMPORT", "GEN", "ISA", "I", "V", "S"
2601N/A , "PRAGMA", "EXPLANATION", "EXPLAIN", "IN", "REF", "ENGLISH", "DUTCH"
2601N/A , "ONE", "BIND", "TOPHP", "BINDING"
2601N/A-- | a line comment starts with --. In haskell this may be part of an operator.
2601N/AlineComment :: CharParser st String
2601N/AlineComment = tryString "--" <++> many (noneOf "\n")
2601N/Askip = skipMany $ forget space
2601N/A <|> forget (nestedComment "{-" "-}" <|> lineComment)
2601N/ApChar = alphaNum <|> oneOf "_'"
2601N/ApKeyS :: String -> CharParser st String
2601N/ApKeyS s = try (string s << notFollowedBy pChar) << skip
1690N/ApKey :: String -> CharParser st ()
2601N/ApSymC :: String -> String -> CharParser st String
2601N/ApSymC s cs = try (string s << notFollowedBy (oneOf cs)) << skip
2601N/A-- do not parse a double colon
2601N/ApColon :: CharParser st String
2601N/A-- do not parse --, ->, or -|
2601N/ApMinus :: CharParser st String
2601N/ApSymS :: String -> CharParser st String
2601N/ApSymS s = tryString s << skip
2601N/ApSym :: String -> CharParser st ()
2601N/ApGenParens :: String -> String -> CharParser st a -> CharParser st a
2601N/ApParens :: CharParser st a -> CharParser st a
2601N/ApParens = pGenParens "(" ")"
1690N/ApSqBrackets :: CharParser st a -> CharParser st a
1690N/ApSqBrackets = pGenParens "[" "]"
1690N/ApConid :: CharParser st String
2601N/ApConid = reserved keywordstxt (upper <:> many pChar) << skip
2601N/ApVarid :: CharParser st String
2601N/ApVarid = (lower <:> many pChar) << skip
1690N/ApString :: CharParser st String
2601N/ApString = (stringLit <|> sQuoted) << skip
2601N/ApADLid :: CharParser st String
2601N/ApADLid = pConid <|> pVarid <|> pString
2601N/ApArchitecture :: CharParser st [PatElem]
2601N/ApArchitecture = flat $ many1 pContext
2601N/ApContext :: CharParser st [PatElem]
2601N/ApBind :: CharParser st String
2601N/ApBind = pKey "BIND" >> pDeclaration << pKey "TOPHP" >> (pConid <|> pString)
2601N/ApContextElement :: CharParser st [PatElem]
1690N/A (choice [pObjDef, pDeclaration, pConceptDef, pKeyDef, pExplain])
1690N/A <|> fmap (const []) (pSqlplug <|> pPhpplug
1690N/A <|> (pKey "POPULATION" >> pMorphism << pKey "CONTAINS" >> pContent))
1690N/ApPattern :: CharParser st [PatElem]
1690N/ApPattern = pKey "PATTERN" >> (pConid <|> pString)
1690N/ApPatElem :: CharParser st PatElem
1690N/ApPatElem = pDeclaration <|> fmap Pr pRuleDef
1690N/A <|> pGen <|> fmap (const Ignored)
2601N/A (pConceptDef <|> pKeyDef <|> pExplain)
1690N/ApDeclaration :: CharParser st PatElem
1690N/A n <- try $ pVarid << pSym "::"
1690N/A s <- pSymS "*" <|> pSymS "->"
1690N/A let ps = if s == "->" then [Uni, Tot] else []
1690N/A return $ Pm (ps ++ as) $ Sgn n c1 c2
2601N/ApProps :: CharParser st [Prop]
2601N/A sepBy (choice $ map (\ p -> pKey (showProp p) >> return p) allProps) pComma
2601N/ApPragma :: CharParser st [String]
2601N/ApPragma = pKey "PRAGMA" >> many1 pString
2601N/ApConceptDef :: CharParser st PatElem
2601N/ApKeyDef :: CharParser st PatElem
2601N/A pParens $ sepBy1 pKeyAtt pComma
2601N/ApLabelProps :: CharParser st String
2601N/A optionL $ pGenParens "{" "}" $ sepBy1 pADLid pComma
2601N/ApKeyAtt :: CharParser st Expression
2601N/A optionMaybe $ try pLabelProps
2601N/ApObjDef :: CharParser st PatElem
2601N/ApObjDef = pKey "SERVICE" >> fmap Service pObj
2601N/ApObj :: CharParser st Object
2601N/A as <- optionL (pKey "ALWAYS" >> many pProp')
2601N/A os <- optionL (pEqual >> pSqBrackets (sepBy pObj pComma))
2601N/ApProp' :: CharParser st Prop
2601N/ApProp' = choice $ map (\ p -> pKey (showProp p) >> return p) [Uni, Tot, Prop]
2601N/ApSqlplug :: CharParser st PatElem
2601N/ApSqlplug = pKey "SQLPLUG" >> pObj >> return Ignored
2601N/ApPhpplug :: CharParser st PatElem
2601N/ApPhpplug = pKey "PHPPLUG" >> pObj >> return Ignored
2601N/ApExplain :: CharParser st PatElem
2601N/A [ "CONCEPT", "RELATION", "RULE", "KEY", "SERVICE", "PATTERN"
2601N/A , "POPULATION", "SQLPLUG", "PHPPLUG" ]
2601N/ApLanguageID :: CharParser st String
2601N/ApLanguageID = pKey "IN" >> (pKeyS "DUTCH" <|> pKeyS "ENGLISH")
2601N/ApRefID :: CharParser st String
2601N/ApRefID = optionL $ pKey "REF" >> pString
2601N/ApExpl :: CharParser st String
2601N/ApExpl = nestedComment "{+" "-}"
2601N/ApContent :: CharParser st PatElem
2601N/ApContent = pSqBrackets (sepBy pRecord $ pSym ";") >> return Ignored
2601N/ApRecord :: CharParser st (String, String)
2601N/ApRecord = pParens $ pair pString $ pComma >> pString
2601N/ApRuleDef :: CharParser st Rule
2601N/A r <- option (Truth e1) $ do
2601N/A sym <- choice $ map pSymS ["=", "|-", "-|"]
2601N/A return $ Rule e1 (case sym of
2601N/ApSignalOrAlways :: CharParser st String
2601N/A (pKey "SIGNAL" >> pADLid << pKey "ON")
2601N/A <|> (pKey "RULE" >> pADLid << (pKey "MAINTAINS" <|> pKey "SIGNALS"))
2601N/ApGen :: CharParser st PatElem
2601N/ApTwo :: CharParser st (Concept, Concept)
2601N/ApTwo = option (Anything, Anything)
2601N/ApConcept :: CharParser st Concept
2601N/ApConcept = fmap C $ pConid <|> pString <|> pKeyS "ONE"
2601N/ApMorphism :: CharParser st Expression
2601N/A nm <- pKeyS "I" <|> pKeyS "V" <|> pVarid <|> (sQuoted << skip)
2601N/ApExpr :: CharParser st Expression
2601N/ApExpr = pPrec Fu pFactorI "\\/"
2601N/ApFactorI :: CharParser st Expression
2601N/ApFactorI = pPrec Fi pFactor "/\\"
2601N/ApFactor :: CharParser st Expression
2601N/ApFactor = pPrec Fd pTermD "!"
2601N/ApTermD :: CharParser st Expression
2601N/ApPrec :: MulOp -> CharParser st Expression -> String
2601N/A -> CharParser st Expression
2601N/ApTerm :: CharParser st Expression
2601N/A e <- pParens pExpr <|> pMorphism
2601N/A rs <- many $ choice $ map (pSymS . (: [])) "+*~"
2601N/A let p = foldl (\ r c -> UnExp (case c of
2601N/A _ -> error "pTerm post strings") r) e rs
2601N/A return $ foldl (\ r _ -> UnExp Cp r) p ms