allow single-word strings in defs.txt without double quotes

This commit is contained in:
yuni 2024-03-20 21:36:53 +01:00
parent 82b7a32286
commit 4c30563ac0
2 changed files with 27 additions and 15 deletions

View file

@ -1,29 +1,29 @@
actor 300000 0 500000 "jupiter"
actor 300000 0 500000 jupiter
scale 80000
rotationy -1.40
angularmomentum 0 0.0001 0
actor 2000 0 0 "asteroid1"
actor 2000 0 0 asteroid1
scale 200
actor -2300 10 0 "pizzeria"
actor -2300 10 0 pizzeria
scale 30
rotationy -1
angularmomentum 0 0.0001 0
actor -50 0 0 "suit"
name "Icarus"
actor -50 0 0 suit
name Icarus
chatid "hi_icarus"
alive "yes"
pronoun "it"
alive yes
pronoun it
actor -2265 10 0 "suit"
actor -2265 10 0 suit
name "Space Pizza™"
chatid "pizzeria"
alive "yes"
pronoun "it"
chatid pizzeria
alive yes
pronoun it
actor 0 0 0 "error"
actor 0 0 0 error
chat "error"
name "ERROR"

View file

@ -362,10 +362,12 @@ pub fn load_defs(
asset_server: Res<AssetServer>,
) {
let re1 = Regex::new(r"^\s*([a-z]+)\s+(.*)$").unwrap();
let re2 = Regex::new("\"([^\"]*)\"|(-?[0-9]+(?:\\.[0-9]+)?)").unwrap();
let re2 = Regex::new("\"([^\"]*)\"|(-?[0-9]+(?:\\.[0-9]+)?)|([a-zA-Z][a-zA-Z0-9]*)").unwrap();
let defs_string = include_str!("defs.txt");
let mut lines = defs_string.lines();
let mut state = ParserState::default();
let mut command;
let mut parameters;
let mut line_nr = -1;
while let Some(line) = lines.next() {
@ -377,17 +379,27 @@ pub fn load_defs(
}
continue;
}
let command = caps.unwrap().get(1).unwrap().as_str();
if let Some(caps) = caps {
command = caps.get(1).unwrap().as_str();
parameters = caps.get(2).unwrap().as_str();
}
else {
error!("Failed to read regex captures in line {}: `{}`", line_nr, line);
continue;
}
let mut parts: Vec<&str> = Vec::new();
parts.push(command);
for caps in re2.captures_iter(line) {
for caps in re2.captures_iter(parameters) {
if let Some(part) = caps.get(1) {
parts.push(&part.as_str());
}
if let Some(part) = caps.get(2) {
parts.push(&part.as_str());
}
if let Some(part) = caps.get(3) {
parts.push(&part.as_str());
}
}
match parts.as_slice() {