Add support for old-style function definitions #23
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.
I'm looking to refactor some very old code and it would be useful to parse old-style (K&R) function definitions. For example:
(I see even the Github syntax highlighting doesn't handle it)
Adding
repeat($.declaration)
in the function definition seems natural.Unfortunately, the attributes cause a little problem. For example in
it isn't clear if the
__attributes__
are attached to the function of the variable (or one each way!). This causes the generator to complain about a conflict.By changing the precedence and adding a conflict rule, I was at least able to get sensible parses in most cases, but I'm not entirely happy with it. Perhaps someone more familiar with tree-sitter parsing can take a look.
I suspect the number of C files using both K&R defs and attributes is vanishingly small, but it would be nice to be complete.
For reference Clang allows the above and attaches the attributes to the function, but throws an error with:
(Just a single newline! Whoever said C was whitespace independent!)
I don't have GCC on hand to check this right now.