pub struct ReplParser<'a> { /* private fields */ }Expand description
REPL line parser
Parses interactive command lines in REPL mode. The parser:
- Splits the line into command name and arguments
- Resolves the command name (including aliases) via the registry
- Delegates to
CliParserfor argument parsing
§Lifetime
Holds a reference to a CommandRegistry and therefore has a
lifetime parameter 'a.
§Example
use dynamic_cli::parser::repl_parser::ReplParser;
use dynamic_cli::registry::CommandRegistry;
let registry = CommandRegistry::new();
let parser = ReplParser::new(®istry);
// Parse various command formats
let parsed = parser.parse_line("command arg1 arg2").unwrap();
let parsed = parser.parse_line("cmd --option value").unwrap();
let parsed = parser.parse_line("alias -v").unwrap();Implementations§
Source§impl<'a> ReplParser<'a>
impl<'a> ReplParser<'a>
Sourcepub fn new(registry: &'a CommandRegistry) -> Self
pub fn new(registry: &'a CommandRegistry) -> Self
Create a new REPL parser with the given registry
§Arguments
registry- The command registry for resolving command names
§Example
use dynamic_cli::parser::repl_parser::ReplParser;
use dynamic_cli::registry::CommandRegistry;
let registry = CommandRegistry::new();
let parser = ReplParser::new(®istry);Sourcepub fn parse_line(&self, line: &str) -> Result<ParsedCommand>
pub fn parse_line(&self, line: &str) -> Result<ParsedCommand>
Parse a REPL command line
Parses a complete command line as entered in the REPL. The line is split into tokens, the first token is resolved as a command name (or alias), and remaining tokens are parsed as arguments and options.
§Arguments
line- The command line to parse
§Returns
A ParsedCommand containing the command name and parsed arguments
§Errors
ParseError::UnknownCommandif the command is not registeredParseError::InvalidSyntaxif the line is empty or malformed- Any errors from
CliParserduring argument parsing
§Example
let parser = ReplParser::new(®istry);
// Simple command
let parsed = parser.parse_line("help").unwrap();
// Command with arguments
let parsed = parser.parse_line("process input.txt output.txt").unwrap();
// Command with options
let parsed = parser.parse_line("run --verbose --count=10").unwrap();Sourcepub fn tokenize(&self, line: &str) -> Result<Vec<String>>
pub fn tokenize(&self, line: &str) -> Result<Vec<String>>
Tokenize a command line into arguments
This function performs simple tokenization by splitting on whitespace while respecting quoted strings. It handles:
- Single quotes:
'quoted string' - Double quotes:
"quoted string" - Escaped quotes within quotes:
"say \"hello\""
§Arguments
line- The line to tokenize
§Returns
Vector of token strings
§Errors
Returns ParseError::InvalidSyntax if quotes are unbalanced
§Example
// Simple tokens
let tokens = parser.tokenize("cmd arg1 arg2").unwrap();
assert_eq!(tokens, vec!["cmd", "arg1", "arg2"]);
// Quoted strings
let tokens = parser.tokenize(r#"cmd "hello world""#).unwrap();
assert_eq!(tokens, vec!["cmd", "hello world"]);Auto Trait Implementations§
impl<'a> Freeze for ReplParser<'a>
impl<'a> !RefUnwindSafe for ReplParser<'a>
impl<'a> Send for ReplParser<'a>
impl<'a> Sync for ReplParser<'a>
impl<'a> Unpin for ReplParser<'a>
impl<'a> !UnwindSafe for ReplParser<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more