diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-02-02T21·39+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2004-02-02T21·39+0000 |
commit | 1c9c0a5a46822be60c999f0196567c9e17cf5fa3 (patch) | |
tree | 6783413d7fd353fdd7562f47a2dc0aac132cd04d /src/libexpr/parser.cc | |
parent | d9f30fe7c74ae8518a575c0d15ee00aa46a2229a (diff) |
* Added syntactic sugar to the construction of attribute sets to
`inherit' variables from the surrounding lexical scope. E.g., {stdenv, libfoo}: derivation { builder = ./bla; inherit stdenv libfoo; xyzzy = 1; } is equivalent to {stdenv, libfoo}: derivation { builder = ./bla; stdenv = stdenv; libfoo = libfoo; xyzzy = 1; } Note that for mutually recursive attribute set definitions (`rec {...}'), this also works, that is, `rec {inherit x;}' is equivalent to `let {fresh = x; body = rec {x = fresh;};}', *not* `rec {x = x}'.
Diffstat (limited to 'src/libexpr/parser.cc')
-rw-r--r-- | src/libexpr/parser.cc | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/src/libexpr/parser.cc b/src/libexpr/parser.cc index 167c34bd83e4..2574a55bd49e 100644 --- a/src/libexpr/parser.cc +++ b/src/libexpr/parser.cc @@ -17,32 +17,52 @@ struct ParseData string error; }; + extern "C" { #include "parser-tab.h" #include "lexer-tab.h" - /* Callbacks for getting from C to C++. Due to a (small) bug in the - GLR code of Bison we cannot currently compile the parser as C++ - code. */ - - void setParseResult(ParseData * data, ATerm t) - { - data->result = t; - } +/* Callbacks for getting from C to C++. Due to a (small) bug in the + GLR code of Bison we cannot currently compile the parser as C++ + code. */ - ATerm absParsedPath(ParseData * data, ATerm t) - { - return string2ATerm(absPath(aterm2String(t), data->basePath).c_str()); - } +void setParseResult(ParseData * data, ATerm t) +{ + data->result = t; +} + +ATerm absParsedPath(ParseData * data, ATerm t) +{ + return string2ATerm(absPath(aterm2String(t), data->basePath).c_str()); +} - void parseError(ParseData * data, char * error, int line, int column) - { - data->error = (format("%1%, at line %2%, column %3%, of %4%") - % error % line % column % data->location).str(); - } +void parseError(ParseData * data, char * error, int line, int column) +{ + data->error = (format("%1%, at line %2%, column %3%, of %4%") + % error % line % column % data->location).str(); +} - int yyparse(yyscan_t scanner, ParseData * data); +ATerm fixAttrs(int recursive, ATermList as) +{ + ATMatcher m; + ATermList bs = ATempty, cs = ATempty; + ATermList * is = recursive ? &cs : &bs; + for (ATermIterator i(as); i; ++i) { + ATermList names; + if (atMatch(m, *i) >> "Inherit" >> names) + for (ATermIterator j(names); j; ++j) + *is = ATinsert(*is, + ATmake("Bind(<term>, Var(<term>))", *j, *j)); + else bs = ATinsert(bs, *i); + } + if (recursive) + return ATmake("Rec(<term>, <term>)", bs, cs); + else + return ATmake("Attrs(<term>)", bs); +} + +int yyparse(yyscan_t scanner, ParseData * data); } |