/
repl.jl
70 lines (61 loc) · 1.44 KB
/
repl.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# This file is part of Reduce.jl. It is licensed under the MIT license
# Copyright (C) 2017 Michael Reed
import REPL.LineEdit
import ReplMaker
ans = nothing
"""
finished(s)
Examine the buffer in the repl to see if the input is complete
"""
function finished(s)
str = String(take!(copy(LineEdit.buffer(s))))
if length(str) == 0
return false
elseif occursin(r"(^|\n)[^%\n]*(;|\$)[ ]*(%[^\n]*)?$",str)
return true
else
return false
end
end
"""
parserepl(input)
Called on valid input from the repl.
"""
function parserepl(input)
if !isempty(strip(input))
global ans = RExpr(input[1:end-1])
if input[end] == ';'
display(ans)
end
end
end
"""
replinit(repl)
Start up the Reduce repl mode.
"""
function repl_init(repl)
ReplMaker.initrepl(
parserepl,
valid_input_checker=finished,
prompt_text="reduce> ",
prompt_color=:cyan,
start_key='}',
mode_name="REDUCE",
repl=repl,
startup_text=false,
)
end
function repl_init()
if isinteractive()
if isdefined(Base,:active_repl)
repl_init(Base.active_repl)
else
atreplinit() do repl
!isdefined(Main,:OhMyREPL) &&
(repl.interface = Base.REPL.setup_interface(repl))
repl_init(Base.active_repl)
print('\n')
end
end
end
end