pub(crate) numbervars: bool,
pub(crate) quoted: bool,
pub(crate) ignore_ops: bool,
+ pub(crate) print_strings_as_strs: bool,
}
macro_rules! push_space_if_amb {
ignore_ops: false,
cyclic_terms: IndexMap::new(),
var_names: IndexMap::new(),
+ print_strings_as_strs: false,
}
}
Constant::Integer(n) => self.print_number(Number::Integer(n), op),
Constant::Float(n) => self.print_number(Number::Float(n), op),
Constant::Rational(n) => self.print_number(Number::Rational(n), op),
- Constant::String(n, s) => self.print_string(iter, n, s),
+ Constant::String(n, s) if self.print_strings_as_strs =>
+ self.print_string_as_str(iter, n, s),
+ Constant::String(n, s) => self.print_string(n, s),
Constant::Usize(i) => self.append_str(&format!("u{}", i)),
}
}
- fn print_string(&mut self, iter: &mut HCPreOrderIterator, offset: usize, s: Rc<String>) {
- let atom = String::from_iter(s[offset ..].chars().map(|c| {
+ fn print_string_as_str(
+ &mut self,
+ iter: &mut HCPreOrderIterator,
+ offset: usize,
+ s: Rc<String>,
+ ) {
+ let atom = String::from_iter(s[offset ..].chars().map(|c| {
char_to_string(true, c)
}));
iter_stack.pop();
iter_stack.pop();
}
+
+ fn print_string(&mut self, offset: usize, s: Rc<String>) {
+ if !self.machine_st.machine_flags().double_quotes.is_atom() {
+ if !s[offset ..].is_empty() {
+ if self.ignore_ops {
+ self.format_struct(2, clause_name!("."));
+ } else {
+ self.push_list();
+ }
+ } else if !self.at_cdr("") {
+ self.append_str("[]");
+ }
+ } else {
+ let atom = String::from_iter(s[offset ..].chars().map(|c| {
+ char_to_string(self.quoted, c)
+ }));
+
+ self.push_char('"');
+ self.append_str(&atom);
+ self.push_char('"');
+ }
+ }
fn push_list(&mut self) {
let cell = Rc::new(Cell::new(true));
printer.quoted = true;
printer.numbervars = true;
+
// the purpose of the offset is to avoid clashes with variable names that might
// occur after the addresses in the expanded term are substituted with the variable
// names in the pre-expansion term. This formula ensures that all generated "numbervars"-
// style variable names will be longer than the keys of the var_dict, and therefore
// not equal to any of them.
printer.numbervars_offset = Integer::from(10).pow(max_var_length as u32) * 26;
+ printer.print_strings_as_strs = true;
printer.drop_toplevel_spec();
printer.see_all_locs();