fn parse_command(keymap: &KeyMap, keys: &[KeyEvent]) -> ParseResult<(usize, Action)> {
    // Generate an iterator of keystrokes, which are treated similar to tokens by the parser.
    let mut key_iter = keys.iter().map(|ev| ev.code).peekable();

    // Parse a count off the front of the command
    let count = parse_count(&mut key_iter);
    // The first non-count keystroke represents the command name.  No keystrokes is an incomplete
    // command.
    let first_key = key_iter.next().ok_or(ParseErr::Incomplete)?;

    Ok((
        count,
        match keymap.get(&first_key).ok_or(ParseErr::Invalid)? {
            CmdType::InsertChild => Action::InsertChild(parse_insertable(&mut key_iter)?),
            CmdType::InsertBefore => Action::InsertBefore(parse_insertable(&mut key_iter)?),
            CmdType::InsertAfter => Action::InsertAfter(parse_insertable(&mut key_iter)?),
            CmdType::Delete => Action::Delete,
            CmdType::Replace => Action::Replace(parse_insertable(&mut key_iter)?),
            CmdType::MoveCursor(direction) => Action::MoveCursor(*direction),
            CmdType::Undo => Action::Undo,
            CmdType::Redo => Action::Redo,
            // "q" quits Sapling
            CmdType::Quit => Action::Quit,
            CmdType::Write => Action::Write,
        },
    ))
}
/// Attempt to parse an entire command.  This is the entry point to the parsing code.  This parser
/// is a recursive descent parser, where there is a separate function for each syntactic element
/// ([`parse_insertable`], [`parse_count`], etc.).
///
/// Note that this parser will return as soon as a valid command is reached.  Therefore,
/// `"q489flshb"` will be treated like `"q"`, and will return [`Action::Quit`] even though
/// `"q489flshb"` is not technically valid.  However, the command buffer is parsed every time the
/// user types a keystroke character, so the user would not be able to input `"q489flshb"` in one
/// go because doing so would require them to first input every possible prefix of `"q489flshb"`,
/// including `"q"`.
Attempt to parse an entire command.  This is the entry point to the parsing code.  This parser
is a recursive descent parser, where there is a separate function for each syntactic element
([`parse_insertable`], [`parse_count`], etc.).

Note that this parser will return as soon as a valid command is reached.
Attempt to parse an entire command . This is the entry point to the parsing code . This parser is a recursive descent parser where there is a separate function for each syntactic element ( [ ` parse_insertable ` ] [ ` parse_count ` ] etc . ) . Note that this parser will return as soon as a valid command is reached .
fn parse_command(keymap: &KeyMap, keys: &[KeyEvent]) -> ParseResult<(usize, Action)> {
    // Generate an iterator of keystrokes, which are treated similar to tokens by the parser.
    let mut key_iter = keys.iter().map(|ev| ev.code).peekable();
    // Parse a count off the front of the command
    let count = parse_count(&mut key_iter);
    // The first non-count keystroke represents the command name.  No keystrokes is an incomplete
    // command.
    let first_key = key_iter.next().ok_or(ParseErr::Incomplete)?;
    Ok((
        count,
        match keymap.get(&first_key).ok_or(ParseErr::Invalid)? {
            CmdType::InsertChild => Action::InsertChild(parse_insertable(&mut key_iter)?),
            CmdType::InsertBefore => Action::InsertBefore(parse_insertable(&mut key_iter)?),
            CmdType::InsertAfter => Action::InsertAfter(parse_insertable(&mut key_iter)?),
            CmdType::Delete => Action::Delete,
            CmdType::Replace => Action::Replace(parse_insertable(&mut key_iter)?),
            CmdType::MoveCursor(direction) => Action::MoveCursor(*direction),
            CmdType::Undo => Action::Undo,
            CmdType::Redo => Action::Redo,
            // "q" quits Sapling
            CmdType::Quit => Action::Quit,
            CmdType::Write => Action::Write,
        },
    ))
}
fn parse_command ( keymap : & KeyMap , keys : & [ KeyEvent ] ) -> ParseResult < ( usize , Action ) > { // Generate an iterator of keystrokes, which are treated similar to tokens by the parser. let mut key_iter = keys . iter ( ) . map ( | ev | ev . code ) . peekable ( ) ; // Parse a count off the front of the command let count = parse_count ( & mut key_iter ) ; // The first non-count keystroke represents the command name.  No keystrokes is an incomplete // command. let first_key = key_iter . next ( ) . ok_or ( ParseErr :: Incomplete ) ? ; Ok ( ( count , match keymap . get ( & first_key ) . ok_or ( ParseErr :: Invalid ) ? { CmdType :: InsertChild => Action :: InsertChild ( parse_insertable ( & mut key_iter ) ? ) , CmdType :: InsertBefore => Action :: InsertBefore ( parse_insertable ( & mut key_iter ) ? ) , CmdType :: InsertAfter => Action :: InsertAfter ( parse_insertable ( & mut key_iter ) ? ) , CmdType :: Delete => Action :: Delete , CmdType :: Replace => Action :: Replace ( parse_insertable ( & mut key_iter ) ? ) , CmdType :: MoveCursor ( direction ) => Action :: MoveCursor ( * direction ) , CmdType :: Undo => Action :: Undo , CmdType :: Redo => Action :: Redo , // "q" quits Sapling CmdType :: Quit => Action :: Quit , CmdType :: Write => Action :: Write , } , ) ) }
Attempt to parse an entire command.
Attempt to parse an entire command .
keymap
&KeyMap
keys
&[KeyEvent]
keymap
&KeyMap
keys
&[KeyEvent]