Arpeggio icon indicating copy to clipboard operation
Arpeggio copied to clipboard

adding support for shortest choice

Open leiyangyou opened this issue 8 years ago • 3 comments

Hi,

Hopefully this is useful for someone (A ShortestChoice variant of OrderedChoice)

leiyangyou avatar Jun 02 '16 10:06 leiyangyou

Hi. Thanks for the contribution. Can you give an example of why this kind of expression would be useful? What is your use-case?

igordejanovic avatar Jun 02 '16 10:06 igordejanovic

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.

leiyangyou avatar Jun 02 '16 11:06 leiyangyou

I see. I think that a similar variant LongestChoice would be event more useful and very similar in implementation.

igordejanovic avatar Jun 03 '16 12:06 igordejanovic