HToken.hs revision 529f678f015ae5276f87da63114cdce750b366ae
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian Maeder{- |
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
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian MaederMaintainer : Christian.Maeder@dfki.de
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederStability : provisional
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederPortability : portable
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maederparser for HasCASL IDs extending "Common.Keywords" and "Common.Token"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-}
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maedermodule HasCASL.HToken where
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Id
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Keywords
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Lexer
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian Maederimport Common.Token
35db0960aa2e2a13652381c756fae5fb2b27213bChristian Maederimport Text.ParserCombinators.Parsec
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * HasCASL keyword handling
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
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
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
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]
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder
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
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder-- | HasCASL's identifier words ('scanAnyWords')
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCWords :: GenParser Char st String
76647324ed70f33b95a881b536d883daccf9568dChristian MaederscanHCWords = reserved hascasl_reserved_words scanAnyWords
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder-- | HasCASL's identifier signs ('scanAnySigns')
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCSigns :: GenParser Char st String
76647324ed70f33b95a881b536d883daccf9568dChristian MaederscanHCSigns = reserved hascasl_reserved_ops scanAnySigns
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder
529f678f015ae5276f87da63114cdce750b366aeChristian Maeder-- | symbols illegal in types and variables
529f678f015ae5276f87da63114cdce750b366aeChristian Maederhascasl_reserved_tops :: [String]
529f678f015ae5276f87da63114cdce750b366aeChristian Maederhascasl_reserved_tops = assignS : lessS : barS : formula_ops
529f678f015ae5276f87da63114cdce750b366aeChristian Maeder
529f678f015ae5276f87da63114cdce750b366aeChristian Maeder-- | symbols illegal in types, variables and constructors
529f678f015ae5276f87da63114cdce750b366aeChristian MaederhcKeysFew :: ([String], [String])
529f678f015ae5276f87da63114cdce750b366aeChristian MaederhcKeysFew =
529f678f015ae5276f87da63114cdce750b366aeChristian Maeder (hascasl_reserved_tops ++ hascasl_reserved_ops, hascasl_reserved_words)
529f678f015ae5276f87da63114cdce750b366aeChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * HasCASL 'Id' parsers
8a1f427564a5ae2db32332512237ef645289c34dChristian Maeder
529f678f015ae5276f87da63114cdce750b366aeChristian Maeder-- | non-type variables
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maedervar :: GenParser Char st Id
529f678f015ae5276f87da63114cdce750b366aeChristian Maedervar = fmap mkId $ start hcKeysFew
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | the HasCASL keys for 'mixId'
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys :: ([String], [String])
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys = (hascasl_reserved_ops, hascasl_reserved_words)
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder-- | if-then-else-identifier
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maederite :: GenParser Char st [Token]
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maederite = do
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder i <- pToken $ keyWord $ string ifS
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder p <- placeT
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder t <- pToken $ keyWord $ string thenS
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder let ts = [i, p , t]
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder es <- option ts $ try $ do
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder q <- placeT
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder e <- pToken $ keyWord $ string elseS
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder return $ ts ++ [q, e]
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder option es $ do
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder r <- placeT
ac9e33c3c35b2663e5cb76483228910f142d9576Christian Maeder return $ es ++ [r]
4be371b81d055e03a5946e4ec333613f313d689bChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | operation 'Id' (reserved stuff excluded)
7de39d39bc1700cc8a9bb9df90b920aad9e18d4aChristian MaederopId :: GenParser Char st Id
ac9e33c3c35b2663e5cb76483228910f142d9576Christian MaederopId = mixId hcKeys hcKeys <?> "id"
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
529f678f015ae5276f87da63114cdce750b366aeChristian Maeder-- | constructor 'Id'
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederhconsId :: GenParser Char st Id
529f678f015ae5276f87da63114cdce750b366aeChristian MaederhconsId = mixId hcKeysFew hcKeys
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | simple 'Id' without compound list (only a words)
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaedertypeVar :: GenParser Char st Id
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian MaedertypeVar = fmap (mkId . (: [])) $ pToken scanHCWords
76647324ed70f33b95a881b536d883daccf9568dChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | simple 'Id' possibly with compound list
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederclassId :: GenParser Char st Id
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian MaederclassId = do
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder s <- pToken scanHCWords
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder (c, p) <- option ([], nullRange) $ comps hcKeys
5b1f1d57c75562a7af79e8256f4afa07febe921bChristian Maeder return $ Id [s] c p