This repository was archived by the owner on Dec 12, 2024. It is now read-only.
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.
Added an
AttributeDeclaration
type in order to round-trip attributes.An attribute in swift is simultaneously overly complicated and inflexible.
The syntax is an @ sign followed by a name followed by an optional argument set off by parens.
What can go in the parens is a seamy, inconsistent set of junk that can included nested lists set off by parentheses, brackets, or braces (as long as they balance).
Examples:
And the contents of the parentheses is determined entirely by the name of the attribute.
So how should we represent this in C#? We get an AttributeDeclaration which has a name and an optional list of parameters.
A parameter is one of a plain AttributeParameter (should never happen), an AttributeParameterLabel (any non-number), an AttributeParameterLiteral (a number), an AttributeParameterSublist.
The XML consumption code is straightforward, although I'm sure it could be better where the right set of attributes/names would make it just read in on its own (cue "old man shouts at clouds" meme).
I added a List to the
BaseDeclaration
and therefore attributes are now available on classes, structs, enums, protocols, properties, and functions (take that, anti-inheritance people!).In addition, the original grammar definition tried to break out a separate rule for platform and version, but it was broken and couldn't handle wild cards, so I got rid of it entirely and got rid of the version parameter. I also made separators and operators get treated as labels. There really isn't any advantage to having those broken out right now (if ever).