Repository navigation
pxf: formatDocument keeps every directive in document order (#188) - #192
Merged
Merged
Conversation
formatDocument dropped @proto and wrote every named directive before every dataset. The draft requires a formatter to keep every directive in document order (trendvidia/protowire#558, #559): an anonymous @proto binds the typed directive after it, so order is part of the meaning. Port protowire-go's topDirectives, formatNamedDirective, formatDataset and formatProto: the three directive lists are merged back by source offset, each directive written after its comments. @type stays first. A document whose only directive is @type formats as before. FormatDirectivesTest ports Go's format_directives_test.go and adds the issue's two inputs; each case checks the output re-parses to the same directives and is a fixed point.
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.
Fixes #188.
Format.formatDocumentused to drop@proto. It also wrote every named directive before every dataset, so a document with@dataset t.v1.T (id)/(1)and then@entry x { a = 1 }came out with the@entryfirst. Order matters here: an anonymous@protobinds the typed directive after it.It now keeps every directive in document order, each after its comments, as the draft requires (trendvidia/protowire#558, #559) and as protowire-go does since protowire-go#262.
@typeis still written first, since it binds no@proto. A dataset is its header and then one row per line, an absent cell left empty andnullwritten. A named directive's body and a@protobody are written as they were read. A document whose only directive is@typeformats exactly as before.Two smaller output changes come with matching Go byte for byte: directives are no longer separated by blank lines, and a dataset with no type (after an anonymous
@proto) is written@dataset (id)rather than@dataset (id).This ports Go's
topDirectives,formatNamedDirective,formatDatasetandformatProto. The newFormatDirectivesTestports Go'sformat_directives_test.goand adds the issue's two inputs. Every case also checks that the output re-parses to the same directives and that formatting it again changes nothing.Evidence
FormatDirectivesTest, 8 tests, 0 failures (from its JUnit XML).Format.javaand the new tests, the runner printed8 tests completed, 7 failed. The one that passed,onlyTypeUnchanged, pins behaviour that did not change. Failing:dataset,entryAndNamedDirective,protoShapes,directivesKeepSourceOrder,directiveComments,issue188ProtoIsKept,issue188DatasetBeforeEntryKeepsOrder../gradlew --no-daemon --continue build -PpxfJavaMeta.repo=/nonexistent(the plugin at the pinnedpxfJavaMeta.ref, as CI builds it):BUILD SUCCESSFUL. JUnit XML across all modules: 830 tests, 0 failures, 0 errors.REQUIRE_PORTS=go,java,java-lite:✓ Every port that ran writes the golden text.(173 pairs)✓ All ports conform to docs/HARDENING.md on the adversarial corpus.(222 pairs)✓ Every port that ran writes protowire-go's bytes.(256 pairs)@entrywith label and type, a bare@flag,@flagwith two prefixes, a dataset with list, timestamp, duration, bytes, escaped-string, non-ASCII and absent cells, a triple-quoted@proto,@typeafter@proto, the issue's two inputs) formatted by protowire-go main'sFormatDocumentand by this branch. 13 are byte-identical; both ports refuse@typebeside@datasetwith the same error. The one difference is not about directives. The Java parser does not keep a trailing comment on an entry, sob = 1 # tccomes out asb = 1, or with# tcmoved onto the next line when another entry follows. That happens on main too, with or without directives, and is not changed here.