import nitc::parser_util
redef class ToolContext
+
+ # --no-prompt
+ var opt_no_prompt = new OptionBool("Disable writing a prompt.", "--no-prompt")
+
+ redef init do
+ super
+ option_context.add_option(opt_no_prompt)
+ end
+
# Parse a full module given as a string
#
# Return a AModule or a AError
var oldtext = ""
loop
- var s = readline(prompt)
+ var s
+ if opt_no_prompt.value then
+ s = stdin.read_line
+ if s == "" and stdin.eof then s = null
+ else
+ s = readline(prompt)
+ end
if s == null then return null
if s == "" then continue
# Run the main if the AST contains a main
if amodule.n_classdefs.not_empty and amodule.n_classdefs.last isa AMainClassdef then
- interpreter.send(mainprop, [mainobj])
+ do
+ interpreter.catch_count += 1
+ interpreter.send(mainprop, [mainobj])
+ catch
+ var e = interpreter.last_error
+ if e != null then
+ var en = e.node
+ if en != null then
+ print "{en.location}: Runtime error: {e.message}\n{en.location.colored_line("0;31")}"
+ else
+ print "Runtime error: {e.message}"
+ end
+ end
+ print interpreter.stack_trace
+ interpreter.frames.clear
+ end
end
end