From: Matthijs Kooijman Date: Thu, 5 Mar 2009 11:59:34 +0000 (+0100) Subject: Strip adjacent underscores from VHDLIds. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=24f59578d64d787aa7663094a428b80be7a207a6;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Strip adjacent underscores from VHDLIds. --- diff --git a/VHDL.hs b/VHDL.hs index f5ab7cd..338aa1d 100644 --- a/VHDL.hs +++ b/VHDL.hs @@ -4,6 +4,7 @@ module VHDL where import qualified Data.Foldable as Foldable +import qualified Data.List as List import qualified Maybe import qualified Control.Monad as Monad import qualified Control.Arrow as Arrow @@ -371,7 +372,13 @@ vhdl_ty_maybe ty = -- Shortcut mkVHDLId :: String -> AST.VHDLId mkVHDLId s = - AST.unsafeVHDLBasicId s' + AST.unsafeVHDLBasicId $ (strip_multiscore . strip_invalid) s where -- Strip invalid characters. - s' = filter (`elem` ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "_.") s + strip_invalid = filter (`elem` ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "_.") + -- Strip multiple adjacent underscores + strip_multiscore = concat . map (\cs -> + case cs of + ('_':_) -> "_" + _ -> cs + ) . List.group