TOML v0.2.0
Tom's Obvious, Minimal Language.
Tom Preston-Werner 著。
警告:この仕様はまだ大きく変化しています。1.0とマークされるまでは、不安定であると仮定し、それに応じて対応する必要があります。
目的
TOMLは、明らかなセマンティクスにより読みやすい、最小限の構成ファイルフォーマットを目指しています。TOMLは、ハッシュテーブルに一意にマッピングされるように設計されています。TOMLは、さまざまな言語でデータ構造に簡単に解析できる必要があります。
仕様
- TOMLは大文字と小文字を区別します。
- 空白とは、タブ(0x09)またはスペース(0x20)を意味します。
コメント
ハッシュ記号を使ってあなたの意見を述べてください。記号から行末までがコメントになります。
# I am a comment. Hear me roar. Roar.
key = "value" # Yeah, you can do this.
文字列
ProTip™: この仕様はJSONの文字列定義と同じであることに気づくかもしれません。ただし、TOMLはUTF-8エンコーディングを要求します。これは意図的なものです。
文字列は、引用符で囲まれた1行の値です。文字列には有効なUTF-8文字のみを含める必要があります。引用符、バックスラッシュ、制御文字(U+0000~U+001F)を除く、任意のUnicode文字を使用できます。
"I'm a string. \"You can quote me\". Name\tJos\u00E9\nLocation\tSF."
便宜上、いくつかの一般的な文字にはコンパクトなエスケープシーケンスがあります。
\b - backspace (U+0008)
\t - tab (U+0009)
\n - linefeed (U+000A)
\f - form feed (U+000C)
\r - carriage return (U+000D)
\" - quote (U+0022)
\/ - slash (U+002F)
\\ - backslash (U+005C)
\uXXXX - unicode (U+XXXX)
任意のUnicode文字は、\uXXXX
形式でエスケープできます。
その他の特殊文字は予約されており、使用された場合、TOMLはエラーを生成する必要があります。これは、Windows上のパスは常に二重バックスラッシュを使用する必要があることを意味します。
wrong = "C:\Users\nodejs\templates" # note: doesn't produce a valid path
right = "C:\\Users\\nodejs\\templates"
バイナリデータには、Base64またはその他の適切なエンコーディングを使用することをお勧めします。そのエンコーディングの処理はアプリケーション固有になります。
整数
整数は、単独の数字です。負の数も可能です。64ビット以上のサイズが想定されます。
42
-17
浮動小数点数
浮動小数点数は、小数点を含む数値です。小数点の左右には少なくとも1つの数字が必要です。64ビット(倍精度)が想定されます。
3.1415
-0.01
ブール値
ブール値は、あなたが慣れているトークンです。常に小文字です。
true
false
日時
日時はISO 8601日付ですが、完全なZulu形式のみが許可されます。
1979-05-27T07:32:00Z
配列
配列は、角括弧内に他のプリミティブを含むものです。空白は無視されます。要素はコンマで区切られます。データ型を混在させることはできません。
[ 1, 2, 3 ]
[ "red", "yellow", "green" ]
[ [ 1, 2 ], [3, 4, 5] ]
[ [ 1, 2 ], ["a", "b", "c"] ] # this is ok
[ 1, 2.0 ] # note: this is NOT ok
配列は複数行にすることもできます。そのため、空白を無視することに加えて、配列は括弧間の改行も無視します。閉じ括弧の前に終端コンマを使用しても問題ありません。
key = [
1, 2, 3
]
key = [
1,
2, # this is ok
]
テーブル
テーブル(ハッシュテーブルまたは辞書とも呼ばれます)は、キーと値のペアのコレクションです。それらは、単独の行に角括弧で囲まれて表示されます。配列は値のみであるため、配列と区別できます。
[table]
その下に、次のテーブルまたはEOFまでは、そのテーブルのキーと値があります。キーは等号の左側に、値は右側にあります。キーは最初の空白以外の文字で始まり、等号の手前の最後の空白以外の文字で終わります。テーブル内のキーと値のペアは順序付けられていません。
[table]
key = "value"
キーとその値は、好きなだけインデントできます。タブまたはスペースを使用できます。自由にどうぞ。なぜですか?入れ子になったテーブルを持つことができるからです。
入れ子になったテーブルは、ドットを含むテーブル名で示されます。テーブルには好きな名前を付けることができますが、ドットを使用しないでください。ドットは予約されています。従ってください。
[dog.tater]
type = "pug"
JSONの世界では、次の構造になります
{ "dog": { "tater": { "type": "pug" } } }
すべてのスーパーテーブルを指定する必要はありません。TOMLは自動的に処理します。
# [x] you
# [x.y] don't
# [x.y.z] need these
[x.y.z.w] # for this to work
空のテーブルは許可されており、キーと値のペアは含まれていません。
スーパーテーブルが直接定義されておらず、特定のキーが定義されていない限り、書き込むことができます。
[a.b]
c = 1
[a]
d = 2
キーやテーブルを複数回定義することはできません。そうすると無効になります。
# DO NOT DO THIS
[a]
b = 1
[a]
c = 2
# DO NOT DO THIS EITHER
[a]
b = 1
[a.b]
c = 2
テーブルの配列
まだ表現されていない最後の型は、テーブルの配列です。これらは、二重角括弧でテーブル名を使用することで表現できます。同じ二重角括弧で囲まれた名前を持つ各テーブルは、配列の要素になります。テーブルは検出された順序で挿入されます。キーと値のペアを含まない二重角括弧で囲まれたテーブルは、空のテーブルと見なされます。
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
[[products]]
name = "Nail"
sku = 284758393
color = "gray"
JSONの世界では、次の構造になります。
{
"products": [
{ "name": "Hammer", "sku": 738594937 },
{ },
{ "name": "Nail", "sku": 284758393, "color": "gray" }
]
}
入れ子になったテーブルの配列も作成できます。サブテーブルに同じ二重角括弧構文を使用するだけです。各二重角括弧で囲まれたサブテーブルは、その上の最後に定義されたテーブル要素に属します。
[[fruit]]
name = "apple"
[fruit.physical]
color = "red"
shape = "round"
[[fruit.variety]]
name = "red delicious"
[[fruit.variety]]
name = "granny smith"
[[fruit]]
name = "banana"
[[fruit.variety]]
name = "plantain"
上記のTOMLは、次のJSONにマップされます。
{
"fruit": [
{
"name": "apple",
"physical": {
"color": "red",
"shape": "round"
},
"variety": [
{ "name": "red delicious" },
{ "name": "granny smith" }
]
},
{
"name": "banana",
"variety": [
{ "name": "plantain" }
]
}
]
}
既に確立された配列と同じ名前の通常のテーブルを定義しようとすると、解析時にエラーが発生する必要があります。
# INVALID TOML DOC
[[fruit]]
name = "apple"
[[fruit.variety]]
name = "red delicious"
# This table conflicts with the previous table
[fruit.variety]
name = "granny smith"
冗談でしょう?
はい。
でもなぜ?
ハッシュテーブルに一意にマッピングされる適切な人間が読める形式が必要であり、YAMLの仕様は80ページの長さで怒りを覚えるからです。いいえ、JSONは数えません。なぜそうなのか分かりますよね。
ああ、神様、あなたは正しい
そうです。手伝ってくれますか?プルリクエストを送信してください。または、パーサーを作成してください。勇敢になりましょう。
実装
実装がある場合は、プルリクエストを送信してこのリストに追加してください。READMEでパーサーがサポートするコミットSHA1またはバージョンタグに注意してください。
- C#/.NET - https://github.com/LBreedlove/Toml.net
- C#/.NET - https://github.com/rossipedia/toml-net
- C#/.NET - https://github.com/RichardVasquez/TomlDotNet
- 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 - https://github.com/asafh/jtoml
- 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)
- Scala - https://github.com/axelarge/tomelette
バリデータ
- Go (@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