HToken.hs revision 6e5180855658f12f9059d9041f447bf0935de344
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
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maedermodule HToken where
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
1d330b771706686190ad2f3711ec5769c555c708Christian Maederimport Id
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maederimport Keywords
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maederimport Lexer
737526b54e46fa1a76c4b5e793124ee765adef6cChristian Maederimport Token(casl_reserved_ops, casl_reserved_words
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder , formula_words, formula_ops, start, mixId)
1d330b771706686190ad2f3711ec5769c555c708Christian Maederimport Parsec
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- further hascasl keyword
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederassignS = ":="
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederminusS = "-"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederplusS = "+"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpFun = funS ++ quMark
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaedercontFun = minusS ++ funS
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederpContFun = minusS ++ pFun
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian MaederlamS = "\\"
1d330b771706686190ad2f3711ec5769c555c708Christian MaederasP = "@"
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
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-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maederhascasl_reserved_ops = [dotS++exMark, cDot++exMark, asP, assignS, lamS]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maeder ++ casl_reserved_ops
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
6e5180855658f12f9059d9041f447bf0935de344Christian Maederhascasl_reserved_fops = formula_ops ++ hascasl_reserved_ops
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder
16060a5c23e794535eb1e7aa62ec4c370f0bff6aChristian Maederhascasl_type_ops = [funS, pFun, contFun, pContFun, prodS, timesS, quMark,
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maeder lessS]
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
e05956d1da3c97e4d808926f97c6841c4a561991Christian Maederhascasl_reserved_words =
c0467970183fa3dc894edea3caf9ca05d3a09fa8Christian Maeder [classS, instanceS, programS, caseS, ofS, letS, derivingS]
613c474338a210f2aad9817376e5a3ce1fdde886Christian Maeder ++ casl_reserved_words
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
6e5180855658f12f9059d9041f447bf0935de344Christian Maederhascasl_reserved_fwords = formula_words ++ hascasl_reserved_words
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
6e5180855658f12f9059d9041f447bf0935de344Christian MaederscanWords = reserved hascasl_reserved_fwords scanAnyWords
6e5180855658f12f9059d9041f447bf0935de344Christian MaederscanTermWords = reserved hascasl_reserved_words scanAnyWords
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
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
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 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
b475a916d62584a2af5f51749240db7a5f0c8b82Christian Maederbrackets parser k = bracketParser parser oBracketT cBracketT commaT k
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- mixIds
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- allow type_ops as op_symbols (like "*")
6e5180855658f12f9059d9041f447bf0935de344Christian MaederuninstOpName = mixId (hascasl_reserved_fwords, hascasl_reserved_fops)
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder (hascasl_reserved_fwords, hascasl_reserved_fops)
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder-- prohibit type_ops on the top-level
6e5180855658f12f9059d9041f447bf0935de344Christian MaedertypeName = mixId (hascasl_reserved_fwords,
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder hascasl_type_ops ++ hascasl_reserved_fops)
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder (hascasl_reserved_fwords, hascasl_reserved_fops)
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
1d330b771706686190ad2f3711ec5769c555c708Christian Maeder-- TYPE-VAR Ids
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- ----------------------------------------------
6e5180855658f12f9059d9041f447bf0935de344Christian Maeder
568a1ce407fd05a2007c5db3c5c57098bf13997fChristian Maeder-- no compound ids (just a word)
b475a916d62584a2af5f51749240db7a5f0c8b82Christian MaedertypeVar :: GenParser Char st Token
b475a916d62584a2af5f51749240db7a5f0c8b82Christian MaedertypeVar = pToken scanWords
375dbb1a6d9b4cd2758c6a25ac526267970437b1Christian Maeder
b475a916d62584a2af5f51749240db7a5f0c8b82Christian MaederclassName = typeVar