feat(tdl): Add Tuple AST node. - #189
Conversation
WalkthroughAdds a new Tuple container node to the TDL AST: CMake exports Tuple sources/headers, Tuple class and implementation (create, serialize_to_str, is_empty) are added, and unit tests are extended to exercise empty and populated Tuple serialization and child counts. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Code
participant TupleFactory as Tuple::create
participant Validator as validate_child_node_type
participant Container as Container (add_child)
participant Result as Result<unique_ptr<Node>>
Test->>TupleFactory: create(vector<unique_ptr<Node>> elements)
loop each element
TupleFactory->>Validator: validate_child_node_type(element)
Validator-->>TupleFactory: ok / error
end
TupleFactory->>Container: add_child(element) (move)
TupleFactory-->>Result: Result<unique_ptr<Tuple>>
sequenceDiagram
participant Test as Test Code
participant TupleNode as Tuple::serialize_to_str
participant Children as Child Nodes
participant Result as Result<string>
Test->>TupleNode: serialize_to_str(indentation)
alt no children
TupleNode-->>Result: Result<string>("[Type[Container[Tuple]]]:Empty")
else has children
TupleNode->>Children: visit_children -> serialize_to_str(indentation+1)
Children-->>TupleNode: serialized parts / errors
TupleNode-->>Result: Result<string>(joined formatted output)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
tests/tdl/test-parser-ast.cpp (1)
239-252: Consider a clearer API for empty tuplesTuple::create({}) works here (empty initializer_list implicitly constructs an empty vector), but it’s a bit subtle. A dedicated no-arg factory would make intent explicit and avoid relying on that implicit conversion.
Follow-up in Tuple.hpp/cpp below adds:
- static create() -> Result<std::unique_ptr>
Also updates this test to call Tuple::create() directly.
Proposed diffs are provided in the Tuple.hpp/cpp comments; a small test tweak is included there as well.
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp (1)
24-33: Optional: Add a dedicated factory for empty tuplesA no-arg create() improves clarity for empty tuples and avoids relying on implicit vector construction from {}.
Apply this header diff:
class Tuple : public Container { public: // Factory function @@ [[nodiscard]] static auto create(std::vector<std::unique_ptr<Node>> elements) -> ystdlib::error_handling::Result<std::unique_ptr<Node>>; + + // Convenience factory for an empty Tuple + [[nodiscard]] static auto create() + -> ystdlib::error_handling::Result<std::unique_ptr<Node>>; @@ [[nodiscard]] auto is_empty() const -> bool { return 0 == get_num_children(); }And in tests, switch Tuple::create({}) to Tuple::create() (see test diff in the tests file comment).
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
19-30: Factory logic is sound; add empty-tuple overload for ergonomicsValidation and move semantics are correct. To support a clearer empty-tuple creation, add a no-arg create().
Apply this addition:
auto Tuple::create(std::vector<std::unique_ptr<Node>> elements) -> ystdlib::error_handling::Result<std::unique_ptr<Node>> { @@ return tuple; } + +auto Tuple::create() + -> ystdlib::error_handling::Result<std::unique_ptr<Node>> { + return std::make_unique<Tuple>(Tuple{}); +}
40-61: Minor perf nit: pre-allocate serialized_children capacityAvoids potential reallocations when serialising many elements.
Apply this diff:
- std::vector<std::string> serialized_children; + std::vector<std::string> serialized_children; + serialized_children.reserve(get_num_children());Optional readability: consider naming serialized_children -> serialized_elements to reflect Tuple semantics.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/spider/CMakeLists.txt(2 hunks)src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp(1 hunks)src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp(1 hunks)tests/tdl/test-parser-ast.cpp(4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp (2)
elements(24-25)indentation_level(28-29)src/spider/tdl/parser/ast/Node.hpp (2)
visit_children(73-74)child(103-104)
tests/tdl/test-parser-ast.cpp (4)
src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.hpp (2)
Tuple(36-36)elements(24-25)src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Tuple.cpp (2)
create(19-30)create(19-20)src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/List.cpp (2)
create(16-23)create(16-17)src/spider/tdl/parser/ast/node_impl/type_impl/container_impl/Map.cpp (2)
create(69-84)create(69-70)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: non-storage-unit-tests (ubuntu-22.04)
- GitHub Check: non-storage-unit-tests (ubuntu-24.04)
- GitHub Check: lint
🔇 Additional comments (2)
src/spider/CMakeLists.txt (1)
204-204: CMake wiring for Tuple looks correctTuple.cpp and Tuple.hpp are added consistently alongside List/Map. No issues from a build/export standpoint.
Also applies to: 223-223
tests/tdl/test-parser-ast.cpp (1)
3-7: Includes and Tuple alias are appropriateNew headers and using-alias for Tuple are consistent with existing patterns.
Also applies to: 20-20, 35-35
Description
This PR introduces the
Tuplecontainer type. A tuple can contain a list of element types. We will use a Tuple as a container to represent return values with multiple types.Notice that a tuple can be empty, meaning that it contains no elements.
Checklist
breaking change.
Validation performed
Tuplenodes.Summary by CodeRabbit
New Features
Tests