-
-
Save carllerche/bfedfcc1e31a905bcbec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defautomata netstring | |
(word (* any ? bytes-remaining $ track-word % print-word)) | |
(frame (+ digit $ track-size) ":" word) | |
(start (* frame ",") frame)) | |
(defn- parse-buffer [buf] | |
(loop [cs (initial-state netstring) | |
i 0 | |
size 0 | |
word [] | |
char (get-char buf i)] | |
(defexecution netstring [i size word] | |
(bytes-remaining (> size 0)) | |
(track-size (next-action i (+ size (char-to-int char)) word)) | |
(track-word (next-action i size (conj word char))) | |
(print-word (println word)) | |
(recur cs (inc i) size char)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment