-
Notifications
You must be signed in to change notification settings - Fork 7
V1.6 #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
/gemini review |
Warning Gemini encountered an error creating the summary. You can try again by commenting |
There was a problem hiding this 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.
asciidoc/anchor.go
Outdated
func (aa *AnchorAttribute) Children() Elements { | ||
return aa.ID | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
func (aa *AnchorAttribute) Children() Elements { | |
return aa.ID | |
} | |
func (aa *AnchorAttribute) Children() Elements { | |
return aa.Label | |
} |
/gemini review |
There was a problem hiding this 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.
/gemini review |
There was a problem hiding this 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.
func (a *Anchor) Clone() Element { | ||
return &Anchor{position: a.position, ID: a.ID, Elements: a.Elements.Clone()} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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()} | |
} |
func (ei *EndIf) Clone() Element { | ||
return &EndIf{position: ei.position, raw: ei.raw, Attributes: ei.Attributes.Clone(), Union: ei.Union, Open: ei.Open} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}
}
func (ofs *overlayFileState) ShouldIncludeFile(path asciidoc.Path) bool { | ||
switch path.Relative { | ||
case "templates/DiscoBallCluster.adoc", "templates/DiscoBallDeviceType.adoc": | ||
return false | ||
default: | ||
return true | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
# 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
# Conflicts: # provisional/cluster.go # provisional/compare.go # provisional/global.go # provisional/patch.go # provisional/pipeline.go
Hefty reworking of spec parsing to be completely non-destructive