feat!: add support for reflection#333
Merged
jdrouhard merged 4 commits intotree-sitter:masterfrom Sep 27, 2025
Merged
Conversation
e593da8 to
fec98f7
Compare
Collaborator
|
Wow, this is exciting. Reflection is going to be amazing. Thanks for getting on this so quickly! I merged another PR in front of this one so I'm going to rebase and regenerate. |
fec98f7 to
a611a0c
Compare
jdrouhard
approved these changes
Sep 16, 2025
This adds support for all the language changes introduced in P2996 which was recently voted into the upcoming c++26 standard. This includes: - reflection expressions: the reflect operator (^^) followed by expressions, type descriptors, or the global namespace (::) - splice specifiers/expressions: [: expression :], which can appear as a type, expression, alias descriptor, and more. - consteval blocks: similar to static_asserts but have been introduced specifically to allow constant evaluation side effects to occur at specific places in code
Related to reflection, annotations use the same syntax as attributes, but begin with an `=` and support any constant expression. Annotations and Attributes can't be mixed within [[ ... ]].
Introduces support for `template for ( init; for-range-decl : expansion-init )` which is a compile-time way to expand (iterate over): - expansion expressions - anything destructurable via structured bindings - ranges with compile time size It was sufficient to simply re-use the existing rule for _for_range_loop_body for the part inside the parentheses, but add the required sequence of `template` followed by `for`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Three commits here for three really huge c++26 features. Included corpus tests that pull most of the examples from the ISO papers themselves.
P2996: reflection
This adds support for all the language changes introduced in P2996 which
was recently voted into the upcoming c++26 standard.
This includes:
^^) followed byexpressions, type descriptors, or the global namespace (
::)[: expression :], which can appear as atype, expression, alias descriptor, and more.
constevalblocks: similar to static_asserts but have been introducedspecifically to allow constant evaluation side effects to occur at
specific places in code
P3394: annotations
Related to reflection, annotations use the same syntax as attributes,
but begin with an
=and support any constant expression. Annotationsand Attributes can't be mixed within [[ ... ]].
P1306: expansion statements
Introduces support for
template for ( init; for-range-decl : expansion-init )which is a compile-time way to expand (iterate over):
It was sufficient to simply re-use the existing rule for
_for_range_loop_body for the part inside the parentheses, but add the
required sequence of
templatefollowed byfor