Dispatch operator
goodmami opened this issue · comments
Add an operator that computes the first character of each alternative of a Choice and then does an immediate jump when one is unambiguous.
E.g.,
A <- "abc" / [x-z] / E / .
E <- "e"
Could be a dispatch like:
'a' >> "abc"
'x' >> [x-z]
'y' >> [x-z]
'z' >> [x-z]
'e' >> E
else >> .
Some situations could get tricky, so this should back off to a regular ordered choice if it's not clear:
A <- "abc" / "d" / "aaa"
becomes
'd' >>> "d"
'a' >>> "abc" / "aaa"
This is basically computing "first sets". The Dispatch() operator function (or whatever it's called) would just be an optimization and wouldn't necessarily get PEG notation associated with it.