]> Repositorios git - scryer-prolog.git/commitdiff
Fix list result parsing
authorNicolas Luck <[email protected]>
Tue, 22 Aug 2023 20:46:00 +0000 (22:46 +0200)
committerNicolas Luck <[email protected]>
Tue, 22 Aug 2023 20:46:00 +0000 (22:46 +0200)
src/machine/lib_machine.rs
src/machine/parsed_results.rs

index a90e7adc89fc5491919da115f46e775ee0e8e213..9c52458837e74aa50dacd0a9cbc0eeb42b92fc28 100644 (file)
@@ -171,6 +171,26 @@ mod tests {
         );
     }
 
+    #[tokio::test]
+    async fn list_results() {
+        let mut machine = Machine::new_lib();
+        machine.load_module_string(
+            "facts",
+                r#"
+                list([1,2,3]).
+            "#.to_string());
+
+        let result = machine.run_query(String::from("list(X)."));
+        assert_eq!(
+            result,
+            Ok(QueryResolution::Matches(vec![
+                QueryMatch::from(btreemap! {
+                    "X" => Value::List(Vec::from([Value::from("1"), Value::from("2"), Value::from("3")]))
+                }),
+            ]))
+        );
+    }
+
 
     #[tokio::test]
     async fn consult() {
index aaec386d914ef5dbf66ab4696c4203c8e76f0d28..ec9b92b8ef23f728af49455c35d02b3eaf830f2a 100644 (file)
@@ -120,7 +120,7 @@ impl From<Vec<QueryResolutionLine>> for QueryResolution {
 fn parse_prolog_response(input: &str) -> HashMap<String, String> {
     let mut map: HashMap<String, String> = HashMap::new();
     // Use regex to match strings including commas inside them
-    let re = Regex::new(r"(\w+)\s=\s([^,]*'[^']*'[^,]*|[^,]*)").unwrap();
+    let re = Regex::new(r"(\w+)\s=\s((?:[^,\[]|\[[^\]]*\])*)").unwrap();
     
     for cap in re.captures_iter(input) {
         let key = cap[1].to_string();