require $& for whitespace before or after a builder

This commit is contained in:
rhiannon morris 2024-08-21 07:40:28 +02:00
parent d18c19a2e6
commit 035aa78920
4 changed files with 16 additions and 10 deletions

View file

@ -18,9 +18,15 @@ import Data.List.NonEmpty (NonEmpty, toList)
data Chunk = Lit String | Var String
-- |
-- * use @$var@ to insert a variable (instance of 'CanBuild')
-- * use @$&@ to insert nothing like @\&@ in a string (e.g. to add whitespace
-- at the start or end, or to have a variable followed by a letter
-- * use @$$@ for a literal @$@
parseB :: String -> ExpQ
parseB = toExpQ . reverse . go "" [] . trim where
trim = dropWhileEnd isSpace . dropWhile (== '\n')
trim = dropWhileEnd isSpace . dropWhile isSpace
go acc cs [] = addLit acc cs
go acc cs ('$':'&':rest) = go acc cs rest -- $&: expands to nothing
go acc cs ('$':'$':rest) = go ('$' : acc) cs rest -- $$: expands to one $