Skip to content

Commit 18348af

Browse files
authored
Allow newlines and trailing comma in inline tables (#904)
1 parent cbf3b13 commit 18348af

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## unreleased
44

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

toml.abnf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,14 @@ std-table-close = ws %x5D ; ] Right square bracket
222222

223223
;; Inline Table
224224

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

227-
inline-table-open = %x7B ws ; {
228-
inline-table-close = ws %x7D ; }
229-
inline-table-sep = ws %x2C ws ; , Comma
227+
inline-table-open = %x7B ; {
228+
inline-table-close = %x7D ; }
229+
inline-table-sep = %x2C ; , Comma
230230

231-
inline-table-keyvals = keyval [ inline-table-sep inline-table-keyvals ]
231+
inline-table-keyvals = ws-comment-newline keyval ws-comment-newline inline-table-sep inline-table-keyvals
232+
inline-table-keyvals =/ ws-comment-newline keyval ws-comment-newline [ inline-table-sep ]
232233

233234
;; Array Table
234235

toml.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -797,23 +797,32 @@ Inline Table
797797
------------
798798

799799
Inline tables provide a more compact syntax for expressing tables. They are
800-
especially useful for grouped data that can otherwise quickly become verbose.
800+
especially useful for grouped nested data that can otherwise quickly become
801+
verbose.
802+
801803
Inline tables are fully defined within curly braces: `{` and `}`. Within the
802804
braces, zero or more comma-separated key/value pairs may appear. Key/value pairs
803805
take the same form as key/value pairs in standard tables. All value types are
804806
allowed, including inline tables.
805807

806-
Inline tables are intended to appear on a single line. A terminating comma (also
807-
called trailing comma) is not permitted after the last key/value pair in an
808-
inline table. No newlines are allowed between the curly braces unless they are
809-
valid within a value. Even so, it is strongly discouraged to break an inline
810-
table onto multiples lines. If you find yourself gripped with this desire, it
811-
means you should be using standard tables.
808+
Inline tables can have multiple key/value pairs on the same line, or they can be
809+
put on different lines. A terminating comma (also called trailing comma) is
810+
permitted after the last key/value pair.
812811

813812
```toml
814813
name = { first = "Tom", last = "Preston-Werner" }
815-
point = { x = 1, y = 2 }
814+
point = {x=1, y=2}
816815
animal = { type.name = "pug" }
816+
contact = {
817+
personal = {
818+
name = "Donald Duck",
819+
email = "[email protected]",
820+
},
821+
work = {
822+
name = "Coin cleaner",
823+
email = "[email protected]",
824+
},
825+
}
817826
```
818827

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

831840
[animal]
832841
type.name = "pug"
842+
843+
[contact.personal]
844+
name = "Donald Duck"
845+
846+
847+
[contact.work]
848+
name = "Coin cleaner"
849+
833850
```
834851

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

0 commit comments

Comments
 (0)