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

Parse expressions in preprocessor #if statement #29

Merged
merged 2 commits into from
Dec 17, 2019

Conversation

calixteman
Copy link
Contributor

No description provided.

@calixteman
Copy link
Contributor Author

@maxbrunsfeld ping ?

Copy link
Contributor

@maxbrunsfeld maxbrunsfeld left a comment

Choose a reason for hiding this comment

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

Is this going to cover all possible #if arguments?

I have been reluctant to try to model the preprocessor too precisely, because I know that it is an entirely different language in some ways. I'm wondering if for most purposes it is better to just parse preproc_arg values as C using a separate (best-effort) pass. That is what Atom currently does for macro definitions, maybe we could expand it to include all preproc_arg values.

I might be open to this, if it is really worth the complexity that it adds. What are your thoughts on the tradeoffs here. What are you using this functionality for?

@calixteman
Copy link
Contributor Author

calixteman commented Nov 20, 2019

Is this going to cover all possible #if arguments?

I'd say yes, I followed the spec here:
https://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_4.html#SEC38

I have been reluctant to try to model the preprocessor too precisely, because I know that it is an entirely different language in some ways. I'm wondering if for most purposes it is better to just parse preproc_arg values as C using a separate (best-effort) pass. That is what Atom currently does for macro definitions, maybe we could expand it to include all preproc_arg values.

I might be open to this, if it is really worth the complexity that it adds. What are your thoughts on the tradeoffs here. What are you using this functionality for?

I did it to try to have a "complete" parser but not sure if it's useful or not (I've no use case right now).
Could it reduce performances ?
Is it something of interest for atom's people (it should be possible to gray some part according the operand of if operator) ?

calixteman and others added 2 commits December 17, 2019 09:22
* Hide the wrapper rules
* Alias the rulres to match their corresponding expression rule
* Handle line continuations as extra tokens
@maxbrunsfeld
Copy link
Contributor

Ok, I think you're right: the rules for preprocessor expressions are pretty clear, so there's no reason not to parse them. I pushed up a small change to make the preprocessor expressions appear similar to normal expressions in the tree.

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.

2 participants