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

[DISCUSSION]: Using dot-notation for setting values #257

Open
ThomasAdam opened this issue Sep 9, 2021 · 1 comment
Open

[DISCUSSION]: Using dot-notation for setting values #257

ThomasAdam opened this issue Sep 9, 2021 · 1 comment

Comments

@ThomasAdam
Copy link

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).

@flowerysong
Copy link
Contributor

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants