人类和计算机可读的分层数据格式,具有跨文件继承性

发布于 2024-09-27 01:17:03 字数 680 浏览 3 评论 0原文

我正在寻找一种具有分层信息的文本文件的数据格式。这些文件将主要由人工输入创建(而不是由程序生成),但将主要由程序读取。主要要求是:

  1. 语法非常简单且整洁。 (例如:由选项卡定义的层次结构级别可以很好地工作。)如此简单,整个语言描述都适合一个页面。

  2. 干净简洁的心智模型。 (例如:树,其中叶子是 int、string、float、bool 类型的值,键是非叶子节点。稍微复杂一点的模型(例如字典)也可以)。

  3. 表示任何给定语义的单一方式;即,没有具有相同含义的等效语法。

  4. 最好是易于用Python等语言解析的;或可用于此目的的稳定库。

  5. 可以允许文件之间进行某种继承。也就是说,我想允许一个文件部分覆盖另一个文件。理想情况下,我什至希望允许多重继承,只需通过禁止从多个父级派生任何值来处理传统的解析顺序冲突。

  6. 不会为用户输入的数据带来任何陷阱(例如,不带引号的文本可以是 YAML 中的字符串,但如果它是保留字,则不是)。

它是现成可用的还是我需要从头开始构建它?

YAML 不起作用,因为它不允许文件之间的继承,具有如上所述的陷阱,并且有许多替代语法结构来完成相同的操作。

YAML / XML 不起作用,因为两者的描述都不适合一页之类的内容。

谢谢你!

I'm looking for a data format for text files with hierarchical information. These files will be created primarily by human input (rather than generated by programs), but will be read primarily by programs. The main requirements are:

  1. Very simple and uncluttered syntax. (Example: levels of hierarchy defined by tabs would work fine.) So simple that the whole language description would fit into a page.

  2. Clean and concise mental model. (Example: tree where leaves are values of types int, string, float, bool, and keys are non-leaf nodes. A slightly more complex model, say with dictionaries, is also ok).

  3. A single way to represent any given semantics; i.e., no equivalent syntax with the same meaning.

  4. Preferably easy to parse in a language like python; or stable libraries available for that purpose.

  5. Can allow some kind of inheritance between files. That is, I would like to allow one file to partially override another. Ideally I'd like to even allow multiple inheritance, with the traditional conflicts of order of resolution handled simply by prohibiting any value to be derived from more than one parent.

  6. Does not create any pitfalls for user-entered data (e.g., unquoted text can be a string in YAML, but if it is a reserved word, then it's not).

Is it something that is available off-the-shelf or do I need to build it from scratch?

YAML doesn't work because it doesn't allow inheritance between files, has pitfalls as described above, and has many alternative syntax constructs to do the same thing.

And YAML / XML doesn't work because the description of neither will fit onto anything like one page.

Thank you!

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

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

发布评论

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

评论(1

灯角 2024-10-04 01:17:03

我不知道有任何数据序列化语言可以满足您的所有这些要求。

我非常喜欢 JSON 和 OGDL(因为它们比 XML 更容易阅读),但它们(至少)都无法允许继承。

PS:维基百科此处对流行数据格式进行了比较。

PPS:我想你应该考虑编写一个 DSL内部(或)实现并不难实现,您可以使用 Python 本身作为宿主语言。

I don't know of any data serialization language that satisfies all of those requirements of yours.

I'm very fond of JSON and OGDL (because they are much easier to read then XML), but they both fail (at least) in allowing inheritance.

PS: Wikipedia has a comparison of popular data formats here.

PPS: I guess you should consider writing a DSL. A internal (or weak) implementation would not be that hard to implement, and you could use Python itself as the host language.

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