fn result(self) -> Self::Output;
fn ends_with(&self, &str) -> bool;
fn len(&self) -> usize;
- fn truncate(&mut self, usize);
+ fn truncate(&mut self, usize);
}
pub struct PrinterOutputter {
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;
},
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
}
}
- 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 {
if self.outputter.ends_with(&format!(" {}", op.as_str())) {
self.outputter.push_char(' ');
}
-
+
self.outputter.push_char('(');
}
if let Some(ref op) = op {
self.state_stack.push(TokenOrRedirect::Open);
-
+
if self.outputter.ends_with(&format!(" {}", op.as_str())) {
self.state_stack.push(TokenOrRedirect::Space);
- }
+ }
}
},
HeapCellValue::NamedStr(0, name, fixity) =>