Arpeggio
Arpeggio copied to clipboard
adding support for shortest choice
Hi,
Hopefully this is useful for someone (A ShortestChoice variant of OrderedChoice)
Hi. Thanks for the contribution. Can you give an example of why this kind of expression would be useful? What is your use-case?
I had to use this while building a pretty complex grammar for tagging parts of a school name (a PEG parser may not have been the best tool for this use case)
It's an equivalent of the non greedy version of regexp operations
say if you have grammar x and y x matches 'ab' y matches 'a'
given input 'ab', ShortestChoice([x, y]) will match 'a' while OrderedChoice([x, y]) will match 'ab'
In my case, I did not know upfront which of x y matches a shorter input, therefore something like ShortestChoice has to be used.
I see. I think that a similar variant LongestChoice
would be event more useful and very similar in implementation.