Open maxsu opened 8 months ago
I added a commit for the get_addr
function. There are some differences with this and the spec you outlined.
Additionally, I made some changes in syntax and test_syntax to accommodate the new addressing tests and functionality.
Node
.
We are finalizing the details of the
get_address
method for the ASTNode
class in our game engine, specifically on the GetAddress branch. The method signature will beNode.get_address(*args)
, withargs
being a mix of strings (for Map nodes) and integers (for Sequence nodes). This discussion includes method implementation, exception handling, and test case development, excluding performance considerations at this stage.Requirements
Node.get_address(*args)
, whereargs
is a list of attributes and indices.@functools.cache
for O(1) lookup after initial access.BadNode
andBadAddress
exceptions for error scenarios.Exceptions
BadNode
: Raised when an accessed node's attribute does not match the expected type, indicating a parsing or address resolution issue.BadAddress
: Raised when the specified address does not correspond to any node within the AST.Test Cases
test_get_address_valid_map_node: Ensure
doc_node.get_address('doc', 'vars', 2)
returns aVar
node instance with the correct value inVar.data["value"]
.test_get_address_valid_sequence_node: Verify accessing a valid index in a sequence returns the expected node.
test_get_address_invalid_key_raises_BadAddress: Confirm that accessing a non-existent key in a map node raises a
BadAddress
exception.test_get_address_invalid_index_raises_BadAddress: Check that accessing an out-of-range index in a sequence raises a
BadAddress
exception.test_get_address_type_mismatch_raises_BadNode: Validate that attempting to access a node attribute of the wrong type raises a
BadNode
exception.test_get_address_on_nonexistent_node_raises_BadAddress: Ensure that trying to access a node that doesn't exist raises a
BadAddress
exception.Proposed Python Implementation Snippet
Discussion Points
@functools.cache
implementation aligns with our requirements for efficient node lookup.Action Items
get_address
method in the ASTNode
class as described.GetAddress
branch for further testing and review.Notes