Merge pull request #1851 from triska/operator_bracketing

bracket all operators that are direct operands of (=)/2
This commit is contained in:
Mark Thom
2023-06-30 00:26:18 -06:00
committed by GitHub

View File

@@ -205,12 +205,14 @@ submit_query_and_print_results(Term, VarList) :-
needs_bracketing(Value, Op) :- needs_bracketing(Value, Op) :-
catch((functor(Value, F, _), nonvar(Value),
current_op(EqPrec, EqSpec, Op), \+ integer(Value),
current_op(FPrec, _, F)), functor(Value, F, Arity),
_, current_op(FPrec, _, F),
false), current_op(EqPrec, EqSpec, Op),
( EqPrec < FPrec -> ( Arity =:= 0 ->
true
; EqPrec < FPrec ->
true true
; FPrec > 0, F == Value, graphic_token_char(F) -> ; FPrec > 0, F == Value, graphic_token_char(F) ->
true true
@@ -228,7 +230,7 @@ write_goal(G, VarList, MaxDepth) :-
), ),
write(Var), write(Var),
write(' = '), write(' = '),
( needs_bracketing(Value, (=)) -> ( needs_bracketing(Value, =) ->
write('('), write('('),
write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]),
write(')') write(')')
@@ -247,7 +249,7 @@ write_last_goal(G, VarList, MaxDepth) :-
), ),
write(Var), write(Var),
write(' = '), write(' = '),
( needs_bracketing(Value, (=)) -> ( needs_bracketing(Value, =) ->
write('('), write('('),
write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]),
write(')') write(')')
@@ -271,8 +273,7 @@ write_eq(G, VarList, MaxDepth) :-
write_last_goal(G, VarList, MaxDepth). write_last_goal(G, VarList, MaxDepth).
graphic_token_char(C) :- graphic_token_char(C) :-
memberchk(C, ['#', '$', '&', '*', '+', '-', '.', ('/'), ':', memberchk(C, [#, $, &, *, +, -, ., /, :, <, =, >, ?, @, ^, ~, \\]).
'<', '=', '>', '?', '@', '^', '~', ('\\')]).
list_last_item([C], C) :- !. list_last_item([C], C) :- !.
list_last_item([_|Cs], D) :- list_last_item([_|Cs], D) :-