add json.spl, fix messed up =>? operator

This commit is contained in:
Daniella / Tove 2024-11-15 15:01:20 +01:00
parent baa981c224
commit c33b25f260
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
5 changed files with 41 additions and 9 deletions

30
spl/json.spl Normal file
View file

@ -0,0 +1,30 @@
construct json namespace {
_StringyJSON
;
props-to-sjson { s | with spaces props this ;
props:last:get<1> dup null eq not if {
"\"" swap _str :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat "\"" concat 2 stop
} pop
"{"
props
:iter
:filter<{ b | :to-stack pop with key ; key ":" eq not key ";" eq not and }>
:map<{ s |
:to-stack with key value ;
"\""
key :replace<"\\" "\\\\">:replace<"\"" "\\\""> concat
"\":" concat spaces if { " " concat }
spaces value properties this:props-to-json concat
}>
:join<", "> concat
"}" concat
}
}
construct json:_StringyJSON {
;
sjson { s | with spaces this ;
spaces this properties json:props-to-sjson
}
}

View file

@ -717,8 +717,8 @@ func _'match-else-error { |
}
func _'match-else-push { |
if {
pop
dup if {
swap pop
}
}

View file

@ -260,19 +260,17 @@ fn read_block_dyn(
"=" => {
if str_words[i + 1] == ">" {
i += 1;
let pushing = if str_words[i + 1] == "?" {
let cword = &str_words[i + 1];
if cword.contains(|c| c == '?' || c == '!') {
i += 1;
}
let pushing = if cword.contains('?') {
words.push(Word::Call("dup".to_owned(), false, 0));
true
} else {
false
};
let throwing = if str_words[i + 1] == "!" {
i += 1;
true
} else {
false
};
let throwing = cword.contains('!');
if str_words[i + 1] == "[" {
i += 1;
let mut block =

View file

@ -17,6 +17,7 @@ pub const SERVER: &str = include_str!("../spl/server.spl");
pub const HTTP_SERVER: &str = include_str!("../spl/httpserver/base.spl");
pub const HTTP_SERVER_STATIC: &str = include_str!("../spl/httpserver/static.spl");
pub const LINKEDLIST: &str = include_str!("../spl/linkedlist.spl");
pub const JSON: &str = include_str!("../spl/json.spl");
pub const NOP: &str = "";
pub fn register(runtime: &mut Runtime) {
@ -38,6 +39,7 @@ pub fn register(runtime: &mut Runtime) {
insert("httpserver/base.spl", HTTP_SERVER);
insert("httpserver/static.spl", HTTP_SERVER_STATIC);
insert("linkedlist.spl", LINKEDLIST);
insert("json.spl", JSON);
insert("nop.spl", NOP);
}
}

View file

@ -327,6 +327,8 @@ func main { int | with args ;
}
}
^ok =>? ^error not if { println }