Skip to content

Conversation

kevinmehall
Copy link
Owner

Rust-peg currently adds &'input to the specified input type. The 'input lifetime violates macro hygiene and is confusing to use along with other explicitly-declared lifetimes used in the input type.

This change also allows Copy input wrapper types like SliceByRef to be zero-cost, instead of adding another layer of pointer indirection.

Breaking change

All grammars must add & to their input type, and if they use the 'input lifetime, must explicitly declare it.

Before:

grammar g() for str {

After:

grammar g() for &str {

or

grammar g<'input>() for &'input str {

Additionally, the signatures of the Parse, ParseElem, ParseLiteral, and ParseSlice traits have changed. If you implement these traits for custom input types, you'll need to make changes to implement these traits for &T rather than T, and take self rather than &self.

To Do

  • Detect unfixed str and [T] input types and either automatically do the right thing or give an error message that is more actionable than the one Rust gives.

@kevinmehall kevinmehall force-pushed the input-lifetime-hygiene branch from 717ee63 to e9d6a02 Compare November 13, 2022 21:18
@kevinmehall kevinmehall mentioned this pull request Mar 2, 2025
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.

1 participant