require $& for whitespace before or after a builder
This commit is contained in:
parent
d18c19a2e6
commit
035aa78920
4 changed files with 16 additions and 10 deletions
|
@ -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 $
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue