diff --git a/Cargo.lock b/Cargo.lock index 864555c..1831eea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,7 +292,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.14.1" +version = "0.14.2" dependencies = [ "display_source", "parser", @@ -585,7 +585,7 @@ version = "0.1.2" [[package]] name = "var_utils" -version = "0.5.0" +version = "0.5.1" dependencies = [ "lazy-regex", ] diff --git a/Cargo.toml b/Cargo.toml index e025a29..9b8eb82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.14.1" +version = "0.14.2" edition = "2021" authors = ["A4-Tacks "] diff --git a/tools/var_utils/Cargo.toml b/tools/var_utils/Cargo.toml index 8e79f12..18f39c1 100644 --- a/tools/var_utils/Cargo.toml +++ b/tools/var_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "var_utils" -version = "0.5.0" +version = "0.5.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/var_utils/src/lib.rs b/tools/var_utils/src/lib.rs index e9ac4eb..9b34685 100644 --- a/tools/var_utils/src/lib.rs +++ b/tools/var_utils/src/lib.rs @@ -105,7 +105,7 @@ impl AsVarType for str { } fn as_number(s: &str) -> Option { static NUM_REGEX: &Lazy = regex!( - r"^-?(?:\d+(?:e[+\-]?\d+|\.\d*)?|\d*(?:\.\d+)?)$" + r"^-?(?:\d+(?:e[+\-]?\d+|\.\d*)?|\d*\.\d+)$" ); static HEX_REGEX: &Lazy = regex!( r"^0x-?[0-9A-Fa-f]+$" @@ -127,7 +127,11 @@ impl AsVarType for str { } } if NUM_REGEX.is_match(s) { - Some(s.parse().unwrap()) + let res = match s.parse() { + Ok(n) => n, + Err(e) => panic!("{}, ({:?})", e, s), + }; + Some(res) } else if HEX_REGEX.is_match(s) { parse_radix(&s[2..], 16) } else if BIN_REGEX.is_match(s) { diff --git a/tools/var_utils/src/tests.rs b/tools/var_utils/src/tests.rs index be91fa4..431d421 100644 --- a/tools/var_utils/src/tests.rs +++ b/tools/var_utils/src/tests.rs @@ -50,6 +50,7 @@ fn test() { } false { "+", + "-", "0xg", "0x_2", "0b3", @@ -105,6 +106,19 @@ fn float_parser_test() { let r#type = src.as_var_type(); assert!(matches!(r#type, VarType::Number(_)), "{:?}", r#type); } + + let bad_src = [ + "-", + "-.", + ".", + "1.2e3", + "e3", + "-e3", + ]; + for src in bad_src { + let r#type = src.as_var_type(); + assert!(!matches!(r#type, VarType::Number(_)), "{:?}", r#type); + } } #[test]