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

Allow other lifetimes in tokens #454

Open
414owen opened this issue Dec 10, 2024 · 3 comments
Open

Allow other lifetimes in tokens #454

414owen opened this issue Dec 10, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers nice to have

Comments

@414owen
Copy link
Contributor

414owen commented Dec 10, 2024

At the moment, I think Logos forbids having more than one lifetime parameter on a token type, and assumes that the lifetime, if present, is that of the input.

This isn't a fair assumption. I actually have things I want to arena-allocate inside the payload of my tokens, so I need to be able to use the lifetime of the arena.

@jeertmans
Copy link
Collaborator

jeertmans commented Dec 10, 2024

Hi @414owen, it's true that it is not a smart constraint.

A workaround might be to require the user to explicitly mention which lifetime refers to the source, if multiple lifetimes are passed.

What do you think?

E.g.,

// OK - defaults to 'source
#[derive(Logos)]
enum<'source> Token<'source> {
}

// OK - 'other lifetime has nothing to do with source
#[derive(Logos)]
#[logos(lifetime = None)]
enum<'other> Token {
}

// OK - defaults to 'source
#[derive(Logos)]
enum<'source> Token<'source> {
}

// OK
#[derive(Logos)]
#[logos(lifetime = 'source)]
enum<'source, 'other> Token {
}

// NOT OK - emits an error saying the source lifetime must be explicitly specified
#[derive(Logos)]
enum<'source, 'other> Token {
}

// NOT OK - emits an error saying the specified lifetime was not found
#[derive(Logos)]
#[logos(lifetime = 'source)]
enum<'other_source, 'other> Token {
}

// NOT OK - emits an error saying the specified lifetime was not found
#[derive(Logos)]
#[logos(lifetime = 'source)]
enum Token {
}

The second example is to provide backward compatibility with existing code.

@jeertmans jeertmans added enhancement New feature or request nice to have labels Dec 10, 2024
@414owen
Copy link
Contributor Author

414owen commented Dec 10, 2024

@jeertmans That API looks really nice! I'd love to see this in logos.

@jeertmans jeertmans added the good first issue Good for newcomers label Dec 11, 2024
@jeertmans
Copy link
Collaborator

I don't have time at the moment to work on this, so I'll label this as good first issue, because I think it should be relatively easy to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers nice to have
Projects
None yet
Development

No branches or pull requests

2 participants