我想用elisp代码在YAML中读取配置.搜索但未在elisp中找到现成的解析器.我错过了有用的东西吗?
六个月后,答案似乎是“不存在可靠的易于使用的elisp YAML解析器”。
如果您真的想在elisp中阅读YAML文档并将其转换为elisp可以与之交互的内容,则必须进行一些麻烦的工作。该EmacsWiki YAML页面已经没有多少给你,并规范YAML模式具有语法提示,但没有实际的解析器。幸运的是,有人实现了一个使用YAML并输出JSON或Python 的YAML解析Web应用程序 -您可以尝试了解一下该外观,并且-或者使用它来检查您自己编写的任何YAML解析器。
祝好运。
几个月后:我想要它,所以这是在python的帮助下如何做:
(defun yaml-parse ()
"yaml to json to a hashmap of current buffer, with python.
There is no yaml parser in elisp.
You need pyYaml and some yaml datatypes like dates are not supported by json."
(interactive)
(let ((json-object-type 'hash-table))
(setq myyaml (json-read-from-string (shell-command-to-string (concat "python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < " (buffer-file-name))))))
;; code here
)
Run Code Online (Sandbox Code Playgroud)
借助,它将当前缓冲区的yaml转换为elisp hashmap json.el。
你需要Python的pyyaml: pip install PyYaml。
json.el:http ://edward.oconnor.cx/2006/03/json.el
| 归档时间: |
|
| 查看次数: |
1789 次 |
| 最近记录: |