Skip to content

Commit 2a2aa62

Browse files
authored
TOML 1.1: Allow newlines and trailing comma in inline tables (#200)
1 parent 38297f8 commit 2a2aa62

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

src/tomli/_parser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def parse_inline_table(
532532
nested_dict = NestedDict()
533533
flags = Flags()
534534

535-
pos = skip_chars(src, pos, TOML_WS)
535+
pos = skip_comments_and_array_ws(src, pos)
536536
if src.startswith("}", pos):
537537
return pos + 1, nested_dict.dict
538538
while True:
@@ -547,16 +547,18 @@ def parse_inline_table(
547547
if key_stem in nest:
548548
raise TOMLDecodeError(f"Duplicate inline table key {key_stem!r}", src, pos)
549549
nest[key_stem] = value
550-
pos = skip_chars(src, pos, TOML_WS)
550+
pos = skip_comments_and_array_ws(src, pos)
551551
c = src[pos : pos + 1]
552552
if c == "}":
553553
return pos + 1, nested_dict.dict
554554
if c != ",":
555555
raise TOMLDecodeError("Unclosed inline table", src, pos)
556+
pos += 1
557+
pos = skip_comments_and_array_ws(src, pos)
558+
if src.startswith("}", pos):
559+
return pos + 1, nested_dict.dict
556560
if isinstance(value, (dict, list)):
557561
flags.set(key, Flags.FROZEN, recursive=True)
558-
pos += 1
559-
pos = skip_chars(src, pos, TOML_WS)
560562

561563

562564
def parse_basic_str_escape(
File renamed without changes.
File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"multiline": {
3+
"a": {
4+
"type": "integer",
5+
"value": "1"
6+
},
7+
"b": {
8+
"type": "integer",
9+
"value": "2"
10+
},
11+
"c": [
12+
{
13+
"type": "integer",
14+
"value": "1"
15+
},
16+
{
17+
"type": "integer",
18+
"value": "2"
19+
},
20+
{
21+
"type": "integer",
22+
"value": "3"
23+
}
24+
],
25+
"d": {
26+
"type": "integer",
27+
"value": "3"
28+
},
29+
"e": {
30+
"type": "integer",
31+
"value": "4"
32+
},
33+
"f": {}
34+
}
35+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
multiline = {
2+
"a" = 1, "b" = 2,
3+
c = [
4+
1,
5+
2,
6+
3,
7+
],# comment
8+
d = 3,
9+
e = 4, f = {
10+
# comment
11+
},
12+
}

tests/test_data.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ def test_valid(self):
4646
# compatible with yet.
4747
if valid.stem in {
4848
"no-seconds",
49-
"newline",
50-
"newline-comment",
5149
"hex-escape",
52-
"common-47",
5350
"common-34",
5451
"common-31",
5552
"common-29",

0 commit comments

Comments
 (0)