ReplParser

Struct ReplParser 

Source
pub struct ReplParser<'a> { /* private fields */ }
Expand description

REPL line parser

Parses interactive command lines in REPL mode. The parser:

  1. Splits the line into command name and arguments
  2. Resolves the command name (including aliases) via the registry
  3. Delegates to CliParser for 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(&registry);

// 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>

Source

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(&registry);
Source

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
§Example
let parser = ReplParser::new(&registry);

// 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();
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.