improve repl

This commit is contained in:
Daniella / Tove 2024-10-21 12:53:06 +02:00
parent 290630adbe
commit c3fffb1e75
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 43 additions and 1 deletions

View file

@ -1,4 +1,6 @@
func !!-cat { | }
func main { mega | with args ;
"Welcome to the SPL REPL!" println
"Enter any code after the cursor to execute it.\n" println
@ -6,7 +8,22 @@ func main { mega | with args ;
"REPL" =program-name
while { 1 } {
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 ;
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
}

View file

@ -44,6 +44,9 @@ construct _str_ext {
find { idx | with search this ;
search _array this _array :find
}
contains { bool | with search this ;
search this:find null eq not
}
starts-with { bool | with beginning this ;
beginning:to-bytes this:to-bytes:starts-with
}