HToken.hs revision 4e013227ed41ccd2e3d09dd44bedd651e1901f38
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederModule : $Header$
81d182b21020b815887e9057959228546cf61b6bChristian MaederDescription : parsers for HasCASL tokens
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederCopyright : (c) Christian Maeder and Uni Bremen 2002-2004
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian MaederLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederStability : provisional
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederPortability : portable
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maederparser for HasCASL IDs extending "Common.Keywords" and "Common.Token"
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * HasCASL keyword handling
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder-- | HasCASL's reserved symbols in lambda terms and patterns
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maederhascasl_reserved_ops :: [String]
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maederhascasl_reserved_ops =
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder [dotS ++ exMark, cDot ++ exMark, asP, lamS] ++ casl_reserved_ops
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maeder-- | HasCASL's reserved symbols in function types
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maederhascasl_type_ops :: [String]
99f16a0f9ca757410960ff51a79b034503384fe2Christian Maederhascasl_type_ops = [funS, pFun, contFun, pContFun, prodS, timesS, quMark]
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder-- | HasCASL's reserved words
8a1f427564a5ae2db32332512237ef645289c34dChristian Maederhascasl_reserved_words :: [String]
76647324ed70f33b95a881b536d883daccf9568dChristian Maederhascasl_reserved_words =
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder [asS, inS, functS, functS ++ sS, classS, classS ++ "es", instanceS,
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder instanceS ++ sS, programS, programS ++ sS, caseS, ofS, letS,
4e013227ed41ccd2e3d09dd44bedd651e1901f38Christian Maeder derivingS, internalS, whereS] ++ casl_reserved_words
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder-- | HasCASL's identifier words ('scanAnyWords')
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCWords :: GenParser Char st String
76647324ed70f33b95a881b536d883daccf9568dChristian MaederscanHCWords = reserved hascasl_reserved_words scanAnyWords
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder-- | HasCASL's identifier signs ('scanAnySigns')
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCSigns :: GenParser Char st String
76647324ed70f33b95a881b536d883daccf9568dChristian MaederscanHCSigns = reserved hascasl_reserved_ops scanAnySigns
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * HasCASL 'Id' parsers
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | non-type variables ('lessS' additionally excluded)
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maedervar :: GenParser Char st Id
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maedervar = fmap mkId (start (lessS : hascasl_reserved_ops, hascasl_reserved_words))
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | the HasCASL keys for 'mixId'
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys :: ([String], [String])
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys = (hascasl_reserved_ops, hascasl_reserved_words)
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder-- | if-then-else-identifier
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maederite :: GenParser Char st [Token]
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder i <- pToken $ keyWord $ string ifS
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder t <- pToken $ keyWord $ string thenS
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder let ts = [i, p , t]
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder es <- option ts $ try $ do
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder e <- pToken $ keyWord $ string elseS
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder return $ ts ++ [q, e]
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder option es $ do
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder return $ es ++ [r]
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | operation 'Id' (reserved stuff excluded)
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian MaederopId :: GenParser Char st Id
ac9e33c3c35b2663e5cb76483228910f142d9576Christian MaederopId = mixId hcKeys hcKeys <?> "id"
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | constructor 'Id' ('barS' additionally excluded)
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederhconsId :: GenParser Char st Id
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian MaederhconsId = mixId (barS:hascasl_reserved_ops, hascasl_reserved_words) hcKeys
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | simple 'Id' without compound list (only a words)
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaedertypeVar :: GenParser Char st Id
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian MaedertypeVar = fmap (mkId . (: [])) $ pToken scanHCWords
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | simple 'Id' possibly with compound list
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederclassId :: GenParser Char st Id
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder s <- pToken scanHCWords
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder (c, p) <- option ([], nullRange) $ comps hcKeys
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder return $ Id [s] c p