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

Accept type parameters on grammar (e.g. lifetimes) (Fixes #220) #254

Merged
merged 1 commit into from
Mar 14, 2021

Conversation

bgw
Copy link
Contributor

@bgw bgw commented Mar 13, 2021

This allows the parser to operate over types like Token<'code> by supplying the lifetime as a type parameter on the grammar (#220):

peg::parser! {
    grammar feeny<'a>() for Tokens<'a> {
        // snip
    }
}

This should work with all type parameters, not just lifetimes, but lifetimes are the motivating example here.

Like @kevinmehall's comment on #220 suggests, this simply adds rust_ty_params() to peg_grammar in the meta-grammar, and then threads that through.

If a rule defines it's own type parameters, those come after the grammar's type parameters on the parser's exported functions/entrypoints.

This allows the parser to operate over types like `Token<'code>` by
supplying the lifetime as a type parameter on the grammar:

```
peg::parser! {
    grammar feeny<'a>() for Tokens<'a> {
        // snip
    }
}
```

This should work with all type parameters, not just lifetimes, but
lifetimes are the motivating example here.

Like @kevinmehall's comment on kevinmehall#220 suggests, this simply adds
`rust_ty_params()` to `peg_grammar` in the meta-grammar, and then
threads that through.

If a rule defines it's own type parameters, those come after the
grammar's type parameters on the parser's exported
functions/entrypoints.

Fixes kevinmehall#220
@kevinmehall kevinmehall merged commit 2dacb48 into kevinmehall:master Mar 14, 2021
@kevinmehall
Copy link
Owner

Thanks!

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.

None yet

2 participants