Skip to content

Commit bb2a2a1

Browse files
author
Amirouche
committed
move chibi specific code to 180/helpers.sld
1 parent 16093cd commit bb2a2a1

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

srfi/180.sld

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
(check)
1818
(srfi 145)
1919
(srfi 151)
20-
(chibi ast)
21-
(chibi regexp))
20+
(srfi 180 helpers))
2221

2322
(include "180/body.scm"))

srfi/180/body.scm

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
(define (pk . args)
2-
(car (reverse args)))
3-
41
(define (json-null? obj)
52
(eq? obj 'null))
63

@@ -27,15 +24,9 @@
2724
(raise (make-json-error "Unexpected character."))))
2825

2926
(define (port->generator port)
30-
(define (%read-error? x)
31-
;; TODO: move to a helper library
32-
(and (error-object? x) (memq (exception-kind x) '(user read read-incomplete)) #t))
33-
34-
(define offset 0)
35-
3627
(lambda ()
3728
(guard (ex ((%read-error? ex) (raise (make-json-error "Read error!"))))
38-
(pk 'read-char (read-char port)))))
29+
(read-char port))))
3930

4031
(define (gcons head generator)
4132
;; returns a generator that will yield, HEAD the first time, and
@@ -163,19 +154,6 @@
163154
(else
164155
(loop (generator) (cons char out)))))))
165156

166-
(define (valid-number? string)
167-
;; TODO: move to a helper library
168-
;; based on https://stackoverflow.com/a/13340826/140837
169-
(regexp-matches '(seq
170-
(? #\-)
171-
(or #\0 (seq (- numeric #\0)
172-
(* numeric)))
173-
(? (seq #\. (+ numeric)))
174-
(? (seq (or #\e #\E)
175-
(? (or #\- #\+))
176-
(+ numeric))))
177-
string))
178-
179157
(define (maybe-read-number generator)
180158
;; accumulate chars until a control char or whitespace is reached,
181159
;; validate that it is JSON number, then intrepret it as Scheme
@@ -307,7 +285,7 @@
307285
(call-with-values continuation
308286
(lambda (event new-continuation)
309287
(set! continuation new-continuation)
310-
(pk 'event event)))))))
288+
event))))))
311289

312290
;; gist
313291

@@ -366,7 +344,6 @@
366344
(lambda ()
367345
(let loop ((seed seed))
368346
(let ((event (events)))
369-
(pk 'ruse-event event)
370347
(if (eof-object? event)
371348
(begin (k seed) #f)
372349
(case (car event)
@@ -420,7 +397,7 @@
420397
(let loop ((plist plist)
421398
(out '()))
422399
(if (null? plist)
423-
out ;; TODO: maybe use reverse
400+
out
424401
(loop (cddr plist) (cons (cons (string->symbol (cadr plist)) (car plist)) out)))))
425402

426403
(define (object-end plist seed)

srfi/180/helpers.sld

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(define-library (srfi 180 helpers)
2+
3+
(export %read-error? valid-number?)
4+
5+
(import (scheme base)
6+
(chibi ast)
7+
(chibi regexp))
8+
9+
(begin
10+
11+
(define (%read-error? x)
12+
(and (error-object? x) (memq (exception-kind x) '(user read read-incomplete)) #t))
13+
14+
(define (valid-number? string)
15+
;; based on https://stackoverflow.com/a/13340826/140837
16+
(regexp-matches '(seq
17+
(? #\-)
18+
(or #\0 (seq (- numeric #\0)
19+
(* numeric)))
20+
(? (seq #\. (+ numeric)))
21+
(? (seq (or #\e #\E)
22+
(? (or #\- #\+))
23+
(+ numeric))))
24+
string))))

0 commit comments

Comments
 (0)