tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
225 stars 100 forks source link

Support #if and #ifdef in if statements #202

Closed MarcelRobitaille closed 5 months ago

MarcelRobitaille commented 5 months ago

Fixes #76

I was not able to add more than $.preproc_if_in_if_statement and $.preproc_ifdef_in_if_statement to _else_clause_preproc. I got some conflicts. I am not very experienced in writing tree-sitter grammars.

amaanq commented 5 months ago

This is a sizable state count increase, and I don't think I really want to support this use case - this just opens the door for many other edge cases with preproc defines as well. Tree-sitter is just not going to handle every possible usage of macros and/or preproc defines well

MarcelRobitaille commented 5 months ago

Thank you for your feedback.

Is there any state count where you would accept this? I got the state count down to 2594 and all of the tests (including the ones I added) pass.

amaanq commented 5 months ago

What's the large state count? But again, this still sets a precedence I don't like anyways, and might be even more harmful for C++ since that would need to be updated with these changes afterwards.

MarcelRobitaille commented 5 months ago
#define LANGUAGE_VERSION 14
#define STATE_COUNT 2594
#define LARGE_STATE_COUNT 693
#define SYMBOL_COUNT 352
#define ALIAS_COUNT 3
#define TOKEN_COUNT 155
#define EXTERNAL_TOKEN_COUNT 0
#define FIELD_COUNT 39
#define MAX_ALIAS_SEQUENCE_LENGTH 9
#define PRODUCTION_ID_COUNT 132