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

Str (String Expression)

Definition

Str String

Fields

FieldTypeDescription
contentsStringThe string contents (DoubleQuoted or Indented)

Description

Str is the expression-level node for strings. It wraps a String node which contains the actual string parts (plain text, antiquotations, escaped newlines).

Nix Source ↔ AST

Double-Quoted String

# Nix
"hello ${world}"

# AST
{
  "tag": "Str",
  "contents": {
    "tag": "DoubleQuoted",
    "contents": [
      { "tag": "Plain", "contents": "hello " },
      { "tag": "Antiquoted", "contents": { "tag": "Sym", "contents": "world" } }
    ]
  }
}

Indented String

# Nix
''
  hello
  world
''

# AST
{
  "tag": "Str",
  "contents": {
    "tag": "Indented",
    "indent": 2,
    "parts": [
      { "tag": "Plain", "contents": "hello\nworld" }
    ]
  }
}
  • String: DoubleQuoted and Indented constructors
  • Antiquoted: Plain, Antiquoted, EscapedNewline parts

Nix Library Access

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