This is an implementation of a domain-specific-language based on JSON that supports embedded S-expressions.
This is part of the excellent book Beautiful Racket, which I would highly recommend checking out.
From Beautiful Racket
- Every valid
jsonic
program produces valid JSON.- Every valid JSON file is a valid
jsonic
program.- Racket expressions can be embedded in place of any JSON value.
- Line comments start with
//
The grammar for this language, in Extended Backus–Naur form is as follows:
jsonic-program : (jsonic-char | jsonic-sexp)*
jsonic-char : CHAR-TOK
jsonic-sexp : SEXP-TOK
- This requires racket
- Clone this repository and
cd
into thejsonic
directory - Run
raco pkg install
Once the package is installed, the following programs can be run using #lang jsonic
.
#lang jsonic
[
null,
42,
true,
["array", "of", "strings"],
{
"key-1": null,
"key-2": false,
"key-3": {"subkey": 21}
}
]
#lang jsonic
// a line comment
[
@$ 'null $@,
@$ (* 6 7) $@,
@$ (= 2 (+ 1 1)) $@,
@$ (list "array" "of" "strings") $@,
@$ (hash 'key-1 'null
'key-2 (even? 3)
'key-3 (hash 'subkey 21)) $@
]
Both of these should output the same result, but the latter uses S-expressions while the former uses hard-coded values.