4752N/ACopyright : (c) Katja Groeblinghoff,
C.Maeder, Uni Bremen 2003 - 2004
4752N/AMaintainer : Christian.Maeder@dfki.de
4752N/ATranslation of identifiers to Haskell.
6982N/A-- | Converts an identifier to a valid lower or upper case Haskell name
4752N/AtranslateIdWithType :: IdCase -> Id -> String
4752N/A c = if null s then error "translateIdWithTyper" else head s
4752N/A if isLower c || c == '_' || isDigit c
4752N/A-- reserved Haskell keywords
4752N/A "case", "class", "data", "default", "deriving", "do", "else",
4752N/A "if", "import", "in", "infix", "infixl", "infixr", "instance",
4752N/A "let", "module", "newtype", "of", "then", "type", "where"]
4752N/Adata IdCase = UpperId | LowerId
4752N/A-- | Converts an identifier to a valid Haskell name
4752N/AtranslateId (Id tlist idlist _) =
4752N/A showSepList id translateToken tlist . translateCompound idlist
4752N/A-- | Translate a 'Token' according to the 'symbolMapping'.
4752N/AtranslateToken :: Token -> ShowS
4752N/AtranslateToken t = let str = tokStr t in showString $
4752N/A else if all isDigit str && not (isSingle str) then '_' : str
4752N/A else if head str == '\'' then
4752N/A "_3" ++ concatMap (('_' : ) . show . ord) (tail str) ++ "_X"
4752N/A else concatMap symbolMapping str
4752N/A-- | Translate a compound list
4752N/AtranslateCompound :: [Id] -> ShowS
4752N/AtranslateCompound ids = noShow (null ids) $ showString "_F"
4752N/A . showSepList (showString "_K") translateId ids
4752N/A-- | Converts characters to parts of Haskell identifiers
4752N/A-- thereby translating special ones
4752N/AsymbolMapping :: Char -> String
4752N/A-- avoid compound symbols and keep map injective