Skip to content

Commit

Permalink
treat consultation of command line modules as regular goals (#2314)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Feb 2, 2024
1 parent 75a94fd commit de6c460
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/toplevel.pl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

'$repl' :-
asserta('$toplevel':started),
(\+ disabled_init_file -> load_scryerrc ; true),
raw_argv(Args0),
( append(Args1, ["--"|_], Args0) ->
Args = Args1
Expand All @@ -38,6 +37,7 @@
delegate_task(TaskArgs, [])
; true
),
(\+ disabled_init_file -> load_scryerrc ; true),
repl.

delegate_task([], []).
Expand All @@ -48,15 +48,17 @@
repl.

delegate_task([Arg0|Args], Goals0) :-
( member(Arg0, ["-h", "--help"]) -> print_help
; member(Arg0, ["-v", "--version"]) -> print_version
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
; member(Arg0, ["-f"]) -> disable_init_file
; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg
( ( member(Arg0, ["-h", "--help"]) -> print_help
; member(Arg0, ["-v", "--version"]) -> print_version
; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0)
; member(Arg0, ["-f"]) -> disable_init_file
; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg
),
!,
delegate_task(Args, Goals0)
; atom_chars(Mod, Arg0),
catch(consult(Mod), E, print_exception(E))
),
delegate_task(Args, Goals0).
delegate_task(Args, [t(consult(Mod))|Goals0])
).

print_help :-
write('Usage: scryer-prolog [OPTIONS] [FILES] [-- ARGUMENTS]'),
Expand Down Expand Up @@ -132,6 +134,14 @@
write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl
),
run_goals(Goals).
run_goals([t(Goal)|Goals]) :- !,
( catch(user:Goal, E, print_exception(E)) ->
true
; write('% Warning: initialization failed for: '),
double_quotes_option(DQ),
write_term(Goal, [double_quotes(DQ)]), nl
),
run_goals(Goals).
run_goals([Goal|_]) :-
loader:write_error(error(domain_error(arg_type, Goal), run_goals/1)),
nl,
Expand Down

0 comments on commit de6c460

Please sign in to comment.