packcc icon indicating copy to clipboard operation
packcc copied to clipboard

parser reads more data than necessary

Open andrewchambers opened this issue 3 years ago • 2 comments

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.

andrewchambers avatar Feb 16 '22 03:02 andrewchambers

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 avatar Mar 06 '22 22:03 arithy

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.

andrewchambers avatar Mar 06 '22 23:03 andrewchambers

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

arithy avatar Apr 24 '24 12:04 arithy