template
template copied to clipboard
Strict variable expansion
We've run into a bit of confusion (here https://github.com/KSF-Media/tuttifrutti/issues/12) with identifier parsing in our log module when using template to support variable interpolation.
While the actual issue comes from the lack of documentation in our library. I think we could eliminate such confusion by adding a "strict" mode in which, $foo
won't be allowed, only ${foo}. It will also eliminate the need to escape $
with $$
.
Such functionality could be added in backwards compatible way by introducing a templateStrict :: Text -> Template
that has such behavior.
I was thinking about this for a while. My idea was to create new module Data.Text.Template.Parse
that would expose following:
data ParseOptions = ParseOptions
{ bracketsRequired :: Bool
, escapeChar :: Char
}
data ParseError = ParseError
{ sourceLocation :: Maybe SrcLoc
-- ^ Location of template parsing function in Haskell source code, if supported.
, templateLocation :: (Int, Int)
-- ^ Location in the template where parsing error was encountered.
}
parse :: HasCallStack => ParseOptions -> Text -> Either ParseError Template
parse = parseImpl
Would something like this work for you as well?