Nix 2.36.0
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 "nix/util/fmt.hh"
#include "nix/expr/value/context.hh"
#include "nix/expr/print-options.hh"
#include <iosfwd>

Go to the source code of this file.

Classes

class  nix::ValuePrinter

Functions

std::ostream & nix::printLiteralString (std::ostream &o, std::string_view s)
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 &o, bool b)
std::ostream & nix::printAttributeName (std::ostream &o, std::string_view s)
std::ostream & nix::printIdentifier (std::ostream &o, std::string_view s)
void nix::printValue (EvalState &state, std::ostream &str, Value &v, PrintOptions options=PrintOptions{}, NixStringContext *context=nullptr)
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

◆ 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 )

Returns `true' is a string is a reserved keyword which requires quotation when printing attribute set field names. */ bool isReservedKeyword(const std::string_view str);

/** 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