mirror of
https://github.com/lightbend/config.git
synced 2025-03-22 15:20:26 +08:00
allow omitting the colon if the value is an object
This commit is contained in:
parent
55595e4c39
commit
39de5aa444
@ -398,14 +398,24 @@ final class Parser {
|
|||||||
} else {
|
} else {
|
||||||
Path path = parseKey(t);
|
Path path = parseKey(t);
|
||||||
Token afterKey = nextTokenIgnoringNewline();
|
Token afterKey = nextTokenIgnoringNewline();
|
||||||
if (!isKeyValueSeparatorToken(afterKey)) {
|
|
||||||
throw parseError("Key may not be followed by token: "
|
|
||||||
+ afterKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
consolidateValueTokens();
|
Token valueToken;
|
||||||
Token valueToken = nextTokenIgnoringNewline();
|
AbstractConfigValue newValue;
|
||||||
AbstractConfigValue newValue = parseValue(valueToken);
|
if (flavor == SyntaxFlavor.CONF
|
||||||
|
&& afterKey == Tokens.OPEN_CURLY) {
|
||||||
|
// can omit the ':' or '=' before an object value
|
||||||
|
valueToken = afterKey;
|
||||||
|
newValue = parseObject();
|
||||||
|
} else {
|
||||||
|
if (!isKeyValueSeparatorToken(afterKey)) {
|
||||||
|
throw parseError("Key may not be followed by token: "
|
||||||
|
+ afterKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
consolidateValueTokens();
|
||||||
|
valueToken = nextTokenIgnoringNewline();
|
||||||
|
newValue = parseValue(valueToken);
|
||||||
|
}
|
||||||
|
|
||||||
String key = path.first();
|
String key = path.first();
|
||||||
Path remaining = path.remainder();
|
Path remaining = path.remainder();
|
||||||
|
44
src/test/resources/equiv01/omit-colons.conf
Normal file
44
src/test/resources/equiv01/omit-colons.conf
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"ints" {
|
||||||
|
"fortyTwo" : 42,
|
||||||
|
"fortyTwoAgain" : 42
|
||||||
|
},
|
||||||
|
|
||||||
|
"floats"
|
||||||
|
{
|
||||||
|
"fortyTwoPointOne" : 42.1,
|
||||||
|
"fortyTwoPointOneAgain" : 42.1
|
||||||
|
},
|
||||||
|
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
{
|
||||||
|
"abcd" : "abcd",
|
||||||
|
"abcdAgain" : "abcd",
|
||||||
|
"a" : "a",
|
||||||
|
"b" : "b",
|
||||||
|
"c" : "c",
|
||||||
|
"d" : "d",
|
||||||
|
"concatenated" : "null bar 42 baz true 3.14 hi"
|
||||||
|
},
|
||||||
|
|
||||||
|
"arrays" {
|
||||||
|
"empty" : [],
|
||||||
|
"1" : [ 1 ],
|
||||||
|
"12" : [1, 2],
|
||||||
|
"123" : [1, 2, 3],
|
||||||
|
"ofString" : [ "a", "b", "c" ]
|
||||||
|
},
|
||||||
|
|
||||||
|
"booleans" {
|
||||||
|
"true" : true,
|
||||||
|
"trueAgain" : true,
|
||||||
|
"false" : false,
|
||||||
|
"falseAgain" : false
|
||||||
|
},
|
||||||
|
|
||||||
|
"nulls" {
|
||||||
|
"null" : null,
|
||||||
|
"nullAgain" : null
|
||||||
|
}
|
||||||
|
}
|
@ -87,6 +87,6 @@ class EquivalentsTest extends TestUtils {
|
|||||||
// it breaks every time you add a file, so you have to update it.
|
// it breaks every time you add a file, so you have to update it.
|
||||||
assertEquals(2, dirCount)
|
assertEquals(2, dirCount)
|
||||||
// this is the number of files not named original.*
|
// this is the number of files not named original.*
|
||||||
assertEquals(8, fileCount)
|
assertEquals(9, fileCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,6 +172,8 @@ abstract trait TestUtils {
|
|||||||
|
|
||||||
private val validConfInvalidJson = List[ParseTest](
|
private val validConfInvalidJson = List[ParseTest](
|
||||||
"""{ "foo" = 42 }""", // equals rather than colon
|
"""{ "foo" = 42 }""", // equals rather than colon
|
||||||
|
"""{ foo { "bar" : 42 } }""", // omit the colon for object value
|
||||||
|
"""{ foo baz { "bar" : 42 } }""", // omit the colon with unquoted key with spaces
|
||||||
"""{ "foo" : bar }""", // no quotes on value
|
"""{ "foo" : bar }""", // no quotes on value
|
||||||
"""{ "foo" : null bar 42 baz true 3.14 "hi" }""", // bunch of values to concat into a string
|
"""{ "foo" : null bar 42 baz true 3.14 "hi" }""", // bunch of values to concat into a string
|
||||||
"{ foo : \"bar\" }", // no quotes on key
|
"{ foo : \"bar\" }", // no quotes on key
|
||||||
|
Loading…
Reference in New Issue
Block a user