Nix 2.26.3
Nix, the purely functional package manager; unstable internal interfaces
 
Loading...
Searching...
No Matches
print.hh File Reference

Common printing functions for the Nix language. More...

#include <iostream>
#include "fmt.hh"
#include "print-options.hh"

Go to the source code of this file.

Classes

class  nix::ValuePrinter
 

Functions

std::ostream & nix::printLiteralString (std::ostream &str, const std::string_view string)
 
std::ostream & nix::printLiteralString (std::ostream &o, const char *s)
 
std::ostream & nix::printLiteralString (std::ostream &o, const std::string &s)
 
std::ostream & nix::printLiteralBool (std::ostream &str, bool boolean)
 
std::ostream & nix::printAttributeName (std::ostream &str, std::string_view name)
 
bool nix::isReservedKeyword (const std::string_view str)
 
std::ostream & nix::printIdentifier (std::ostream &str, std::string_view s)
 
void nix::printValue (EvalState &state, std::ostream &output, Value &v, PrintOptions options)
 
std::ostream & nix::operator<< (std::ostream &output, const ValuePrinter &printer)
 

Detailed Description

Common printing functions for the Nix language.

While most types come with their own methods for printing, they share some functions that are placed here.

Function Documentation

◆ isReservedKeyword()

bool nix::isReservedKeyword ( const std::string_view str)

Returns ‘true’ is a string is a reserved keyword which requires quotation when printing attribute set field names.

◆ operator<<()

std::ostream & nix::operator<< ( std::ostream & output,
const ValuePrinter & printer )

Print true or false. Print a string as an attribute name in the Nix expression language syntax.

Prints a quoted string if necessary. Returns ‘true’ is a string is a reserved keyword which requires quotation when printing attribute set field names. Print a string as an identifier in the Nix expression language syntax.

FIXME: "identifier" is ambiguous. Identifiers do not have a single textual representation. They can be used in variable references, let bindings, left-hand sides or attribute names in a select expression, or something else entirely, like JSON. Use one of the print* functions instead. A partially-applied form of printValue which can be formatted using << without allocating an intermediate string.

◆ printAttributeName()

std::ostream & nix::printAttributeName ( std::ostream & o,
std::string_view s )

Print a string as an attribute name in the Nix expression language syntax.

Prints a quoted string if necessary.

◆ printIdentifier()

std::ostream & nix::printIdentifier ( std::ostream & o,
std::string_view s )

Print a string as an identifier in the Nix expression language syntax.

FIXME: "identifier" is ambiguous. Identifiers do not have a single textual representation. They can be used in variable references, let bindings, left-hand sides or attribute names in a select expression, or something else entirely, like JSON. Use one of the print* functions instead.

◆ printLiteralBool()

std::ostream & nix::printLiteralBool ( std::ostream & o,
bool b )

Print true or false.

◆ printLiteralString()

std::ostream & nix::printLiteralString ( std::ostream & o,
std::string_view s )

Print a string as a Nix string literal.

Quotes and fairly minimal escaping are added.

Parameters
oThe output stream to print to
sThe logical string