HToken.hs revision 31242f7541fd6ef179e4eb5be7522ddf54ae397b
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari Authors: Christian Maeder
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari parser for HasCASL IDs
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari adapted from HetCATS/CASL/Token.hs, v 1.9
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegariimport Common.Token(casl_reserved_ops, casl_reserved_words
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari , start, comps, mixId)
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari-- ----------------------------------------------
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari-- further hascasl keyword
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder-- ----------------------------------------------
d3d15411081a9ac4a84d409079153135bb30442aDaniel CalegariassignS, minusS, plusS, pFun, contFun, pContFun, lamS, asP :: String
d3d15411081a9ac4a84d409079153135bb30442aDaniel CalegariassignS = ":="
1a38107941725211e7c3f051f7a8f5e12199f03acmaederminusS = "-"
a58d43a4b2864a25ab74b96758fb9d98f18eeed7Daniel CalegaripFun = funS ++ quMark
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegaricontFun = minusS ++ funS
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegaripContFun = minusS ++ pFun
1a38107941725211e7c3f051f7a8f5e12199f03acmaederclassS, programS, instanceS, caseS, ofS, letS, derivingS :: String
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegariclassS = "class"
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegariprogramS = "program"
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegariinstanceS = "instance"
a58d43a4b2864a25ab74b96758fb9d98f18eeed7Daniel CalegaricaseS = "case"
d3d15411081a9ac4a84d409079153135bb30442aDaniel CalegariderivingS = "deriving"
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari-- ----------------------------------------------
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari-- hascasl keyword handling
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari-- ----------------------------------------------
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegarihascasl_reserved_ops, hascasl_type_ops :: [String]
1a38107941725211e7c3f051f7a8f5e12199f03acmaederhascasl_reserved_ops = [dotS++exMark, cDot++exMark, asP, assignS, lamS]
a58d43a4b2864a25ab74b96758fb9d98f18eeed7Daniel Calegari ++ casl_reserved_ops
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederhascasl_type_ops = [funS, pFun, contFun, pContFun, prodS, timesS, quMark]
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroederhascasl_reserved_words :: [String]
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegarihascasl_reserved_words =
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari [classS, instanceS, programS, caseS, ofS, letS, derivingS]
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari ++ casl_reserved_words
1a38107941725211e7c3f051f7a8f5e12199f03acmaederscanWords, scanSigns :: GenParser Char st String
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegariscanWords = reserved hascasl_reserved_words scanAnyWords
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegariscanSigns = reserved hascasl_reserved_ops scanAnySigns
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- ----------------------------------------------
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- non-compound mixfix ids (variables)
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- ----------------------------------------------
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederrestrictedVar :: [String] -> GenParser Char st Id
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegarirestrictedVar ops = fmap (\l -> Id l [] [])
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari (start (ops ++ hascasl_reserved_ops,
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari hascasl_reserved_words))
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegarivar :: GenParser Char st Id
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegarivar = restrictedVar []
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari-- ----------------------------------------------
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari-- bracketed lists
1a38107941725211e7c3f051f7a8f5e12199f03acmaeder-- ----------------------------------------------
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegaribracketParser :: GenParser Char st a -> GenParser Char st Token
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari -> GenParser Char st Token -> GenParser Char st Token
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder -> ([a] -> [Pos] -> b) -> GenParser Char st b
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegaribracketParser parser op cl sep k =
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder (ts, ps) <- option ([], [])
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder (parser `separatedBy` sep)
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel Calegari return (k ts (toPos o ps c))
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegarimkBrackets :: GenParser Char st a -> ([a] -> [Pos] -> b) -> GenParser Char st b
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegarimkBrackets parser k = bracketParser parser oBracketT cBracketT commaT k
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel Calegari-- ----------------------------------------------
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel Calegari-- ----------------------------------------------
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegarihcKeys :: ([String], [String])
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von SchroederhcKeys = (hascasl_reserved_ops, hascasl_reserved_words)
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegariuninstOpId, hconsId :: GenParser Char st Id
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegariuninstOpId = mixId hcKeys hcKeys
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel CalegarihconsId = mixId (quMark:barS:hascasl_reserved_ops, hascasl_reserved_words)
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel Calegari-- ----------------------------------------------
eb06c6332e2e2ef6f5d1cdd74c5ce7abbd23de28Daniel Calegari-- TYPE-VAR Ids
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder-- ----------------------------------------------
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari-- no compound ids
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegaritypeVar :: GenParser Char st Id
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegaritypeVar = restrictedVar [lessS]
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari-- simple id with compound list
acc049a844d19fb294ce7f68742390dee87447dcDaniel CalegariclassId :: GenParser Char st Id
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari do s <- pToken scanWords
acc049a844d19fb294ce7f68742390dee87447dcDaniel Calegari (c, p) <- option ([], []) $ comps hcKeys
d3d15411081a9ac4a84d409079153135bb30442aDaniel Calegari return (Id [s] c p)