Search code examples
syntaxconfiguration-files

Configuration file syntax


I'm developing software that will utilize a config file. I don't know many syntaxes or formats of config files. Here are the two I know:

(common with .conf files)

[section]
key=value
#comment

or (common with .ini)

key value
; comment

My interest is something versatile that's almost a language. Let's say

[Default]
Start = 0
End = 10
Speed = 1

[Section 3-6]
Speed = 2

This would act as an override. However this isn't any convention that I know of. Is there a common syntax that allows for this?


Solution

  • This once-valid answer is being voted down in 2020, so I edited it.

    In 2011, I suggested you use an xml format. This was the de-facto standard then.

    The configuration document could have looked like this:

    <?xml version="1.0" encoding="utf-8">
    <configuraton>
        <default>
            <start>0</start>
            <end>10</end>
            <speed>1</speed>
        </default>
        <section from="3" to="6">
            <speed>2</speed>
        </section>
    </configuration>
    

    There are many libraries to parse such files.