My input text might have a simple statement like this:
aircraft
In my language I call this a name which represents a set of instances with various properties. It yields an instance_set of all aircraft instances in this example.
I can apply a filter in parenthesis to any instance_set:
aircraft(Altitude < ceiling)
It yields another, possibly reduced instance_set. And since it is an instance set, I can filter it yet again:
aircraft(Altitude < ceiling)(Speed > min_speed)
I foolishly thought I could do something like this in my grammar:
instance_set = expr
expr = source / instance_set
source = name filter?
It parses my first two cases correctly, but chokes on the last one:
aircraft(Altitude < ceiling)(Speed > min_speed)
The error reported being just before the second open paren.
Why doesn't Arpeggio see that there is just a filtered instance_set which is itself a filtered instance set?
I humbly submit my appeal to the peg parsing gods and await insight...
Your first two cases both match
source. Oncesourceis matched, it's matched; that's the PEG contract. So the parser isn't going to explore the alternative.But suppose it did. How could that help? The rule says that if an
expris not asource, then it's aninstance_set. But aninstance_setis just anexpr. In other words, anexpris either asourceor it's anexpr. Clearly the alternative doesn't get us anywhere.I'm pretty sure Arpeggio has repetitions, which is what you really want here: