HToken.hs revision 8a1f427564a5ae2db32332512237ef645289c34d
f11f713bebd8e1e623a0a4361065df256033de47Christian Maeder Authors: Christian Maeder
3f69b6948966979163bdfe8331c38833d5d90ecdChristian Maeder parser for HasCASL IDs
967e5f3c25249c779575864692935627004d3f9eChristian Maeder adapted from HetCATS/CASL/Token.hs, v 1.9
717686b54b9650402e2ebfbaadf433eab8ba5171Christian Maedermodule HToken where
967e5f3c25249c779575864692935627004d3f9eChristian Maederimport Keywords
967e5f3c25249c779575864692935627004d3f9eChristian Maederimport Token(casl_reserved_ops, casl_reserved_words
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian Maeder , start, mixId)
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder-- ----------------------------------------------
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder-- further hascasl keyword
ac19f8695aa1b2d2d1cd1319da2530edd8f46a96Christian Maeder-- ----------------------------------------------
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian MaederassignS, minusS, plusS, pFun, contFun, pContFun, lamS, asP :: String
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian MaederassignS = ":="
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaederpFun = funS ++ quMark
fd896e2068ad7e50aed66ac18c3720ea7ff2619fChristian MaedercontFun = minusS ++ funS
967e5f3c25249c779575864692935627004d3f9eChristian MaederpContFun = minusS ++ pFun
717686b54b9650402e2ebfbaadf433eab8ba5171Christian MaederclassS, programS, instanceS, caseS, ofS, letS, derivingS :: String
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian MaederclassS = "class"
a95f5379cabb30d3beb0545002cf50e9e4fc2c86Christian MaederprogramS = "program"
967e5f3c25249c779575864692935627004d3f9eChristian MaederinstanceS = "instance"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaedercaseS = "case"
551af0e4ba6d96bb24f3555f3b30ed648e22e34aChristian MaederderivingS = "deriving"
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 Maederhascasl_type_ops = [funS, pFun, contFun, pContFun, prodS, timesS, quMark]
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maederhascasl_reserved_words :: [String]
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maederhascasl_reserved_words =
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder [classS, instanceS, programS, caseS, ofS, letS, derivingS]
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder ++ casl_reserved_words
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)
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maedervar :: GenParser Char st Id
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maedervar = fmap (\l -> Id l [] []) (start hcKeys)
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 MaederbracketParser parser op cl sep k =
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder (ts, ps) <- option ([], [])
67d92da5e9610aabad39055a16031154b4dc3748Christian Maeder (parser `separatedBy` sep)
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder return (k ts (toPos o ps c))
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 MaederhcMixId, uninstOpId, typeId :: GenParser Char st Id
a89389521ddf76109168a0b339031575aafbd512Christian MaederhcMixId = mixId hcKeys hcKeys
a89389521ddf76109168a0b339031575aafbd512Christian MaederuninstOpId = hcMixId
a89389521ddf76109168a0b339031575aafbd512Christian MaedertypeId = hcMixId
a89389521ddf76109168a0b339031575aafbd512Christian Maeder-- ----------------------------------------------
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- TYPE-VAR Ids
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- ----------------------------------------------
1a75698c909ad515d59c76e65bd783f015c21c4dChristian Maeder-- no compound ids (just a word)
1a75698c909ad515d59c76e65bd783f015c21c4dChristian MaedertypeVar :: GenParser Char st Token
67d92da5e9610aabad39055a16031154b4dc3748Christian MaedertypeVar = pToken scanWords
e1839fb37a3a2ccd457464cb0dcc5efd466dbe22Christian Maeder-- simple id with compound list
67d92da5e9610aabad39055a16031154b4dc3748Christian MaederclassId :: GenParser Char st Id
51fb5d7edd9369c367dda2f8b15ddd6f8a146606Christian Maeder do s <- typeVar
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder (c, p) <- option ([], []) $ brackets hcMixId (,)
ee93fb771fcf3000d73c8e2f2000adb4b9a5158cChristian Maeder return (Id [s] c p)