From 71e5010c34d63a9b27af86108474c5e2d9b1758f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 13 Apr 2013 18:08:32 -0400 Subject: better splice joining --- Build/EvilSplicer.hs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'Build/EvilSplicer.hs') diff --git a/Build/EvilSplicer.hs b/Build/EvilSplicer.hs index 0936e78eb..216b818d5 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 -- cgit v1.2.3