]> Repositorios git - scryer-prolog.git/commitdiff
ENHANCED: use newly available read_term_from_chars/3 for better errors
authorMarkus Triska <[email protected]>
Sun, 16 Jul 2023 07:14:02 +0000 (09:14 +0200)
committerMarkus Triska <[email protected]>
Sun, 16 Jul 2023 12:16:07 +0000 (14:16 +0200)
Examples, previously:

    $ scryer-prolog -g "member(X,Ls"
    ?-
    $ scryer-prolog -g "member(X,Ls)"
    member(_542,_543) causes: error(existence_error(procedure,member/2),member/2)
    ?-

Now:

    $ scryer-prolog -g "member(X,Ls"
    "member(X,Ls" cannot be read: error(syntax_error(incomplete_reduction),read_term_from_chars/3:0)
    $ scryer-prolog -g "member(X,Ls)"
    member(X,Ls) causes: error(existence_error(procedure,member/2),member/2)
    ?-

This also addresses #1185.

src/toplevel.pl

index 8318f43b476f5e7a054fff327f9572c7540de38e..5431bad187c2604b80687c08d7894187e6de3f86 100644 (file)
@@ -115,18 +115,27 @@ layout_and_dot([C|Cs]) :-
     layout_and_dot(Cs).
 
 run_goals([]).
-run_goals([g(Gs0)|Goals]) :-
+run_goals([g(Gs0)|Goals]) :- !,
     (   ends_with_dot(Gs0) -> Gs1 = Gs0
     ;   append(Gs0, ".", Gs1)
     ),
-    read_from_chars(Gs1, Goal),
-    (   catch(
-            user:Goal,
-            Exception,
-            (write(Goal), write(' causes: '), write(Exception), nl) % halt?
-        )
-    ;   write('Warning: initialization failed for '),
-        write(Gs0), nl
+    double_quotes_option(DQ),
+    catch(read_term_from_chars(Gs1, Goal, [variable_names(VNs)]),
+          E,
+          (   write_term(Gs0, [double_quotes(DQ)]),
+              write(' cannot be read: '), write(E), nl,
+              halt
+          )
+    ),
+    (   catch(user:Goal,
+              Exception,
+              (   write_term(Goal, [variable_names(VNs),double_quotes(DQ)]),
+                  write(' causes: '),
+                  write_term(Exception, [double_quotes(DQ)]), nl % halt?
+              )
+        ) -> true
+    ;   write('Warning: initialization failed for: '),
+        write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl
     ),
     run_goals(Goals).
 run_goals([Goal|_]) :-