
Hi all, Is there a simple tool or command to remove all comments from a Haskell file, i.e. something that outputs the input file but without any comments on it? Best Miguel Vilaça

jmvilaca:
Hi all,
Is there a simple tool or command to remove all comments from a Haskell file, i.e. something that outputs the input file but without any comments on it?
Using Language.Haskell, such a program is almost trivial: -- -- strip comments from haskell source -- {- the main module -} import Language.Haskell.Parser import Language.Haskell.Pretty main = interact $ \s -> case parseModule s of ParseFailed loc str -> (show loc) ++ "\n" ParseOk m -> (prettyPrint m) ++ "\n" And running this program on itself: $ runhaskell A.hs < A.hs module Main (main) where import Language.Haskell.Parser import Language.Haskell.Pretty main = interact $ \ s -> case parseModule s of ParseFailed loc str -> (show loc) ++ "\n" ParseOk m -> (prettyPrint m) ++ "\n" Hehe, it also pretty prints :-) -- Don

Is it possible to use Language.Haskell to print a program with comments preserved? That might be useful for refactoring. Not that Language.Haskell isn't already cool enough, if the answer is "no", of course. Frederik On Fri, May 04, 2007 at 10:33:07AM +1000, Donald Bruce Stewart wrote:
jmvilaca:
Hi all,
Is there a simple tool or command to remove all comments from a Haskell file, i.e. something that outputs the input file but without any comments on it?
Using Language.Haskell, such a program is almost trivial:
-- -- strip comments from haskell source --
{- the main module -}
import Language.Haskell.Parser import Language.Haskell.Pretty
main = interact $ \s -> case parseModule s of ParseFailed loc str -> (show loc) ++ "\n" ParseOk m -> (prettyPrint m) ++ "\n"
And running this program on itself:
$ runhaskell A.hs < A.hs module Main (main) where import Language.Haskell.Parser import Language.Haskell.Pretty main = interact $ \ s -> case parseModule s of ParseFailed loc str -> (show loc) ++ "\n" ParseOk m -> (prettyPrint m) ++ "\n"
Hehe, it also pretty prints :-)
-- Don _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Fri, 2007-05-04 at 15:01 +0100, Frederik Eaton wrote:
Is it possible to use Language.Haskell to print a program with comments preserved? That might be useful for refactoring.
Not that Language.Haskell isn't already cool enough, if the answer is "no", of course.
The answer is no, but take a look at HaRe the Haskell Refactoring tool: http://www.cs.kent.ac.uk/projects/refactor-fp/hare.html Duncan
participants (4)
-
dons@cse.unsw.edu.au
-
Duncan Coutts
-
Frederik Eaton
-
José Miguel Vilaça