why does this boost::spirit::qi rule not work?

Posted by Tobias Langner on Stack Overflow See other posts from Stack Overflow or by Tobias Langner
Published on 2012-11-15T22:57:36Z Indexed on 2012/11/15 22:59 UTC
Read the original article Hit count: 286

I have a grammar that defines the following rules:

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;

and I want it to match the following strings:

test[1] testident.ident

and it should not match

test[1.2] testident.5

but it fails to match the first 2 strings.

The lexer constructor is as follows:

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;
}

Why don't I get a match for the mentioned strings?

Thank you Tobias

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost