improve repl
This commit is contained in:
parent
290630adbe
commit
c3fffb1e75
2 changed files with 43 additions and 1 deletions
41
spl/repl.spl
41
spl/repl.spl
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
func !!-cat { | }
|
||||||
|
|
||||||
func main { mega | with args ;
|
func main { mega | with args ;
|
||||||
"Welcome to the SPL REPL!" println
|
"Welcome to the SPL REPL!" println
|
||||||
"Enter any code after the cursor to execute it.\n" println
|
"Enter any code after the cursor to execute it.\n" println
|
||||||
|
@ -6,7 +8,22 @@ func main { mega | with args ;
|
||||||
"REPL" =program-name
|
"REPL" =program-name
|
||||||
while { 1 } {
|
while { 1 } {
|
||||||
catch {
|
catch {
|
||||||
" > " print readln dyn-read exec2 "\n" print
|
def line "" =line
|
||||||
|
while { line is-complete not } {
|
||||||
|
def s
|
||||||
|
line " > " print readln =s
|
||||||
|
s "!!-cat" eq dup if { line println }
|
||||||
|
not if { s "\n" concat concat =line }
|
||||||
|
}
|
||||||
|
"!!-end" line:contains if {
|
||||||
|
2 stop
|
||||||
|
}
|
||||||
|
"!!-cat" line:contains if {
|
||||||
|
"" println
|
||||||
|
line print
|
||||||
|
"." println
|
||||||
|
}
|
||||||
|
line dyn-read exec2 "\n" print
|
||||||
}
|
}
|
||||||
{ with err ;
|
{ with err ;
|
||||||
err:message dup null eq if {
|
err:message dup null eq if {
|
||||||
|
@ -27,3 +44,25 @@ func main { mega | with args ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func is-complete { bool | with line ;
|
||||||
|
"!!-end" line:contains
|
||||||
|
0 line _array :foreach<{ | with char ;
|
||||||
|
char "{" :_char eq
|
||||||
|
char "(" :_char eq or
|
||||||
|
char "<" :_char eq or
|
||||||
|
char "[" :_char eq or
|
||||||
|
if {
|
||||||
|
++
|
||||||
|
}
|
||||||
|
char "}" :_char eq
|
||||||
|
char ")" :_char eq or
|
||||||
|
char ">" :_char eq or
|
||||||
|
char "]" :_char eq or
|
||||||
|
if {
|
||||||
|
--
|
||||||
|
}
|
||||||
|
}> not
|
||||||
|
or
|
||||||
|
"" line eq not and
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,9 @@ construct _str_ext {
|
||||||
find { idx | with search this ;
|
find { idx | with search this ;
|
||||||
search _array this _array :find
|
search _array this _array :find
|
||||||
}
|
}
|
||||||
|
contains { bool | with search this ;
|
||||||
|
search this:find null eq not
|
||||||
|
}
|
||||||
starts-with { bool | with beginning this ;
|
starts-with { bool | with beginning this ;
|
||||||
beginning:to-bytes this:to-bytes:starts-with
|
beginning:to-bytes this:to-bytes:starts-with
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue