Skip to content

Commit bb7687b

Browse files
committed
Include SRFI 233.
1 parent e0a137f commit bb7687b

File tree

9 files changed

+318
-4
lines changed

9 files changed

+318
-4
lines changed

LispKit.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,10 @@
965965
CCCB66E2282DBBDB0004827D /* DrawBarCharts.scm in Copy examples */ = {isa = PBXBuildFile; fileRef = CCCB66E0282DB9790004827D /* DrawBarCharts.scm */; };
966966
CCCB66E4283056E30004827D /* StyledTextLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCB66E3283056E30004827D /* StyledTextLibrary.swift */; };
967967
CCCB66E5283056E30004827D /* StyledTextLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCB66E3283056E30004827D /* StyledTextLibrary.swift */; };
968+
CCCD1AB9298C6CD50057DCEB /* 233.sld in Copy pre-installed SRFI libraries */ = {isa = PBXBuildFile; fileRef = CCCD1AB8298C6BEE0057DCEB /* 233.sld */; };
969+
CCCD1ABA298C6CE40057DCEB /* 233.sld in Copy pre-installed SRFI libraries */ = {isa = PBXBuildFile; fileRef = CCCD1AB8298C6BEE0057DCEB /* 233.sld */; };
970+
CCCD1ABC298C6DBF0057DCEB /* SRFI-233.scm in Copy tests */ = {isa = PBXBuildFile; fileRef = CCCD1ABB298C6D910057DCEB /* SRFI-233.scm */; };
971+
CCCD1ABD298C6DCC0057DCEB /* SRFI-233.scm in Copy tests */ = {isa = PBXBuildFile; fileRef = CCCD1ABB298C6D910057DCEB /* SRFI-233.scm */; };
968972
CCCEB3FF1DF2DAA9009BF66B /* FileHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCEB3FE1DF2DAA9009BF66B /* FileHandler.swift */; };
969973
CCD3E15425C5ECC8007FCE8A /* prolog.sld in Copy pre-installed LispKit libraries */ = {isa = PBXBuildFile; fileRef = CCD3E15325C5EB83007FCE8A /* prolog.sld */; };
970974
CCD3E15925C638F5007FCE8A /* Schelog.scm in Copy examples */ = {isa = PBXBuildFile; fileRef = CCD3E15825C63898007FCE8A /* Schelog.scm */; };
@@ -1110,6 +1114,7 @@
11101114
dstPath = Root/LispKit/Tests;
11111115
dstSubfolderSpec = 7;
11121116
files = (
1117+
CCCD1ABC298C6DBF0057DCEB /* SRFI-233.scm in Copy tests */,
11131118
CCB7B0D02960F16700F0DB20 /* SRFI-228.scm in Copy tests */,
11141119
CC6E93CA281CA1150002C4BC /* SRFI-232.scm in Copy tests */,
11151120
CC372CDA27D504800091C474 /* LispKit-Enum.scm in Copy tests */,
@@ -1739,6 +1744,7 @@
17391744
dstPath = Root/LispKit/Libraries/srfi;
17401745
dstSubfolderSpec = 7;
17411746
files = (
1747+
CCCD1AB9298C6CD50057DCEB /* 233.sld in Copy pre-installed SRFI libraries */,
17421748
CCB7B0CF2960F15000F0DB20 /* 228.sld in Copy pre-installed SRFI libraries */,
17431749
CCCB5C9D28403E870005248D /* 118.sld in Copy pre-installed SRFI libraries */,
17441750
CC6E93CB281CA1320002C4BC /* 232.sld in Copy pre-installed SRFI libraries */,
@@ -1851,6 +1857,7 @@
18511857
dstPath = Root/LispKit/Libraries/srfi;
18521858
dstSubfolderSpec = 7;
18531859
files = (
1860+
CCCD1ABA298C6CE40057DCEB /* 233.sld in Copy pre-installed SRFI libraries */,
18541861
CCB7B0D12960F17C00F0DB20 /* 228.sld in Copy pre-installed SRFI libraries */,
18551862
CCCB5C9E28403E960005248D /* 118.sld in Copy pre-installed SRFI libraries */,
18561863
CC6E93CC281CA15A0002C4BC /* 232.sld in Copy pre-installed SRFI libraries */,
@@ -2209,6 +2216,7 @@
22092216
dstPath = Root/LispKit/Tests;
22102217
dstSubfolderSpec = 7;
22112218
files = (
2219+
CCCD1ABD298C6DCC0057DCEB /* SRFI-233.scm in Copy tests */,
22122220
CCB7B0D22960F19B00F0DB20 /* SRFI-228.scm in Copy tests */,
22132221
CC6E93CD281CA1650002C4BC /* SRFI-232.scm in Copy tests */,
22142222
CC372CDB27D5048E0091C474 /* LispKit-Enum.scm in Copy tests */,
@@ -2917,6 +2925,8 @@
29172925
CCCB5C9F284224260005248D /* StyledTextDoc.scm */ = {isa = PBXFileReference; lastKnownFileType = text; path = StyledTextDoc.scm; sourceTree = "<group>"; };
29182926
CCCB66E0282DB9790004827D /* DrawBarCharts.scm */ = {isa = PBXFileReference; lastKnownFileType = text; path = DrawBarCharts.scm; sourceTree = "<group>"; };
29192927
CCCB66E3283056E30004827D /* StyledTextLibrary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StyledTextLibrary.swift; sourceTree = "<group>"; };
2928+
CCCD1AB8298C6BEE0057DCEB /* 233.sld */ = {isa = PBXFileReference; lastKnownFileType = text; path = 233.sld; sourceTree = "<group>"; };
2929+
CCCD1ABB298C6D910057DCEB /* SRFI-233.scm */ = {isa = PBXFileReference; lastKnownFileType = text; path = "SRFI-233.scm"; sourceTree = "<group>"; };
29202930
CCCEB3FE1DF2DAA9009BF66B /* FileHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileHandler.swift; sourceTree = "<group>"; };
29212931
CCD3E15325C5EB83007FCE8A /* prolog.sld */ = {isa = PBXFileReference; lastKnownFileType = text; path = prolog.sld; sourceTree = "<group>"; };
29222932
CCD3E15725C60FBC007FCE8A /* red.sld */ = {isa = PBXFileReference; lastKnownFileType = text; path = red.sld; sourceTree = "<group>"; };
@@ -3116,6 +3126,7 @@
31163126
CCB7B0CD2960F04D00F0DB20 /* SRFI-228.scm */,
31173127
CCBDF72D2749B17600635B5C /* SRFI-229.scm */,
31183128
CC6E93C9281CA00C0002C4BC /* SRFI-232.scm */,
3129+
CCCD1ABB298C6D910057DCEB /* SRFI-233.scm */,
31193130
);
31203131
path = Tests;
31213132
sourceTree = "<group>";
@@ -3502,6 +3513,7 @@
35023513
CCBDF72A2749AFAC00635B5C /* 229.sld */,
35033514
CC2DA75C2787EBAE00DE69CF /* 230.sld */,
35043515
CC6E93C8281C9F820002C4BC /* 232.sld */,
3516+
CCCD1AB8298C6BEE0057DCEB /* 233.sld */,
35053517
);
35063518
path = srfi;
35073519
sourceTree = "<group>";

Sources/LispKit iOS/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>$(CURRENT_PROJECT_VERSION)</string>
2323
<key>NSHumanReadableCopyright</key>
24-
<string>Copyright © 2016–2022 Matthias Zenger. All rights reserved.</string>
24+
<string>Copyright © 2016–2023 Matthias Zenger. All rights reserved.</string>
2525
</dict>
2626
</plist>

Sources/LispKit/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<true/>
2929
</dict>
3030
<key>NSHumanReadableCopyright</key>
31-
<string>Copyright © 2016–2022 Matthias Zenger. All rights reserved.</string>
31+
<string>Copyright © 2016–2023 Matthias Zenger. All rights reserved.</string>
3232
<key>NSPrincipalClass</key>
3333
<string></string>
3434
</dict>
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
;;; SRFI 233
2+
;;; INI files
3+
;;;
4+
;;; An INI file is a configuration file that consists of key-value pairs
5+
;;; for properties, and sections that group the properties. The name of
6+
;;; these configuration files comes from the filename extension INI,
7+
;;; short for initialization. The format has become an informal standard
8+
;;; in many contexts of configuration. This SRFI provides access to the
9+
;;; contents of an INI file.
10+
;;;
11+
;;; Author of spec: John Cowan
12+
;;;
13+
;;; Copyright © 2022 Arvydas Silanskas. All rights reserved.
14+
;;;
15+
;;; Permission is hereby granted, free of charge, to any person obtaining a copy
16+
;;; of this software and associated documentation files (the "Software"), to deal
17+
;;; in the Software without restriction, including without limitation the rights
18+
;;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
;;; copies of the Software, and to permit persons to whom the Software is
20+
;;; furnished to do so, subject to the following conditions:
21+
;;;
22+
;;; The above copyright notice and this permission notice shall be included in all
23+
;;; copies or substantial portions of the Software.
24+
;;;
25+
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
;;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
27+
;;; FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
28+
;;; COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
29+
;;; IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30+
;;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31+
;;;
32+
;;; Adaptation to LispKit
33+
;;; Copyright © 2023 Matthias Zenger. All rights reserved.
34+
35+
(define-library (srfi 233)
36+
37+
(export make-ini-file-generator
38+
make-ini-file-accumulator)
39+
40+
(import (lispkit base))
41+
42+
(begin
43+
44+
(define make-ini-file-accumulator
45+
(case-lambda
46+
((port)
47+
(make-accumulator port #\= #\;
48+
))
49+
((port key-value-sep)
50+
(make-accumulator port key-value-sep #\;
51+
))
52+
((port key-value-sep comment-delim)
53+
(make-accumulator port key-value-sep comment-delim))))
54+
55+
(define (make-accumulator port key-value-sep comment-delim)
56+
(define current-section '||)
57+
58+
(define (write-comment str)
59+
(display comment-delim port)
60+
(display " " port)
61+
(display str port)
62+
(newline port))
63+
64+
(define (write-data section key value)
65+
(unless (equal? section current-section)
66+
(set! current-section section)
67+
(display "[" port)
68+
(display section port)
69+
(display "]" port)
70+
(newline port))
71+
(display key port)
72+
(display key-value-sep port)
73+
(display value port)
74+
(newline port))
75+
76+
(define (data-triple? arg)
77+
(and (list? arg)
78+
(= 3 (length arg))
79+
(symbol? (list-ref arg 0))
80+
(symbol? (list-ref arg 1))
81+
(string? (list-ref arg 2))))
82+
83+
(lambda (arg)
84+
(cond
85+
((eof-object? arg) (eof-object))
86+
((string? arg) (write-comment arg))
87+
((data-triple? arg) (apply write-data arg))
88+
(else (error "Unexpected input")))))
89+
90+
(define make-ini-file-generator
91+
(case-lambda
92+
((port)
93+
(make-generator port #\= #\;
94+
))
95+
((port key-value-sep)
96+
(make-generator port key-value-sep #\;
97+
))
98+
((port key-value-sep comment-delim)
99+
(make-generator port key-value-sep comment-delim))))
100+
101+
(define (make-generator port key-value-sep comment-delim)
102+
103+
;; remove space from both ends of string
104+
(define (trim str)
105+
(define (space? char) (char=? #\space char))
106+
(let loop1 ((end (string-length str)))
107+
(if (and (> end 0) (space? (string-ref str (- end 1))))
108+
(loop1 (- end 1))
109+
(let loop2 ((start 0))
110+
(if (and (< start end) (space? (string-ref str start)))
111+
(loop2 (+ start 1))
112+
(substring str start end))))))
113+
114+
;; return #t if the line is a comment,
115+
;; #f otherwise
116+
(define (comment line)
117+
(define len (string-length line))
118+
(let loop ((i 0))
119+
(cond
120+
((>= i len) #f)
121+
((equal? (string-ref line i) #\space) (loop (+ 1 i)))
122+
((equal? (string-ref line i) comment-delim) #t)
123+
(else #f))))
124+
125+
;; return section name as a symbol if the line is a section declaration,
126+
;; #f otherwise
127+
(define (section line)
128+
(define len (string-length line))
129+
(cond
130+
((= len 0) #f)
131+
((not (char=? (string-ref line 0) #\[)) #f)
132+
(else (let loop ((i 0))
133+
(cond
134+
((>= i len) #f)
135+
((and (= i (- len 1))
136+
(char=? (string-ref line i) #\]))
137+
(string->symbol (substring line 1 (- len 1))))
138+
(else (loop (+ i 1))))))))
139+
140+
;; return pair of key and value
141+
;;
142+
;; if line has a separator char,
143+
;; key is a (whitespace trimmed) symbol up to first separator char,
144+
;; value is a (whitespace trimmed) string
145+
;;
146+
;; if line doesn't have a separator char
147+
;; key is a #f, value is the entire line
148+
;;
149+
;; if separator char is encounted multiple times, first one is used
150+
;; to distinguish key from value
151+
(define (key-value line)
152+
(define len (string-length line))
153+
(let loop ((i 0))
154+
(cond
155+
;; line parsed without encountering a separator
156+
((>= i len)
157+
(cons #f
158+
line))
159+
;; encountered a (first leftmost) separator
160+
((char=? key-value-sep (string-ref line i))
161+
(cons (string->symbol (trim (substring line 0 i)))
162+
(if (>= (+ i 1) len)
163+
""
164+
(trim (substring line (+ i 1) len)))))
165+
(else
166+
(loop (+ i 1))))))
167+
168+
(define current-section '||)
169+
(define eof #f)
170+
171+
(lambda ()
172+
(or (and eof (eof-object))
173+
(let loop ()
174+
(define line (read-line port))
175+
(if (eof-object? line)
176+
(begin
177+
(set! eof #t)
178+
(eof-object))
179+
(let ((trimmed-line (trim line)))
180+
(cond
181+
((= 0 (string-length trimmed-line))
182+
(loop))
183+
((comment trimmed-line)
184+
(loop))
185+
((section trimmed-line) =>
186+
(lambda (section)
187+
(set! current-section section)
188+
(loop)))
189+
((key-value trimmed-line) =>
190+
(lambda (key-value-pair)
191+
(list current-section
192+
(car key-value-pair)
193+
(cdr key-value-pair)))))))))))
194+
)
195+
)

Sources/LispKit/Resources/Tests/All.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
(load "Tests/SRFI-228")
5757
(load "Tests/SRFI-229")
5858
(load "Tests/SRFI-232")
59+
(load "Tests/SRFI-233")
5960

6061
(test-end)
6162

Sources/LispKit/Resources/Tests/Import.scm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
(import (srfi 229))
172172
(import (srfi 230))
173173
(import (srfi 232))
174+
(import (srfi 233))
174175

175176
; this needs to be last
176177
(import (srfi 101))

0 commit comments

Comments
 (0)