Hi Ted,

If I were building a completion checker, I'd probably do something like the
following.

Hope this helps,

Damian

-----cut----------cut----------cut----------cut----------cut-----

   use Parse::RecDescent;

   my @trial_inputs = (
       '',
       'm',
       'mv',
       'mv ',
       'mv f',
       'mv file',
       'mv file ',
       'mv file t',
       'mv file to',
       'mv file to ',
       'mv file to f',
       'mv file to file',
       'mv file to file ',
   );

   my $grammar = q{
       partial_cmd: <rulevar: local $expecting = ''>
               | cmd { 'nothing (cmd is complete)' }
               | { $expecting }

       cmd: <skip: ''>
           { $expecting = 'cmd_name' }   cmd_name
           { $expecting = 'file1'    }   ws file ws
           { $expecting = 'to'       }   'to'
           { $expecting = 'file2'    }   ws file ws

       cmd_name: 'mv' | 'cp' | 'ln'

       file: /\S+/

       ws:   /\s+/
   };

   my $parser = Parse::RecDescent->new($grammar);

   for my $input (@trial_inputs) {
       print "'$input' : complete on ", $parser->partial_cmd($input), "\n";
   }

-----END----------END----------END----------END----------END-----

Reply via email to