]> Repositorios git - scryer-prolog.git/commitdiff
Fix parsing of floats
authorNicolas Luck <[email protected]>
Thu, 24 Aug 2023 16:10:47 +0000 (18:10 +0200)
committerNicolas Luck <[email protected]>
Thu, 24 Aug 2023 16:10:47 +0000 (18:10 +0200)
src/machine/lib_machine.rs
src/machine/parsed_results.rs

index 9c52458837e74aa50dacd0a9cbc0eeb42b92fc28..a3438783ee77ddb780fbb74e6ca88d8796599c88 100644 (file)
@@ -52,7 +52,7 @@ impl Machine {
                 .iter()
                 // 4. Trim and remove empty lines
                 .map(|s| s.trim())
-                .map(|s| s.replace(".", ""))
+                .map(|s| if s.ends_with(".") { s[..s.len()-1].to_string() } else { s.to_string() })
                 .filter(|s| !s.is_empty())
                 // 5. Parse into QueryResolutionLine
                 .map(QueryResolutionLine::try_from)
index ec9b92b8ef23f728af49455c35d02b3eaf830f2a..01ba6d5430701999b09a002cc9542e4834a0e199 100644 (file)
@@ -163,7 +163,13 @@ impl TryFrom<String> for Value {
     fn try_from(string: String) -> Result<Self, Self::Error> {
         let trimmed = string.trim();
 
-        if trimmed.starts_with("'") && trimmed.ends_with("'") {
+        if let Ok(float_value) = string.parse::<f64>() {
+            println!("float value: {} -> {}", string, float_value);
+            Ok(Value::Float(OrderedFloat(float_value)))
+        } else if let Ok(int_value) = string.parse::<i128>() {
+            println!("int value: {} -> {}", string, int_value);
+            Ok(Value::Integer(int_value.into()))
+        } else if trimmed.starts_with("'") && trimmed.ends_with("'") {
             Ok(Value::String(trimmed[1..trimmed.len() - 1].into()))
         } else if trimmed.starts_with("\"") && trimmed.ends_with("\"") {
             Ok(Value::String(trimmed[1..trimmed.len() - 1].into()))