elisp中最好的YAML解析器是什么?

Viv*_*odo 13 emacs yaml elisp

我想用elisp代码在YAML中读取配置.搜索但未在elisp中找到现成的解析器.我错过了有用的东西吗?

Bri*_*ell 5

六个月后,答案似乎是“不存在可靠的易于使用的elisp YAML解析器”。

如果您真的想在elisp中阅读YAML文档并将其转换为elisp可以与之交互的内容,则必须进行一些麻烦的工作。该EmacsWiki YAML页面已经没有多少给你,并规范YAML模式具有语法提示,但没有实际的解析器。幸运的是,有人实现了一个使用YAML并输出JSON或Python 的YAML解析Web应用程序 -您可以尝试了解一下该外观,并且-或者使用它来检查您自己编写的任何YAML解析器。

祝好运。

  • http://edward.oconnor.cx/2006/03/json.el对于比较和想法也可能有用。显然,YAML不是JSON,但是它们确实有一些相似之处。 (2认同)

Ehv*_*nce 5

几个月后:我想要它,所以这是在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


Rad*_*ugh 5

三年后,我们有了动态模块emacs-libyaml看起来很有趣。它使用动态模块系统在Elisp中公开libyaml的C绑定。我希望性能会非常出色,尽管我尚未对其进行测试。