pe icon indicating copy to clipboard operation
pe copied to clipboard

Dispatch operator

Open goodmami opened this issue 5 years ago • 0 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.

goodmami avatar Mar 18 '20 08:03 goodmami