Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用spirit x3解析后跟字符串列表的字符串列表_C++_Parsing_C++14_Boost Spirit_Boost Spirit X3 - Fatal编程技术网

C++ 使用spirit x3解析后跟字符串列表的字符串列表

C++ 使用spirit x3解析后跟字符串列表的字符串列表,c++,parsing,c++14,boost-spirit,boost-spirit-x3,C++,Parsing,C++14,Boost Spirit,Boost Spirit X3,我正在尝试使用boost spirit x3将字符串解析为结构: struct identifier { std::vector<std::string> namespaces; std::vector<std::string> classes; std::string identifier; }; 我的解析器规则如下所示 auto const nested_identifier_def = x3::lexeme[

我正在尝试使用boost spirit x3将字符串解析为结构:

struct identifier {
    std::vector<std::string> namespaces;
    std::vector<std::string> classes;
    std::string identifier;

};
我的解析器规则如下所示

auto const nested_identifier_def =
        x3::lexeme[
                -(id_string % "::")
                >> -(id_string % ".")
                >> id_string
        ];
其中
id\u string
解析
alphanum
的组合。 我知道这条规则不能按我所希望的那样进行解析,因为在解析
foo.bar
时,例如规则的这一部分
-(id\u string%”)
会消耗整个字符串。
如何更改规则以在结构中正确解析?

假设您的
id\u字符串是这样的:

foo::bar::baz.bla.blub
foo.bar
boo::bar
foo
auto const id_string = x3::rule<struct id_string_tag, std::string>{} =
    x3::lexeme[
            (x3::alpha | '_')
        >> *(x3::alnum | '_')
    ];

问题在于,
p%different
p>>*(different>>p)
的简写,即它总是在分隔符后消耗一个
p
。但是,您需要的是
*(p>>定界)
,这样就不会在定界符之后使用
p
,而是留给下一个规则使用

auto const nested_identifier_def =
       *(id_string >> "::")
    >> *(id_string >> '.')
    >>  id_string;