Skip to content

feat: parent pointer#10

Open
mxsgx wants to merge 2 commits into
mainfrom
parent-pointer
Open

feat: parent pointer#10
mxsgx wants to merge 2 commits into
mainfrom
parent-pointer

Conversation

@mxsgx

@mxsgx mxsgx commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Checklist

  • Tests added or updated
  • README updated if public API changed
  • CHANGELOG updated if user-visible
  • VERSIONING.md updated if release policy changed
  • go test ./... passes locally

@mxsgx mxsgx linked an issue Apr 30, 2026 that may be closed by this pull request
@mxsgx mxsgx requested a review from Copilot April 30, 2026 17:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds upward navigation in the AST by introducing parent pointers on Block nodes, enabling features like root detection and depth calculation while keeping parent links updated during parsing and mutation.

Changes:

  • Add Block.Parent plus IsRoot() and Depth() helpers for upward traversal.
  • Link/unlink parent pointers during parse (ParseReader) and AST mutations (Append/Insert/Remove), plus include-resolution nesting updates.
  • Add tests and a runnable example demonstrating parent-pointer usage; update README/CHANGELOG.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ast.go Introduces Container, adds Block.Parent, and implements parent-linking helpers.
parser.go Calls setParents(doc) after parse; updates include-resolution path to set parents on resolved child blocks.
document.go Ensures parent pointers are attached/detached on document-level mutations.
block.go Ensures parent pointers are attached/detached on block-level mutations; adds IsRoot()/Depth().
parent_test.go Adds coverage for parent pointers after parsing and after mutation/removal.
examples/parent-pointer/main.go Demonstrates upward traversal and parent-safe mutations.
README.md Documents the new example.
CHANGELOG.md Notes the new runnable example.

Comment thread parser.go
Comment thread parent_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

ast.go:49

  • Statement is implemented by Block via a value receiver (func (Block) isStatement()), which means callers can append a non-pointer Block value into a Document/Block Statements slice. Most of the codebase (rendering, walking, FindBlocks, parent wiring) only handles *Block, so a value Block will be silently skipped and won’t get Parent pointers. Consider making Block implement Statement only for *Block (pointer receiver) or consistently handling both Block and *Block in type switches/assertions.
// Block represents a container directive, e.g. `<Directory /var/www> ... </Directory>`.
type Block struct {
	Name       string
	Args       []string
	Children   []Statement
	Parent     Container
	Pos        Position
	EndPos     Position
	EndComment string
}

func (Block) isStatement() {}

Comment thread block.go
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.

Parent pointer

2 participants