fixed clippy lints
This commit is contained in:
+38
-38
@@ -41,14 +41,11 @@ pub fn token_parse(
|
||||
// Get the next token
|
||||
let token: String = match tokens.get(index)
|
||||
{
|
||||
Some(tokenise::Token::Keyword(s)) => s.to_string(),
|
||||
Some(tokenise::Token::Keyword(s)) => s.clone(),
|
||||
// Ignore closing braces and jump over opening brace blocks
|
||||
Some(tokenise::Token::Bracket((bracket,new_index))) =>
|
||||
{
|
||||
if bracket == &tokenise::Bracket::Closing
|
||||
{
|
||||
index += 1;
|
||||
}
|
||||
if bracket == &tokenise::Bracket::Closing { index += 1; }
|
||||
else
|
||||
{
|
||||
warn!("Unexpected brace block, jumping over...");
|
||||
@@ -59,7 +56,7 @@ pub fn token_parse(
|
||||
// Handle a character
|
||||
Some(tokenise::Token::Character(character_name)) => // TODO add support for narrator
|
||||
{
|
||||
index = match character_parse::character_parse(index+1,tokens,character_name.to_string(),characters,data_to_send)
|
||||
index = match character_parse::character_parse(index+1,tokens,character_name.clone(),characters,data_to_send)
|
||||
{
|
||||
Ok(increment) => increment,
|
||||
Err((err,increment)) =>
|
||||
@@ -89,32 +86,8 @@ pub fn token_parse(
|
||||
},
|
||||
"choice" =>
|
||||
{
|
||||
let mut next_token: String = token;
|
||||
let mut choices: Vec<String> = Vec::new();
|
||||
let mut choice_indeces: Vec<usize> = Vec::new();
|
||||
while next_token == "or" || next_token == "choice"
|
||||
{
|
||||
index += 1;
|
||||
choices.push
|
||||
(
|
||||
tokenise::get_string_token(tokens, index)?
|
||||
);
|
||||
index += 1;
|
||||
choice_indeces.push(index+1);
|
||||
index = match tokenise::get_closing_index(tokens,index)
|
||||
{
|
||||
Ok(new_index) => new_index + 1,
|
||||
Err(_) => break,
|
||||
};
|
||||
next_token = match tokenise::get_keyword_token(tokens, index)
|
||||
{
|
||||
Ok(string) => string,
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
debug!("{choices:?}");
|
||||
let choice_indeces = choice_parse(tokens, index, data_to_send)?;
|
||||
debug!("{choice_indeces:?}");
|
||||
api::modify_data(data_to_send, "choice".to_string(), String::new(), String::new(), choices);
|
||||
if rx.recv().is_err() { warn!("Error sending choices to client"); }
|
||||
let choice = match rx.recv()
|
||||
{
|
||||
@@ -141,14 +114,11 @@ pub fn token_parse(
|
||||
{
|
||||
index += 1;
|
||||
let label = tokenise::get_keyword_token(tokens, index)?;
|
||||
index = match labels.get(&label)
|
||||
index = if let Some(label_index) = labels.get(&label) { *label_index }
|
||||
else
|
||||
{
|
||||
Some(label_index) => *label_index,
|
||||
None =>
|
||||
{
|
||||
warn!("Label {label} does not exist");
|
||||
index
|
||||
}
|
||||
warn!("Label {label} does not exist");
|
||||
index + 1
|
||||
};
|
||||
debug!("Jumping to {index}");
|
||||
continue 'parse_loop
|
||||
@@ -165,3 +135,33 @@ pub fn token_parse(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn choice_parse(tokens: &[tokenise::Token], mut index: usize, data_to_send: &Arc<Mutex<api::DataToSend>>,)
|
||||
-> Result<Vec<usize>, String>
|
||||
{
|
||||
let mut next_token: String = "choice".to_string();
|
||||
let mut choices: Vec<String> = Vec::new();
|
||||
let mut choice_indeces: Vec<usize> = Vec::new();
|
||||
while next_token == "or" || next_token == "choice"
|
||||
{
|
||||
index += 1;
|
||||
choices.push
|
||||
(
|
||||
tokenise::get_string_token(tokens, index)?
|
||||
);
|
||||
index += 1;
|
||||
choice_indeces.push(index+1);
|
||||
index = match tokenise::get_closing_index(tokens,index)
|
||||
{
|
||||
Ok(new_index) => new_index + 1,
|
||||
Err(_) => break,
|
||||
};
|
||||
next_token = match tokenise::get_keyword_token(tokens, index)
|
||||
{
|
||||
Ok(string) => string,
|
||||
Err(_) => break,
|
||||
}
|
||||
};
|
||||
api::modify_data(data_to_send, "choice".to_string(), String::new(), String::new(), choices);
|
||||
Ok(choice_indeces)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user