You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
//! 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 to 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) -> Result<TokenResult, &'static str> { |
|
|
|
// TODO: Remove the /n from the end |
|
|
|
let tokens: Vec<&str> = s.split_whitespace().collect::<Vec<&str>>(); |
|
|
|
// TODO: Parse things based on the token, probably need a special function for each token based on a switch |
|
// of tokens[0]. |
|
} |
|
} |
|
|
|
|
|
|
|
|