Skip to content

Conversation

@seborama
Copy link
Owner

@seborama seborama commented May 2, 2025

similarly to general object properties

Summary by CodeRabbit

  • Documentation

    • Improved and reorganised the section on dot accessors for objects, adding clearer explanations and a new example illustrating method chaining.
  • Tests

    • Added a new test to validate chained method calls on objects.
    • Renamed a test for consistency.
  • Refactor

    • Simplified handling of object receivers and error reporting for object property and method accessors.
    • Improved internal code clarity and consistency.

similarly to general object properties
@coderabbitai
Copy link

coderabbitai bot commented May 2, 2025

Walkthrough

The changes reorganise and clarify the documentation for object dot accessors, add a new example demonstrating chained method calls, and improve the explanation of how Go objects are accessed within expressions. In the tests, a new function is added to verify chained method call parsing and evaluation, and an existing test is renamed. Code changes introduce an experimental DotFunction struct, remove unused imports and debug statements, and refactor object accessor functions for clarity and consistency, including improved error handling and variable naming.

Changes

File(s) Change Summary
README.md Reorganised and clarified the "Objects Dot accessors" documentation section; added a second example for chained method calls; fixed a typo; improved structure and explanations.
gal_test.go Renamed TestObjects_ChainedProperties to TestObjects_Chained_Properties; added new test TestObjects_Chained_Methods for validating chained method call parsing and evaluation; included a TODO for future test enhancements.
object.go Added new experimental DotFunction struct; removed unused log/slog import and debug logging from goAnyToGalType function; no functional changes to existing logic.
tree.go Simplified entry interface declaration; refactored object accessor functions by renaming variables, changing types for clarity, unwrapping receivers, improving error messages, and removing redundant debug statements.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GalExpressionParser
    participant GalEvaluator
    participant GoObject

    User->>GalExpressionParser: Parse "aCar.GetThinger().Thing().Add('::with a suffix')"
    GalExpressionParser->>GalEvaluator: Build AST for chained method calls
    GalEvaluator->>GoObject: Call GetThinger()
    GoObject-->>GalEvaluator: Returns Thinger object
    GalEvaluator->>GoObject: Call Thing() on Thinger
    GoObject-->>GalEvaluator: Returns Thing object
    GalEvaluator->>GoObject: Call Add("::with a suffix") on Thing
    GoObject-->>GalEvaluator: Returns final result string
    GalEvaluator-->>User: Result: "it's a thing!::with a suffix"
Loading

Possibly related PRs

  • seborama/gal#24: Refines and clarifies the "Objects Dot accessors" documentation, directly building upon the section introduced in this PR.
  • seborama/gal#23: Introduces explicit support for user-defined object methods, which is extended by the new tests and documentation in the current PR.
  • seborama/gal#28: Refactors core evaluation logic for object methods and properties, related as both PRs touch object method/property handling and function evaluation.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: can't load config: can't set severity rule option: no default severity defined
Failed executing command with error: can't load config: can't set severity rule option: no default severity defined

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tree.go (1)

8-8: Consider replacing the entry type with any directly.

The comment already suggests this change. Go's any type was introduced as a more readable alias for interface{} and has become the preferred approach in modern Go code.

-type entry interface{} // NOTE: this could be dropped in favour of using `any` directly.
+type entry = any
object.go (1)

12-17: New DotFunction struct provides foundation for enhanced method chaining.

This experimental structure is well designed to encapsulate a method call with its receiver, name, function body, and arguments. While not yet integrated into the codebase (as noted in the comment), it provides a clear foundation for implementing the method chaining functionality that the tests now cover.

Consider documenting the intended usage pattern and providing an example to guide future development.

// Example of intended usage:
// expr := `obj.Method1().Method2(arg)`
// might be represented as:
// DotFunction{
//   Name: "Method2",
//   Receiver: DotFunction{
//     Name: "Method1",
//     Receiver: objectVal,
//     BodyFn: method1Fn,
//   },
//   Args: []Tree{{argValue}},
// }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e42687d and 82f803c.

📒 Files selected for processing (4)
  • README.md (2 hunks)
  • gal_test.go (2 hunks)
  • object.go (1 hunks)
  • tree.go (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
object.go (3)
value.go (1)
  • Value (7-13)
function.go (1)
  • FunctionalValue (12-12)
tree.go (1)
  • Tree (10-10)
tree.go (4)
value_undefined.go (4)
  • Undefined (16-18)
  • Undefined (91-93)
  • Undefined (95-97)
  • NewUndefinedWithReasonf (24-28)
value.go (1)
  • Value (7-13)
object.go (5)
  • ObjectValue (36-39)
  • Object (29-29)
  • ObjectGetMethod (183-285)
  • Dot (21-23)
  • ObjectGetProperty (124-180)
variable.go (1)
  • Variable (3-5)
🔇 Additional comments (9)
tree.go (4)

99-100: Good optimization to fail fast on undefined values.

Moving this check earlier prevents unnecessary processing when an undefined value is already detected. This is a sensible optimization.


207-221: Improved object receiver handling provides better type safety.

The refactoring to use any for the receiver and explicitly unwrap ObjectValue objects improves the accessor code in several ways:

  1. Better type representation (receiver is truly "any" type)
  2. More descriptive variable name ("receiver" vs "vVal")
  3. Explicit handling of ObjectValue unwrapping with clear comments
  4. Better error messages that guide the user to check if the receiver is nil

This change aligns with the PR's goal of extending support for general object methods and improves maintainability.


235-235: Simplified error return path improves readability.

Directly returning the result of vFv (which will be an Undefined type) streamlines the error handling path and removes the need for creating a new Undefined instance.


241-255: Consistent pattern applied to variable accessor function.

The same improvement pattern from objectAccessorDotFunctionFn has been correctly applied to objectAccessorDotVariableFn, ensuring consistency between both accessor functions.

gal_test.go (3)

396-396: Consistent naming pattern applied to test function.

The renamed test function now follows a consistent naming pattern with underscores between words, which improves readability and aligns with the new test added below.


541-592: Comprehensive test for chained method calls.

This test effectively validates both parsing and evaluation of chained method calls, which is a key part of the PR's goal. The test:

  1. Verifies the correct AST structure for nested method calls
  2. Confirms evaluation produces the expected result
  3. Ensures the unwrapping of receivers works correctly through the chain

The test aligns perfectly with the updated README example and provides good coverage for the implemented functionality.


539-539:

Details

❓ Verification inconclusive

Interesting exploration idea for future development.

The TODO comment suggests exploring nested parentheses expressions like ((aCar.Stereo).Brand).Country, which would be a valuable extension to test the robustness of the accessor implementation.

To better understand the current limitations around parenthesized expressions, we could verify if the parser currently supports this syntax:


🏁 Script executed:

#!/bin/bash
# Check for any existing tests with parenthesized object expressions
grep -r "(\s*[a-zA-Z0-9_]*\.[a-zA-Z0-9_]*\s*)" --include="*.go" .

Length of output: 4664


No nested parentheses property access tests found

I searched the existing Go tests for parenthesised field-access expressions (e.g. ((aCar.Stereo).Brand).Country) and didn’t find any examples. We should confirm whether our parser grammar already supports nested, parenthesised object accessors. If it doesn’t, extending the grammar and adding a dedicated test in gal_test.go (or a new tree_builder_test.go case) for ((aCar.Stereo).Brand).Country will help verify and harden this functionality.

• Verify parser support in the expression grammar (e.g. in tree.go or grammar definitions).
• Add a unit test covering a nested, parenthesised accessor expression.

README.md (2)

225-228: Clearer explanation of dot accessor semantics.

The revised description more concisely explains how gal handles object properties and methods through the dot accessor, and the automatic type conversion capabilities that support expression evaluation.


239-256: Well-structured examples clarify dot accessor usage patterns.

The new examples section with distinct "Example 1" and "Example 2" headings provides clear, focused illustrations of both property access chains and method call chains. This organization makes the documentation more readable and the examples more discoverable.

Example 2 nicely demonstrates the method chaining functionality that was implemented in the code and tested in the new test function, showing good alignment between documentation and implementation.

@seborama seborama merged commit 196c4f9 into main May 2, 2025
3 checks passed
@seborama seborama deleted the feat/GeneralObjectMethods branch May 2, 2025 23:44
This was referenced May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants