]> Repositorios git - scryer-prolog.git/commitdiff
update prolog_parser, refine bracketing tests.
authorMark Thom <[email protected]>
Sun, 7 Apr 2019 18:56:31 +0000 (12:56 -0600)
committerMark Thom <[email protected]>
Sun, 7 Apr 2019 18:56:31 +0000 (12:56 -0600)
Cargo.toml
src/prolog/heap_print.rs

index 5f2ef3576fcb5c78559c5eca2d3f124a31341251..e9944e99f7ca78ffa50886c2241d668e335769ea 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.50"
+version = "0.8.51"
 authors = ["Mark Thom <[email protected]>"]
 repository = "https://github.com/mthom/scryer-prolog"
 description = "A modern Prolog implementation written mostly in Rust."
@@ -14,7 +14,7 @@ cfg-if = "0.1.7"
 downcast = "0.10.0"
 num = "0.2"
 ordered-float = "0.5.0"
-prolog_parser = "0.8.17"
+prolog_parser = "0.8.18"
 readline_rs_compat = { version = "0.1.7", optional = true }
 ref_thread_local = "0.0.0"
 
index e472fa2eff31c75023a19dfaa681660235092c97..79319e95180f24c80d53c6a024bae0e88295b753 100644 (file)
@@ -37,6 +37,15 @@ impl DirectedOp {
                 name.as_str() == "-" && is_prefix!(cell.assoc())
         }
     }
+
+    #[inline]
+    fn is_left(&self) -> bool {
+        if let &DirectedOp::Left(..) = self {
+            true
+        } else {
+            false
+        }
+    }
 }
 
 fn needs_bracketing(child_spec: &SharedOpDesc, op: &DirectedOp) -> bool
@@ -62,7 +71,7 @@ fn needs_bracketing(child_spec: &SharedOpDesc, op: &DirectedOp) -> bool
             if child_spec.prec() > priority || (child_spec.prec() == priority && is_strict_left) {
                 true
             } else if (is_postfix!(spec) || is_infix!(spec)) && !is_postfix!(child_spec.assoc()) {
-                child_spec.prec() == priority
+                !SharedOpDesc::ptr_eq(&cell, &child_spec) && child_spec.prec() == priority
             } else {
                 false
             }
@@ -281,7 +290,9 @@ macro_rules! push_space_if_amb {
 fn requires_space(atom: &str, op: &str) -> bool {
     match atom.chars().last() {
         Some(ac) => op.chars().next().map(|oc| {
-            if alpha_numeric_char!(ac) {
+            if ac == '0' {
+                oc == 'b' || oc == 'x' || oc == 'o' || !non_quoted_token(op.chars())
+            } else if alpha_numeric_char!(ac) {
                 oc == '(' || alpha_numeric_char!(oc)
             } else if graphic_token_char!(ac) {
                 graphic_token_char!(oc)
@@ -293,8 +304,6 @@ fn requires_space(atom: &str, op: &str) -> bool {
                 sign_char!(oc) || decimal_digit_char!(oc)
             } else if single_quote_char!(ac) {
                 single_quote_char!(oc)
-            } else if ac == '0' {
-                oc == 'b' || oc == 'x' || oc == 'o' || !non_quoted_token(op.chars())
             } else {
                 false
             }
@@ -808,7 +817,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter>
                     self.state_stack.push(TokenOrRedirect::Open);
 
                     if let Some(ref op) = &op {
-                        if requires_space(op.as_str(), "(") {
+                        if op.is_left() && requires_space(op.as_str(), "(") {
                             self.state_stack.push(TokenOrRedirect::Space);
                         }
                     }