用于未排序模式的boost :: Spirit语法 [英] boost::Spirit Grammar for unsorted schema

查看:100
本文介绍了用于未排序模式的boost :: Spirit语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一部分模型需要解析.可以这样说.

I have a section of a schema for a model that I need to parse. Lets say it looks like the following.

{
  type = "Standard";
  hostname="x.y.z";
  port="123";
}

属性为:

  1. 这些元素可能显示为无序.
  2. 作为架构一部分的所有元素都必须出现,并且没有其他元素.
  3. 所有元素的综合属性都放入一个结构中.
  4. (可选)将来,架构可能取决于类型字段-即基于类型的不同字段-但是我目前对此并不担心.

推荐答案

根据Spirit论坛,以下是答案.

According to the Spirit forums, the following is the answer.

您可能想看看 排列解析器:

You might want to have a look at the permutation parser:

a ^ b ^ c 

与a或b或c(或a 组合).

Which matches a or b or c (or a combination thereof) in any sequence.

如果目标是解析为一个结构,那么测试所有必需成员已初始化的最佳方法不是测试天气,最好用boost::optional<>包装该结构成员.然后可以在运行期间的解析后轻松测试该属性的存在时间.

If the objective is to parse into a struct, than the best way to test weather all essential members have been initialized, the struct members should be wrapped with boost::optional<> The attribute presence may then be easily tested post-parsing during run-time.

这篇关于用于未排序模式的boost :: Spirit语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆