Taylor Bockman
7 years ago
2 changed files with 63 additions and 40 deletions
@ -0,0 +1,63 @@ |
|||||||
|
//! Parser contains the command parser for handling receiving commands from the GUI
|
||||||
|
|
||||||
|
use std::collections::HashMap; |
||||||
|
use commands; |
||||||
|
|
||||||
|
/// Token represents a parsable token in the string sent via STDIN from the GUI
|
||||||
|
pub enum Token { |
||||||
|
UCI, |
||||||
|
DEBUG, |
||||||
|
ISREADY, |
||||||
|
SETOPTION, |
||||||
|
REGISTER, |
||||||
|
UCINEWGAME, |
||||||
|
POSITION, |
||||||
|
GO, |
||||||
|
STOP, |
||||||
|
PONDERHIT, |
||||||
|
QUIT, |
||||||
|
} |
||||||
|
|
||||||
|
pub enum CommandValue { |
||||||
|
Int(i32), |
||||||
|
Float(f64), |
||||||
|
Text(String), |
||||||
|
Boolean(bool), |
||||||
|
} |
||||||
|
|
||||||
|
pub struct Parser {} |
||||||
|
|
||||||
|
/// TokenResult is a convenient way t package an entire command string. It is identified by it's associated
|
||||||
|
/// Token, and the arguments.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
///
|
||||||
|
/// setoption name Hash value 32
|
||||||
|
/// --------- ---- ---- ----- --
|
||||||
|
/// Token arg val arg val
|
||||||
|
///
|
||||||
|
///
|
||||||
|
/// 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.
|
||||||
|
pub struct TokenResult { |
||||||
|
token: Token, |
||||||
|
args: Option<HashMap<&'static str, CommandValue>>, |
||||||
|
} |
||||||
|
|
||||||
|
impl Parser { |
||||||
|
|
||||||
|
/// Instantiates a new Parser
|
||||||
|
pub fn new() -> Parser { |
||||||
|
Parser{} |
||||||
|
} |
||||||
|
|
||||||
|
/// Parses a single string from the GUI and turns it into a neatly packaged TokenResult for processing
|
||||||
|
/// by the engine
|
||||||
|
pub fn parse(s: &str) -> TokenResult { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue