# The Nit interactive interpreter
module nitin
+import prompt
+
import nitc::interpreter
import nitc::frontend
import nitc::parser_util
return tree.n_base.as(not null)
end
- # Read an user-line with a given `prompt`
- #
- # Return `null` if end of file
- fun readline(prompt: String): nullable String do
- printn prompt
- var res = stdin.read_line
- if res == "" and stdin.eof then return null
- return res
- end
-
- # Add `text` in the history for `readline`.
- #
- # With the default implementation, the history is dropped
- fun readline_add_history(text: String) do end
-
# The last line number read by `i_parse`
var last_line = 0
s = stdin.read_line
if s == "" and stdin.eof then s = null
else
- s = readline(prompt)
+ s = sys.prompt(prompt)
end
if s == null then return null
if s == "" then
oldtext = ""
var n = p_module(text)
- if n isa AParserError and (n.token isa EOF) then
+ if n isa AParserError and (n.token isa EOF or n.token isa TBadTString or n.token isa TBadExtern) then
# Unexpected end of file, thus continuing
if oldtext == "" then prompt = "." * prompt.length
oldtext = text
end
last_line = n.location.file.line_starts.length - 1
- readline_add_history(text.chomp)
+ prompt_add_history(text.chomp)
return n
end
end