From 39ee22574f9fe7095e87bd6f5a31c0a76742e61f Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Mon, 11 Feb 2019 01:51:09 -0500 Subject: [PATCH] support for multi-line defines --- Language/SystemVerilog/Parser/Preprocess.hs | 27 ++++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Language/SystemVerilog/Parser/Preprocess.hs b/Language/SystemVerilog/Parser/Preprocess.hs index c67376f..e228f19 100644 --- a/Language/SystemVerilog/Parser/Preprocess.hs +++ b/Language/SystemVerilog/Parser/Preprocess.hs @@ -48,18 +48,21 @@ preprocess env file content = unlines $ pp True [] env $ lines $ uncomment file where pp :: Bool -> [Bool] -> [(String, String)] -> [String] -> [String] pp _ _ _ [] = [] - pp on stack env (a : rest) = case words a of - "`define" : name : value -> "" : pp on stack (if on then (name, ppLine env $ unwords value) : env else env) rest - "`ifdef" : name : _ -> "" : pp (on && (elem name $ fst $ unzip env)) (on : stack) env rest - "`ifndef" : name : _ -> "" : pp (on && (notElem name $ fst $ unzip env)) (on : stack) env rest - "`else" : _ - | not $ null stack -> "" : pp (head stack && not on) stack env rest - | otherwise -> error $ "`else without associated `ifdef/`ifndef: " ++ file - "`endif" : _ - | 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 + pp on stack env (a : rest) = + if a /= "" && last a == '\\' && head a == '`' + then pp on stack env $ ((init a) ++ " " ++ (head rest)) : (tail rest) + else case words a of + "`define" : name : value -> "" : pp on stack (if on then (name, ppLine env $ unwords value) : env else env) rest + "`ifdef" : name : _ -> "" : pp (on && (elem name $ fst $ unzip env)) (on : stack) env rest + "`ifndef" : name : _ -> "" : pp (on && (notElem name $ fst $ unzip env)) (on : stack) env rest + "`else" : _ + | not $ null stack -> "" : pp (head stack && not on) stack env rest + | otherwise -> error $ "`else without associated `ifdef/`ifndef: " ++ file + "`endif" : _ + | 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 _ "" = ""