irc: support lookup paths and import keyword

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I0d16726646aef82ce675c4f8d209029a6a6a6964
This commit is contained in:
raf 2026-02-22 12:48:09 +03:00
commit 775bb42c63
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 116 additions and 60 deletions

View file

@ -2,10 +2,8 @@
#define NIX_IRC_TYPES_H
#include <cstdint>
#include <fstream>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
@ -25,11 +23,13 @@ enum class NodeType : uint8_t {
CONST_BOOL = 0x04,
CONST_NULL = 0x05,
CONST_URI = 0x07,
CONST_LOOKUP_PATH = 0x08,
VAR = 0x10,
LAMBDA = 0x20,
APP = 0x21,
BINARY_OP = 0x22,
UNARY_OP = 0x23,
IMPORT = 0x24,
ATTRSET = 0x30,
SELECT = 0x31,
HAS_ATTR = 0x34,
@ -107,6 +107,12 @@ struct ConstURINode {
ConstURINode(std::string v = "", uint32_t l = 0) : value(std::move(v)), line(l) {}
};
struct ConstLookupPathNode {
std::string value; // e.g., "nixpkgs" or "nixpkgs/lib"
uint32_t line = 0;
ConstLookupPathNode(std::string v = "", uint32_t l = 0) : value(std::move(v)), line(l) {}
};
struct VarNode {
uint32_t index = 0;
std::optional<std::string> name;
@ -204,6 +210,12 @@ struct AssertNode {
AssertNode(std::shared_ptr<Node> c, std::shared_ptr<Node> b, uint32_t l = 0);
};
struct ImportNode {
std::shared_ptr<Node> path; // Path expression to import
uint32_t line = 0;
ImportNode(std::shared_ptr<Node> p, uint32_t l = 0);
};
struct ThunkNode {
std::shared_ptr<Node> expr;
uint32_t line = 0;
@ -221,9 +233,9 @@ class Node {
public:
using Variant =
std::variant<ConstIntNode, ConstFloatNode, ConstStringNode, ConstPathNode, ConstBoolNode,
ConstNullNode, ConstURINode, VarNode, LambdaNode, AppNode, BinaryOpNode,
UnaryOpNode, AttrsetNode, SelectNode, HasAttrNode, WithNode, IfNode, LetNode,
LetRecNode, AssertNode, ThunkNode, ForceNode>;
ConstNullNode, ConstURINode, ConstLookupPathNode, VarNode, LambdaNode, AppNode,
BinaryOpNode, UnaryOpNode, ImportNode, AttrsetNode, SelectNode, HasAttrNode,
WithNode, IfNode, LetNode, LetRecNode, AssertNode, ThunkNode, ForceNode>;
Variant data;
@ -270,6 +282,8 @@ inline LetRecNode::LetRecNode(std::shared_ptr<Node> b, uint32_t l) : body(std::m
inline AssertNode::AssertNode(std::shared_ptr<Node> c, std::shared_ptr<Node> b, uint32_t l)
: cond(std::move(c)), body(std::move(b)), line(l) {}
inline ImportNode::ImportNode(std::shared_ptr<Node> p, uint32_t l) : path(std::move(p)), line(l) {}
inline ThunkNode::ThunkNode(std::shared_ptr<Node> e, uint32_t l) : expr(std::move(e)), line(l) {}
inline ForceNode::ForceNode(std::shared_ptr<Node> e, uint32_t l) : expr(std::move(e)), line(l) {}