Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow newlines and trailing comma in inline tables #904

Merged
merged 4 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased

* Allow newline after key/values in inline tables.
* Allow trailing comma in inline tables.
* Clarify where and how dotted keys define tables.
* Add new `\e` shorthand for the escape character.

Expand Down
11 changes: 6 additions & 5 deletions toml.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,14 @@ std-table-close = ws %x5D ; ] Right square bracket

;; Inline Table

inline-table = inline-table-open [ inline-table-keyvals ] inline-table-close
inline-table = inline-table-open [ inline-table-keyvals ] ws-comment-newline inline-table-close

inline-table-open = %x7B ws ; {
inline-table-close = ws %x7D ; }
inline-table-sep = ws %x2C ws ; , Comma
inline-table-open = %x7B ; {
inline-table-close = %x7D ; }
inline-table-sep = %x2C ; , Comma

inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
inline-table-keyvals = ws-comment-newline keyval ws-comment-newline inline-table-sep inline-table-keyvals
inline-table-keyvals =/ ws-comment-newline keyval ws-comment-newline [ inline-table-sep ]

;; Array Table

Expand Down
33 changes: 25 additions & 8 deletions toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -797,23 +797,32 @@ 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.
especially useful for grouped nested data that can otherwise quickly become
verbose.

Inline tables are fully defined within 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. A terminating comma (also
called trailing comma) is not permitted after the last key/value pair in an
inline table. 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.
Inline tables can have multiple key/value pairs on the same line, or they can be
put on different lines. A terminating comma (also called trailing comma) is
permitted after the last key/value pair.

```toml
name = { first = "Tom", last = "Preston-Werner" }
point = { x = 1, y = 2 }
point = {x=1, y=2}
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
animal = { type.name = "pug" }
contact = {
personal = {
name = "Donald Duck",
email = "donald@duckburg.com",
},
work = {
name = "Coin cleaner",
email = "donald@ScroogeCorp.com",
},
}
```

The inline tables above are identical to the following standard table
Expand All @@ -830,6 +839,14 @@ y = 2

[animal]
type.name = "pug"

[contact.personal]
name = "Donald Duck"
email = "donald@duckburg.com"

[contact.work]
name = "Coin cleaner"
email = "donald@ScroogeCorp.com"
```

Inline tables are fully self-contained and define all keys and sub-tables within
Expand Down