- PACKAGE VARIABLES AND EXPORTS
App::Dochazka::CLI::Parser - Parser module
Parse the command string entered by the user.
Given a state expressed as a stack of tokens, return list of possible tokens.
Given a command string, process it (by parsing, calling the handler, etc.) and return the result.
The semantic tree is a traversable tree representation of the CLI commands, i.e. the keys of the dispatch map
Generate the semantic context tree.
The set of keys of
%$dispatch_map contains all the possible commands, each expressed as a sequence of tokens. The semantic context tree is generated from the dispatch map keys. Each node of the tree represents a possible token and the set of nodes at depth n of the tree is the set of possible tokens in the nth position within the command.
Taking, for example, a dispatch map consisting of the following two commands:
ABE BABEL CAROL DALE EARL JENSEN PARLOR DALE TWIT
The semantic tree would be:
(root) | +-----------+ | | ABE DALE | | | +------+ | | | BABEL EARL TWIT | | CAROL JENSEN | PARLOR
The point of this exercise is to facilitate command completion. If two a single token ABE has been entered by the user and <TAB> is pressed, finding out that BABEL is the only possible command in this position is a simple matter of traversing the above semantic tree. (And this is exactly what is done by the
possible_words routine in App::Dochazka::CLI::Parser.)
This routine takes an optional argument which, if provided, is assumed to be a reference to a dispatch map. In the absence of this argument, the
$dispatch_map package variable (initialized above) is used.
For this and more examples, see
Given a normalized command string such as "GET BUGREPORT", look it up in the dispatch map and return the corresponding coderef, or nothing if the lookup fails.
Parse command string entered by the user. Takes the command string, and returns:
The normalized command - suitable for lookup via
The token stack - a reference to the list of normalized tokens
The token hash - a hash where the keys are the normalized tokens and the values are the raw values extracted from the command string. Whatever is left after command string parsing completes will be placed in the '_REMAINDER' key.
Given a token stack, return the list of possible tokens.
Given a command entered by the user, process it and return the result.