From 436ca9b6302ae75067d144590e94b0e7ee21c7e7 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 15 Jul 2014 17:27:01 -0700 Subject: [PATCH] Add inline table syntax. --- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/README.md b/README.md index a7a020ed..d68119d6 100644 --- a/README.md +++ b/README.md @@ -363,6 +363,39 @@ All table names and keys must be non-empty. = "no key name" # not allowed ``` +Inline Table +------------ + +Inline tables provide a more compact syntax for expressing tables. They are +especially useful for grouped data that can otherwise quickly become verbose. +Inline tables are enclosed in curly braces `{` and `}`. Within the braces, zero +or more comma separated key/value pairs may appear. Key/value pairs take the +same form as key/value pairs in standard tables. All value types are allowed, +including inline tables. + +Inline tables are intended to appear on a single line. No newlines are allowed +between the curly braces unless they are valid within a value. Even so, it is +strongly discouraged to break an inline table onto multiples lines. If you find +yourself gripped with this desire, it means you should be using standard tables. + +```toml +name = { first = "Tom", last = "Preston-Werner" } +point = { x = 1, y = 2 } +``` + +The inline tables above are identical to the following standard table +definitions: + +```toml +[name] +first = "Tom" +last = "Preston-Werner" + +[point] +x = 1 +y = 2 +``` + Array of Tables --------------- @@ -464,6 +497,14 @@ array must produce an error at parse time. name = "granny smith" ``` +You may also use inline tables where appropriate: + +```toml +points = [ { x = 1, y = 2, z = 3 }, + { x = 7, y = 8, z = 9 }, + { x = 2, y = 4, z = 8 } ] +``` + Seriously? ----------