cl-inix

2026-01-01

cl-inix is a flexible library for .INI/.conf file parsing

Upstream URL

Author

Artyom Bologov

License

BSD-2 Clause
README

1cl-inix

cl-inix is a flexible .ini/.conf file parser with sane defaults.

cl-inix is an attempt at making an .ini parser that'd work for me. Meaning:

  • Configurable key format.
  • Support for arbitrary section and key names.
  • Flexible output format.
  • Defaults that don't break anything.

This library is partially inspired by cl-ini. Which is a reasonable library, actually. Just not as configurable/flexible as I prefer.

1.1Getting Started

Clone the Git repository:
  git clone --recursive https://github.com/aartaka/cl-inix ~/.local/share/common-lisp/source/

And then load :cl-inix in the REPL:

  (asdf:load-system :cl-inix)
  ;; or, if you use Quicklisp
  (ql:quickload :cl-inix)

1.2API

The main entry point is, of course, .ini parsing, available with read:
  (cl-inix:read "a = b")
  ;; ((T ("a" . "b")))
  (cl-inix:read #p"~/.gitconfig")
  ;; (("user" ("name" . "Artyom Bologov"))
  ;;  ("init" ("defaultBranch" . "main"))
  ;;  ("core" ("editor" . "aed")))

There are multiple key conversion helpers for read, including keyword, string (essentially cl:identity), symbol:

  (cl-inix:read "a = b" :key :keyword)
  ;; ((T (:a . "b")))
  (cl-inix:read "a = b" :key :string)
  ;; ((T ("a" . "b")))
  (cl-inix:read "a = b" :key :symbol :package :cl-inix)
  ;; ((T (cl-inix::a . "b")))
  (cl-inix:read "a = b" :key #'(lambda (key &rest args) (uiop:strcat "---" key)))
  ;; ((T ("---a" . "b")))

Output format is also configurable, being either of alist (default) or hash-table:

  (cl-inix:read #p"~/.gitconfig" :format :hash-table)
  ;; #<HASH-TABLE :TEST EQUAL :COUNT 6 {12038D18C3}>

Values can also be fetched with get, whatever the format of the parsed .ini:

  (cl-inix:get "name" (cl-inix:read #p"~/.gitconfig" :format :hash-table) :section "user")
  ;; => "Artyom Bologov", T
  (cl-inix:get "name" (cl-inix:read #p"~/.gitconfig") :section "user")
  ;; => "Artyom Bologov"

There are typed helpers for get:

  • get-string as a no-op to get the value under the key
  • get-integer to get integer from under the key
  • get-boolean to get a (configurable format) boolean
  • get-array to parse (with delimiters) an array
  • get-read to cl:read any value from under the key

Finally, values can be write-n as .ini text:

  (cl-inix:write (cl-inix:read #p"~/.gitconfig" :key :symbol) #p"~/.gitconfig2"
                 :delimiter ": "
                 :key-case :upcase)

Dependencies (1)

  • lisp-unit2

Dependents (0)

    • GitHub
    • Quicklisp