fix ambiguity_check
@@ -151,7 +151,12 @@ pub struct HCPrinter<'a, Outputter> {
macro_rules! push_space_if_amb {
($self:expr, $atom:expr, $op:expr, $action:block) => (
match $self.ambiguity_check($atom, $op) {
- Some(DirectedOp::Left(..)) => {
+ Some(DirectedOp::Left(_, false)) => {
+ $self.outputter.push_char(' ');
+ $action;
+ },
+ Some(DirectedOp::Left(lop, true)) => {
+ $self.outputter.insert_from_end(lop.as_str().len(), ' ');
$self.outputter.push_char(' ');
$action;
},
@@ -254,18 +259,34 @@ pub fn new(machine_st: &'a MachineState, output: Outputter) -> Self
ignore_ops: false }
}
+ pub fn from_heap_locs(machine_st: &'a MachineState, output: Outputter,
+ heap_locs: &'a HeapVarDict)
+ -> Self
+ {
+ let mut printer = Self::new(machine_st, output);
+
+ printer.heap_locs = reverse_heap_locs(machine_st, heap_locs);
+ printer
+ }
+
+ #[inline]
+ pub fn see_all_locs(&mut self) {
+ for key in self.heap_locs.keys().cloned() {
+ self.printed_vars.insert(key);
+ }
+ }
+
// return op itself if there is an ambiguity to indicate the direction the op
// lies, None otherwise.
- fn ambiguity_check(&mut self, atom: &str, op: &Option<DirectedOp>) -> Option<DirectedOp>
+ fn ambiguity_check(&self, atom: &str, op: &Option<DirectedOp>) -> Option<DirectedOp>
{
match op {
&Some(DirectedOp::Left(ref lop, false)) if continues_with_append(lop.as_str(), atom) =>
Some(DirectedOp::Left(lop.clone(), false)),
&Some(DirectedOp::Left(ref lop, true)) =>
if self.outputter.ends_with(&format!(" {}", lop.as_str())) {
- Some(DirectedOp::Left(lop.clone(), true))
+ Some(DirectedOp::Left(lop.clone(), false))
} else if continues_with_append(lop.as_str(), atom) {
- self.outputter.insert_from_end(lop.as_str().len(), ' ');
Some(DirectedOp::Left(lop.clone(), true))
} else {
None
@@ -277,22 +298,6 @@ fn ambiguity_check(&mut self, atom: &str, op: &Option<DirectedOp>) -> Option<Dir
}
}
- pub fn from_heap_locs(machine_st: &'a MachineState, output: Outputter,
- heap_locs: &'a HeapVarDict)
- -> Self
- {
- let mut printer = Self::new(machine_st, output);
-
- printer.heap_locs = reverse_heap_locs(machine_st, heap_locs);
- printer
- }
-
- #[inline]
- pub fn see_all_locs(&mut self) {
- for key in self.heap_locs.keys().cloned() {
- self.printed_vars.insert(key);
- }
- }
fn enqueue_op(&mut self, ct: ClauseType, fixity: Fixity) {
match fixity {
