redesigned how file is tokenised into string, keyword, identifier, bracket and character

added support for GOTOs and removed object recursive calls
This commit is contained in:
2026-05-18 13:22:29 +01:00
parent d4947a4434
commit 051bfe46e4
8 changed files with 197 additions and 123 deletions
+7 -10
View File
@@ -28,12 +28,9 @@ pub fn character_parse
{
let mut sum_index: usize = index;
// Ensure the index is valid (the index is not beyond the vector)
let token = match tokens.get(sum_index) {
Some(tokenise::Token::String(s)) => s.clone(),
Some(_) => return Err(("Unexpected token".to_string(), sum_index + 1)),
None => return Err(("File unexpectedly reached termination point".to_string(), sum_index)),
};
match token.to_lowercase().as_str()
let keyword = tokenise::get_keyword_token(tokens, sum_index)
.map_err(|err| (err, sum_index))?;
match keyword.to_lowercase().as_str()
{
// The character is saying something, so grab the text and pass it
// to the client
@@ -51,7 +48,7 @@ pub fn character_parse
"change" =>
{
sum_index += 1;
let feature = tokenise::get_string_token(tokens, sum_index)
let feature = tokenise::get_keyword_token(tokens, sum_index)
.map_err(|err| (err, index))?;
sum_index += 1;
let string = tokenise::get_string_token(tokens, sum_index)
@@ -69,13 +66,13 @@ pub fn character_parse
"to"|"animate" =>
{
sum_index += 1;
let content = tokenise::get_string_token(tokens, sum_index)
let content = tokenise::get_keyword_token(tokens, sum_index)
.map_err(|err| (err, index))?;
api::modify_data(data_to_send, token.to_lowercase(), content, character_name, vec![]);
api::modify_data(data_to_send, keyword.to_lowercase(), content, character_name, vec![]);
},
// Catch all condition, if the instruction is unrecognised as a
// character command
_ => return Err((format!("Invalid command: {token}"),sum_index)),
_ => return Err((format!("Invalid command: {keyword}"),sum_index)),
}
sum_index += 1;
Ok(sum_index)