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

查看:13
本文介绍了保留注释的数据结构格式(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|... for key values).

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 听起来很酷,简单地说,它不存在B>,然而

更新: 你可能想使用 Config::General,它的 apache 配置格式(xmlish)

不,PPI 不是通用工具,如果你想要 BNF-ness,你想使用 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天全站免登陆