Fixed some clippy lints
This commit is contained in:
+12
-13
@@ -40,9 +40,8 @@ pub async fn api_process
|
|||||||
// This data must be passed through to the api route in order to be used
|
// This data must be passed through to the api route in order to be used
|
||||||
let happening_queue_filter = warp::any().map(move || Arc::clone(&happening_queue));
|
let happening_queue_filter = warp::any().map(move || Arc::clone(&happening_queue));
|
||||||
let characters_filter = warp::any().map(move || Arc::clone(&characters));
|
let characters_filter = warp::any().map(move || Arc::clone(&characters));
|
||||||
let tx_filter = warp::any().map(move || tx.clone());
|
let tx_filter1 = warp::any().map(move || tx.clone());
|
||||||
let tx_filter2 = tx_filter.clone();
|
let tx_filter2 = tx_filter1.clone();
|
||||||
let tx_filter3 = tx_filter.clone();
|
|
||||||
|
|
||||||
info!("Running server");
|
info!("Running server");
|
||||||
|
|
||||||
@@ -50,13 +49,13 @@ pub async fn api_process
|
|||||||
let main = warp::path("happening")
|
let main = warp::path("happening")
|
||||||
.and(warp::get())
|
.and(warp::get())
|
||||||
.and(happening_queue_filter)
|
.and(happening_queue_filter)
|
||||||
.and(tx_filter)
|
|
||||||
// Perform this code on a GET request
|
// Perform this code on a GET request
|
||||||
.map(|queue: Arc<Mutex<VecDeque<DataToSend>>>, tx_handle: Sender<(usize,String)>|
|
.map(|queue: Arc<Mutex<VecDeque<DataToSend>>>|
|
||||||
{
|
{
|
||||||
//debug!("GET: {state:?}");
|
//debug!("GET: {state:?}");
|
||||||
let mut queue = queue.lock().unwrap();
|
let mut queue = queue.lock().unwrap_or_exit("Queue Mutex was poisoned", 2);
|
||||||
let reply = queue.pop_front().unwrap_or_default();
|
let reply = queue.pop_front().unwrap_or_default();
|
||||||
|
drop(queue);
|
||||||
warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON)
|
warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON)
|
||||||
}).boxed();
|
}).boxed();
|
||||||
let characters = warp::path("character")
|
let characters = warp::path("character")
|
||||||
@@ -90,7 +89,7 @@ pub async fn api_process
|
|||||||
let choice = warp::path("choice")
|
let choice = warp::path("choice")
|
||||||
.and(warp::post())
|
.and(warp::post())
|
||||||
.and(warp::body::json())
|
.and(warp::body::json())
|
||||||
.and(tx_filter2)
|
.and(tx_filter1)
|
||||||
.map(|index: usize, tx_handle: Sender<(usize,String)>| {
|
.map(|index: usize, tx_handle: Sender<(usize,String)>| {
|
||||||
debug!("Choice: {index}");
|
debug!("Choice: {index}");
|
||||||
let _ = tx_handle.send((index,String::new()));
|
let _ = tx_handle.send((index,String::new()));
|
||||||
@@ -100,7 +99,7 @@ pub async fn api_process
|
|||||||
let input = warp::path("input")
|
let input = warp::path("input")
|
||||||
.and(warp::post())
|
.and(warp::post())
|
||||||
.and(warp::body::json())
|
.and(warp::body::json())
|
||||||
.and(tx_filter3)
|
.and(tx_filter2)
|
||||||
.map(|input: String, tx_handle: Sender<(usize, String)>|
|
.map(|input: String, tx_handle: Sender<(usize, String)>|
|
||||||
{
|
{
|
||||||
let _ = tx_handle.send((0,input));
|
let _ = tx_handle.send((0,input));
|
||||||
@@ -122,16 +121,16 @@ pub fn modify_data // TODO rename
|
|||||||
happening_queue: &Arc<Mutex<VecDeque<DataToSend>>>,
|
happening_queue: &Arc<Mutex<VecDeque<DataToSend>>>,
|
||||||
action_type: String,
|
action_type: String,
|
||||||
content: String,
|
content: String,
|
||||||
character_name: String,
|
character: String,
|
||||||
choices: Vec<String>,
|
choices: Vec<String>,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
let mut queue = happening_queue.lock().unwrap_or_exit("Data to send Mutex was poisoned",2);
|
let mut queue = happening_queue.lock().unwrap_or_exit("Data to send Mutex was poisoned",2);
|
||||||
let new_data = DataToSend {
|
let new_data = DataToSend {
|
||||||
action_type: action_type,
|
action_type,
|
||||||
content: content,
|
content,
|
||||||
character: character_name,
|
character,
|
||||||
choices: choices,
|
choices,
|
||||||
};
|
};
|
||||||
queue.push_back(new_data);
|
queue.push_back(new_data);
|
||||||
drop(queue);
|
drop(queue);
|
||||||
|
|||||||
+5
-10
@@ -32,17 +32,16 @@ pub fn token_parse(
|
|||||||
let mut index: usize = 0;
|
let mut index: usize = 0;
|
||||||
info!("Client has connected");
|
info!("Client has connected");
|
||||||
// Run an infinite loop
|
// Run an infinite loop
|
||||||
'parse_loop: loop
|
loop
|
||||||
{
|
{
|
||||||
debug!("Reading {index}");
|
debug!("Reading {index}");
|
||||||
// Get the next token
|
// Get the next token
|
||||||
let token: String = match tokens.get(index)
|
match tokens.get(index)
|
||||||
{
|
{
|
||||||
Some(tokenise::Token::Keyword(token)) =>
|
Some(tokenise::Token::Keyword(token)) =>
|
||||||
{
|
{
|
||||||
if token.to_lowercase().as_str() == "end" { return Ok(()); };
|
if token.to_lowercase().as_str() == "end" { return Ok(()); }
|
||||||
index = keyword_parse::keyword_parse(tokens, token.to_string(), index, characters, happening_queue, labels, rx).unwrap();
|
index = keyword_parse::keyword_parse(tokens, token, index, happening_queue, labels, rx)?;
|
||||||
continue 'parse_loop;
|
|
||||||
},
|
},
|
||||||
// Ignore closing braces and jump over opening brace blocks
|
// Ignore closing braces and jump over opening brace blocks
|
||||||
Some(tokenise::Token::Bracket((bracket,new_index))) =>
|
Some(tokenise::Token::Bracket((bracket,new_index))) =>
|
||||||
@@ -53,7 +52,6 @@ pub fn token_parse(
|
|||||||
warn!("Unexpected brace block, jumping over...");
|
warn!("Unexpected brace block, jumping over...");
|
||||||
index = new_index + 1;
|
index = new_index + 1;
|
||||||
}
|
}
|
||||||
continue 'parse_loop
|
|
||||||
},
|
},
|
||||||
// Handle a character
|
// Handle a character
|
||||||
Some(tokenise::Token::Character(character_name)) => // TODO add support for narrator
|
Some(tokenise::Token::Character(character_name)) => // TODO add support for narrator
|
||||||
@@ -67,17 +65,14 @@ pub fn token_parse(
|
|||||||
increment
|
increment
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
continue 'parse_loop
|
|
||||||
}
|
}
|
||||||
Some(_) =>
|
Some(_) =>
|
||||||
{
|
{
|
||||||
warn!("Unexpected token");
|
warn!("Unexpected token");
|
||||||
index += 1;
|
index += 1;
|
||||||
continue 'parse_loop
|
|
||||||
},
|
},
|
||||||
None => return Err("File unexpectedly reached termination point".to_string()),
|
None => return Err("File unexpectedly reached termination point".to_string()),
|
||||||
};
|
}
|
||||||
debug!("{index}: {token}");
|
|
||||||
// The instructions are related to characters
|
// The instructions are related to characters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use crate::
|
use crate::
|
||||||
{
|
{
|
||||||
tokenise,
|
tokenise,
|
||||||
character,
|
|
||||||
api,
|
api,
|
||||||
|
|
||||||
HashMap,
|
HashMap,
|
||||||
@@ -16,9 +15,8 @@ use crate::
|
|||||||
|
|
||||||
pub fn keyword_parse(
|
pub fn keyword_parse(
|
||||||
tokens: &[tokenise::Token],
|
tokens: &[tokenise::Token],
|
||||||
token: String,
|
token: &str,
|
||||||
mut index: usize,
|
mut index: usize,
|
||||||
characters: &Arc<Mutex<HashMap::<String, character::Character>>>,
|
|
||||||
happening_queue: &Arc<Mutex<VecDeque<api::DataToSend>>>,
|
happening_queue: &Arc<Mutex<VecDeque<api::DataToSend>>>,
|
||||||
labels: &HashMap<String, usize>,
|
labels: &HashMap<String, usize>,
|
||||||
rx: &Receiver<(usize,String)>,
|
rx: &Receiver<(usize,String)>,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ pub enum Token
|
|||||||
{
|
{
|
||||||
String(String),
|
String(String),
|
||||||
Keyword(String), // Keywords aren't checked for validity in this stage
|
Keyword(String), // Keywords aren't checked for validity in this stage
|
||||||
|
#[allow(dead_code)] // This is unused rn, but am going to add it later
|
||||||
Identifier(String),
|
Identifier(String),
|
||||||
Bracket((Bracket,usize)), // Stores the index of the matching deliminator
|
Bracket((Bracket,usize)), // Stores the index of the matching deliminator
|
||||||
Character(String),
|
Character(String),
|
||||||
|
|||||||
Reference in New Issue
Block a user