equal
deleted
inserted
replaced
13 char '{' >> notFollowedBy (char '$') >> manyTill anyChar (try $ char '}') >> return "" |
13 char '{' >> notFollowedBy (char '$') >> manyTill anyChar (try $ char '}') >> return "" |
14 , (try $ string "(*") >> manyTill anyChar (try $ string "*)") >> return "" |
14 , (try $ string "(*") >> manyTill anyChar (try $ string "*)") >> return "" |
15 , (try $ string "//") >> manyTill anyChar (try newline) >> return "\n" |
15 , (try $ string "//") >> manyTill anyChar (try newline) >> return "\n" |
16 ] |
16 ] |
17 |
17 |
|
18 initDefines = Map.fromList [("FPC", "")] |
|
19 |
18 preprocess :: String -> IO String |
20 preprocess :: String -> IO String |
19 preprocess fn = do |
21 preprocess fn = do |
20 r <- runParserT (preprocessFile fn) (Map.empty, [True]) "" "" |
22 r <- runParserT (preprocessFile fn) (initDefines, [True]) "" "" |
21 case r of |
23 case r of |
22 (Left a) -> do |
24 (Left a) -> do |
23 hPutStrLn stderr (show a) |
25 hPutStrLn stderr (show a) |
24 return "" |
26 return "" |
25 (Right a) -> return a |
27 (Right a) -> return a |
79 ifdef = do |
81 ifdef = do |
80 s <- try (string "IFDEF") <|> try (string "IFNDEF") |
82 s <- try (string "IFDEF") <|> try (string "IFNDEF") |
81 let f = if s == "IFNDEF" then not else id |
83 let f = if s == "IFNDEF" then not else id |
82 |
84 |
83 spaces |
85 spaces |
84 d <- many1 alphaNum |
86 d <- identifier |
85 spaces |
87 spaces |
86 char '}' |
88 char '}' |
87 |
89 |
88 updateState $ \(m, b) -> |
90 updateState $ \(m, b) -> |
89 (m, (f $ d `Map.member` m) : b) |
91 (m, (f $ d `Map.member` m) : b) |
101 return "" |
103 return "" |
102 define = do |
104 define = do |
103 try $ string "DEFINE" |
105 try $ string "DEFINE" |
104 spaces |
106 spaces |
105 i <- identifier |
107 i <- identifier |
106 d <- option "" (string ":=" >> many (noneOf "}")) |
108 d <- ((string ":=" >> return ())<|> spaces) >> many (noneOf "}") |
107 char '}' |
109 char '}' |
108 updateState $ \(m, b) -> (if and b then Map.insert i d m else m, b) |
110 updateState $ \(m, b) -> (if and b then Map.insert i d m else m, b) |
109 return "" |
111 return "" |
110 replace s = do |
112 replace s = do |
111 (m, _) <- getState |
113 (m, _) <- getState |