parsley
parsley copied to clipboard
[BUG] Incorrect error alternatives for `JumpTable`
Description
The JumpTable
instruction does not correctly emit all the possible expected messages unless it fails on the default path. Reading any other character present in the table will only present the labels of other parsers with that same leading character.
Reproduction Steps
import parsley.combinator.attemptChoice
import parsley.character.string
val p = attemptChoice(string("hello"), string("hi"), string("abc"), string("good"), string("g"))
p.parse("h")
/*(line 1, column 1):
unexpected "h"
expected "hello" or "hi"
>h
^*/
p.parse("b")
/*(line 1, column 1):
unexpected "b"
expected "abc", "g", "good", "hello", or "hi"
>b
^*/
p.parse("a")
/*(line 1, column 1):
unexpected "a"
expected "abc"
>a
^*/
Expected behavior
Only p.parse("b")
has the correct behaviour in the above snippet: this is because it is the default path. All of the error messages generated by the above parser should have the same expected clause as "b"
does.
Additional context
Parsley Version: 3.3.6/4.0.0 Scala Version: 2.12/2.13/3.1