mirror of
https://github.com/NixOS/nix.git
synced 2025-11-14 22:42:41 +01:00
Add an 'include' keyword
Inclusion is like importing, except that all variables that in scope at the 'include' site are in scope of the included file. Thus, if ./foo.nix contains 'x', then let x = 1; in include ./foo.nix evaluates to 1. (Note that 'include' has to be a keyword, not a builtin function, because inclusion takes place within a specific scope. I.e. 'include ./foo.nix' would not be equivalent to 'let f = include; in ... f ./foo.nix ...'.)
This commit is contained in:
parent
939cf4cceb
commit
64ea7cc437
10 changed files with 75 additions and 4 deletions
|
|
@ -86,9 +86,9 @@ struct Expr
|
|||
std::ostream & operator << (std::ostream & str, Expr & e);
|
||||
|
||||
#define COMMON_METHODS \
|
||||
void show(std::ostream & str); \
|
||||
void eval(EvalState & state, Env & env, Value & v); \
|
||||
void bindVars(const StaticEnv & env);
|
||||
void show(std::ostream & str) override; \
|
||||
void eval(EvalState & state, Env & env, Value & v) override; \
|
||||
void bindVars(const StaticEnv & env) override;
|
||||
|
||||
struct ExprInt : Expr
|
||||
{
|
||||
|
|
@ -326,6 +326,15 @@ struct ExprPos : Expr
|
|||
COMMON_METHODS
|
||||
};
|
||||
|
||||
struct ExprInclude : Expr
|
||||
{
|
||||
Pos pos;
|
||||
Expr * path;
|
||||
StaticEnv * staticEnv;
|
||||
ExprInclude(const Pos & pos, Expr * path) : pos(pos), path(path) { };
|
||||
COMMON_METHODS
|
||||
};
|
||||
|
||||
|
||||
/* Static environments are used to map variable names onto (level,
|
||||
displacement) pairs used to obtain the value of the variable at
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue