ToId.hs revision 3f69b6948966979163bdfe8331c38833d5d90ecd
{- |
Module : $Header$
Copyright : (c) T.Mossakowski, C.Maeder and Uni Bremen 2006
License : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
Maintainer : Christian.Maeder@dfki.de
Stability : provisional
Portability : portable
Description : converting (ie. kif) strings to CASL identifiers
-}
module Common.ToId where
import Common.Id
import Common.ProofUtils
import Common.Token
import Common.Lexer
import qualified Data.Map as Map
import Text.ParserCombinators.Parsec
-- | convert a string to a legal simple CASL identifier
toSimpleId :: String -> Token
toSimpleId s = mkSimpleId $
case parse (reserved (casl_reserved_words
++ formula_words) scanAnyWords >> eof)
"Common.ToId" s of
Left _ -> 'a' : concatMap ( \ c -> '_' : Map.findWithDefault [c] c
(Map.insert '_' "U" charMap)) s
Right _ -> s
-- | convert a string to a legal CASL identifier
toId :: String -> Id
toId = simpleIdToId . toSimpleId