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

parser reads more data than necessary #59

Closed
andrewchambers opened this issue Feb 16, 2022 · 3 comments
Closed

parser reads more data than necessary #59

andrewchambers opened this issue Feb 16, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@andrewchambers
Copy link

andrewchambers commented Feb 16, 2022

If you have a grammar like:

foo <- "foobar\n" / "foo\n"

and input the string "foo\n..........", then packcc will read 8 bytes for this rule when it really only needed to read 4.

As an example of where this is a problem, consider an interactive parser where the user enters data line by line, if the user types "foo\n", the parser will request two or more lines of input from the user when only one was actually needed.

@arithy
Copy link
Owner

arithy commented Mar 6, 2022

Can you work around this issue by modifying the PEG as shown below?

foo <- "foo\n" / "foobar\n"

The shorter string has to be put before the longer ones.

@arithy arithy added the enhancement New feature or request label Mar 6, 2022
@arithy arithy self-assigned this Mar 6, 2022
@andrewchambers
Copy link
Author

andrewchambers commented Mar 6, 2022

That's a good suggestion but maybe does not work for more complicated grammars where such interactions are less obvious.

In the end I have rewritten my code to buffer lines before passing it to the parser after a known terminator, this issue no longer affects me, I don't mind closing it.

arithy added a commit that referenced this issue Apr 24, 2024
@arithy
Copy link
Owner

arithy commented Apr 24, 2024

@andrewchambers , I have fixed this issue. I inform you, just in case.

@arithy arithy closed this as completed Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants