Merged
Conversation
sdroege
reviewed
May 10, 2023
sdroege
previously approved these changes
May 11, 2023
ranfdev
commented
May 11, 2023
Member
Author
ranfdev
left a comment
There was a problem hiding this comment.
Ah, I've noticed I still need to change some little things, please don't merge yet.
da9c950 to
a45ee11
Compare
sdroege
approved these changes
May 12, 2023
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.
closes #1061
Problem
syn 2.0 removed the type
NestedMeta, that was extensively used by gtk-rs-core to parse macro attributes, without providing a direct replacement type.Instead, the suggested way to parse an attribute is now to use
Attribute::parse_nested_meta, which iterates over the arguments of an attribute and forces you to parse them.parse_nested_metatracks the spans of the arguments being parsed, so in the case an error is returned, it provides good error messages.Most of the glib-macros depended on utility functions defined in
glib-macros::utils. Those functions often tried to retrieve a single argument inside an attribute, without caring about the other arguments. This is not possible when usingAttribute::parse_nested_meta, because it requires to handle every possible argument in a single place. We can't just parse the argumentname = "value"and skipnick = "nick", becauseparse_nested_metawill considernickas an unexpected value and will throw an error.Proposed solution
Rewriting the parsing of attributes taking advantage of
parse_nested_meta, which is now the suggested way to parse attribute arguments (also see https://docs.rs/syn/latest/syn/meta/struct.ParseNestedMeta.html). A new set of utilities have been implemented inglib-macro::utilsto ease the parsing process.To do
implement some tests for the new parsing utility functions, to polish their interface and ensure correctness.
Observations
I would consider using the crate https://github.com/jf2048/deluxe (by @jf2048, #970) to handle attribute parsing.
Conclusions
parse_nested_metakeeps track of argument spans and ensures every argument is parsed correctly.