From 24f59578d64d787aa7663094a428b80be7a207a6 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 5 Mar 2009 12:59:34 +0100 Subject: [PATCH] Strip adjacent underscores from VHDLIds. --- VHDL.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 -- 2.30.2