/*コメント*/を取り除く

http://ja.doukaku.org/17/より。いたってふつう。

module Main (main) where

removeComment :: String -> String
removeComment [] = []
removeComment ('/' : '*' : xs) = inComment xs
removeComment (x : xs) = x : removeComment xs

inComment :: String -> String
inComment [] = []
inComment ('*' : '/' : xs) = removeComment xs
inComment (_ : xs) = inComment xs

main :: IO ()
main = do
  print $ removeComment "AAA"                     -- => "AAA"
  print $ removeComment "AAA/*BBB*/"              -- => "AAA"
  print $ removeComment "AAA/*BBB"                -- => "AAA"
  print $ removeComment "AAA/*BBB*/CCC"           -- => "AAACCC"
  print $ removeComment "AAA/*BBB/*CCC*/DDD*/EEE" -- => "AAADDD*/EEE"
  print $ removeComment "AAA/a//*BB*B**/CCC"      -- => "AAA/a/CCC"