提升精神 x3 解析为结构,如果它为空,则跳过成员
Boost spirit x3 parse into struct with skipping member if it empty
我正在尝试找出解析以下文本的方法
function() {body ...}
function(args_) {body...}
我应该对两个变体使用相同的结构,还是只能用一个结构来完成
struct function
{
std::string name_;
std::vector<std::string> args_;
statement_list body_;
};
我现在解析它的方式(如果没有参数,如何跳过参数(:
auto const identifier_def = raw[lexeme[(alpha | '_') >> *(alnum | '_')]];
auto const function_def =
lexeme["function" >> !(alnum | '_')] >> identifier
>> '(' >> ((identifier % ',') )>> ')'
>> '{' >> statement >> '}'
;
我可以解析带有参数的变体,但不能解析没有参数的变体!
我正在尝试使用类似OR运算符的东西,但没有成功。
谢谢!
作为快速提示,通常这有效:
>> '(' >> -(identifier % ',') >> ')'
根据特定类型(尤其是identifier
声明(,您可能会进行如下调整:
>> '(' >> (-identifier % ',') >> ')'
强制它的想法:
x3::rule<struct arglist_, std::vector<std::string> > { "arglist" }
= '(' >> (
identifier % ','
| x3::attr(std::vector<std::string> ())
)
>> ')';
相关文章:
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 如果基类包含双指针成员,则派生类的构造函数
- int数据类型的指针指向的是什么,如果是一个类的私有数据成员,我们创建了该类的两个对象?
- 基类中的默认析构函数禁用子类中的移动构造函数(如果有成员)
- 提升精神 x3 解析为结构,如果它为空,则跳过成员
- 在 C++ 中声明 const 对象需要用户定义的默认构造函数.如果我有一个可变成员变量,为什么不呢?
- 如果参数与数据成员的参数同名,该怎么办?
- 在C++中,如果成员引用在其声明中初始化,为什么需要存储空间?
- 检查私有成员变量是否在一定范围内,如果没有调整
- C++类析构函数删除成员(如果"owner"?
- 如果我必须覆盖非虚拟成员函数怎么办
- 如果模板中存在成员函数指针,如何获取该指针
- 如果函数是在类的主体中定义的,我是否需要在成员函数的返回类型中指定 typename?
- 如果类在 C++ 中具有常量或引用类型的非静态数据成员,为什么编译器不提供默认赋值运算符?
- 如果包含引用成员的类中缺少原始变量,为什么它仍然可以访问?
- 如果成员具有非平凡的noexcept赋值运算符,则默认的移动赋值不能显式为noexcept
- 如果成员对象是父类的一部分,则无法创建成员对象
- 在 C++ 中,如果成员指针指向某个数据,如何保护该数据不被修改
- 如果成员指针是成员变量,是否有一个boost或STL类可以包装成员指针?
- 在C++中,如果成员函数是虚拟的,什么时候可以使用静态绑定