Skip to content

Instantly share code, notes, and snippets.

@cmoore
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoore/30d894187a08fcff1382 to your computer and use it in GitHub Desktop.
Save cmoore/30d894187a08fcff1382 to your computer and use it in GitHub Desktop.
(defvar *previous-readtables* nil)
(defmacro enable-toml-syntax ()
'(eval-when (:compile-toplevel :load-toplevel :execute)
(push *readtable* *previous-readtables*)
(setq *readtable* (copy-readtable))
(set-macro-character #\[ 'read-left-bracket)
; more calls to (set-macro-character)
...))
(defmacro disable-toml-syntax ()
'(eval-when (:compile-toplevel :load-toplevel :execute)
(setq *readtable* (pop *previous-readtables*))))
(defun parse (contents)
(let ((result nil))
(with-input-from-string (in contents)
(enable-toml-syntax)
(setq result (read in))
(disable-toml-syntax))
result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment