]> Repositorios git - scryer-prolog.git/commitdiff
Fix lists of chars as strings
authorbakaq <[email protected]>
Fri, 16 Aug 2024 03:34:46 +0000 (00:34 -0300)
committerbakaq <[email protected]>
Fri, 16 Aug 2024 03:34:46 +0000 (00:34 -0300)
src/machine/parsed_results.rs

index 305e6a4d73e617b0064887d4cede20e8cf8e39b7..cedbc9f03bef7506638cab3b6318675cf027b9a6 100644 (file)
@@ -194,6 +194,20 @@ impl Value {
                     let head = term_stack.pop().unwrap();
 
                     let list = match tail {
+                        Value::Atom(atom) if atom == "[]" => match head {
+                            Value::Atom(ref a) if a.chars().collect::<Vec<_>>().len() == 1 => {
+                                // Handle lists of char as strings
+                                Value::String(a.to_string())
+                            }
+                            _ => Value::List(vec![head]),
+                        },
+                        Value::List(elems) if elems.is_empty() => match head {
+                            Value::Atom(ref a) if a.chars().collect::<Vec<_>>().len() == 1 => {
+                                // Handle lists of char as strings
+                                Value::String(a.to_string())
+                            },
+                            _ => Value::List(vec![head]),
+                        },
                         Value::List(mut elems) => {
                             elems.insert(0, head);
                             Value::List(elems)
@@ -213,13 +227,6 @@ impl Value {
                                 Value::List(elems)
                             }
                         },
-                        Value::Atom(atom) if atom == "[]" =>  match head {
-                            Value::Atom(ref a) if a.chars().collect::<Vec<_>>().len() == 1 => {
-                                // Handle lists of char as strings
-                                Value::String(a.to_string())
-                            }
-                            _ => Value::List(vec![head]),
-                        },
                         _ => Value::Structure(".".into(), vec![head, tail]),
                     };
                     term_stack.push(list);