add json.spl, fix messed up =>? operator
This commit is contained in:
parent
baa981c224
commit
c33b25f260
5 changed files with 41 additions and 9 deletions
30
spl/json.spl
Normal file
30
spl/json.spl
Normal 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
|
||||||
|
}
|
||||||
|
}
|
|
@ -717,8 +717,8 @@ func _'match-else-error { |
|
||||||
}
|
}
|
||||||
|
|
||||||
func _'match-else-push { |
|
func _'match-else-push { |
|
||||||
if {
|
dup if {
|
||||||
pop
|
swap pop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/lexer.rs
12
src/lexer.rs
|
@ -260,19 +260,17 @@ fn read_block_dyn(
|
||||||
"=" => {
|
"=" => {
|
||||||
if str_words[i + 1] == ">" {
|
if str_words[i + 1] == ">" {
|
||||||
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;
|
i += 1;
|
||||||
|
}
|
||||||
|
let pushing = if cword.contains('?') {
|
||||||
words.push(Word::Call("dup".to_owned(), false, 0));
|
words.push(Word::Call("dup".to_owned(), false, 0));
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
let throwing = if str_words[i + 1] == "!" {
|
let throwing = cword.contains('!');
|
||||||
i += 1;
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
if str_words[i + 1] == "[" {
|
if str_words[i + 1] == "[" {
|
||||||
i += 1;
|
i += 1;
|
||||||
let mut block =
|
let mut block =
|
||||||
|
|
|
@ -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: &str = include_str!("../spl/httpserver/base.spl");
|
||||||
pub const HTTP_SERVER_STATIC: &str = include_str!("../spl/httpserver/static.spl");
|
pub const HTTP_SERVER_STATIC: &str = include_str!("../spl/httpserver/static.spl");
|
||||||
pub const LINKEDLIST: &str = include_str!("../spl/linkedlist.spl");
|
pub const LINKEDLIST: &str = include_str!("../spl/linkedlist.spl");
|
||||||
|
pub const JSON: &str = include_str!("../spl/json.spl");
|
||||||
pub const NOP: &str = "";
|
pub const NOP: &str = "";
|
||||||
|
|
||||||
pub fn register(runtime: &mut Runtime) {
|
pub fn register(runtime: &mut Runtime) {
|
||||||
|
@ -38,6 +39,7 @@ pub fn register(runtime: &mut Runtime) {
|
||||||
insert("httpserver/base.spl", HTTP_SERVER);
|
insert("httpserver/base.spl", HTTP_SERVER);
|
||||||
insert("httpserver/static.spl", HTTP_SERVER_STATIC);
|
insert("httpserver/static.spl", HTTP_SERVER_STATIC);
|
||||||
insert("linkedlist.spl", LINKEDLIST);
|
insert("linkedlist.spl", LINKEDLIST);
|
||||||
|
insert("json.spl", JSON);
|
||||||
insert("nop.spl", NOP);
|
insert("nop.spl", NOP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
test.spl
2
test.spl
|
@ -327,6 +327,8 @@ func main { int | with args ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
^ok =>? ^error not if { println }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue