You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.9 KiB
JavaScript
82 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("assert");
|
|
|
|
let types = module.exports = {
|
|
/* NOTE: Synthesized attribute sets are non-recursive:
|
|
nix-repl> rec { data = 1; sub = { data = 2; }; sub.ref = data; }.sub.ref
|
|
1
|
|
|
|
nix-repl> rec { data = 1; sub = rec { data = 2; }; sub.ref = data; }.sub.ref
|
|
2
|
|
|
|
nix-repl> rec { data = 1; sub.data = 2; sub.ref = data; }.sub.ref
|
|
1
|
|
*/
|
|
NixAttributeSet: function (bindings, recursive = false) {
|
|
return {
|
|
type: "NixAttributeSet",
|
|
bind: bindings,
|
|
recursive: recursive
|
|
};
|
|
},
|
|
NixBinding: function (attributePath, value) {
|
|
return {
|
|
type: "NixBinding",
|
|
attrpath: types.NixAttributePath(attributePath),
|
|
expression: value
|
|
};
|
|
},
|
|
NixAttributePath: function (attributes) {
|
|
// NOTE: This does not accept an array of strings! Instead, specify as an array of NixAttributeIdentifiers
|
|
// TODO: Add proper validation for this
|
|
assert(Array.isArray(attributes));
|
|
assert(!attributes.some((attribute) => typeof attribute === "string"));
|
|
|
|
return {
|
|
type: "NixAttributePath",
|
|
attr: attributes
|
|
};
|
|
},
|
|
NixIdentifier: function (name) {
|
|
return {
|
|
type: "NixIdentifier",
|
|
name: name
|
|
};
|
|
},
|
|
NixAttributeIdentifier: function (name) {
|
|
return {
|
|
type: "NixAttributeIdentifier",
|
|
name: name
|
|
};
|
|
},
|
|
NixAttributeSelection: function (expression, attributePath) {
|
|
return {
|
|
type: "NixAttributeSelection",
|
|
attrpath: types.NixAttributePath(attributePath),
|
|
expression: expression
|
|
};
|
|
},
|
|
NixLetIn: function (bindings, body) {
|
|
return {
|
|
type: "NixLetIn",
|
|
bind: bindings,
|
|
body: body
|
|
};
|
|
},
|
|
// jsNix-specific structures
|
|
// FIXME: Should these be template modules instead?
|
|
JSNixLet: function (bindings, body) {
|
|
return types.NixAttributeSelection(
|
|
types.NixAttributeSet([
|
|
... bindings,
|
|
types.NixBinding(
|
|
[ types.NixIdentifier("$letBody") ],
|
|
body
|
|
)
|
|
], true),
|
|
[ types.NixIdentifier("$letBody") ]
|
|
);
|
|
}
|
|
};
|