]> Repositorios git - scryer-prolog.git/commitdiff
add ambiguity check for period printing, remove extraneous space between last goal...
authorMark Thom <[email protected]>
Wed, 27 Nov 2019 02:38:43 +0000 (19:38 -0700)
committerMark Thom <[email protected]>
Wed, 27 Nov 2019 02:38:43 +0000 (19:38 -0700)
src/prolog/toplevel.pl

index d04d7b104158b43b8ab73aec2cc50242b0d15540..634335544b4fbbc245deb383015e215d1250eafc 100644 (file)
     ;  write_term(G, [quoted(true), variable_names(VarList)])
     ).
 
+'$write_last_goal'(G, VarList) :-
+    (  G = (Var = Value) ->
+       write(Var),
+       write(' = '),
+       (  '$needs_bracketing'(Value, (=)) ->
+         write('('),
+         write_term(Value, [quoted(true), variable_names(VarList)]),
+         write(')')              
+       ;  write_term(Value, [quoted(true), variable_names(VarList)]),
+         (  '$trailing_period_is_ambiguous'(Value) ->
+            write(' ')
+         ;  true
+         )
+       )
+    ;  G == [] ->
+       write('true')
+    ;  write_term(G, [quoted(true), variable_names(VarList)])
+    ).
+
 '$write_eq'((G1, G2), VarList) :-
     !,
     '$write_goal'(G1, VarList),
     write(', '),
     '$write_eq'(G2, VarList).
 '$write_eq'(G, VarList) :-
-    '$write_goal'(G, VarList).
+    '$write_last_goal'(G, VarList).
+    
+'$graphic_token_char'(C) :-
+    memberchk(C, ['#', '$', '&', '*', '+', '-', '.', ('/'), ':',
+                  '<', '=', '>', '?', '@', '^', '~', ('\\')]).
+
+'$list_last_item'([C], C) :- !.
+'$list_last_item'([_|Cs], D) :-
+    '$list_last_item'(Cs, D).
+
+'$trailing_period_is_ambiguous'(Value) :-
+    atom(Value),
+    atom_chars(Value, ValueChars),
+    '$list_last_item'(ValueChars, Char),
+    '$graphic_token_char'(Char).
 
 '$write_eqs_and_read_input'(B, VarList) :-
     sort(VarList, SortedVarList),
          write('true.'), nl
        ;  thread_goals(Goals, ThreadedGoals, (',')),
          '$write_eq'(ThreadedGoals, VarList),
-         write(' .'),
+         write('.'),
          nl
        )
     ;  thread_goals(Goals, ThreadedGoals, (',')),