Git Product home page Git Product logo

Comments (8)

jmgurney avatar jmgurney commented on July 17, 2024

if I'm given guidance on what the examples should look like, I'm more than willing to submit an update.

from libucl.

vstakhov avatar vstakhov commented on July 17, 2024

That works fine with Lua.

local u = require "ucl"
local p = u.parser()
p:parse_file('tt.ucl')
print(u.to_json(p:get_object()))

gives:

{
    "section": {
        "number": 10000,
        "subsection": {
            "host": [
                {
                    "host": "hostname",
                    "port": 900
                },
                {
                    "host": "hostname",
                    "port": 901
                }
            ]
        },
        "flag": true,
        "param1": "value1",
        "time": 0.200000,
        "string": "something",
        "param": "value"
    },
    "param": "value"
}

Unfortunately, I don't know the details about how Python part works as it has been contributed by another person.

from libucl.

jmgurney avatar jmgurney commented on July 17, 2024

I'll take a look at the python. But will you be updating the JSON in the example to match the above? I only even tried this because of the mismatch.

from libucl.

jmgurney avatar jmgurney commented on July 17, 2024

Ok, looks like lua is treating objects as arrays in special, undocumented cases (at least I couldn't find anything about checking obj->next in libucl/doc):
https://github.com/vstakhov/libucl/blob/master/lua/lua_ucl.c#L156

Which is why it works, and it doesn't work on the Python code:
https://github.com/vstakhov/libucl/blob/master/python/src/uclmodule.c#L46

from libucl.

vstakhov avatar vstakhov commented on July 17, 2024

Yes, multi-value keys were the biggest design mistake in UCL, I agree :(

from libucl.

jmgurney avatar jmgurney commented on July 17, 2024

why not simply change libucl to return the object as an array when that happens? at least it'd give expected results in that consumers should be treating them as arrays instead of objects.

It'd also catch cases where consumers weren't expecting an object become array, and also handle the POLA case where the consumer wasn't handling it (e.g. this python library), and the other objects just disappear, or ignored causing the end user no idea WHY their configuration isn't working the way they expected it to.

from libucl.

vstakhov avatar vstakhov commented on July 17, 2024

why not simply change libucl to return the object as an array when that happens?

libucl has a parser flag to do that: UCL_PARSER_NO_IMPLICIT_ARRAYS

from libucl.

jmgurney avatar jmgurney commented on July 17, 2024

Ok, adding the flag fixes UCL_PARSER_NO_IMPLICIT_ARRAYS the python test case. I'll submit a PR for Python module including a test for this case.

from libucl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.