Skip to content

Conversation

@taminomara
Copy link
Contributor

@taminomara taminomara commented Jun 5, 2025

This commit adds a new directive %parse-generics, which allows passing arbitrary generics (types and lifetimes) to the generated parser implementation.

The generics are propagated to action functions and __GtActionsKind, so they're available in return types as well.

This change only affects generated code: generics are not propagated to parser backend.

I've also added an example with my use case: passing an arena allocator, and returning references to AST nodes.

@taminomara taminomara force-pushed the generic-params branch 2 times, most recently from 93119d1 to 23007f4 Compare June 6, 2025 00:10
@ltratt ltratt self-assigned this Jun 7, 2025
@ltratt
Copy link
Member

ltratt commented Jun 7, 2025

This looks good to me. @ratmice, any comments?

@ratmice
Copy link
Collaborator

ratmice commented Jun 7, 2025

I've been a bit preoccupied so my analysis isn't going to be particularly deep.
There is some stuff in here Generics::split_for_impl which I'm not familiar with,
but I feel like I can reasonably follow it, it seems like a more principled approach for constructing the generic types!

The only thing I noticed is it'd be good to rewrite the commit message which still references %type-params that was changed to %parse-generics.

This commit adds a new directive `%parse-generics`, which allows passing arbitrary generics (types and lifetimes) to the generated parser implementation.

The generics are propagated to action functions and `__GtActionsKind`, so they're available in return types as well.

This change only affects generated code: generics are not propagated to parser backend.

I've also added an example with my use case: passing an arena allocator, and returning references to AST  nodes.
@ltratt ltratt added this pull request to the merge queue Jun 7, 2025
Merged via the queue into softdevteam:master with commit 072287c Jun 7, 2025
2 checks passed
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.

3 participants