HToken.hs revision 7c57322afb6342e5cc8b1fdc96050b707407fc61
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder Authors: Christian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder parser for HasCASL IDs
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder adapted from HetCATS/CASL/Token.hs, v 1.9
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maedermodule HToken where
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maederimport Keywords
737526b54e46fa1a76c4b5e793124ee765adef6cChristian Maederimport Token(casl_reserved_ops, casl_reserved_words
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder , formula_words, formula_ops, start, mixId)
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- further hascasl keyword
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian MaederassignS, minusS, plusS, pFun, contFun, pContFun, lamS, asP :: String
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederassignS = ":="
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpFun = funS ++ quMark
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaedercontFun = minusS ++ funS
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpContFun = minusS ++ pFun
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian MaederclassS, programS, instanceS, caseS, ofS, letS, derivingS :: String
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederclassS = "class"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederprogramS = "program"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederinstanceS = "instance"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaedercaseS = "case"
fe883661c9d1a5a8b42ac4e8673ec133d9dad354Christian MaederderivingS = "deriving"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- hascasl keyword handling
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maederhascasl_reserved_ops, hascasl_reserved_fops, hascasl_type_ops :: [String]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maederhascasl_reserved_ops = [dotS++exMark, cDot++exMark, asP, assignS, lamS]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maeder ++ casl_reserved_ops
6e5180855658f12f9059d9041f447bf0935de344Christian Maederhascasl_reserved_fops = formula_ops ++ hascasl_reserved_ops
16060a5c23e794535eb1e7aa62ec4c370f0bff6aChristian Maederhascasl_type_ops = [funS, pFun, contFun, pContFun, prodS, timesS, quMark,
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maederhascasl_reserved_words, hascasl_reserved_fwords :: [String]
e05956d1da3c97e4d808926f97c6841c4a561991Christian Maederhascasl_reserved_words =
c0467970183fa3dc894edea3caf9ca05d3a09fa8Christian Maeder [classS, instanceS, programS, caseS, ofS, letS, derivingS]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maeder ++ casl_reserved_words
6e5180855658f12f9059d9041f447bf0935de344Christian Maederhascasl_reserved_fwords = formula_words ++ hascasl_reserved_words
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian MaederscanWords, scanTermWords :: GenParser Char st String
6e5180855658f12f9059d9041f447bf0935de344Christian MaederscanWords = reserved hascasl_reserved_fwords scanAnyWords
6e5180855658f12f9059d9041f447bf0935de344Christian MaederscanTermWords = reserved hascasl_reserved_words scanAnyWords
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- ----------------------------------------------
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- non-compound mixfix ids (variables)
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- ----------------------------------------------
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maedervar :: GenParser Char st Id
6e5180855658f12f9059d9041f447bf0935de344Christian Maedervar = fmap (\l -> Id l [] []) (start (hascasl_reserved_fwords,
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder hascasl_reserved_ops))
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder-- ----------------------------------------------
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- bracketed lists
b475a916d62584a2af5f51749240db7a5f0c8b82Christian 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 MaederbracketParser parser op cl sep k =
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder (ts, ps) <- option ([], [])
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder (parser `separatedBy` sep)
9e5221faf8ff37ebdac127972874fccd378ccbe0Christian Maeder return (k ts (toPos o ps c))
c4e912fc181d72c8d0e0e38d0351278182f0d0b5Christian Maederbrackets :: GenParser Char st a -> ([a] -> [Pos] -> b) -> GenParser Char st b
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maederbrackets parser k = bracketParser parser oBracketT cBracketT commaT k
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- allow type_ops as op_symbols (like "*")
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederuninstOpId, typeId :: GenParser Char st Id
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederuninstOpId = mixId (hascasl_reserved_fops, hascasl_reserved_fwords)
e9eabfa1c01c628c09220b942fbde7c0effc3e80Christian Maeder (hascasl_reserved_fops, hascasl_reserved_fwords)
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- prohibit type_ops on the top-level
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaedertypeId = mixId (hascasl_type_ops ++ hascasl_reserved_fops,
e9eabfa1c01c628c09220b942fbde7c0effc3e80Christian Maeder hascasl_reserved_fwords)
e9eabfa1c01c628c09220b942fbde7c0effc3e80Christian Maeder (hascasl_reserved_fops, hascasl_reserved_fwords)
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
1d330b771706686190ad2f3711ec5769c555c708Christian Maeder-- TYPE-VAR Ids
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- no compound ids (just a word)
7c56ba9d3d481421a827c947233e669059056ca3Christian MaedertypeVar :: GenParser Char st Token
b475a916d62584a2af5f51749240db7a5f0c8b82Christian MaedertypeVar = pToken scanWords
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian MaederclassId :: GenParser Char st Id
7c56ba9d3d481421a827c947233e669059056ca3Christian Maeder do s <- typeVar
7c57322afb6342e5cc8b1fdc96050b707407fc61Christian Maeder (c, p) <- option ([], []) $ brackets typeId (,)
7c56ba9d3d481421a827c947233e669059056ca3Christian Maeder return (Id [s] c p)