Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Core of the nyan-interpolation
library.
Use it to define your own variation of the interpolator, customizing the default switches and other parameters to your preferences.
int :: QuasiQuoter int = mkInt defaultInterpolatorOptions { defaultSwitchesOptions = recommendedDefaultSwitchesOptions { defSpacesTrimming = Just True } }
Synopsis
- mkInt :: InterpolatorOptions -> QuasiQuoter
- data InterpolatorOptions
- defaultInterpolatorOptions :: InterpolatorOptions
- defaultSwitchesOptions :: InterpolatorOptions -> DefaultSwitchesOptions
- valueInterpolator :: InterpolatorOptions -> ValueInterpolator
- invisibleCharsPreview :: InterpolatorOptions -> InvisibleCharsPreview
- data DefaultSwitchesOptions
- basicDefaultSwitchesOptions :: DefaultSwitchesOptions
- recommendedDefaultSwitchesOptions :: DefaultSwitchesOptions
- defSpacesTrimming :: DefaultSwitchesOptions -> Maybe Bool
- defIndentationStripping :: DefaultSwitchesOptions -> Maybe Bool
- defLeadingNewlineStripping :: DefaultSwitchesOptions -> Maybe Bool
- defTrailingSpacesStripping :: DefaultSwitchesOptions -> Maybe Bool
- defReducedNewlines :: DefaultSwitchesOptions -> Maybe Bool
- defReturnType :: DefaultSwitchesOptions -> Maybe ReturnType
- defMonadic :: DefaultSwitchesOptions -> Maybe Bool
- newtype ValueInterpolator = ValueInterpolator {
- runValueInterpolator :: Text -> ExpQ
- simpleValueInterpolator :: ValueInterpolator
- tickedValueInterpolator :: ValueInterpolator
- newtype InvisibleCharsPreview = InvisibleCharsPreview {}
- simpleInvisibleCharsPreview :: InvisibleCharsPreview
- newtype RMode a = RMode {
- renderWithMode :: a -> Builder
- data QuasiQuoter
Interpolator
mkInt :: InterpolatorOptions -> QuasiQuoter Source #
Construct an interpolator.
Usually you pass some options here that you consider canonical and use the resulting interolator throughout your project.
Interpolator options
data InterpolatorOptions Source #
Options set when creating an interpolator.
defaultInterpolatorOptions :: InterpolatorOptions Source #
The most interpolator options.
- Tries to keep the text as much unchanged as possible.
- Interpolates only variables.
Field accessors for interpolator options
defaultSwitchesOptions :: InterpolatorOptions -> DefaultSwitchesOptions Source #
Default switches options.
valueInterpolator :: InterpolatorOptions -> ValueInterpolator Source #
Expands text in #{}
into AST.
We have to leave this changeable because there is no "perfect" expander.
Using the most appropriate one would require relying on haskell-src-exts
package which is quite a heavy-weight dependency.
Some users would prefer a simpler solution which would only allow
variables in #{}
.
Interpreting the passed text in tricky ways is valid.
For instance, for specialized interpolators #{var}
could be expanded to local'var
, view varLens
, or more complex
Haskell code.
invisibleCharsPreview :: InterpolatorOptions -> InvisibleCharsPreview Source #
In case, when the switches are set to preview the resulting text
with invisibles being marked specially (!!
), how to update the pieces
of text.
Default switches options
data DefaultSwitchesOptions Source #
Default switches options set in the interpolator, those that are used
in [int||...|]
.
When no default value for a switch is specified, this switch is left mandatory for specifying in the interpolator.
Instances
Show DefaultSwitchesOptions Source # | |
Defined in Text.Interpolation.Nyan.Core.Internal.Base showsPrec :: Int -> DefaultSwitchesOptions -> ShowS # show :: DefaultSwitchesOptions -> String # showList :: [DefaultSwitchesOptions] -> ShowS # |
basicDefaultSwitchesOptions :: DefaultSwitchesOptions Source #
Default DefaultSwitchesOptions
.
This set of switches tries to leave the text as much unmodified as possible.
It does not define default switches used by Text.Interpolation.Nyan
module, and you will likely want to enable at least some options here.
recommendedDefaultSwitchesOptions :: DefaultSwitchesOptions Source #
DefaultSwitchesOptions
used in the Text.Interpolation.Nyan
module
in the default interpolator.
Field accessors for default switches options
Value interpolators
newtype ValueInterpolator Source #
How to expand values in #{}
into Haskell AST.
simpleValueInterpolator :: ValueInterpolator Source #
Interpolates only strings containing single variable.
This allows for {var}
-like interpolated values, no applications,
operators or other constructions are allowed.
tickedValueInterpolator :: ValueInterpolator Source #
This is a variation of simpleValueInterpolator
that requires all the
referred variables to start from a special i'
prefix.
One major issue with simpleValueInterpolator
is that, with it the user can
mistakenly pick a value from the wrong scope, for instance, a global value
instead of a local one.
This value interpolator tries to solve the issue by bringing the practice
to call the interpolator like
let renderedText = let i'value1 = ... i'value2 = ... in [int||Values are {value1} and {value2}]
and so interpolating only local declarations.
Adjusting preview
newtype InvisibleCharsPreview Source #
Transformation that describes how to mark the invisible characters.
Use Monoid
instance to sequence multiple such transformations.
simpleInvisibleCharsPreview :: InvisibleCharsPreview Source #
Marks the most common space-like characters.
Rendering modes
Type that describes rendering modes.
An interpolator that has rmode'xxx :: RMode t
variable available in scope
will be able to use xxx
rendering mode.
More precisely, any #xxx{expr}
in interpolator will be expanded to
renderWithMode rmode'xxx (expr)
Haskell code
(some switches may slightly change this behaviour though).
>>>
rmode's :: Show a => RMode a
>>>
rmode's = RMode (build . show)
>>>
>>>
[int||Value is #s{5}|]
"Value is 5"
>>>
rmode'hex :: RMode Word
>>>
rmode'hex = RMode Fmt.hexF
>>>
>>>
[int||Value is #hex{32}]
"Value is 0x20"
RMode | |
|
Re-exports
data QuasiQuoter #
The QuasiQuoter
type, a value q
of this type can be used
in the syntax [q| ... string to parse ...|]
. In fact, for
convenience, a QuasiQuoter
actually defines multiple quasiquoters
to be used in different splice contexts; if you are only interested
in defining a quasiquoter to be used for expressions, you would
define a QuasiQuoter
with only quoteExp
, and leave the other
fields stubbed out with errors.