Copyright | (c) 2014 Peter Trsko |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | experimental |
Portability | DeriveDataTypeable, DeriveGeneric, NoImplicitPrelude |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Simple string template used by pkg-config.
- type PkgTemplate = Template
- newtype Template = Template [Fragment]
- data Fragment
- var :: Text -> PkgTemplate
- lit :: Text -> PkgTemplate
- strLit :: String -> PkgTemplate
- singletonLit :: Char -> PkgTemplate
- toLazyText :: Template -> Text
- toStrictText :: Template -> Text
- toTextBuilder :: Template -> Builder
- fragmentToBuilder :: Fragment -> Builder
- fragmentToStrictText :: Fragment -> Text
- variables :: PkgTemplate -> [Text]
Template
type PkgTemplate = Template Source
Template consists of variables and literal strings. All special characters ('$', '#', '\' and end-of-line sequences) contained in literals are escaped when serialized.
Template
fragment ca be either literal or variable. Literals are subject
to escaping rules when serialized.
Smart Constructors
var :: Text -> PkgTemplate Source
Construct variable fragment of a template.
>>>
var "prefix" <> lit "/bin"
$prefix/bin
lit :: Text -> PkgTemplate Source
Construct literal fragment of a template. This is useful if language
extension OverloadedStrings
is not enabled.
>>>
var "prefix" <> lit "/bin"
$prefix/bin
strLit :: String -> PkgTemplate Source
Create PkgTemplate
literal from String
by packing it in to strict
Text
first.
singletonLit :: Char -> PkgTemplate Source
Crate one character long PkgTemplate
literal.
Serialize
Serialize Template
toLazyText :: Template -> Text Source
Serialize template in to lazy Text
.
toStrictText :: Template -> Text Source
Serialize template in to strict Text
.
toTextBuilder :: Template -> Builder Source
Serialize template in to Builder
.
Serialize Fragment
fragmentToBuilder :: Fragment -> Builder Source
Serialize fragment in to Builder
.
fragmentToStrictText :: Fragment -> Text Source
Serialize fragment in to strict Text
. For literals function
performs escaping of special characters.
Query Template
variables :: PkgTemplate -> [Text] Source
List all variables mentioned in PkgTemplate
.
>>>
variables $ var "foo" </> "bar" </> var "baz"
["foo","baz"]