Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
nix::ToBeStringyExpr Class Reference

#include <parser-state.hh>

Public Member Functions

 ToBeStringyExpr (std::string_view v)
 ToBeStringyExpr (Expr *expr)
template<class F>
void visit (const F &f)
Expr * toExpr (Exprs &exprs)

Detailed Description

This represents a string-like parse that possibly has yet to be constructed.

Examples: "foo" ${"foo" + "bar"} "foo.bar" "foo-${a}"

Using this type allows us to avoid construction altogether in cases where what we actually need is the string contents. For example in foo."bar.baz", there is no need to construct an AST node for "bar.baz", but we don't know that until we bubble the value up during parsing and see that it's a node in an AttrPath.

Member Function Documentation

◆ toExpr()

Expr * nix::ToBeStringyExpr::toExpr ( Exprs & exprs)
inline

Get or create an Expr from either an existing Expr or from a string. Delays the allocation or an AST node in case the parser only cares about string contents.

◆ visit()

template<class F>
void nix::ToBeStringyExpr::visit ( const F & f)
inline

Visits the expression and invokes an overloaded functor object f. If the underlying Expr has a dynamic type of ExprString the overload taking std::string_view is invoked.

Used to consistently handle simple StringExpr ${"string"} as non-dynamic attributes.

See also
https://github.com/NixOS/nix/issues/14642

The documentation for this class was generated from the following file: