关于人类可编辑数据文件格式/解析库的建议
例如,现在我有一个自己的解决方案,它使用包含以下块的数据文件:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我想说最常见的选择是:
I'd say the most common choices are:
您可以尝试以下位置提供的 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.
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.
Yaml 是一个很好的解决方案,非常接近您所拥有的解决方案。 搜索一下。
Yaml is a good solution and very close to what you have. Search for it.
我赞同 YAML 建议。 它非常容易编辑,对错误非常宽容并且得到广泛支持(特别是在动态语言中)。
I second the YAML suggestion. It's extremely easy to edit, very forgiving of mistakes and widely supported (especially among the dynamic languages).
我建议使用 JSON。
I would suggest JSON.