Created
October 14, 2011 06:29
-
-
Save lieutar/1286397 to your computer and use it in GitHub Desktop.
elisp で YAML を読むために
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
(defun yaml2json (yaml) | |
"Converts a YAML string to a JSON string. | |
This function is not 100% pure elisp. | |
This function depends to perl , YAML::Syck and JSON::Syck." | |
(with-temp-buffer | |
(let ((proc (start-process | |
" *yaml2json*" | |
(current-buffer) | |
"perl" | |
"-MYAML::Syck" | |
"-MJSON::Syck" | |
"-e" | |
"print JSON::Syck::Dump(YAML::Syck::Load(join '', <>))")) | |
(waiting t)) | |
(set-process-sentinel | |
proc | |
(lambda (&rest args) | |
(let ((sig (and (cdr args)(cadr args)))) | |
(when (equal sig "finished\n") | |
(setq waiting nil))))) | |
(process-send-string proc yaml) | |
(process-send-eof proc) | |
(while waiting (sleep-for 0.1)) | |
(buffer-substring (point-min)(point-max))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment