Skip to content

Instantly share code, notes, and snippets.

@amtal
Created April 12, 2011 08:18
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 amtal/915157 to your computer and use it in GitHub Desktop.
Save amtal/915157 to your computer and use it in GitHub Desktop.
(defmacro bin-parser ((cons name raw-clauses)
(flet ((fun-clause
((list (list* cmd chan match) body)
`((,cmd ,chan (binary ,@(: lists map (fun bin-chunk 1) match))) ,body))
((x) (error `(what_is_this ,x))))
(bin-chunk
(((list name n)) (when (is_integer n))
`(,name little integer (size ,(* 8 n))))
(((list name 'float))
`(,name little float))
(((list name 'bits))
`(,name bits))
((x) (error `(bad_chunk_spec ,x)))))
(let ((clauses (: lists map (lambda (c) (fun-clause c)) raw-clauses)))
`(defun ,name ,clauses)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment