always print a space between prefix operator and its operand
This commit is contained in:
@@ -590,31 +590,21 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
right_directed_op,
|
||||
));
|
||||
} else if is_prefix!(spec.get_spec()) {
|
||||
match name {
|
||||
atom!("-") | atom!("\\") => {
|
||||
self.format_prefix_op_with_space(max_depth, name, spec);
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
if self.check_max_depth(&mut max_depth) {
|
||||
self.iter.pop_stack();
|
||||
|
||||
self.state_stack.push(TokenOrRedirect::Atom(atom!("...")));
|
||||
self.state_stack.push(TokenOrRedirect::Op(name, spec));
|
||||
self.state_stack.push(TokenOrRedirect::Space);
|
||||
self.state_stack.push(TokenOrRedirect::Atom(name));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let left_directed_op = DirectedOp::Left(name, spec);
|
||||
let op = DirectedOp::Left(name, spec);
|
||||
|
||||
self.state_stack.push(TokenOrRedirect::CompositeRedirect(
|
||||
max_depth,
|
||||
left_directed_op,
|
||||
));
|
||||
|
||||
self.state_stack.push(TokenOrRedirect::Op(name, spec));
|
||||
self.state_stack.push(TokenOrRedirect::CompositeRedirect(max_depth, op));
|
||||
self.state_stack.push(TokenOrRedirect::Space);
|
||||
self.state_stack.push(TokenOrRedirect::Atom(name));
|
||||
} else {
|
||||
match name.as_str() {
|
||||
"|" => {
|
||||
@@ -687,24 +677,6 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
true
|
||||
}
|
||||
|
||||
fn format_prefix_op_with_space(&mut self, mut max_depth: usize, name: Atom, spec: OpDesc) {
|
||||
if self.check_max_depth(&mut max_depth) {
|
||||
self.iter.pop_stack();
|
||||
|
||||
self.state_stack.push(TokenOrRedirect::Atom(atom!("...")));
|
||||
self.state_stack.push(TokenOrRedirect::Space);
|
||||
self.state_stack.push(TokenOrRedirect::Atom(name));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let op = DirectedOp::Left(name, spec);
|
||||
|
||||
self.state_stack.push(TokenOrRedirect::CompositeRedirect(max_depth, op));
|
||||
self.state_stack.push(TokenOrRedirect::Space);
|
||||
self.state_stack.push(TokenOrRedirect::Atom(name));
|
||||
}
|
||||
|
||||
fn format_bar_separator_op(&mut self, mut max_depth: usize, name: Atom, spec: OpDesc) {
|
||||
if self.check_max_depth(&mut max_depth) {
|
||||
self.iter.pop_stack();
|
||||
@@ -1348,12 +1320,14 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
||||
self.state_stack.push(TokenOrRedirect::Open);
|
||||
|
||||
if let Some(ref op) = &op {
|
||||
if !self.outputter.ends_with(" ") {
|
||||
if op.is_left() && requires_space(op.as_atom().as_str(), "(") {
|
||||
self.state_stack.push(TokenOrRedirect::Space);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn print_tcp_listener(&mut self, tcp_listener: &TcpListener, max_depth: usize) {
|
||||
|
||||
@@ -341,7 +341,7 @@ test_67 :- setup_call_cleanup(( current_op(P,fy,+),
|
||||
op(P,fy,+)).
|
||||
|
||||
test_257 :- writeq_term_to_chars([+{a},+[]], Chars),
|
||||
Chars == "[+{a},+[]]".
|
||||
Chars == "[+ {a},+ []]".
|
||||
|
||||
test_68 :- [(:-)|(:-)]=[:-|:-].
|
||||
|
||||
@@ -568,7 +568,7 @@ test_131_132_133 :-
|
||||
C0 == "' op' '1 '",
|
||||
read_from_chars("' op'[].", T1),
|
||||
writeq_term_to_chars(T1, C1),
|
||||
C1 == "' op'[]"
|
||||
C1 == "' op' []"
|
||||
),
|
||||
op(0, fx, ' op')
|
||||
).
|
||||
@@ -932,7 +932,7 @@ test_274_275 :-
|
||||
setup_call_cleanup(op(20,fx,--),
|
||||
( read_from_chars("--(a).", T0),
|
||||
writeq_term_to_chars(T0, C0),
|
||||
C0 == "--a",
|
||||
C0 == "-- a",
|
||||
op(0,fx,--),
|
||||
read_from_chars("--(a).", T1),
|
||||
writeq_term_to_chars(T1, C1),
|
||||
@@ -981,7 +981,7 @@ test_305 :- writeq_term_to_chars(\ (a = b), C),
|
||||
C == "\\ (a=b)".
|
||||
|
||||
test_306 :- writeq_term_to_chars(+ (a = b), C),
|
||||
C == "+(a=b)".
|
||||
C == "+ (a=b)".
|
||||
|
||||
test_307 :- writeq_term_to_chars([/**/], C),
|
||||
C == "[]".
|
||||
|
||||
Reference in New Issue
Block a user