A Common Lisp INI file reader and writer.
Note:
cl-iniis a temporary name because it is already taken on Quicklisp.
Clone the repository into your local Quicklisp projects directory, then load with ASDF or Quicklisp:
(ql:quickload :io.github.cl-sdk.ini);; Parse an INI string
(io.github.cl-sdk.ini:parse-ini "[section]
key = value
other = 42")
;; => (("section" ("key" . "value") ("other" . "42")))
;; Read from a file
(io.github.cl-sdk.ini:read-ini #p"config.ini")
;; => (("section" ("key" . "value")))
;; You can also pass :parser to parse-ini/read-ini for custom event handling.parse-ini accepts a custom parser instance that subclasses io.github.cl-sdk.ini:ini-parser.
(defclass recording-parser (io.github.cl-sdk.ini:ini-parser)
((events :initform '() :accessor events)))
(defmethod io.github.cl-sdk.ini:ini-parser-begin-document ((parser recording-parser))
(push '(:begin-document nil) (events parser)))
(defmethod io.github.cl-sdk.ini:ini-parser-section ((parser recording-parser) section-name)
(push (list :section section-name) (events parser)))
(defmethod io.github.cl-sdk.ini:ini-parser-pair ((parser recording-parser) pair)
(push (list :pair pair) (events parser)))
(defmethod io.github.cl-sdk.ini:ini-parser-end-document ((parser recording-parser))
(push '(:end-document nil) (events parser)))
(defmethod io.github.cl-sdk.ini:ini-parser-result ((parser recording-parser))
(nreverse (events parser)))
(io.github.cl-sdk.ini:parse-ini "[section]
key = value"
:parser (make-instance 'recording-parser))
;; => ((:BEGIN-DOCUMENT NIL)
;; (:SECTION "section")
;; (:PAIR ("key" . "value"))
;; (:END-DOCUMENT NIL));; Write INI data to a string
(io.github.cl-sdk.ini:write-ini-to-string '(("section" ("key" . "value") ("other" . "42"))))
;; => "[section]
;; key = value
;; other = 42
;; "
;; Write to a file
(io.github.cl-sdk.ini:write-ini '(("section" ("key" . "value"))) #p"config.ini")INI data is represented as an association list of sections. Each section is a list whose first element is the section name (a string) and whose remaining elements are (key . value) cons pairs:
(("section-name" ("key1" . "value1")
("key2" . "value2"))
("other-section" ("foo" . "bar")))- Sections:
[section-name] - Key/value pairs:
key = valueorkey: value - Comments: lines starting with
;or#are ignored - Whitespace around keys and values is trimmed
(ql:quickload :io.github.cl-sdk.ini.test)
(fiveam:run! :io.github.cl-sdk.ini)This software is released into the public domain. See LICENSE for details.