From 3b9b9e75c41ed62e2e5d15f245324f2c36b48e60 Mon Sep 17 00:00:00 2001 From: Markus Triska Date: Wed, 5 Jul 2023 21:22:49 +0200 Subject: [PATCH] make double_quotes write option not dependent on double_quotes flag This gives consistent results without depending on another flag. --- src/heap_print.rs | 5 +---- src/machine/machine_state.rs | 1 - src/machine/mock_wam.rs | 1 - src/toplevel.pl | 19 +++++++++++++------ 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/heap_print.rs b/src/heap_print.rs index 7cd8b713..10a211a1 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -487,7 +487,6 @@ pub struct HCPrinter<'a, Outputter> { iter: StackfulPreOrderHeapIter<'a>, atom_tbl: &'a mut AtomTable, op_dir: &'a OpDir, - flags: MachineFlags, state_stack: Vec, toplevel_spec: Option, last_item_idx: usize, @@ -555,7 +554,6 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { atom_tbl: &'a mut AtomTable, stack: &'a mut Stack, op_dir: &'a OpDir, - flags: MachineFlags, output: Outputter, cell: HeapCellValue, ) -> Self { @@ -564,7 +562,6 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { iter: stackful_preorder_iter(heap, stack, cell), atom_tbl, op_dir, - flags, state_stack: vec![], toplevel_spec: None, last_item_idx: 0, @@ -1187,7 +1184,7 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> { let at_cdr = self.outputter.ends_with("|"); - if self.double_quotes && self.flags.double_quotes == DoubleQuotes::Chars { + if self.double_quotes { if !at_cdr && !self.ignore_ops && end_cell.is_string_terminator(&self.iter.heap) { self.remove_list_children(focus.value() as usize); return self.print_proper_string(focus.value() as usize, max_depth); diff --git a/src/machine/machine_state.rs b/src/machine/machine_state.rs index 78b1a7f5..5ef74003 100644 --- a/src/machine/machine_state.rs +++ b/src/machine/machine_state.rs @@ -786,7 +786,6 @@ impl MachineState { &mut self.atom_tbl, &mut self.stack, op_dir, - self.flags, PrinterOutputter::new(), term_to_be_printed, ); diff --git a/src/machine/mock_wam.rs b/src/machine/mock_wam.rs index a4aad74c..70264ac9 100644 --- a/src/machine/mock_wam.rs +++ b/src/machine/mock_wam.rs @@ -64,7 +64,6 @@ impl MockWAM { &mut self.machine_st.atom_tbl, &mut self.machine_st.stack, &self.op_dir, - self.machine_st.flags, PrinterOutputter::new(), heap_loc_as_cell!(term_write_result.heap_loc), ); diff --git a/src/toplevel.pl b/src/toplevel.pl index 2df6d360..870b6990 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -221,7 +221,13 @@ arity_specifier(0, _). arity_specifier(1, S) :- atom_chars(S, [_,_]). arity_specifier(2, S) :- atom_chars(S, [_,_,_]). +double_quotes_option(DQ) :- + ( current_prolog_flag(double_quotes, chars) -> DQ = true + ; DQ = false + ). + write_goal(G, VarList, MaxDepth) :- + double_quotes_option(DQ), ( G = (Var = Value) -> ( var(Value) -> select((Var = _), VarList, NewVarList) @@ -231,16 +237,17 @@ write_goal(G, VarList, MaxDepth) :- write(' = '), ( needs_bracketing(Value, =) -> write('('), - write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(true)]), + write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(DQ)]), write(')') - ; write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(true)]) + ; write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(DQ)]) ) ; G == [] -> write('true') - ; write_term(G, [quoted(true), variable_names(VarList), max_depth(MaxDepth), double_quotes(true)]) + ; write_term(G, [quoted(true), variable_names(VarList), max_depth(MaxDepth), double_quotes(DQ)]) ). write_last_goal(G, VarList, MaxDepth) :- + double_quotes_option(DQ), ( G = (Var = Value) -> ( var(Value) -> select((Var = _), VarList, NewVarList) @@ -250,9 +257,9 @@ write_last_goal(G, VarList, MaxDepth) :- write(' = '), ( needs_bracketing(Value, =) -> write('('), - write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(true)]), + write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(DQ)]), write(')') - ; write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(true)]), + ; write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth), double_quotes(DQ)]), ( trailing_period_is_ambiguous(Value) -> write(' ') ; true @@ -260,7 +267,7 @@ write_last_goal(G, VarList, MaxDepth) :- ) ; G == [] -> write('true') - ; write_term(G, [quoted(true), variable_names(VarList), max_depth(MaxDepth), double_quotes(true)]) + ; write_term(G, [quoted(true), variable_names(VarList), max_depth(MaxDepth), double_quotes(DQ)]) ). write_eq((G1, G2), VarList, MaxDepth) :- -- 2.54.0