dhall-1.42.3: A configuration language guaranteed to terminate

Safe Haskell | None
Language | Haskell2010

Dhall.Pretty

Contents

- Pretty

Description

This module contains logic for pretty-printing expressions, including support for syntax highlighting

Synopsis

- data Ann
  - = Keyword
  - | Syntax
  - | Label
  - | Literal
  - | Builtin
  - | Operator
- annToAnsiStyle :: Ann -> AnsiStyle
- prettyExpr :: Pretty a => Expr s a -> Doc Ann
- data CharacterSet
  - = ASCII
  - | Unicode
- defaultCharacterSet :: CharacterSet
- detectCharacterSet :: Expr Src a -> CharacterSet
- prettyCharacterSet :: Pretty a => CharacterSet -> Expr Src a -> Doc Ann
- layout :: Doc ann -> SimpleDocStream ann
- layoutOpts :: LayoutOptions
- escapeEnvironmentVariable :: Text -> Text
- data UnescapedLabel
  - = NonReservedLabel
  - | AnyLabel
  - | AnyLabelOrSome
- escapeLabel :: UnescapedLabel -> Text -> Text
- temporalToText :: Pretty a => Expr s a -> Maybe Text

# Pretty

data Ann Source #

Annotation type used to tag elements in a pretty-printed document for syntax highlighting purposes

Constructors

Keyword | Used for syntactic keywords
Syntax | Syntax punctuation such as commas, parenthesis, and braces
Label | Record labels
Literal | Literals such as integers and strings
Builtin | Builtin types and values
Operator | Operators

#### Instances

Instances details

Show Ann Source # |
Instance details Defined in Dhall.Pretty.Internal Methods showsPrec :: Int -> Ann -> ShowS Source # show :: Ann -> String Source # showList :: [Ann] -> ShowS Source #

annToAnsiStyle :: Ann -> AnsiStyle Source #

Convert annotations to their corresponding color for syntax highlighting purposes

prettyExpr :: Pretty a => Expr s a -> Doc Ann Source #

Pretty print an expression

data CharacterSet Source #

This type determines whether to render code as `ASCII` or `Unicode`

Constructors

ASCII |
Unicode |

#### Instances

Instances details

FromJSON CharacterSet Source # |
Instance details Defined in Dhall.Pretty.Internal Methods parseJSON :: Value -> Parser CharacterSet Source # parseJSONList :: Value -> Parser [CharacterSet] Source # omittedField :: Maybe CharacterSet Source #
NFData CharacterSet Source # |
Instance details Defined in Dhall.Pretty.Internal Methods rnf :: CharacterSet -> () Source #
Monoid CharacterSet Source # |
Instance details Defined in Dhall.Pretty.Internal Methods mempty :: CharacterSet Source # mappend :: CharacterSet -> CharacterSet -> CharacterSet Source # mconcat :: [CharacterSet] -> CharacterSet Source #
Semigroup CharacterSet Source # | Since ASCII is a subset of Unicode, if either argument is Unicode, the result is Unicode
Instance details Defined in Dhall.Pretty.Internal Methods (<>) :: CharacterSet -> CharacterSet -> CharacterSet Source # sconcat :: NonEmpty CharacterSet -> CharacterSet Source # stimes :: Integral b => b -> CharacterSet -> CharacterSet Source #
Data CharacterSet Source # |

Instance details

Defined in Dhall.Pretty.Internal

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CharacterSet -> c CharacterSet Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c CharacterSet Source #

toConstr :: CharacterSet -> Constr Source #

dataTypeOf :: CharacterSet -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c CharacterSet) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c CharacterSet) Source #

gmapT :: (forall b. Data b => b -> b) -> CharacterSet -> CharacterSet Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CharacterSet -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CharacterSet -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> CharacterSet -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> CharacterSet -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> CharacterSet -> m CharacterSet Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CharacterSet -> m CharacterSet Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CharacterSet -> m CharacterSet Source #

Generic CharacterSet Source # |

Instance details

Defined in Dhall.Pretty.Internal

Associated Types

type Rep CharacterSet |
Instance details Defined in Dhall.Pretty.Internal type Rep CharacterSet = D1 ('MetaData "CharacterSet" "Dhall.Pretty.Internal" "dhall-1.42.3-EZu4kpogyzhJMovFi16F5D" 'False) (C1 ('MetaCons "ASCII" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Unicode" 'PrefixI 'False) (U1 :: Type -> Type))

Methods

from :: CharacterSet -> Rep CharacterSet x Source #

to :: Rep CharacterSet x -> CharacterSet Source #

Show CharacterSet Source # |
Instance details Defined in Dhall.Pretty.Internal Methods showsPrec :: Int -> CharacterSet -> ShowS Source # show :: CharacterSet -> String Source # showList :: [CharacterSet] -> ShowS Source #
Eq CharacterSet Source # |
Instance details Defined in Dhall.Pretty.Internal Methods (==) :: CharacterSet -> CharacterSet -> Bool Source # (/=) :: CharacterSet -> CharacterSet -> Bool Source #
Ord CharacterSet Source # |

Instance details

Defined in Dhall.Pretty.Internal

Methods

compare :: CharacterSet -> CharacterSet -> Ordering Source #

(<) :: CharacterSet -> CharacterSet -> Bool Source #

(<=) :: CharacterSet -> CharacterSet -> Bool Source #

(>) :: CharacterSet -> CharacterSet -> Bool Source #

(>=) :: CharacterSet -> CharacterSet -> Bool Source #

max :: CharacterSet -> CharacterSet -> CharacterSet Source #

min :: CharacterSet -> CharacterSet -> CharacterSet Source #

Lift CharacterSet Source # |
Instance details Defined in Dhall.Pretty.Internal Methods lift :: Quote m => CharacterSet -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => CharacterSet -> Code m CharacterSet Source #
type Rep CharacterSet Source # |
Instance details Defined in Dhall.Pretty.Internal type Rep CharacterSet = D1 ('MetaData "CharacterSet" "Dhall.Pretty.Internal" "dhall-1.42.3-EZu4kpogyzhJMovFi16F5D" 'False) (C1 ('MetaCons "ASCII" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Unicode" 'PrefixI 'False) (U1 :: Type -> Type))

defaultCharacterSet :: CharacterSet Source #

The character set used by default in functions throughout the Dhall code base.

detectCharacterSet :: Expr Src a -> CharacterSet Source #

Detect which character set is used for the syntax of an expression If any parts of the expression uses the Unicode syntax, the whole expression is deemed to be using the Unicode syntax.

prettyCharacterSet :: Pretty a => CharacterSet -> Expr Src a -> Doc Ann Source #

Pretty-print an `Expr` using the given `CharacterSet`.

`prettyCharacterSet` largely ignores `Note`s. `Note`s do however matter for the layout of let-blocks:

    >>> let inner = Let (Binding Nothing "x" Nothing Nothing Nothing (NaturalLit 1)) (Var (V "x" 0)) :: Expr Src ()
    >>> prettyCharacterSet ASCII (Let (Binding Nothing "y" Nothing Nothing Nothing (NaturalLit 2)) inner)
    let y = 2 let x = 1 in x
    >>> prettyCharacterSet ASCII (Let (Binding Nothing "y" Nothing Nothing Nothing (NaturalLit 2)) (Note (Src unusedSourcePos unusedSourcePos "") inner))
    let y = 2 in let x = 1 in x

This means the structure of parsed let-blocks is preserved.

layout :: Doc ann -> SimpleDocStream ann Source #

Layout using `layoutOpts`

Tries hard to fit the document into 80 columns.

This also removes trailing space characters (`' '`) unless they are enclosed in an annotation.

layoutOpts :: LayoutOptions Source #

Default layout options

escapeEnvironmentVariable :: Text -> Text Source #

Escape an environment variable if not a valid Bash environment variable

data UnescapedLabel Source #

The set of labels which do not need to be escaped

Constructors

NonReservedLabel | This corresponds to the `nonreserved-label` rule in the grammar
AnyLabel | This corresponds to the `any-label` rule in the grammar
AnyLabelOrSome | This corresponds to the `any-label-or-some` rule in the grammar

escapeLabel :: UnescapedLabel -> Text -> Text Source #

Escape a label if it is not valid when unquoted

temporalToText :: Pretty a => Expr s a -> Maybe Text Source #

Convert an expression representing a temporal value to `Text`, if possible

This is used by downstream integrations (e.g. `dhall-json` for treating temporal values as strings