关于人类可编辑数据文件格式/解析库的建议

发布于 2024-07-06 01:26:51 字数 535 浏览 4 评论 0原文

例如,现在我有一个自己的解决方案,它使用包含以下块的数据文件:

PlayerCharacter Fighter
  Hitpoints 25
  Strength 10
  StartPosition (0, 0, 0)
  Art
    Model BigBuffGuy
    Footprint LargeFootprint
  end
  InventoryItem Sword
  InventoryItem Shield
  InventoryItem HealthPotion
end
  • 人类可编辑(理想情况下具有最少的垃圾字符)
  • 对错误有弹性(最少的“哇,我无法再解析任何有用的东西”样式错误,因此我丢失了文件其余部分中的所有数据) - 但当然仍然能够识别和报告它们。 我的例子中唯一完整的失败案例是缺少“end”。
  • 嵌套结构样式数据
  • 数组/列表样式数据
  • 可定制的基础类型
  • 快速

是否有任何众所周知的解决方案可以满足/超出这些要求?

For example, right now I have a roll-my-own solution that uses data files that include blocks like:

PlayerCharacter Fighter
  Hitpoints 25
  Strength 10
  StartPosition (0, 0, 0)
  Art
    Model BigBuffGuy
    Footprint LargeFootprint
  end
  InventoryItem Sword
  InventoryItem Shield
  InventoryItem HealthPotion
end
  • human editable (w/ minimal junk characters, ideally)
  • resilient to errors (fewest 'wow i can't parse anything useful anymore' style errors, and thus i've lost all of the data in the rest of the file) - but still able to identify and report them, of course. My example the only complete failure case is missing 'end's.
  • nested structure style data
  • array/list style data
  • customizable foundation types
  • fast

Are there any well known solutions that meet/exceed these requirements?

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

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

发布评论

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

评论(6

迷鸟归林 2024-07-13 01:26:51

我想说最常见的选择是:

  1. JSON (官方网站) - 非常灵活,尽管标点符号可能需要一些时间让人们习惯
  2. INI - 使用起来超级简单,但数据类型有点有限
  3. XML - 非常灵活、常见,但有时太冗长

I'd say the most common choices are:

  1. JSON (offical site) - very flexible, though the punctuation can take a bit for people to get used to
  2. INI - super simple to use, but a bit limited in data-types
  3. XML - pretty flexible, common, but way too verbose sometimes
凹づ凸ル 2024-07-13 01:26:51

您可以尝试以下位置提供的 JSON: http://www.json.org/

它是为 javascript 设计的,最初使用网络。 但它非常干净,并且支持多种语言。

You could try JSON available at: http://www.json.org/

It was designed for javascript and web usage initially. But it's pretty clean, and supported in many languages.

紫南 2024-07-13 01:26:51

Lua 被设计为一种编程语言,其语法也让您可以轻松地将其用作标记语言,这样您就可以像代码一样包含数据文件。 许多计算机游戏都使用它来编写脚本,例如《魔兽世界》,因为它的速度快且易于使用。 然而它最初是为能源行业设计和维护的,所以有一个严肃的背景。

带有 S 表达式的方案也是一种非常好的但外观不同的数据语法。 最后,您获得了 XML,大多数入门级开发人员都了解它。 您还可以使用 ANTLR 等优秀的开发套件来推出自己定义明确且高效的解析器。

Lua was designed to be a programming language where the syntax lets you easily use it as a markup language as well, so that you include data files as if they were code. Many computer games use it for their scripting, such as World of Warcraft due to its speed and ease of use. However it's originally designed and maintained for the energy industry so there's a serious background.

Scheme with its S-expressions is also a very nice but different-looking syntax for data. Finally, you've got XML that has the benefit of the most entry-level developers knowing it. You can also roll your own well-defined and efficient parser with a nice development suite such as ANTLR.

离线来电— 2024-07-13 01:26:51

Yaml 是一个很好的解决方案,非常接近您所拥有的解决方案。 搜索一下。

Yaml is a good solution and very close to what you have. Search for it.

迷爱 2024-07-13 01:26:51

我赞同 YAML 建议。 它非常容易编辑,对错误非常宽容并且得到广泛支持(特别是在动态语言中)。

I second the YAML suggestion. It's extremely easy to edit, very forgiving of mistakes and widely supported (especially among the dynamic languages).

痴意少年 2024-07-13 01:26:51

我建议使用 JSON

  • 与 YAML 一样可读/可编辑
  • 如果您碰巧用于 Web,则可以将其 eval() 转换为 JavaScript 对象
  • 可能与 YAML 一样跨语言

I would suggest JSON.

  • Just as readable/editable as YAML
  • If you happen to use for Web then can be eval()'ed into JavaScript objects
  • Probably as cross language as YAML
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文