Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Indented (Multi-line String)

Definition

Indented { indent :: Int, parts :: [Antiquoted Text] }

Fields

FieldTypeDescription
indentIntIndentation level (spaces stripped from each line)
parts[Antiquoted Text]List of string parts

Nix Source ↔ AST

Simple Indented String

# Nix
''
  hello
  world
''

# String node
{
  "tag": "Indented",
  "indent": 2,
  "parts": [
    { "tag": "Plain", "contents": "hello\nworld" }
  ]
}

With Antiquotation

# Nix
''
  hello
  ${name}
''

# String node
{
  "tag": "Indented",
  "indent": 2,
  "parts": [
    { "tag": "Plain", "contents": "hello\n" },
    { "tag": "Antiquoted", "contents": { "tag": "Sym", "contents": "name" } }
  ]
}

Escaped Newline

# Nix
''
  first line \
  second line
''

# String node
{
  "tag": "Indented",
  "indent": 2,
  "parts": [
    { "tag": "Plain", "contents": "first line " },
    { "tag": "EscapedNewline" },
    { "tag": "Plain", "contents": "second line" }
  ]
}

Expression Wrapper

{
  "tag": "Str",
  "contents": { "tag": "Indented", "indent": 2, "parts": [...] }
}

Nix Library Access

syntax.mkStr (syntax.mkIndented 2 [syntax.mkPlain "hello\nworld"])