goodmami / pe

Fastest general-purpose parsing library for Python with a familiar API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.