diff --git a/Build/EvilSplicer.hs b/Build/EvilSplicer.hs index 0936e78ebe..216b818d5e 100644 --- a/Build/EvilSplicer.hs +++ b/Build/EvilSplicer.hs @@ -201,16 +201,10 @@ expandSplice s lls = concat [before, new:splicerest, end] l:r -> (expandtabs l, take (length r) (repeat [])) _ -> ([], []) new = concat - [ beforesplice + [ joinsplice $ deqqstart $ take (coordColumn cs - 1) splicestart , addindent (findindent splicestart) (mangleCode $ splicedCode s) , deqqend $ drop (coordColumn ce) splicestart ] - where - beforesplice = - let s = deqqstart $ take (coordColumn cs - 1) splicestart - in if all isSpace s - then "" - else s ++ " $ " {- coordinates assume tabs are expanded to 8 spaces -} expandtabs = replace "\t" (take 8 $ repeat ' ') @@ -222,6 +216,23 @@ expandSplice s lls = concat [before, new:splicerest, end] deqqend (')':s) = s deqqend s = s + {- Prepare the code that comes just before the splice so + - the splice will combine with it appropriately. -} + joinsplice s + -- all indentation? Skip it, we'll use the splice's indentation + | all isSpace s = "" + -- function definition needs no preparation + -- ie: foo = $(splice) + | "=" `isSuffixOf` s' = s + -- already have a $ to set off the splice + -- ie: foo $ $(splice) + | "$" `isSuffixOf` s' = s + -- need to add a $ to set off the splice + -- ie: bar $(splice) + | otherwise = s ++ " $ " + where + s' = filter (not . isSpace) s + findindent = length . takeWhile isSpace addindent n = unlines . map (i ++) . lines where