Browse Source

some parsy stuff

ag-yep
Taylor Bockman 7 years ago
parent
commit
9b9e466cdb
  1. 40
      src/commands.rs
  2. 63
      src/parser.rs

40
src/commands.rs

@ -1,46 +1,6 @@
//! Commands contains the command constants expected during the UCI lifecycle //! Commands contains the command constants expected during the UCI lifecycle
//! It is useful to note many of these commands do not end with '\n'. This is because they expect arguments. //! It is useful to note many of these commands do not end with '\n'. This is because they expect arguments.
///////// GUI to Engine /////////
/// Tell engine to use the UCI (Universal Chess Interface)
pub const UCI: &'static str = "uci\n";
/// DEBUG toggles the debug mode of the engine on or off
pub const DEBUG: &'static str = "debug";
pub const DEBUGON: &'static str = "on";
pub const DEBUGOFF: &'static str = "off";
/// ISREADY synchronizes the engine with the GUI
pub const ISREADY: &'static str = "isready\n";
/// SETOPTION is sent to the engine when the user wants to change an internal parameter
pub const SETOPTION: &'static str = "setoption";
/// REGISTER is the command used to try to register an engine or tell the engine that registration will be done
/// later
pub const REGISTER: &'static str = "register";
/// UCINEWGAME is sent to the engine when the next search (started with "position" and "go") will be from a different
/// game
pub const UCINEWGAME: &'static str = "ucinewgame\n";
/// POSITION is sent to set up the position described in fenstring on the internal board and play the moves on the
/// internal chess board
pub const POSITION: &'static str = "position";
/// GO signals to start calculating on the current position set up with the "position" command
pub const GO: &'static str = "go\n";
/// STOP signals to stop calculating as soon as possible
pub const STOP: &'static str = "stop\n";
/// PONDERHIT will be sent if the engine was told to ponder on the same move the user has played
pub const PONDERHIT: &'static str = "ponderhit\n";
/// QUIT signals to quit the program as soon as possible
pub const QUIT: &'static str = "quit\n";
///////// Engine to GUI ///////// ///////// Engine to GUI /////////

63
src/parser.rs

@ -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…
Cancel
Save