Rework Entity parsing implementation, foundation for comment improvements #1580
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.
This PR refactors the way that the initial entity definition blocks are parsed by the
parse
function before they then get turned into anUnboundEntityDef
. This is an initial change that hopefully will make it easier to implement #1297 and #1296.I have added an example test file that illustrates various possible comment styles and what the parse currently is or isn't picking up. This test can be used when tackling the issues linked above. The content of this test is here:
https://github.com/yesodweb/persistent/blob/54be9d68125984249587f81971269f1c7c599a4a/persistent/test/Database/Persist/TH/CommentsSpec.hs
I'm not sure exactly what behavior is expected for comments, so I'd welcome any input on what the behavior should be as I might have made some assumptions that are not desired for the library. But I'd assume everything I've included there persistent would want to be parsed as comments.
The only actual behavioral change regarding comments in this change is illustrated here:
54be9d6#diff-a2bb675c726f8d466d83a85584878a9053dd6304d85aedf0511b8affb8074c56
With this change, that style of comment on the fields is now picked up by the parser, everything else should be the same.
I've also re-worked some of the unit tests, as I've changed some of the types exposed by this module. I've tried to make the tests a bit more flexible as whenever making a change to this module there is often quite a lot to change in the tests. Hopefully
ParsedEntityDef
andParsedFieldDef
can better replaceLinesWithComments
which is a lot more low level. I appreciate the coverage you get from the lower level tests, so I have tried to balance things here between flexibility and coverage, I've been through all the tests I had to remove and ensured that we're still covered by a new test based around the types I've added here.Before submitting your PR, check that you've:
@since
declarations to the Haddockfourmolu
on any changed files (restyled
will do this for you, soaccept the suggested changes if it makes them)
.editorconfig
andfourmolu.yaml
files for details)After submitting your PR:
(unreleased)
on the Changelog