fix for new carp

This commit is contained in:
2021-01-19 13:25:58 +01:00
parent 2074e75ee4
commit 34047b573f
5 changed files with 318 additions and 308 deletions

View File

@@ -4,13 +4,13 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div class="content">
<div class="logo">
<a href="http://github.com/carp-lang/Carp">
<img src="logo.png">
<a href="https://veitheller/git/carpentry/redis">
<img src="">
</a>
<div class="title">
redis
@@ -53,7 +53,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [(Array String)] RESP)
(Fn [(Array String)] RESP)
</p>
<span>
@@ -73,7 +73,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [String] RESP)
(Fn [String] RESP)
</p>
<span>
@@ -93,7 +93,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [Int] RESP)
(Fn [Int] RESP)
</p>
<span>
@@ -113,7 +113,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [] RESP)
(Fn [] RESP)
</p>
<span>
@@ -133,7 +133,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [String] RESP)
(Fn [String] RESP)
</p>
<span>
@@ -153,7 +153,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [(Ref RESP a)] RESP)
(Fn [(Ref RESP a)] RESP)
</p>
<span>
@@ -173,7 +173,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
defn
</div>
<p class="sig">
(λ [(Ref String a)] (Result RESP String))
(Fn [(Ref String a)] (Result RESP String))
</p>
<pre class="args">
(from-string s)
@@ -193,7 +193,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [(Ref RESP a)] Int)
(Fn [(Ref RESP a)] Int)
</p>
<span>
@@ -213,7 +213,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
instantiate
</div>
<p class="sig">
(λ [(Ref RESP a)] String)
(Fn [(Ref RESP a)] String)
</p>
<span>
@@ -233,7 +233,7 @@ the interface <code>to-redis</code>, the signature of which is <code>(Fn [a] RES
defn
</div>
<p class="sig">
(λ [(Ref RESP a)] String)
(Fn [(Ref RESP a)] String)
</p>
<pre class="args">
(str r)

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="../style.css">
</head>
<body>
<div class="content">

View File

@@ -4,7 +4,7 @@
(Project.config "docs-directory" "./docs/")
(Project.config "docs-logo" "")
(Project.config "docs-url" "https://veitheller/git/carpentry/redis")
(Project.config "docs-styling" "style.css")
(Project.config "docs-styling" "../style.css")
(Project.config "docs-prelude" "is a collection of modules for talking
to Redis.

View File

@@ -1,4 +1,4 @@
(load "git@github.com:carpentry-org/sockets@master")
(load "git@github.com:carpentry-org/sockets@0.0.2")
(deftype RESP
(Null [])
@@ -30,11 +30,12 @@
(if (starts-with? s "-1\r\n")
(Success (Null))
(let [splt (split #"\r\n" s)
l &(unsafe-first &splt)]
(if (not (num? l))
(Error @"Error decoding bulk string: does not start with length!")
(Success (Str
(String.prefix &(join "\r\n" &(suffix &splt 1)) (from-string l))))))))
l (unsafe-first &splt)]
(match (from-string l)
(Maybe.Nothing) (Error @"Error decoding bulk string: does not start with length!")
(Maybe.Just il)
(Success (Str
(String.prefix &(join "\r\n" &(suffix &splt 1)) il)))))))
(hidden agg)
(private agg)
@@ -56,42 +57,49 @@
(if (starts-with? s "*0\r\n")
(Success (Null))
(let [splt (split #"\r\n" &(chomp s))
sl &(unsafe-first &splt)]
(if (not (num? sl))
(Error @"Error decoding array: does not start with length!")
(let-do [l (from-string sl)
a (Array.allocate l)
idx 0
err ""]
(for [i 0 (- (length &splt) 1)]
; TODO: have nested structures
(let-do [el (unsafe-nth &splt (+ i 1))]
(case (head el)
\$
(let [il (from-string &(tail el))]
(if (= -1 il)
(aset-uninitialized! &a idx @"")
(let-do [rest (suffix &splt (+ i 2))]
(aset-uninitialized! &a idx (String.prefix &(join "\r\n" &rest) il))
(set! i (+ i (agg &rest il))))))
\*
(do
(set! err "TODO: cannot deal with nested arrays")
(break))
(aset-uninitialized! &a idx (chomp el)))
(set! idx (inc idx))))
(if (= err "")
(Success (Arr a))
(Error @err)))))))
sl (unsafe-first &splt)]
(match (from-string sl)
(Maybe.Nothing)
(Error @"Error decoding array: does not start with length!")
(Maybe.Just l)
(let-do [a (Array.allocate l)
idx 0
err ""]
(for [i 0 (- (length &splt) 1)]
; TODO: have nested structures
(let-do [el (unsafe-nth &splt (+ i 1))]
(case (head el)
\$
(match (from-string &(tail el))
(Maybe.Nothing)
(aset-uninitialized! &a idx @"")
(Maybe.Just il)
(let-do [rest (suffix &splt (+ i 2))]
(aset-uninitialized! &a idx (String.prefix &(join "\r\n" &rest) il))
(set! i (+ i (agg &rest il)))))
\*
(do
(set! err "TODO: cannot deal with nested arrays")
(break))
(aset-uninitialized! &a idx (chomp el)))
(set! idx (inc idx))))
(if (= err "")
(Success (Arr a))
(Error @err)))))))
(doc from-string "converts a RESP string into a `RESP` data structure.")
(defn from-string [s]
(if (empty? s)
(Success (Null))
(case (head s)
\+ (Success (Str (unsafe-first &(split #"\r\n" &(tail s)))))
\- (Success (Err (unsafe-first &(split #"\r\n" &(tail s)))))
\: (Success (Integer (from-string &(unsafe-first &(split #"\r\n" &(tail s))))))
\+ (Success (Str @(unsafe-first &(split #"\r\n" &(tail s)))))
\- (Success (Err @(unsafe-first &(split #"\r\n" &(tail s)))))
\:
(match (from-string (unsafe-first &(split #"\r\n" &(tail s))))
(Maybe.Nothing)
(Error @"Could not parse integer in result.")
(Maybe.Just i)
(Success (Integer i)))
\$ (decode-bulk-string &(tail s))
\* (decode-arr &(tail s))
(Error (fmt "Malformed RESP data: got %s" s)))))
@@ -101,10 +109,12 @@
(defmodule String
(defn to-redis [s] (RESP.Str s))
(implements to-redis String.to-redis)
)
(defmodule Int
(defn to-redis [s] (RESP.Integer s))
(implements to-redis Int.to-redis)
)
(deftype Redis [