Some meditation (I didn't re(veal|ad) your code) ...

As far as I understand the complication is in the grammar and not in the auto-completion and you are shying away from implementing/maintaining a state-machine.

From your description I understand this (pseudo syntax)

But it seems to me that kill shouldn't allow further commands

It's also not clear if give and take_to can be followed by further commands

Or if you can have multiple items:

What about senseless food-selection by animal?

select camel give fish #???

hence we need

The next question is validation , what happens if a someone manually types select horse ... which isn't in the animal-list, shouldn't that be rejected?

My naïve approach would be to implement/translate that grammar to a nested regex and input that doesn't match is rejected.

Typing TAB after a command displays the completion list.²

But I have a hunch there are already better ways to implement such grammars on CPAN.

Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery

²) from what I remember this can be done with Term::ReadLine by adding call backs for evaluation and expansion.


In reply to Re: [challenge] Nested autocompletion by LanX
in thread [challenge] Nested autocompletion by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.