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_meta
tracks 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_meta
will considernick
as 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::utils
to 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_meta
keeps track of argument spans and ensures every argument is parsed correctly.