提升精神 - 单一结构,多重规则

时间:2013-01-25 03:43:32

标签: c++ boost boost-spirit

鉴于boost文档中的example,如何为同一个结构编写另一条规则?

例如,假设我希望解析器也接受如下规则:

start2 %=
        lit("employee2")
        >> '['
        >>  double_ >> ','
        >>  quoted_string >> ','
        >>  quoted_string >> ','
        >>  int_
        >>  ']'
        ;

这样输入就会接受格式为

的数据
employee { int, "string", "string", double} 

OR

employee2 [ double, "string", "string", int")

使用与示例中提供的结构相同的结构。这可能不必使用另一个“适配器”结构吗?如果是这样,怎么样?

0 个答案:

没有答案