Skip to content

Conversation

hasty
Copy link
Contributor

@hasty hasty commented Sep 8, 2025

Hefty reworking of spec parsing to be completely non-destructive

@hasty hasty requested a review from a team as a code owner September 8, 2025 23:35
@hasty
Copy link
Contributor Author

hasty commented Sep 8, 2025

/gemini review

@gemini-code-assist
Copy link

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and commendable refactoring to make spec parsing completely non-destructive. The core of this change is the new overlay package and the addition of Clone() methods across the data model, which is a solid approach for this kind of task. The changes are extensive and generally well-executed. I've identified a few issues, primarily related to incorrect or incomplete Clone() implementations and some inconsistencies in the new traversal logic. Addressing these will help ensure the robustness and correctness of the new parsing mechanism.

Comment on lines 73 to 75
func (aa *AnchorAttribute) Children() Elements {
return aa.ID
}

Choose a reason for hiding this comment

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

high

The Children() method returns aa.ID, while the Append() method modifies aa.Label. This is inconsistent. The Parent interface, which Children() is part of, implies that Children() should return the elements that can be modified by Append(). To maintain consistency, Children() should probably return aa.Label.

Suggested change
func (aa *AnchorAttribute) Children() Elements {
return aa.ID
}
func (aa *AnchorAttribute) Children() Elements {
return aa.Label
}

@hasty
Copy link
Contributor Author

hasty commented Oct 6, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a major refactoring to make the AsciiDoc parsing process non-destructive. This is a significant architectural change, primarily implemented through a new overlay package and the addition of Clone() methods to all AST elements. This allows for modifications to the document structure without altering the original parsed tree. The changes are extensive and affect many parts of the codebase, including core data structures, parsing logic, and command-line tools. Overall, this is a well-executed refactoring that improves the robustness of the parsing pipeline. I've identified a couple of critical bugs in the new Clone() implementations and in a test file, along with some minor inconsistencies that should be addressed.

@hasty
Copy link
Contributor Author

hasty commented Oct 6, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant and impressive refactoring of the AsciiDoc parsing logic to make it completely non-destructive. The core changes involve adding Clone() methods to all AST elements and introducing a new overlay package to manage modifications to the parsed document tree. This new approach is much cleaner and should make further processing of the spec more robust. The introduction of the spec.Library concept to manage document collections is also a great improvement over the previous DocGroup system.

The changes are extensive and well-executed. I've found a couple of minor issues in the new Clone() implementations where some fields were not being deep-copied, which could lead to shared state issues. I've also pointed out a case of hardcoded paths that could be made more configurable. Overall, this is a very solid piece of work that greatly improves the architecture of the parser.

Comment on lines 114 to 116
func (a *Anchor) Clone() Element {
return &Anchor{position: a.position, ID: a.ID, Elements: a.Elements.Clone()}
}

Choose a reason for hiding this comment

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

high

The ID field is of type Elements, which is a slice of Element. It is not being cloned here, which will lead to shared state between the original and the cloned Anchor instances. This can cause unexpected side effects when one of them is modified. You should perform a deep copy of the ID field by calling its Clone() method.

Suggested change
func (a *Anchor) Clone() Element {
return &Anchor{position: a.position, ID: a.ID, Elements: a.Elements.Clone()}
}
func (a *Anchor) Clone() Element {
return &Anchor{position: a.position, ID: a.ID.Clone(), Elements: a.Elements.Clone()}
}

Comment on lines 186 to 187
func (ei *EndIf) Clone() Element {
return &EndIf{position: ei.position, raw: ei.raw, Attributes: ei.Attributes.Clone(), Union: ei.Union, Open: ei.Open}

}

Choose a reason for hiding this comment

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

high

The Open field, which is of type Element, is not being cloned. Since Element is an interface that can hold a pointer, this will result in a shallow copy, leading to shared state between the original and cloned EndIf instances. This can cause unintended mutations. You should clone the Open element, making sure to handle the case where it might be nil.

A possible implementation:

func (ei *EndIf) Clone() Element {
	var openCloned Element
	if ei.Open != nil {
		openCloned = ei.Open.Clone()
	}
	return &EndIf{position: ei.position, raw: ei.raw, Attributes: ei.Attributes.Clone(), Union: ei.Union, Open: openCloned}
}

Comment on lines +96 to +103
func (ofs *overlayFileState) ShouldIncludeFile(path asciidoc.Path) bool {
switch path.Relative {
case "templates/DiscoBallCluster.adoc", "templates/DiscoBallDeviceType.adoc":
return false
default:
return true
}
}

Choose a reason for hiding this comment

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

medium

This function contains hardcoded paths (templates/DiscoBallCluster.adoc, templates/DiscoBallDeviceType.adoc). This makes the code less reusable and harder to maintain if these paths change or if this logic needs to be applied to other files. Consider making these paths configurable, for example by passing them in as options or reading them from a configuration file.

hasty added 21 commits October 7, 2025 10:09
# Conflicts:
#	asciidoc/fenced.go
# Conflicts:
#	matter/spec/cluster.go
#	matter/spec/requirements.go

# Conflicts:
#	matter/spec/commands.go
#	matter/spec/devicetype.go
#	matter/spec/event.go
#	matter/spec/requirements.go

# Conflicts:
#	matter/spec/conditions.go
#	matter/spec/devicetype.go
#	matter/spec/doc.go
#	matter/spec/preparse.go
#	matter/spec/requirements.go
#	matter/spec/section.go

# Conflicts:
#	disco/sections.go

# Conflicts:
#	matter/spec/devicetype.go
#	matter/spec/field.go

# Conflicts:
#	matter/spec/cluster.go
# Conflicts:
#	cmd/cli/conformance.go
#	matter/conformance/conformance_test.go
#	matter/conformance/context.go
#	matter/conformance/identifier.go
#	matter/conformance/parse.go
#	zap/conformance.go
#	zap/render/composed.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.

1 participant