cliif-common-lisp

2026-11-29

No Description

Upstream URL

github.com/Xs-and-10s/cliif-common-lisp

Author

xs-and-10s (Mark Manley)

Maintainer

xs-and-10s (Mark Manley)

License

MIT
README

CLIIF

CLIIF — Common Lisp Information Interchange Format — is to Common Lisp what JSON is to JavaScript: a natural data notation for the host language, rich enough that other ecosystems can exchange the same values. This is the IMPL-5 text profile: () for lists, [head …] for every typed value, plist-style object and explicit-pair map. A single document touring the whole value model:

#cliif 1
[object
  :name             "Ada Lovelace"            ; string
  :id               [uuid "018f7d5e-3300-7c8d-9b40-6a9e7f9e6c1a"]
  :active           true                      ; boolean
  :deleted-at       null                      ; the null sentinel
  :login-count      1024                      ; arbitrary-precision integer
  :balance          [decimal "10.50"]         ; exact decimal
  :trust-score      [float64 "0.875"]         ; IEEE double
  :status           pending                   ; a symbol (bare name)
  :roles            [vector :admin :editor]   ; indexed sequence
  :tags             [set :lisp :interop]      ; unordered, unique
  :recent-actions   (:login :view-report :logout)   ; a list
  :created-at       [instant "2026-06-04T18:30:00Z"]
  :birthday         [date "1815-12-10"]
  :daily-standup    [time "09:30:00"]
  :last-seen        [offset-date-time "2026-06-04T14:30:00-04:00"]
  :session-ttl      [duration "PT1H30M"]
  :membership       [period "P1Y2M10D"]
  :avatar           [bytes "QQ=="]            ; base64 octets
  :preferences      [map                      ; arbitrary keys, explicit (k v) pairs
                      (:theme  "dark")
                      (:locale "en-US")]
  :signature        [tag "vendor/ed25519" [bytes "3q2+7w=="]]]  ; extension type

Keywords (:name) and bare symbols (pending) are distinct kinds, ; runs to end of line as a comment, and every value above is valid as written — it parses, validates, and round-trips through both the text and JSON encodings. Identifier names may use any UAX #31 Unicode letter (:λ, :café, :naïve) and are NFC-normalized, so canonically-equivalent spellings compare equal; bind cliif-lexer:*name-syntax* to :ascii for a strict ASCII-only profile.

The same value also has a JSON carrier encoding — a second official wire format that travels through any JSON parser (see "JSON carrier" below).

Status

v1.0.0. The value model, canonical writer, streaming lexer, parser, and the lossless JSON carrier (IMPL-3) are complete and tested. UAX #31 Unicode identifiers with NFC normalization are implemented and are the default profile (:ascii remains available as an opt-in strict mode); the pinned Unicode version and its bump policy are documented in docs/cliif-unicode-versioning.md. Core CLIIF (no floats) is byte-identical across implementations — verified by an equal corpus digest on SBCL and ECL. The code is ANSI-only with no dependencies; the CI matrix additionally exercises CCL and CLISP.

Layout

cliif/
├── cliif.asd
├── LICENSE                       MIT
├── README.md
├── .github/workflows/ci.yml      multi-implementation test matrix
├── src/
│   ├── cliif-nfc.lisp            NFC (UAX #15) normalizer for identifier names
│   ├── cliif-canonical.lisp     value model, canonical writer, value=, valid-p/check
│   ├── cliif-unicode.lisp       UAX #31 XID_Start / XID_Continue classification
│   ├── cliif-lexer.lisp         position-tracking streaming lexer
│   ├── cliif-parser.lisp        recursive-descent parser
│   ├── cliif-json.lisp          JSON carrier: reader + canonical writer (no deps)
│   └── cliif-api.lisp           public façade (loaded last)
├── test/
│   ├── cliif-conformance.lisp    value generator + property tests
│   ├── cliif-unicode-tests.lisp  XID table digests + cross-module version agreement
│   ├── cliif-lexer-tests.lisp
│   ├── cliif-parser-tests.lisp
│   ├── cliif-corpus.lisp         self-checking text corpus + JSON emitter
│   ├── cliif-corpus.json         portable, language-neutral text fixtures
│   ├── cliif-json-tests.lisp     JSON carrier tests + round-trip properties
│   ├── cliif-json-corpus.lisp    self-checking JSON corpus + emitter
│   ├── cliif-json-corpus.json    portable, language-neutral JSON fixtures
│   ├── cliif-nfc-corpus.lisp     deterministic NFC conformance corpus
│   ├── cliif-nfc-tests.lisp      NFC singleton digest + corpus + idempotence
│   └── cliif-unicode-data.txt    portable XID summary (version, digests, counts)
├── tools/
│   ├── gen-unicode-xid.py        regenerates src/cliif-unicode.lisp (offline)
│   └── gen-unicode-nfc.py        regenerates src/cliif-nfc.lisp + corpus (offline)
└── docs/
    ├── cliif-value-model.md      the keystone spec (value model, equality, canonicalization)
    ├── cliif-grammar.ebnf        the grammar
    └── cliif-unicode-versioning.md  pinned Unicode version + bump policy

Load and test

Put the repository where ASDF can discover cliif.asd. The Quicklisp local-projects route is the lowest-friction setup:

mkdir -p ~/quicklisp/local-projects
ln -sfn "$PWD" ~/quicklisp/local-projects/cliif

Alternatively, clone or symlink the repo to ~/common-lisp/cliif/. Then:

(asdf:load-system "cliif")     ; the library
(asdf:test-system "cliif")     ; runs every suite; prints "CLIIF: all suites passed."

Public API

All public symbols live in the cliif package. It shadows cl:read, cl:write, cl:read-from-string, and cl:write-to-string, so do not :use it alongside :cl without resolving those four names.

OperationFunction
Parse one document (banner + value)cliif:read-from-string
Read one value (stream/string/lexer), :eof at endcliif:read
Canonical text of a valuecliif:write-to-string / cliif:canonical-text
Write canonical text to a streamcliif:write
Parse one JSON-carrier documentcliif:read-json-from-string
Read one JSON-carrier value (string/stream)cliif:read-json
Canonical JSON of a valuecliif:write-json-to-string
Write canonical JSON to a streamcliif:write-json
Equality (the one relation)cliif:value= (alias cliif:cliif=)
Validate (predicate / asserting)cliif:valid-p / cliif:check
Constructorscliif:make-object, make-map, make-vector*, make-set, make-list*, make-keyword*, make-decimal, make-instant, …
Sentinelscliif:+null+, cliif:+true+, cliif:+false+
Errorscliif:cliif-error ⊃ cliif:cliif-parse-error, cliif:cliif-lex-error, cliif:cliif-json-error; cliif:error-line / error-column / error-snippet
(let ((v (cliif:read-from-string "[object :name \"Ada\" :tags [set :lisp :interop]]")))
  (cliif:write-to-string v)                 ; => "[object :name \"Ada\" :tags [set :interop :lisp]]"
  (cliif:value= v (cliif:read-from-string (cliif:write-to-string v)))) ; => T  (round-trip)

(handler-case (cliif:read-from-string "[object :a 1 :a 2]")
  (cliif:cliif-error (e)
    (format t "~A at ~D:~D~%"
            (cliif:cliif-error-message e) (cliif:error-line e) (cliif:error-column e))))
;; Duplicate object key: :a at 1:14

Streaming (ND-CLIIF)

cliif:read consumes one value at a time and is the basis for newline-delimited streams — make a lexer once and loop:

(let ((lx (cliif-lexer:make-lexer some-stream)))
  (loop for v = (cliif:read lx) until (eq v :eof) do (handle v)))

JSON carrier (IMPL-3)

The JSON carrier is a second encoding of the same value model — not a separate format. It uses JSON as the transport and tagged objects ({"~#…": …}) for the kinds JSON lacks, so any value round-trips through any JSON parser without loss. The scalar tag payloads reuse the text profile's canonical reps, so the two encodings agree by construction.

(let ((v (cliif:read-from-string "[object :name \"Ada\" :tags [set :lisp :interop]]")))
  (cliif:write-json-to-string v))
;; => {"~#obj":[[{"~#kw":"name"},"Ada"],[{"~#kw":"tags"},{"~#set":[{"~#kw":"interop"},{"~#kw":"lisp"}]}]]}

;; round-trips back to the identical value
(let ((v (cliif:read-from-string "[object :name \"Ada\" :tags [set :lisp :interop]]")))
  (cliif:value= (cliif:read-json-from-string (cliif:write-json-to-string v)) v)) ; => T

Encoding

CLIIF kindJSON
null / true / falsenull / true / false
integer, |n| ≤ 2⁵³−1bare number
integer, larger{"~#int":"<digits>"}
decimal, float64{"~#decimal":"…"}, {"~#float64":"…"}
stringJSON string
keyword, symbol{"~#kw":"ns/name"}, {"~#sym":"name"}
uuid, bytes{"~#uuid":"…"}, {"~#bytes":"<base64>"}
instant / date / time / offset-date-time / duration / period{"~#<head>":"…"}
vectorJSON array
list{"~#list":[…]}
set{"~#set":[…]} (sorted)
object, all string keys{ "k": v, … }
object, any keyword/mixed key{"~#obj":[[k,v],…]}
map{"~#map":[[k,v],…]}
tagged value{"~#tag":["name",<rep>]}

A plain JSON object encodes a string-keyed CLIIF object:

(cliif:write-json-to-string (cliif:read-from-string "[object \"a\" 1 \"b\" 2]"))
;; => {"a":1,"b":2}

Because the carrier is lossless, a keyword- or mixed-key object cannot pose as a plain (string-keyed) JSON object; it travels as ~#obj pairs, which is distinct from ~#map and preserves the object kind on the way back.

Canonical form and validity

write-json-to-string is canonical: compact, ASCII-only (non-ASCII and astral characters are escaped as \uXXXX / surrogate pairs), with object, map, and set members ordered by the value-model canonical order. Two values are value= iff their canonical JSON is byte-identical — the same keystone the text profile rests on.

The reader is strict. It rejects bare fractional or exponent numbers (they must be tagged with ~#decimal or ~#float64), duplicate object keys, ~#-prefixed keys in plain objects, lone surrogates, unknown ~# tags, and trailing content, each with a line/column position:

(handler-case (cliif:read-json-from-string "4.5")
  (cliif:cliif-error (e) (cliif:cliif-error-message e)))
;; => "Fractional/exponent JSON number must be tagged (~#decimal or ~#float64): 4.5 at line 1, column 1
;;     4.5
;;     ^"

cliif:read-json accepts a string or a character stream; cliif:write-json writes canonical JSON to a stream and returns the value.

Guarantees (all under test)

  • Cross-implementation canonical identity — canonical-text and canonical JSON are both byte-for-byte identical across implementations (an equal corpus digest, and identical JSON output, on SBCL and ECL).
  • Equality ⇔ canonical identity — value=(a,b) iff canonical-text(a) = canonical-text(b), and likewise iff write-json-to-string(a) = write-json-to-string(b) (property tests, 5000 cases each).
  • Round-trip — read-from-string(canonical-text(v)) = v and read-json-from-string(write-json-to-string(v)) = v (property tests, 5000 cases each, plus targeted fixtures).
  • Cross-encoding agreement — for every value, the text and JSON encodings decode to the same value: read-json(write-json(v)) = read(canonical-text(v)) (5000 cases).

Conformance corpus

test/cliif-corpus.json and test/cliif-json-corpus.json are language-neutral, ASCII-only fixture sets: valid inputs paired with their expected canonical output, and invalid inputs paired with an expected error category and (for the text corpus) position. Implementations in other languages can conform to the identical fixtures. Regenerate them with (cliif-corpus:emit-json "test/cliif-corpus.json") and (cliif-json-corpus:emit-json "test/cliif-json-corpus.json").

Documentation

  • docs/cliif-value-model.md — the normative value model, the single equality relation, and the canonical form of every value. The keystone: value=, the canonical writer, and the dedup/sort rules all derive from it.
  • docs/cliif-grammar.ebnf — the IMPL-5 grammar, including the identifier profile and the documented UAX #31 target.

Dependencies (0)

    Dependents (0)

      • GitHub
      • Quicklisp