Commit 39ee2257 by Zachary Snow

support for multi-line defines

parent cb42f37b
...@@ -48,18 +48,21 @@ preprocess env file content = unlines $ pp True [] env $ lines $ uncomment file ...@@ -48,18 +48,21 @@ preprocess env file content = unlines $ pp True [] env $ lines $ uncomment file
where where
pp :: Bool -> [Bool] -> [(String, String)] -> [String] -> [String] pp :: Bool -> [Bool] -> [(String, String)] -> [String] -> [String]
pp _ _ _ [] = [] pp _ _ _ [] = []
pp on stack env (a : rest) = case words a of pp on stack env (a : rest) =
"`define" : name : value -> "" : pp on stack (if on then (name, ppLine env $ unwords value) : env else env) rest if a /= "" && last a == '\\' && head a == '`'
"`ifdef" : name : _ -> "" : pp (on && (elem name $ fst $ unzip env)) (on : stack) env rest then pp on stack env $ ((init a) ++ " " ++ (head rest)) : (tail rest)
"`ifndef" : name : _ -> "" : pp (on && (notElem name $ fst $ unzip env)) (on : stack) env rest else case words a of
"`else" : _ "`define" : name : value -> "" : pp on stack (if on then (name, ppLine env $ unwords value) : env else env) rest
| not $ null stack -> "" : pp (head stack && not on) stack env rest "`ifdef" : name : _ -> "" : pp (on && (elem name $ fst $ unzip env)) (on : stack) env rest
| otherwise -> error $ "`else without associated `ifdef/`ifndef: " ++ file "`ifndef" : name : _ -> "" : pp (on && (notElem name $ fst $ unzip env)) (on : stack) env rest
"`endif" : _ "`else" : _
| not $ null stack -> "" : pp (head stack) (tail stack) env rest | not $ null stack -> "" : pp (head stack && not on) stack env rest
| otherwise -> error $ "`endif without associated `ifdef/`ifndef: " ++ file | otherwise -> error $ "`else without associated `ifdef/`ifndef: " ++ file
"`default_nettype" : _ -> "" : pp on stack env rest "`endif" : _
_ -> (if on then ppLine env a else "") : pp on stack env rest | not $ null stack -> "" : pp (head stack) (tail stack) env rest
| otherwise -> error $ "`endif without associated `ifdef/`ifndef: " ++ file
"`default_nettype" : _ -> "" : pp on stack env rest
_ -> (if on then ppLine env a else "") : pp on stack env rest
ppLine :: [(String, String)] -> String -> String ppLine :: [(String, String)] -> String -> String
ppLine _ "" = "" ppLine _ "" = ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment