print lists as strings when possible (#295)
This commit is contained in:
@@ -1024,31 +1024,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_string(
|
fn print_proper_string(&mut self, buf: String, max_depth: usize) {
|
||||||
&mut self,
|
|
||||||
iter: &mut HCPreOrderIterator,
|
|
||||||
mut max_depth: usize,
|
|
||||||
h: usize,
|
|
||||||
n: usize,
|
|
||||||
) {
|
|
||||||
iter.stack().pop();
|
|
||||||
iter.stack().pop();
|
|
||||||
|
|
||||||
if self.check_max_depth(&mut max_depth) {
|
|
||||||
self.state_stack.push(TokenOrRedirect::Atom(clause_name!("...")));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut heap_pstr_iter =
|
|
||||||
self.machine_st.heap_pstr_iter(Addr::PStrLocation(h, n));
|
|
||||||
|
|
||||||
let buf = heap_pstr_iter.to_string();
|
|
||||||
let end_addr = heap_pstr_iter.focus();
|
|
||||||
|
|
||||||
let at_cdr = self.at_cdr(",");
|
|
||||||
|
|
||||||
if !at_cdr && Addr::EmptyList == end_addr {
|
|
||||||
if !self.machine_st.flags.double_quotes.is_codes() {
|
|
||||||
self.push_char('"');
|
self.push_char('"');
|
||||||
|
|
||||||
let buf =
|
let buf =
|
||||||
@@ -1073,7 +1049,42 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
|||||||
|
|
||||||
self.append_str(&buf);
|
self.append_str(&buf);
|
||||||
self.push_char('"');
|
self.push_char('"');
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_list_like(
|
||||||
|
&mut self,
|
||||||
|
iter: &mut HCPreOrderIterator,
|
||||||
|
addr: Addr,
|
||||||
|
mut max_depth: usize,
|
||||||
|
) {
|
||||||
|
let a1 = iter.stack().pop();
|
||||||
|
let a2 = iter.stack().pop();
|
||||||
|
|
||||||
|
if self.check_max_depth(&mut max_depth) {
|
||||||
|
self.state_stack.push(TokenOrRedirect::Atom(clause_name!("...")));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut heap_pstr_iter =
|
||||||
|
self.machine_st.heap_pstr_iter(addr);
|
||||||
|
|
||||||
|
let buf = heap_pstr_iter.to_string();
|
||||||
|
|
||||||
|
if buf.is_empty() {
|
||||||
|
iter.stack().push(a2.unwrap());
|
||||||
|
iter.stack().push(a1.unwrap());
|
||||||
|
|
||||||
|
self.push_list(iter, max_depth);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let end_addr = heap_pstr_iter.focus();
|
||||||
|
|
||||||
|
let at_cdr = self.at_cdr(",");
|
||||||
|
|
||||||
|
if !at_cdr && Addr::EmptyList == end_addr {
|
||||||
|
if !self.machine_st.flags.double_quotes.is_codes() {
|
||||||
|
self.print_proper_string(buf, max_depth);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1332,13 +1343,13 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
|||||||
self.append_str(&format!("{}", u));
|
self.append_str(&format!("{}", u));
|
||||||
}
|
}
|
||||||
&HeapCellValue::Addr(Addr::PStrLocation(h, n)) => {
|
&HeapCellValue::Addr(Addr::PStrLocation(h, n)) => {
|
||||||
self.print_string(iter, max_depth, h, n);
|
self.print_list_like(iter, Addr::PStrLocation(h, n), max_depth);
|
||||||
}
|
}
|
||||||
&HeapCellValue::Addr(Addr::Lis(_)) => {
|
&HeapCellValue::Addr(Addr::Lis(l)) => {
|
||||||
if self.ignore_ops {
|
if self.ignore_ops {
|
||||||
self.format_struct(iter, max_depth, 2, clause_name!("."));
|
self.format_struct(iter, max_depth, 2, clause_name!("."));
|
||||||
} else {
|
} else {
|
||||||
self.push_list(iter, max_depth);
|
self.print_list_like(iter, Addr::Lis(l), max_depth); //self.push_list(iter, max_depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&HeapCellValue::Addr(addr) => {
|
&HeapCellValue::Addr(addr) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user