irc: improve multi-line strings; complete list concat and dynamic attrs
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I64e53c68d90b62f3ca306865ceda32af6a6a6964
This commit is contained in:
parent
e6231f546d
commit
8a093aa9e8
5 changed files with 204 additions and 61 deletions
|
|
@ -34,6 +34,7 @@ enum class NodeType : uint8_t {
|
|||
SELECT = 0x31,
|
||||
HAS_ATTR = 0x34,
|
||||
WITH = 0x32,
|
||||
LIST = 0x33,
|
||||
IF = 0x40,
|
||||
LET = 0x50,
|
||||
LETREC = 0x51,
|
||||
|
|
@ -152,8 +153,24 @@ struct UnaryOpNode {
|
|||
UnaryOpNode(UnaryOp o, std::shared_ptr<Node> operand, uint32_t l = 0);
|
||||
};
|
||||
|
||||
struct AttrBinding {
|
||||
std::optional<std::string> static_name; // Static key like "foo"
|
||||
std::shared_ptr<Node> dynamic_name; // Dynamic key like ${expr}
|
||||
std::shared_ptr<Node> value;
|
||||
|
||||
// Static attribute
|
||||
AttrBinding(std::string name, std::shared_ptr<Node> val)
|
||||
: static_name(std::move(name)), value(std::move(val)) {}
|
||||
|
||||
// Dynamic attribute
|
||||
AttrBinding(std::shared_ptr<Node> name_expr, std::shared_ptr<Node> val)
|
||||
: dynamic_name(std::move(name_expr)), value(std::move(val)) {}
|
||||
|
||||
bool is_dynamic() const { return !static_name.has_value(); }
|
||||
};
|
||||
|
||||
struct AttrsetNode {
|
||||
std::vector<std::pair<std::string, std::shared_ptr<Node>>> attrs;
|
||||
std::vector<AttrBinding> attrs;
|
||||
bool recursive = false;
|
||||
uint32_t line = 0;
|
||||
AttrsetNode(bool rec = false, uint32_t l = 0) : recursive(rec), line(l) {}
|
||||
|
|
@ -228,14 +245,21 @@ struct ForceNode {
|
|||
ForceNode(std::shared_ptr<Node> e, uint32_t l = 0);
|
||||
};
|
||||
|
||||
struct ListNode {
|
||||
std::vector<std::shared_ptr<Node>> elements;
|
||||
uint32_t line = 0;
|
||||
ListNode(std::vector<std::shared_ptr<Node>> elems = {}, uint32_t l = 0)
|
||||
: elements(std::move(elems)), line(l) {}
|
||||
};
|
||||
|
||||
// Node wraps a variant for type-safe AST
|
||||
class Node {
|
||||
public:
|
||||
using Variant =
|
||||
std::variant<ConstIntNode, ConstFloatNode, ConstStringNode, ConstPathNode, ConstBoolNode,
|
||||
ConstNullNode, ConstURINode, ConstLookupPathNode, VarNode, LambdaNode, AppNode,
|
||||
BinaryOpNode, UnaryOpNode, ImportNode, AttrsetNode, SelectNode, HasAttrNode,
|
||||
WithNode, IfNode, LetNode, LetRecNode, AssertNode, ThunkNode, ForceNode>;
|
||||
using Variant = std::variant<ConstIntNode, ConstFloatNode, ConstStringNode, ConstPathNode,
|
||||
ConstBoolNode, ConstNullNode, ConstURINode, ConstLookupPathNode,
|
||||
VarNode, LambdaNode, AppNode, BinaryOpNode, UnaryOpNode, ImportNode,
|
||||
AttrsetNode, SelectNode, HasAttrNode, WithNode, IfNode, LetNode,
|
||||
LetRecNode, AssertNode, ThunkNode, ForceNode, ListNode>;
|
||||
|
||||
Variant data;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue