-
Notifications
You must be signed in to change notification settings - Fork 0
Add WriteTo method to DelimitedSyntaxList to eliminate manual token iteration patterns #11
Copy link
Copy link
Closed
Description
We currently duplicate a low-level pattern for writing DelimitedSyntaxList instances across the codebase, both in the MLIR project and in code generated by MLIR.Generators. This pattern manually iterates over elements and separator tokens, handling spacing and delimiter tokens inline.
This leads to:
- Boilerplate code repeated in multiple places
- Increased risk of inconsistencies or subtle formatting bugs
- Reduced readability and higher maintenance cost
Proposed Change
Introduce a WriteTo method directly on DelimitedSyntaxList that encapsulates this logic.
The method should:
- Handle writing of
OpenTokenandCloseToken - Iterate over elements and interleave
SeparatorTokenscorrectly - Apply appropriate spacing (e.g., no leading space for the first element, space before subsequent elements)
- Delegate to each element’s own
WriteTomethod
Example of Current Pattern
The following pattern appears in multiple places and should be replaced:
if (Arguments.OpenToken != null)
{
writer.WriteToken(Arguments.OpenToken.Value, string.Empty);
for (var i = 0; i < Arguments.Count; i++)
{
if (i > 0)
{
writer.WriteToken(Arguments.SeparatorTokens[i - 1], string.Empty);
}
Arguments[i].WriteTo(writer, i > 0 ? " " : string.Empty);
}
writer.WriteToken(Arguments.CloseToken!.Value, string.Empty);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels