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

@ -1,7 +1,6 @@
#include "serializer.h"
#include <cstring>
#include <iostream>
#include <sstream>
namespace nix_irc {
@ -43,6 +42,8 @@ struct Serializer::Impl {
return NodeType::CONST_NULL;
if (node.holds<ConstURINode>())
return NodeType::CONST_URI;
if (node.holds<ConstLookupPathNode>())
return NodeType::CONST_LOOKUP_PATH;
if (node.holds<VarNode>())
return NodeType::VAR;
if (node.holds<LambdaNode>())
@ -53,6 +54,8 @@ struct Serializer::Impl {
return NodeType::BINARY_OP;
if (node.holds<UnaryOpNode>())
return NodeType::UNARY_OP;
if (node.holds<ImportNode>())
return NodeType::IMPORT;
if (node.holds<AttrsetNode>())
return NodeType::ATTRSET;
if (node.holds<SelectNode>())
@ -97,6 +100,8 @@ struct Serializer::Impl {
// No data for null
} else if (auto* n = node.get_if<ConstURINode>()) {
write_string(n->value);
} else if (auto* n = node.get_if<ConstLookupPathNode>()) {
write_string(n->value);
} else if (auto* n = node.get_if<VarNode>()) {
write_u32(n->index);
} else if (auto* n = node.get_if<LambdaNode>()) {
@ -118,6 +123,9 @@ struct Serializer::Impl {
write_u8(static_cast<uint8_t>(n->op));
if (n->operand)
write_node(*n->operand);
} else if (auto* n = node.get_if<ImportNode>()) {
if (n->path)
write_node(*n->path);
} else if (auto* n = node.get_if<AttrsetNode>()) {
write_u8(n->recursive ? 1 : 0);
write_u32(n->attrs.size());
@ -289,6 +297,10 @@ struct Deserializer::Impl {
std::string val = read_string();
return std::make_shared<Node>(ConstURINode(val, line));
}
case NodeType::CONST_LOOKUP_PATH: {
std::string val = read_string();
return std::make_shared<Node>(ConstLookupPathNode(val, line));
}
case NodeType::VAR: {
uint32_t index = read_u32();
return std::make_shared<Node>(VarNode(index, "", line));
@ -314,6 +326,10 @@ struct Deserializer::Impl {
auto operand = read_node();
return std::make_shared<Node>(UnaryOpNode(op, operand, line));
}
case NodeType::IMPORT: {
auto path = read_node();
return std::make_shared<Node>(ImportNode(path, line));
}
case NodeType::ATTRSET: {
bool recursive = read_u8() != 0;
uint32_t num_attrs = read_u32();