经过:原本,我一直以为,yml格式非常好用,至少比 properties要科学,比 json 要简洁、强大,然而,下面遇到的这个案例,让我意识到,yaml并不是万能,也并不是最科学、简洁的,甚至是比较糟糕的。
我有这样一个 spring-boot的配置文件(原本是properties格式如下):
|
还是比较直观,而且 借助复制粘贴 写起来倒也简单。
然而,我在另一个新项目中,想把它转换成 yaml格式,很快,我发现不妙,不信你可以试试。
我转换的结果是这样的:
|
转换费了我不少功夫,而且一看,这是什么玩意儿啊,乱七八糟的,不直观,反人类啊。
于是 我找到了一个 “像样的人类可读的格式”(easy for humans to read and write)
——那就是 TOML。
GitHub 目前的新项目已经转用 CoffeeScript 了。CoffeeScript 比JavaScript 要简洁优雅得多。
同样地,GitHub 也觉得 YAML 不够简洁优雅,因此捣鼓出了一个TOML。
TOML 的全称是 Tom's Obvious, Minimal Language,因为它的作者是 GitHub 联合创始人 Tom Preston-Werner 。
TOML 的目标
TOML 的目标是成为一个极简的配置文件格式。TOML 被设计成可以无歧义地被映射为哈希表,从而被多种语言解析。
例子
|
详见官方文档:https://github.com/toml-lang/toml/blob/master/versions/cn/toml-v0.5.0.md
TOML的实现和各种语言支持
如果你有一个实现,请发一个合并请求,把你的实现加入到这个列表中。请在你的解析器的 README 中标记你的解析器支持的 提交SHA1 或 版本号。
C#/.NET - https://github.com/LBreedlove/Toml.net
C#/.NET - https://github.com/rossipedia/toml-net
C (@ajwans) - https://github.com/ajwans/libtoml
C++ (@evilncrazy) - https://github.com/evilncrazy/ctoml
C++ (@skystrife) - https://github.com/skystrife/cpptoml
Clojure (@lantiga) - https://github.com/lantiga/clj-toml
Clojure (@manicolosi) - https://github.com/manicolosi/clojoml
CoffeeScript (@biilmann) - https://github.com/biilmann/coffee-toml
Common Lisp (@pnathan) - https://github.com/pnathan/pp-toml
Erlang - https://github.com/kalta/etoml.git
Erlang - https://github.com/kaos/tomle
Emacs Lisp (@gongoZ) - https://github.com/gongo/emacs-toml
Go (@thompelletier) - https://github.com/pelletier/go-toml
Go (@laurent22) - https://github.com/laurent22/toml-go
Go w/ Reflection (@BurntSushi) - https://github.com/BurntSushi/toml
Haskell (@seliopou) - https://github.com/seliopou/toml
Haxe (@raincole) - https://github.com/raincole/haxetoml
Java (@agrison) - https://github.com/agrison/jtoml
Java (@johnlcox) - https://github.com/johnlcox/toml4j
Java (@mwanji) - https://github.com/mwanji/toml4j
Java w/ ANTLR (@MatthiasSchuetz) - https://github.com/mschuetz/toml
Julia (@pygy) - https://github.com/pygy/TOML.jl
Literate CoffeeScript (@JonathanAbrams) - https://github.com/JonAbrams/tomljs
node.js - https://github.com/aaronblohowiak/toml
node.js/browser - https://github.com/ricardobeat/toml.js (npm install tomljs)
node.js - https://github.com/BinaryMuse/toml-node
node.js (@redhotvengeance) - https://github.com/redhotvengeance/topl (topl npm package)
node.js/browser (@alexanderbeletsky) - https://github.com/alexanderbeletsky/toml-js (npm browser amd)
Objective C (@mneorr) - https://github.com/mneorr/toml-objc.git
Objective-C (@SteveStreza) - https://github.com/amazingsyco/TOML
Ocaml (@mackwic) https://github.com/mackwic/to.ml
Perl (@alexkalderimis) - https://github.com/alexkalderimis/config-toml.pl
Perl - https://github.com/dlc/toml
PHP (@leonelquinteros) - https://github.com/leonelquinteros/php-toml.git
PHP (@jimbomoss) - https://github.com/jamesmoss/toml
PHP (@coop182) - https://github.com/coop182/toml-php
PHP (@checkdomain) - https://github.com/checkdomain/toml
PHP (@zidizei) - https://github.com/zidizei/toml-php
PHP (@yosymfony) - https://github.com/yosymfony/toml
Python (@socketubs) - https://github.com/socketubs/pytoml
Python (@f03lipe) - https://github.com/f03lipe/toml-python
Python (@uiri) - https://github.com/uiri/toml
Python - https://github.com/bryant/pytoml
Python (@elssar) ) https://github.com/elssar/tomlgun
Python (@marksteve) - https://github.com/marksteve/toml-ply
Python (@hit9) - https://github.com/hit9/toml.py
Ruby (@jm) - https://github.com/jm/toml (toml gem)
Ruby (@eMancu) - https://github.com/eMancu/toml-rb (toml-rb gem)
Ruby (@charliesome) - https://github.com/charliesome/toml2 (toml2 gem)
Ruby (@sandeepravi) - https://github.com/sandeepravi/tomlp (tomlp gem)
校验
@BurntSushi) - https://github.com/BurntSushi/toml/tree/master/tomlv
TOML 测试套件 (语言无关)
toml-test (@BurntSushi) - https://github.com/BurntSushi/toml-test
编辑器支持
Emacs (@dryman) - https://github.com/dryman/toml-mode.el
Sublime Text 2 & 3 (@lmno) - https://github.com/lmno/TOML
TextMate (@infininight) - https://github.com/textmate/toml.tmbundle
Vim (@cespare) - https://github.com/cespare/vim-toml
编码器
PHP (@ayushchd) - https://github.com/ayushchd/php-toml-encoder