| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Text.Format.Heavy.Parse.Shell
Contents
Description
This module defines shell-like syntax of format strings, generally described as "any part after dollar sign is a variable substitution".
Examples of valid variable substitutions are:
"Simple: ${}". Note that to have auto-numbered placeholders in this syntax, you have to write${}; both dollar sign and braces are necessary."Numbered: $1"or"Numbered: ${1}"."Named: $var"or"Named: ${var}"."Specifying variable formatting: ${var:+8.4}". To specify variable format, you have to use braces.
This syntax is not the default, so to use it you have to explicitly call parseShellFormat':
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Time
import qualified Data.Text.Lazy.IO as TLIO
import Data.Text.Format.Heavy
import Data.Text.Format.Heavy.Parse.Shell
main :: IO ()
main = do
name <- getLine
time <- getZonedTime
TLIO.putStrLn $ format (parseShellFormat' "Hello, ${}! It is ${:%H:%M:%S} now.") (name, time)
Parse functions
parseShellFormat :: Text -> Either ParseError Format Source #
Parse string format definition.
parseShellFormat' :: Text -> Format Source #
Version of parseShellFormat which throws error in case of syntax error in the formatting string.
Parsec functions
pShellFormat :: Parser Format Source #
Parsec parser for string format.