配置文件语法

发布于 2024-12-03 11:35:45 字数 362 浏览 3 评论 0原文

我正在开发将利用配置文件的软件。我不知道配置文件的很多语法或格式。以下是我所知道的两个:(

与 .conf 文件常见)

[section]
key=value
#comment

或(与 .ini 常见)

key value
; comment

我的兴趣是几乎是一种语言的多功能事物。假设

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

[Section 3-6]
Speed = 2

这将充当覆盖。然而,据我所知,这不是任何约定。是否有允许这样做的通用语法?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘你却要生生世世 2024-12-10 11:35:45

截至 2015 年,xml 不再是事实上的标准。以下是选项。

TOML

# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[servers]

  # tabs / spaces ok but not required
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

YAML

%YAML 1.2
---
YAML: YAML Ain't Markup Language

Projects:
  C/C++ Libraries:
  - libyaml       # "C" Fast YAML 1.1
  - Syck          # (dated) "C" YAML 1.0
  - yaml-cpp      # C++ YAML 1.2 implementation

CSON

# Comments!!!

greatDocumentaries: [
    'earthlings.com'
    'forksoverknives.com'
]

importantFacts:
    # Multi-Line Strings! Without Quote Escaping!
    emissions: '''
        Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
        '''

JSON5Human JSON - 灵活的 json 超集

属性文件 - 由 java 程序使用

As of 2015, xml is no longer the de facto standard. Here are options.

TOML

# This is a TOML document.

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[servers]

  # tabs / spaces ok but not required
  [servers.alpha]
  ip = "10.0.0.1"
  dc = "eqdc10"

YAML

%YAML 1.2
---
YAML: YAML Ain't Markup Language

Projects:
  C/C++ Libraries:
  - libyaml       # "C" Fast YAML 1.1
  - Syck          # (dated) "C" YAML 1.0
  - yaml-cpp      # C++ YAML 1.2 implementation

CSON

# Comments!!!

greatDocumentaries: [
    'earthlings.com'
    'forksoverknives.com'
]

importantFacts:
    # Multi-Line Strings! Without Quote Escaping!
    emissions: '''
        Livestock and their byproducts account for at least 32,000 million tons of carbon dioxide (CO2) per year, or 51% of all worldwide greenhouse gas emissions.
        '''

JSON5 and Human JSON - flexible json supersets

Properties File - used by java programs

听不够的曲调 2024-12-10 11:35:45

这个曾经有效的答案将在 2020 年被否决,所以我对其进行了编辑。

2011年,我建议你使用xml格式。这是当时事实上的标准。

配置文档可能如下所示:

<?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>

有许多库可以解析此类文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文