HToken.hs revision 76fa667489c5e0868ac68de9f0253ac10f73d0b5
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian Maeder{- |
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederModule : $Header$
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederCopyright : (c) Christian Maeder and Uni Bremen 2002-2004
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederLicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian Maeder
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederMaintainer : hets@tzi.de
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederStability : provisional
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian MaederPortability : portable
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder parser for HasCASL IDs
076b559b2ea7b2f1d303df992ae71cd6c6fe563cChristian Maeder 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
30203b61afb4393c8e459470b3a16d1fe26acc7fChristian Maederimport Common.Lib.Parsec
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * further HasCASL key signs
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maeder
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian MaederassignS, minusS, plusS, pFun, contFun, pContFun, lamS, asP :: String
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederassignS = ":="
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederminusS = "-"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederplusS = "+"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpFun = funS ++ quMark
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaedercontFun = minusS ++ funS
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpContFun = minusS ++ pFun
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederlamS = "\\"
1d330b771706686190ad2f3711ec5769c555c708Christian MaederasP = "@"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * further HasCASL keywords
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaederinternalS, classS, programS, instanceS, caseS, ofS, letS, derivingS :: String
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederclassS = "class"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederprogramS = "program"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederinstanceS = "instance"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaedercaseS = "case"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederofS = "of"
e05956d1da3c97e4d808926f97c6841c4a561991Christian MaederletS = "let"
fe883661c9d1a5a8b42ac4e8673ec133d9dad354Christian MaederderivingS = "deriving"
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaederinternalS = "internal"
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | the new keyword fun ('funS' is already defined differently)
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederfunctS :: String
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian MaederfunctS = "fun"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * HasCASL keyword handling
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
8a1f427564a5ae2db32332512237ef645289c34dChristian Maederhascasl_reserved_ops, hascasl_type_ops :: [String]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maederhascasl_reserved_ops = [dotS++exMark, cDot++exMark, asP, assignS, lamS]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maeder ++ casl_reserved_ops
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
8a1f427564a5ae2db32332512237ef645289c34dChristian Maederhascasl_type_ops = [funS, pFun, contFun, pContFun, prodS, timesS, quMark]
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder
8a1f427564a5ae2db32332512237ef645289c34dChristian Maederhascasl_reserved_words :: [String]
e05956d1da3c97e4d808926f97c6841c4a561991Christian Maederhascasl_reserved_words =
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder [functS, functS ++ sS, classS, classS ++ "es", instanceS, instanceS ++ sS,
c18e9c3c6d5039618f1f2c05526ece84c7794ea3Christian Maeder programS, programS ++ sS, caseS, ofS, letS, derivingS, internalS]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maeder ++ casl_reserved_words
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder-- | HasCASL identifier words ('scanAnyWords')
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCWords :: GenParser Char st String
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCWords = reserved hascasl_reserved_words scanAnyWords
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder-- | HasCASL identifier signs ('scanAnySigns')
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCSigns :: GenParser Char st String
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaederscanHCSigns = reserved hascasl_reserved_ops scanAnySigns
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- * HasCASL 'Id' parsers
8a1f427564a5ae2db32332512237ef645289c34dChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | non-type variables ('lessS' additionally excluded)
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maedervar :: GenParser Char st Id
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maedervar = fmap (\l -> Id l [] []) (start (lessS : hascasl_reserved_ops,
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder hascasl_reserved_words))
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | the HasCASL keys for 'mixId'
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys :: ([String], [String])
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys = (hascasl_reserved_ops, hascasl_reserved_words)
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | operation 'Id' (reserved stuff excluded)
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederuninstOpId :: GenParser Char st Id
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederuninstOpId = mixId hcKeys hcKeys
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | constructor 'Id' ('barS' additionally excluded)
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaederhconsId :: GenParser Char st Id
37bd4066d4a1d6bf8126681f920165aa9a873d91Christian MaederhconsId = mixId (barS:hascasl_reserved_ops, hascasl_reserved_words)
31242f7541fd6ef179e4eb5be7522ddf54ae397bChristian Maeder hcKeys
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | mixfix and compound type 'Id' (more signs excluded)
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaedertypeId :: GenParser Char st Id
ac510075311023bf24175f7a76b89ec2bbda0626Christian MaedertypeId = mixId (lessS:equalS:barS:hascasl_type_ops++hascasl_reserved_ops,
37bd4066d4a1d6bf8126681f920165aa9a873d91Christian Maeder hascasl_reserved_words) hcKeys
37bd4066d4a1d6bf8126681f920165aa9a873d91Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | simple 'Id' without compound list (only a words)
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaedertypeVar :: GenParser Char st Id
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian MaedertypeVar = do s <- pToken scanHCWords
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder return $ Id [s] [] []
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder-- | simple 'Id' possibly with compound list
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederclassId :: GenParser Char st Id
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederclassId =
76fa667489c5e0868ac68de9f0253ac10f73d0b5Christian Maeder do s <- pToken scanHCWords
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder (c, p) <- option ([], []) $ comps hcKeys
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder return $ Id [s] c p
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder
ac510075311023bf24175f7a76b89ec2bbda0626Christian Maeder