dhall-1.32.0: 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
- prettyCharacterSet :: Pretty a => CharacterSet -> Expr Src a -> Doc Ann
- layout :: Doc ann -> SimpleDocStream ann
- layoutOpts :: LayoutOptions
- escapeEnvironmentVariable :: Text -> Text
- escapeLabel :: Bool -> Text -> 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

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

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

escapeLabel :: Bool -> Text -> Text Source #

Escape a label if it is not valid when unquoted