feat: parent pointer#10
Open
mxsgx wants to merge 2 commits into
Open
Conversation
Open
Contributor
There was a problem hiding this comment.
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.ParentplusIsRoot()andDepth()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. |
Contributor
There was a problem hiding this comment.
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() {}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
go test ./...passes locally