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,
|
right_directed_op,
|
||||||
));
|
));
|
||||||
} else if is_prefix!(spec.get_spec()) {
|
} 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) {
|
if self.check_max_depth(&mut max_depth) {
|
||||||
self.iter.pop_stack();
|
self.iter.pop_stack();
|
||||||
|
|
||||||
self.state_stack.push(TokenOrRedirect::Atom(atom!("...")));
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let left_directed_op = DirectedOp::Left(name, spec);
|
let op = DirectedOp::Left(name, spec);
|
||||||
|
|
||||||
self.state_stack.push(TokenOrRedirect::CompositeRedirect(
|
self.state_stack.push(TokenOrRedirect::CompositeRedirect(max_depth, op));
|
||||||
max_depth,
|
self.state_stack.push(TokenOrRedirect::Space);
|
||||||
left_directed_op,
|
self.state_stack.push(TokenOrRedirect::Atom(name));
|
||||||
));
|
|
||||||
|
|
||||||
self.state_stack.push(TokenOrRedirect::Op(name, spec));
|
|
||||||
} else {
|
} else {
|
||||||
match name.as_str() {
|
match name.as_str() {
|
||||||
"|" => {
|
"|" => {
|
||||||
@@ -687,24 +677,6 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
|||||||
true
|
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) {
|
fn format_bar_separator_op(&mut self, mut max_depth: usize, name: Atom, spec: OpDesc) {
|
||||||
if self.check_max_depth(&mut max_depth) {
|
if self.check_max_depth(&mut max_depth) {
|
||||||
self.iter.pop_stack();
|
self.iter.pop_stack();
|
||||||
@@ -1348,8 +1320,10 @@ impl<'a, Outputter: HCValueOutputter> HCPrinter<'a, Outputter> {
|
|||||||
self.state_stack.push(TokenOrRedirect::Open);
|
self.state_stack.push(TokenOrRedirect::Open);
|
||||||
|
|
||||||
if let Some(ref op) = &op {
|
if let Some(ref op) = &op {
|
||||||
if op.is_left() && requires_space(op.as_atom().as_str(), "(") {
|
if !self.outputter.ends_with(" ") {
|
||||||
self.state_stack.push(TokenOrRedirect::Space);
|
if op.is_left() && requires_space(op.as_atom().as_str(), "(") {
|
||||||
|
self.state_stack.push(TokenOrRedirect::Space);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ test_67 :- setup_call_cleanup(( current_op(P,fy,+),
|
|||||||
op(P,fy,+)).
|
op(P,fy,+)).
|
||||||
|
|
||||||
test_257 :- writeq_term_to_chars([+{a},+[]], Chars),
|
test_257 :- writeq_term_to_chars([+{a},+[]], Chars),
|
||||||
Chars == "[+{a},+[]]".
|
Chars == "[+ {a},+ []]".
|
||||||
|
|
||||||
test_68 :- [(:-)|(:-)]=[:-|:-].
|
test_68 :- [(:-)|(:-)]=[:-|:-].
|
||||||
|
|
||||||
@@ -568,7 +568,7 @@ test_131_132_133 :-
|
|||||||
C0 == "' op' '1 '",
|
C0 == "' op' '1 '",
|
||||||
read_from_chars("' op'[].", T1),
|
read_from_chars("' op'[].", T1),
|
||||||
writeq_term_to_chars(T1, C1),
|
writeq_term_to_chars(T1, C1),
|
||||||
C1 == "' op'[]"
|
C1 == "' op' []"
|
||||||
),
|
),
|
||||||
op(0, fx, ' op')
|
op(0, fx, ' op')
|
||||||
).
|
).
|
||||||
@@ -932,7 +932,7 @@ test_274_275 :-
|
|||||||
setup_call_cleanup(op(20,fx,--),
|
setup_call_cleanup(op(20,fx,--),
|
||||||
( read_from_chars("--(a).", T0),
|
( read_from_chars("--(a).", T0),
|
||||||
writeq_term_to_chars(T0, C0),
|
writeq_term_to_chars(T0, C0),
|
||||||
C0 == "--a",
|
C0 == "-- a",
|
||||||
op(0,fx,--),
|
op(0,fx,--),
|
||||||
read_from_chars("--(a).", T1),
|
read_from_chars("--(a).", T1),
|
||||||
writeq_term_to_chars(T1, C1),
|
writeq_term_to_chars(T1, C1),
|
||||||
@@ -981,7 +981,7 @@ test_305 :- writeq_term_to_chars(\ (a = b), C),
|
|||||||
C == "\\ (a=b)".
|
C == "\\ (a=b)".
|
||||||
|
|
||||||
test_306 :- writeq_term_to_chars(+ (a = b), C),
|
test_306 :- writeq_term_to_chars(+ (a = b), C),
|
||||||
C == "+(a=b)".
|
C == "+ (a=b)".
|
||||||
|
|
||||||
test_307 :- writeq_term_to_chars([/**/], C),
|
test_307 :- writeq_term_to_chars([/**/], C),
|
||||||
C == "[]".
|
C == "[]".
|
||||||
|
|||||||
Reference in New Issue
Block a user