4

I would like to match a C++ function declaration with default argument values, but ignoring these values. For example:

int myFunction(int a, int b = 5 + 4);

Here is (a part of) the lexer:

struct Lexer : boost::spirit::lex::lexer<lexer_type>
{
    Lexer()
    {
        identifier = "[A-Za-z_][A-Za-z0-9_]*";
        numLiteral = "([0-9]+)|(0x[0-9a-fA-F]+)";

        this->self.add
            ("int")
            ('+')
            ('=')
            ('(')
            (')')
            (';')
            (',')
            (identifier)
            (numLiteral);
    }
};

I would like to write a couple of parser rules like:

function = qi::lit("int") >> lexer.identifier >> '(' >> arglist >> ')' >> ';';
arglist = (lexer.numLiteral >> lexer.identifier >> -(lit('=') >> rvalue )) % ',';
rvalue = +(qi::token() - ',' - ')');

I've seen here that "The parser primitives qi::token and qi::tokenid can now be used without any argument. In this case they will match any token.". Which is what I want (and what I wrote), but unfortunately it does not compile. qi::token() really needs at leat one argument. Did I miss something?

ZeeByeZon
  • 112
  • 8
  • You don't show any SSCCE, so I'm not going waste any time. Have you tried without the parentheses (this is a EDSL convention, _cf._ `qi::string` vs. `qi::string("value")`) – sehe Jun 09 '15 at 09:15
  • Thank you @sehe for the tip: no parentheses. Now it compiles. By the way, what is EDSL? – ZeeByeZon Jun 09 '15 at 09:27
  • Edsl: [Embedded Domain Specific Language](http://c2.com/cgi/wiki?EmbeddedDomainSpecificLanguage) (spirit's expressions templates are an example; Phoenix's lazy actors [in semantic actions] are another) – sehe Jun 09 '15 at 09:58

1 Answers1

2

Ok, since this was apparently enough to answer it:

Which is what I want (and what I wrote), but unfortunately it does not compile. qi::token() really needs at leat one argument. Did I miss something?

Probably you didn't miss enough: did you leave the ()? Because in the EDSL it's convention to drop the parentheses for the parameter-less version (cf. qi::string vs. qi::string("value"))

sehe
  • 374,641
  • 47
  • 450
  • 633