HToken.hs revision 8a1f427564a5ae2db32332512237ef645289c34d
967e5f3c25249c779575864692935627004d3f9eChristian Maeder
967e5f3c25249c779575864692935627004d3f9eChristian Maeder{- HetCATS/HasCASL/HToken.hs
81d182b21020b815887e9057959228546cf61b6bChristian Maeder $Id$
f11f713bebd8e1e623a0a4361065df256033de47Christian Maeder Authors: Christian Maeder
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder Year: 2002
967e5f3c25249c779575864692935627004d3f9eChristian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maeder parser for HasCASL IDs
967e5f3c25249c779575864692935627004d3f9eChristian Maeder adapted from HetCATS/CASL/Token.hs, v 1.9
89054b2b95a3f92e78324dc852f3d34704e2ca49Christian Maeder-}
f3a94a197960e548ecd6520bb768cb0d547457bbChristian Maeder
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maedermodule HToken where
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maeder
967e5f3c25249c779575864692935627004d3f9eChristian Maederimport Id
967e5f3c25249c779575864692935627004d3f9eChristian Maederimport Keywords
967e5f3c25249c779575864692935627004d3f9eChristian Maederimport Lexer
967e5f3c25249c779575864692935627004d3f9eChristian Maederimport Token(casl_reserved_ops, casl_reserved_words
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder , start, mixId)
7221c71b38c871ce66eee4537cb681d468308dfbChristian Maederimport Parsec
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder-- ----------------------------------------------
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder-- further hascasl keyword
ac19f8695aa1b2d2d1cd1319da2530edd8f46a96Christian Maeder-- ----------------------------------------------
8b9fda012e5ee53b7b2320c0638896a0ff6e99f3Christian Maeder
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian MaederassignS, minusS, plusS, pFun, contFun, pContFun, lamS, asP :: String
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian MaederassignS = ":="
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian MaederminusS = "-"
4ef2a978e66e2246ff0b7f00c77deb7aabb28b8eChristian MaederplusS = "+"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaederpFun = funS ++ quMark
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian MaedercontFun = minusS ++ funS
967e5f3c25249c779575864692935627004d3f9eChristian MaederpContFun = minusS ++ pFun
ad187062b0009820118c1b773a232e29b879a2faChristian MaederlamS = "\\"
ad270004874ce1d0697fb30d7309f180553bb315Christian MaederasP = "@"
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder
717686b54b9650402e2ebfbaadf433eab8ba5171Christian MaederclassS, programS, instanceS, caseS, ofS, letS, derivingS :: String
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian MaederclassS = "class"
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian MaederprogramS = "program"
967e5f3c25249c779575864692935627004d3f9eChristian MaederinstanceS = "instance"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaedercaseS = "case"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaederofS = "of"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaederletS = "let"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaederderivingS = "deriving"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder-- ----------------------------------------------
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder-- hascasl keyword handling
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian Maeder-- ----------------------------------------------
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederhascasl_reserved_ops, hascasl_type_ops :: [String]
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederhascasl_reserved_ops = [dotS++exMark, cDot++exMark, asP, assignS, lamS]
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maeder ++ casl_reserved_ops
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederhascasl_type_ops = [funS, pFun, contFun, pContFun, prodS, timesS, quMark]
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maederhascasl_reserved_words :: [String]
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederhascasl_reserved_words =
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder [classS, instanceS, programS, caseS, ofS, letS, derivingS]
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ++ casl_reserved_words
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder
67d92da5e9610aabad39055a16031154b4dc3748Christian MaederscanWords, scanSigns :: GenParser Char st String
67d92da5e9610aabad39055a16031154b4dc3748Christian MaederscanWords = reserved hascasl_reserved_words scanAnyWords
67d92da5e9610aabad39055a16031154b4dc3748Christian MaederscanSigns = reserved hascasl_reserved_ops scanAnySigns
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder-- ----------------------------------------------
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder-- non-compound mixfix ids (variables)
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder-- ----------------------------------------------
67d92da5e9610aabad39055a16031154b4dc3748Christian MaederhcKeys :: ([String], [String])
67d92da5e9610aabad39055a16031154b4dc3748Christian MaederhcKeys = (hascasl_reserved_ops, hascasl_reserved_words)
7a879b08ae0ca30006f9be887a73212b07f10204Christian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maedervar :: GenParser Char st Id
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maedervar = fmap (\l -> Id l [] []) (start hcKeys)
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- ----------------------------------------------
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder-- bracketed lists
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- ----------------------------------------------
1a75698c909ad515d59c76e65bd783f015c21c4dChristian MaederbracketParser :: GenParser Char st a -> GenParser Char st Token
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder -> GenParser Char st Token -> GenParser Char st Token
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder -> ([a] -> [Pos] -> b) -> GenParser Char st b
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian MaederbracketParser parser op cl sep k =
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder do o <- op
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder (ts, ps) <- option ([], [])
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder (parser `separatedBy` sep)
7a879b08ae0ca30006f9be887a73212b07f10204Christian Maeder c <- cl
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder return (k ts (toPos o ps c))
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian Maederbrackets :: GenParser Char st a -> ([a] -> [Pos] -> b) -> GenParser Char st b
a89389521ddf76109168a0b339031575aafbd512Christian Maederbrackets parser k = bracketParser parser oBracketT cBracketT commaT k
a89389521ddf76109168a0b339031575aafbd512Christian Maeder
a89389521ddf76109168a0b339031575aafbd512Christian Maeder-- ----------------------------------------------
a89389521ddf76109168a0b339031575aafbd512Christian Maeder-- mixIds
a89389521ddf76109168a0b339031575aafbd512Christian Maeder-- ----------------------------------------------
a89389521ddf76109168a0b339031575aafbd512Christian Maeder
a89389521ddf76109168a0b339031575aafbd512Christian MaederhcMixId, uninstOpId, typeId :: GenParser Char st Id
a89389521ddf76109168a0b339031575aafbd512Christian MaederhcMixId = mixId hcKeys hcKeys
a89389521ddf76109168a0b339031575aafbd512Christian MaederuninstOpId = hcMixId
a89389521ddf76109168a0b339031575aafbd512Christian MaedertypeId = hcMixId
a89389521ddf76109168a0b339031575aafbd512Christian Maeder
a89389521ddf76109168a0b339031575aafbd512Christian Maeder-- ----------------------------------------------
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- TYPE-VAR Ids
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- ----------------------------------------------
a89389521ddf76109168a0b339031575aafbd512Christian Maeder
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- no compound ids (just a word)
1a75698c909ad515d59c76e65bd783f015c21c4dChristian MaedertypeVar :: GenParser Char st Token
67d92da5e9610aabad39055a16031154b4dc3748Christian MaedertypeVar = pToken scanWords
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maeder
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian Maeder-- simple id with compound list
67d92da5e9610aabad39055a16031154b4dc3748Christian MaederclassId :: GenParser Char st Id
b66eb6038bfbcd2fe520d87c151bb4f1f510e985Christian MaederclassId =
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maeder do s <- typeVar
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder (c, p) <- option ([], []) $ brackets hcMixId (,)
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder return (Id [s] c p)
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder