From 416a3100726789181c8df702a824e9be39901e0d Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 20 Sep 2024 12:43:25 +0200 Subject: [PATCH] [http/server] add query handling, [std] make or operator smarter --- spl/http/server.spl | 20 +++++++++++++++++--- spl/isbpl.spl | 5 +++++ spl/iter.spl | 2 +- src/std_fns.rs | 11 ++--------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/spl/http/server.spl b/spl/http/server.spl index 6ad36bf..4c1b3d6 100644 --- a/spl/http/server.spl +++ b/spl/http/server.spl @@ -29,7 +29,8 @@ construct net:http:server:Request { stream head body - method path version + method raw-path version + path query headers wrote-body ; @@ -57,8 +58,21 @@ construct net:http:server:Request { this:head:split<"\r\n"> this:=head def iter this:head:iter =iter iter:next:readf<"{} {} HTTP/{}"> dup if { - dup:to-stack this:=version this:=path this:=method + dup:to-stack this:=version this:=raw-path this:=method } pop + MicroMap:new this:=query + def p "{}?{}" this:raw-path:readf =p + this:raw-path + p if { + { | with attrib ; + "{}={}" attrib:readf dup if { + dup:to-stack this:query:set; + } not if { + attrib "" this:query:set; + } + } "&" p:1:split:foreach + pop p:0 + } this:=path MicroMap:new this:=headers iter:foreach<{ | with header ; header:readf<"{}: {}"> dup if { @@ -70,7 +84,7 @@ construct net:http:server:Request { head-str { str | with this ; this:method " " concat - this:path concat + this:raw-path concat " HTTP/" concat this:version concat "\r\n" concat diff --git a/spl/isbpl.spl b/spl/isbpl.spl index d217418..e560df1 100644 --- a/spl/isbpl.spl +++ b/spl/isbpl.spl @@ -19,11 +19,16 @@ func argv { func eputs { print } +def import-transformers List:new =import-transformers func isbplmod'import-transform { with s ; "spl: [compat] transforming import " s concat println s:_char "#" :_char eq if { "#nop.spl" =s } + + { with tf ; + s tf:call =s + } import-transformers:foreach "spl: [compat] transformed to " s concat println s } diff --git a/spl/iter.spl b/spl/iter.spl index a91720f..49dbca7 100644 --- a/spl/iter.spl +++ b/spl/iter.spl @@ -42,7 +42,7 @@ construct _Iter { join { str | with separator this ; { str | with accum item ; accum _str separator item _str concat concat - } this:reduce:calculate + } this:reduce:calculate "" or } filter { FilterIter | with filter this ; filter this FilterIter:new diff --git a/src/std_fns.rs b/src/std_fns.rs index ea0ebac..e063ca3 100644 --- a/src/std_fns.rs +++ b/src/std_fns.rs @@ -198,16 +198,9 @@ pub fn and(stack: &mut Stack) -> OError { } pub fn or(stack: &mut Stack) -> OError { - let a = stack.pop(); let b = stack.pop(); - stack.push( - Value::Int(if a.lock_ro().is_truthy() || b.lock_ro().is_truthy() { - 1 - } else { - 0 - }) - .spl(), - ); + let a = stack.pop(); + stack.push(if a.lock_ro().is_truthy() { a } else { b }); Ok(()) }