On Tue, 30 Mar 2010 13:44:46 -0500 Ted Zlatanov <t...@lifelogs.com> wrote:
TZ> I've got a working grammar that will parse, say TZ> A a1 a2 a3 TZ> B b1 b2 TZ> into structures. A and B don't overlap so I know that any sequence TZ> beginning with A must have a1, a2, and a3. TZ> Now I'm interested in finding out how much of the A rule can be matched, TZ> for tab-completion (so I can tell if a1, a2, or a3 should be TZ> completed). I'm using Term::ReadLine::Gnu but that's not too TZ> important. Basically I want, given "A a1", to say "oh you want all the TZ> possible values for a2 and a1 is already given." TZ> I'm currently doing this by making a1..3 optional and then assembling TZ> them back in order, but was wondering if there's a better way to fail TZ> the match but tell me how far the parser got before it failed. Here's an example of a rule: get: 'get' family(?) keys(?) getparams(?) { $return = [ [ family => $item[2], keys => $item[3], getparams => $item[4] ], \&::internalPRD_get, \&::dump_hash, $item[2], $item[3], $item[4] ]; } (I could have used IxHash for the first parameter instead of an array) So then my code looks at the first item returned, that's my structure. It figures out that e.g. "family" is filled but "keys" is not and does completion on the keys parameter. There's a little more logic to distinguish between a partially-filled key vs. an empty one but that's about it. Ted