HToken.hs revision e8ffec0fa3d3061061bdc16e44247b9cf96b050f
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder{- HetCATS/HasCASL/HToken.hs
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder $Id$
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder Authors: Christian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder Year: 2002
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder parser for HasCASL IDs
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder adapted from HetCATS/CASL/Token.hs, v 1.9
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-}
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maedermodule HasCASL.HToken where
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Id
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Keywords
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Lexer
e8ffec0fa3d3061061bdc16e44247b9cf96b050fChristian Maederimport Common.Token(casl_reserved_ops, casl_reserved_words
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder , start, comps, mixId)
30203b61afb4393c8e459470b3a16d1fe26acc7fChristian Maederimport Common.Lib.Parsec
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- further hascasl keyword
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
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
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian MaederclassS, 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"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- hascasl keyword handling
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian 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 =
c0467970183fa3dc894edea3caf9ca05d3a09fa8Christian Maeder [classS, instanceS, programS, caseS, ofS, letS, derivingS]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maeder ++ casl_reserved_words
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
8a1f427564a5ae2db32332512237ef645289c34dChristian MaederscanWords, scanSigns :: GenParser Char st String
8a1f427564a5ae2db32332512237ef645289c34dChristian MaederscanWords = reserved hascasl_reserved_words scanAnyWords
8a1f427564a5ae2db32332512237ef645289c34dChristian MaederscanSigns = reserved hascasl_reserved_ops scanAnySigns
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- ----------------------------------------------
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- non-compound mixfix ids (variables)
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- ----------------------------------------------
8a1f427564a5ae2db32332512237ef645289c34dChristian Maeder
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederrestrictedVar :: [String] -> GenParser Char st Id
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederrestrictedVar ops = fmap (\l -> Id l [] [])
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder (start (ops ++ hascasl_reserved_ops,
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder hascasl_reserved_words))
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maedervar :: GenParser Char st Id
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maedervar = restrictedVar []
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- ----------------------------------------------
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- bracketed lists
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- ----------------------------------------------
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder
b475a916d62584a2af5f51749240db7a5f0c8b82Christian MaederbracketParser :: GenParser Char st a -> GenParser Char st Token
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder -> GenParser Char st Token -> GenParser Char st Token
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder -> ([a] -> [Pos] -> b) -> GenParser Char st b
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder
b475a916d62584a2af5f51749240db7a5f0c8b82Christian MaederbracketParser parser op cl sep k =
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder do o <- op
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder (ts, ps) <- option ([], [])
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder (parser `separatedBy` sep)
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder c <- cl
9e5221faf8ff37ebdac127972874fccd378ccbe0Christian Maeder return (k ts (toPos o ps c))
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder
2f98027959ced502c0332e557618b42e41a2504aChristian MaedermkBrackets :: GenParser Char st a -> ([a] -> [Pos] -> b) -> GenParser Char st b
2f98027959ced502c0332e557618b42e41a2504aChristian MaedermkBrackets parser k = bracketParser parser oBracketT cBracketT commaT k
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- mixIds
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys :: ([String], [String])
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederhcKeys = (hascasl_reserved_ops, hascasl_reserved_words)
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederuninstOpId, typeId :: GenParser Char st Id
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaederuninstOpId = mixId hcKeys hcKeys
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaedertypeId = mixId (lessS:hascasl_reserved_ops, hascasl_reserved_words) hcKeys
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
1d330b771706686190ad2f3711ec5769c555c708Christian Maeder-- TYPE-VAR Ids
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder-- no compound ids
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaedertypeVar :: GenParser Char st Id
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian MaedertypeVar = restrictedVar [lessS]
375dbb1a6d9b4cd2758c6a25ac526267970437b1Christian Maeder
8a1f427564a5ae2db32332512237ef645289c34dChristian Maeder-- simple id with compound list
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederclassId :: GenParser Char st Id
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederclassId =
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder do s <- pToken scanWords
fd5d3885a092ac0727fa2436cdfc3b248318ebd8Christian Maeder (c, p) <- option ([], []) $ comps hcKeys
7c56ba9d3d481421a827c947233e669059056ca3Christian Maeder return (Id [s] c p)