
2013/11/5 beet <r.berlich@gemfony.eu>
Dear Tongari, dear all,
[...]
I have created the following rule:
qi::rule<std::string::const_iterator, VARTYPE(), ascii::space_type> varReference = ( (attr(0) >> attr("empty") >> uint_) | (attr(1) >> identifier >> '[' >> uint_ >> ']') | (attr(2) >> identifier >> attr(0)) );
Here, VARTYPE is a typedef for boost::tuple<std::size_t, std::string, std::size_t>, and "identifier" stands for lexeme[+char_("0-9a-zA-Z_")] as per your suggestion.
The idea is to provide the user with a mode-variable to allow easy distinction between all three cases, and to fill unused parts of the tuple with some placeholder (such as "empty" or 0), with the help of attr(). So the first entry of the tuple represents the mode, the second the variable name and the third an optional index.
Now, parsing a string like "MY_DPAR_02[3]" yields "emptyMY_DPAR_02" for the std::string component of the tuple, and "SOME_IPAR_17" results in "emptySOME_IPAR_17SOME_IPAR_17" . Parsing a single 0 yields the correct result.
So the parser seems to go through all three components of varReference, until it finds a matching rule. However, instead of overwriting the std::string with the string it has found, it appears to concatenate the strings of all rules it has gone through.
Try this: http://www.boost.org/doc/libs/1_54_0/libs/spirit/doc/html/spirit/qi/referenc...
This is a bit mysterious to me and I would appreciate your help.
HTH