我有一个定义以下规则的语法:
constantValue = qi::token(ID_FLOAT) | qi::token(ID_INTEGER);
postfixExpression = primaryExpression |
(postfixExpression >> qi::token(ID_OPENBRACKET) >> qi::token(ID_INTEGER) >> qi::token(ID_CLOSEBRACKET)) |
(postfixExpression >> qi::token(ID_DOT) >> qi::token(ID_IDENTIFIER));
primaryExpression = qi::token(ID_IDENTIFIER) |
constantValue |
(qi::token(ID_OPENPAREN) >> primaryExpression >> qi::token(ID_CLOSEPAREN));
ges = postfixExpression >> qi::eoi;
我希望它匹配以下字符串:
测试[1] testident.ident
它不应该匹配
测试[1.2] testident.5
但它无法匹配前 2 个字符串。
词法分析器构造函数如下:
custom_lexer()
: identifier("[a-zA-Z_][a-zA-Z0-9_]*")
, white_space("[ \\t\\n]+")
, integer_value("[1-9][0-9]*")
, hex_value("0[xX][0-9a-fA-F]+")
, float_value("[0-9]*\\.[0-9]+([eE][+-]?[0-9]+)?")
, float_value2("[0-9]+\\.([eE][+-]?[0-9]+)?")
, punctuator("&>|\\*\\*|\\*|\\+|-|~|!|\\/|%|<<|>>|<|>|<=|>=|==|!=|\\^|&|\\||\\^\\^|&&|\\|\\||\\?|:|,")// [ ] ( ) . &> ** * + - ~ ! / % << >> < > <= >= == != ^ & | ^^ && || ? : ,
{
using boost::spirit::lex::_start;
using boost::spirit::lex::_end;
this->self.add
(identifier, ID_IDENTIFIER)
/*(white_space, ID_WHITESPACE)*/
(integer_value, ID_INTEGER)
(hex_value, ID_INTEGER)
(float_value, ID_FLOAT)
(float_value2, ID_FLOAT)
("\\(", ID_OPENPAREN)
("\\)", ID_CLOSEPAREN)
("\\[", ID_OPENBRACKET)
("\\]", ID_CLOSEBRACKET)
("\\.", ID_DOT)
(punctuator, ID_PUNCTUATOR)
;
this->self("WS") = white_space;
}
为什么我找不到上述字符串的匹配项?
谢谢托比亚斯