保留注释的数据结构格式(YAML或诸如此类)的往返解析,用于编写配置 [英] Round-trip parsing of data structure format (YAML or whatnot) preserving comments, for writing configuration

查看:226
本文介绍了保留注释的数据结构格式(YAML或诸如此类)的往返解析,用于编写配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在多个应用程序中使用YAML作为配置文件格式,但除了一件事之外一切都进行得很顺利:当我的程序需要在YAML配置文件中写入/修改配置变量时,它会通过加载和转储破坏格式和注释整个文件/结构.

I have been using YAML as configuration file format in several applications, and all went well except one thing: when my program needs to write/modify a config variable in a YAML config file, it destroys formatting and comments by loading and dumping the entire file/structure.

(嗯,YAML确实存在另一个问题.大多数用户(其中​​很多不是程序员)会被YAML规则的细节所困扰,例如某些地方的空白含义.但这并不是一个主要问题. )

(Well, there is another problem with YAML actually. Most users, many of them are not programmers, will be tripped over the details of YAML rules, like the significance of whitespace in some places. But this is not a major gripe.)

我希望使用YAML加载程序/转储程序,它可以进行往返解析(保留所有空格和注释),或具有此类解析器的其他一些人类可读的序列化格式.我什至考虑使用Perl文档和PPI,因为PPI是往返安全的解析器.还是PPI可以专心于处理YAML或类似格式?我宁愿不使用XML,在那之前我要求助于INI +(JSON | YAML | ...作为键值).

What I would prefer is a YAML loader/dumper which can do round-trip parsing (preserving all whitespaces & comments), or some other human-readable serialization format which has such parser. I'm even considering using Perl document and PPI, since PPI is a round-trip safe parser. Or perhaps PPI can be bent to deal with YAML or similar formats? I'd rather not use XML, I'd resort to INI+(JSON|YAML|... for key values) before that.

有任何建议或指示吗?

推荐答案

是的,您和所有认为哇,yaml听起来很酷的人,简而言之,它不存在,但是

更新:您可能要使用Config :: General,它的Apache配置格式(xmlish)

不,PPI不是通用工具,如果您想使用BNF,请使用Marpa

在所有INI/JSON/YAML/XML中,XML可能对非程序员具有最佳的编辑器支持(听起来很疯狂)

Yeah, you and everyone who thought wow, yaml sounds cool, simply put, it doesn't exist, yet

update: you probably want to use Config::General, its apache config format (xmlish)

No, PPI is not general purpose tool, if you want BNF-ness, you want to use Marpa

Of all INI/JSON/YAML/XML, XML probably has the best editor support for non-programmers (sounds crazy)

这篇关于保留注释的数据结构格式(YAML或诸如此类)的往返解析,用于编写配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆