所以我的问题很简单,在我的词法分析器类(扩展lex::lexer<T>
)中,我有以下内容;
this->self.add
...
("&&", AND_AND)
("||", OR_OR)
...
在我的构造函数内部,它编译得很好,但在运行时触发了 SegFault。问题很明显|
是正则表达式系统中的“或”运算符,我该如何解决这个问题?
所以我的问题很简单,在我的词法分析器类(扩展lex::lexer<T>
)中,我有以下内容;
this->self.add
...
("&&", AND_AND)
("||", OR_OR)
...
在我的构造函数内部,它编译得很好,但在运行时触发了 SegFault。问题很明显|
是正则表达式系统中的“或”运算符,我该如何解决这个问题?
From http://www.boost.org/doc/libs/1_54_0/libs/spirit/doc/html/spirit/lex/quick_reference/lexer.html
\X
If X is a, b, e, n, r, f, t, v then the ANSI-C interpretation of \x. Otherwise a literal X (used to escape operators such as *)
So you would use
("\\|\\|", OR_OR)
The first backslash in each pair is treated as an escape character by the C++ string parser, causing the second one to be placed into the string content. That backslash in the string content then is seen by Spirit::Lex and acts to escape the regex operator.