From 4c30563ac029d91d878bb59233c91c5935546358 Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 20 Mar 2024 21:36:53 +0100 Subject: [PATCH] allow single-word strings in defs.txt without double quotes --- src/defs.txt | 24 ++++++++++++------------ src/world.rs | 18 +++++++++++++++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/defs.txt b/src/defs.txt index 22a2f58..0a58722 100644 --- a/src/defs.txt +++ b/src/defs.txt @@ -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" diff --git a/src/world.rs b/src/world.rs index 92dc433..66bc2e4 100644 --- a/src/world.rs +++ b/src/world.rs @@ -362,10 +362,12 @@ pub fn load_defs( asset_server: Res, ) { 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() {