]> Repositorios git - scryer-prolog.git/commitdiff
print chars somewhat appropriately.
authorMark Thom <[email protected]>
Tue, 29 May 2018 02:19:52 +0000 (20:19 -0600)
committerMark Thom <[email protected]>
Tue, 29 May 2018 02:19:52 +0000 (20:19 -0600)
src/prolog/ast.rs
src/prolog/heap_print.rs
src/prolog/lib/builtins.pl
src/prolog/parser
src/tests.rs

index 1b85a388e38d6be3e63ce676723349464726ec67..7ba8174890a6a876972698aa17af5d5261b4f81e 100644 (file)
@@ -167,7 +167,6 @@ pub fn default_op_dir() -> OpDir {
     op_dir.insert((clause_name!(":-"), Fixity::In),  (XFX, 1200, module_name.clone()));
     op_dir.insert((clause_name!(":-"), Fixity::Pre), (FX, 1200, module_name.clone()));
     op_dir.insert((clause_name!("?-"), Fixity::Pre), (FX, 1200, module_name.clone()));    
-    op_dir.insert((clause_name!(","),  Fixity::In), (XFY, 1000, module_name.clone()));
 
     op_dir
 }
index 721a9cceb0800a458789fa9b739ee2c5924d752f..c8ca8a9dae581bb701b43ca06059e82e55a87068 100644 (file)
@@ -46,6 +46,7 @@ pub trait HCValueOutputter {
     type Output;
 
     fn new() -> Self;
+    fn push_char(&mut self, char);
     fn append(&mut self, &str);
     fn begin_new_var(&mut self);
     fn result(self) -> Self::Output;
@@ -69,6 +70,10 @@ impl HCValueOutputter for PrinterOutputter {
         self.contents += contents;
     }
 
+    fn push_char(&mut self, c: char) {
+        self.contents.push(c);
+    }
+    
     fn begin_new_var(&mut self) {
         if self.contents.len() != 0 {
             self.contents += ", ";
@@ -233,12 +238,17 @@ impl<'a, Formatter: HCValueFormatter, Outputter: HCValueOutputter>
         match c {
             Constant::Char(c) if c == '\n' =>
                 self.outputter.append("'\\n'"),
-//            Constant::Char(c) if c == '\f' =>
-//                self.outputter.append("\\f"),
+            //            Constant::Char(c) if c == '\f' =>
+            //                self.outputter.append("\\f"),
             Constant::Char(c) if c == '\r' =>
                 self.outputter.append("'\\r'"),
             Constant::Char(c) if c == '\t' =>
                 self.outputter.append("'\\t'"),
+            Constant::Char(c) => {
+                self.outputter.append("'");
+                self.outputter.push_char(c);
+                self.outputter.append("'");
+            },
 //            Constant::Char(c) if c == '\b' =>
 //                self.outputter.append("\\b"),
 //            Constant::Char(c) if c == '\\a' =>
index 58dccdd5620aaeb5fd102dfcb153fc7917631ed5..35953a405109d8dab5957bb017f8cb4f8e3c3e05 100644 (file)
@@ -7,15 +7,6 @@
        (\==)/2, (@=<)/2, (@>=)/2, (@<)/2, (@>)/2, (=@=)/2, (\=@=)/2,
        catch/3, throw/1, true/0, false/0]).
 
-','(G1, G2) :- '$get_cp'(B), ','(G1, G2, B).
-
-','(!, ','(G1, G2), B) :- '$set_cp'(B), ','(G1, G2, B).
-','(!, !, B) :- '$set_cp'(B).
-','(!, G, B) :- '$set_cp'(B), G.
-','(G, ','(G2, G3), B) :- !, G, ','(G2, G3, B).
-','(G, !, B) :- !, G, '$set_cp'(B).
-','(G1, G2, _) :- G1, G2.
-
 % arithmetic operators.
 :- op(700, xfx, is).
 :- op(500, yfx, +).
@@ -72,6 +63,15 @@ false :- '$fail'.
 
 % control operators.
 
+','(G1, G2) :- '$get_cp'(B), ','(G1, G2, B).
+
+','(!, ','(G1, G2), B) :- '$set_cp'(B), ','(G1, G2, B).
+','(!, !, B) :- '$set_cp'(B).
+','(!, G, B) :- '$set_cp'(B), G.
+','(G, ','(G2, G3), B) :- !, G, ','(G2, G3, B).
+','(G, !, B) :- !, G, '$set_cp'(B).
+','(G1, G2, _) :- G1, G2.
+
 ;(G1, G2) :- '$get_cp'(B), ;(G1, G2, B).
 
 ;(G1, G4, B) :- compound(G1), G1 = ->(G2, G3), (G2 -> G3 ; '$set_cp'(B), G4).
@@ -87,8 +87,8 @@ G1 -> G2 :- '$get_cp'(B), ->(G1, G2, B).
 
 % arg.
 
-/* Here is the old, SWI Prolog-imitative arg/3. The new, ISO Prolog
- * compliant arg/3 is implemented in Rust.
+/* Here is the old, SWI Prolog-imitative arg/3. It has been superseded by an ISO Prolog
+ * compliant arg/3 implemented in Rust.
 
 arg(N, Functor, Arg) :- var(N), !, functor(Functor, _, Arity), arg_(N, 1, Arity, Functor, Arg).
 arg(N, Functor, Arg) :- integer(N), !, functor(Functor, _, Arity), '$get_arg'(N, Functor, Arg).
index 52034e3a66b694fd16b164c509c525aeaf28470a..25b422477921de898dd50b0aa33be8fac5a0ec61 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 52034e3a66b694fd16b164c509c525aeaf28470a
+Subproject commit 25b422477921de898dd50b0aa33be8fac5a0ec61
index 2581884af2179ec3141451978f924c2b442ccd2e..ca6842b81ab0ac9110b1832dd260a901567c95a8 100644 (file)
@@ -36,6 +36,10 @@ impl HCValueOutputter for TestOutputter {
         self.focus += focus;
     }
 
+    fn push_char(&mut self, c: char) {
+        self.focus.push(c);
+    }
+
     fn begin_new_var(&mut self) {
         if !self.focus.is_empty() {
             let mut focus = String::new();