ToId.hs revision ad270004874ce1d0697fb30d7309f180553bb315
{- |
Module : $Header$
Copyright : (c) T.Mossakowski, C.Maeder and Uni Bremen 2006
License : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
Maintainer : maeder@tzi.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