Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rework translation-unit top-level items to disallow binary expressions #146

Merged
merged 4 commits into from
Jul 18, 2023

Conversation

amaanq
Copy link
Member

@amaanq amaanq commented Jul 17, 2023

Closes #48

I don't like how this looks with the nearly repeated rule, but it's the best option I could think of that didn't impact state count too much, maybe some JS-magic could make it look prettier with manipulating top_level_item

@XVilka if you have some more test cases I could add them

cc @ahlinc

@amaanq amaanq changed the title Decl binop conflict fix: rework translation-unit top-level items to disallow binary expressions Jul 17, 2023
@XVilka
Copy link
Contributor

XVilka commented Jul 17, 2023

@amaanq no additional testcases, sorry, but this one should be sufficient.

@XVilka
Copy link
Contributor

XVilka commented Jul 17, 2023

@amaanq actually, I might have one - char (*ptr_to_array)[];

@amaanq
Copy link
Member Author

amaanq commented Jul 17, 2023

That one seems to work on master, but good to add

grammar.js Outdated Show resolved Hide resolved
grammar.js Outdated Show resolved Hide resolved
@amaanq amaanq force-pushed the decl-binop-conflict branch 2 times, most recently from 8a57c83 to 5897d88 Compare July 17, 2023 19:43
@amaanq amaanq requested a review from aryx July 17, 2023 19:43
grammar.js Show resolved Hide resolved
grammar.js Show resolved Hide resolved
@@ -649,6 +680,36 @@ module.exports = grammar({
$._statement,
),

// This is missing binary expressions, others were kept so that macro code can be parsed better and code examples
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to say why we skipped binary expressions. what's the problem with binary expression at the top?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's because of this ambiguity with pointer expressions, could have been solved in another way? by playing with dynamic priorities?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I did try a lot w/ dynamic precendences, but that caused other issues elsewhere mainly and sometimes didn't do anything as well

grammar.js Show resolved Hide resolved
@amaanq
Copy link
Member Author

amaanq commented Jul 18, 2023

reworked

@XVilka
Copy link
Contributor

XVilka commented Jul 18, 2023

@amaanq as you rework top level statement, I wonder if it makes sense to also target this case: #129

@amaanq
Copy link
Member Author

amaanq commented Jul 18, 2023

I'm not sure about that one, I think it is correct to associate the pointer declarator with a function name/identifier

This resolves conflicts with declarations that can be interpreted as binary_expressions
Previously, pointers were associated with the function identifier, now they're associated with the return type
@amaanq amaanq merged commit 5c2cb95 into tree-sitter:master Jul 18, 2023
@amaanq
Copy link
Member Author

amaanq commented Jul 18, 2023

I reworked it anyways just for top level functions..if that proves to be incorrect/disputed I will revert @XVilka

@amaanq
Copy link
Member Author

amaanq commented Jul 18, 2023

Actually, that breaks error recovery a bit in upstream tests and still doesn't fit fully right w/ me, so I reverted it, sorry. That needs a better solution than what I had

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error parsing a declaration
4 participants