Preprocessor strips comments
authorunc0rr
Tue, 22 Nov 2011 22:48:02 +0300
changeset 6413 6714531e7bd2
parent 6412 4b9a59116535
child 6414 8474b7fa84d6
Preprocessor strips comments
tools/PascalPreprocessor.hs
--- a/tools/PascalPreprocessor.hs	Tue Nov 22 19:34:15 2011 +0300
+++ b/tools/PascalPreprocessor.hs	Tue Nov 22 22:48:02 2011 +0300
@@ -5,6 +5,14 @@
 import System.IO
 import qualified Data.Map as Map
 
+
+-- comments are removed
+comment = choice [
+        char '{' >> notFollowedBy (char '$') >> manyTill anyChar (try $ char '}') >> return ""
+        , (try $ string "(*") >> manyTill anyChar (try $ string "*)") >> return ""
+        , (try $ string "//") >> manyTill anyChar (try newline) >> return "\n"
+        ]
+
 preprocess :: String -> IO String
 preprocess fn = do
     r <- runParserT (preprocessFile fn) Map.empty "" ""
@@ -20,14 +28,20 @@
         f <- liftIO (readFile fn)
         setInput f
         preprocessor
+        
     preprocessor, codeBlock, switch :: ParsecT String (Map.Map String String) IO String
+    
     preprocessor = chainl codeBlock (return (++)) ""
+    
     codeBlock = choice [
             switch
-            --, comment
+            , comment
             , char '\'' >> many (noneOf "'") >>= \s -> char '\'' >> return ('\'' : s ++ "'")
-            , many1 $ noneOf "{'"
+            , many1 $ noneOf "{'/("
+            , char '/' >> notFollowedBy (char '/') >> return "/"
+            , char '(' >> notFollowedBy (char '*') >> return "("
             ]
+            
     switch = do
         try $ string "{$"
         s <- choice [
@@ -35,6 +49,7 @@
             , unknown
             ]
         return s
+        
     include = do
         try $ string "INCLUDE"
         spaces