libucl
libucl copied to clipboard
[DISCUSSION]: Using dot-notation for setting values
Hello,
It's currently possible via ucl_object_lookup_path()
to lookup objects. For example, given the following configuration:
section {
A {
B {
key = value;
}
}
}
You could use the string:
"section.A.B.key"
Which would return value
.
I'm proposing that we can do the inverse, and change the parser, such that the following examples are possible:
section.A.B.key = "value";
foo.bar.baz = [1,2,3,4];
... which would result in:
section {
A {
B {
key = "value";
}
}
}
foo {
bar {
baz = [1,2,3,4]
}
}
I know it's possible to do:
section "A" "B" {
key = value
}
But this isn't quite the same thing as what I'm suggesting.
I suppose we might have an issue whereby if someone has:
section.A.B.key = value
In their config already, then the existing parser will use section.A.B.key
as the key, and value
as its value, so there might be a slight backwards-compatible issue.
What do you think? I'm happy to do the work, but wanted to check before going ahead.
One of the reasons for suggesting this, is it makes it possible to create configuration values which are entirely line-based (rather than block-based).
I'm strongly against this suggestion; it changes the syntax in a backwards-incompatible way for very little gain.
The current syntax already allows you to express your examples as single lines:
section A B { key = value }
foo bar baz [1,2,3,4]