//! The assignment command parser.
//!
//! This can parse arbitrary input, giving the user to be assigned.
//!
//! The grammar is as follows:
//!
//! ```text
//! Command: `@bot claim`, `@bot release-assignment`, or `@bot assign @user`.
//! ```
use crate::error::Error;
use crate::token::{Token, Tokenizer};
use std::fmt;
#[derive(PartialEq, Eq, Debug)]
pub enum AssignCommand {
Own,
Release,
User { username: String },
}
#[derive(PartialEq, Eq, Debug)]
pub enum ParseError {
ExpectedEnd,
MentionUser,
NoUser,
}
impl std::error::Error for ParseError {}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ParseError::MentionUser => write!(f, "user should start with @"),
ParseError::ExpectedEnd => write!(f, "expected end of command"),
ParseError::NoUser => write!(f, "specify user to assign to"),
}
}
}
impl AssignCommand {
pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result