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

Grammar input type requires a ".len()" method #251

Closed
adrianwn opened this issue Feb 19, 2021 · 1 comment · Fixed by #252
Closed

Grammar input type requires a ".len()" method #251

adrianwn opened this issue Feb 19, 2021 · 1 comment · Fixed by #252

Comments

@adrianwn
Copy link
Contributor

adrianwn commented Feb 19, 2021

The generated parser code calls the len() method on the grammar input, but the Parse trait doesn't contain such a function. This limits the types that can be used as input for the parser. I can think of two ways to fix this:

  1. Add a len() function to the Parse trait.
  2. I believe there are only two places where len() is called on the input, and both are conditions in the form of __pos == __input.len(). So instead of adding a len() trait function, I suggest fn is_eof(&self, p: usize) -> bool, which can easily be implemented for any type that already has a len() method.

What do you think? I'd be happy to provide a pull request, if desired.

@kevinmehall
Copy link
Owner

Yeah, all the methods called on input should go through the traits -- thanks for pointing that out.

Option 2 sounds good to me.

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 a pull request may close this issue.

2 participants