|
|
@ -1,10 +1,15 @@ |
|
|
|
//! Parser contains the command parser for handling receiving commands from the GUI
|
|
|
|
//! Parser contains the command parser for handling receiving commands from the GUI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use std::collections::HashMap; |
|
|
|
use std::collections::HashMap; |
|
|
|
use commands; |
|
|
|
use commands; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use either::Either; |
|
|
|
|
|
|
|
pub use either::Left; |
|
|
|
|
|
|
|
pub use either::Right; |
|
|
|
|
|
|
|
|
|
|
|
/// Token represents a parsable token in the string sent via STDIN from the GUI
|
|
|
|
/// Token represents a parsable token in the string sent via STDIN from the GUI
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug, Eq, PartialEq)] |
|
|
|
pub enum Token { |
|
|
|
pub enum Token { |
|
|
|
UCI, |
|
|
|
UCI, |
|
|
|
DEBUG, |
|
|
|
DEBUG, |
|
|
@ -38,13 +43,25 @@ pub struct Parser {} |
|
|
|
/// --------- ---- ---- ----- --
|
|
|
|
/// --------- ---- ---- ----- --
|
|
|
|
/// Token arg val arg val
|
|
|
|
/// Token arg val arg val
|
|
|
|
///
|
|
|
|
///
|
|
|
|
|
|
|
|
/// debug on
|
|
|
|
|
|
|
|
/// ----- --
|
|
|
|
|
|
|
|
/// Token val
|
|
|
|
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// The user is still responsible for knowing what to look for in the hashmap but this structure makes it far
|
|
|
|
/// The user is still responsible for knowing what to look for in the hashmap but this structure makes it far
|
|
|
|
/// easier to work with commands. Some commands don't have arguments, in that case the args will be None.
|
|
|
|
/// easier to work with commands. Some commands don't have arguments, in that case the args will be None.
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug, PartialEq)] |
|
|
|
pub struct TokenResult { |
|
|
|
pub struct TokenResult { |
|
|
|
token: Token, |
|
|
|
token: Token, |
|
|
|
args: Option<HashMap<&'static str, CommandValue>>, |
|
|
|
args: Either<Option<HashMap<&'static str, CommandValue>>, &'static str>, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl TokenResult { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Intantiates a new TokenResult
|
|
|
|
|
|
|
|
pub fn new(token: Token, args: Either<Option<HashMap<&'static str, CommandValue>>, &'static str>>) -> TokenResult { |
|
|
|
|
|
|
|
TokenResult { token, args } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Parser { |
|
|
|
impl Parser { |
|
|
@ -56,7 +73,7 @@ impl Parser { |
|
|
|
|
|
|
|
|
|
|
|
/// Parses a single string from the GUI and turns it into a neatly packaged TokenResult for processing
|
|
|
|
/// Parses a single string from the GUI and turns it into a neatly packaged TokenResult for processing
|
|
|
|
/// by the engine.
|
|
|
|
/// by the engine.
|
|
|
|
pub fn parse(s: &str) -> Result<TokenResult, &'static str> { |
|
|
|
pub fn parse(&self, s: &str) -> Result<TokenResult, &'static str> { |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Remove the /n from the end
|
|
|
|
// TODO: Remove the /n from the end
|
|
|
|
|
|
|
|
|
|
|
@ -67,7 +84,7 @@ impl Parser { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove this when it's working
|
|
|
|
// remove this when it's working
|
|
|
|
Err("lol") |
|
|
|
Ok(TokenResult::new(Token::SETOPTION, Left(Some(HashMap::new())))) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|