Boost logo

Boost Users :

Subject: [Boost-users] [Spirit] Parser omits certain characters
From: beet (r.berlich_at_[hidden])
Date: 2013-10-31 19:51:07


Dear all,

For all of the following, please see the attached test-case.

I would like to specify certain characterstics of variables in the
following way: d(MY_DPAR_01,-10.3,12.8,100) . So in this case there is a
type-identifyer (d stands for "double") and then, in parantheses, a
variable name (or alternatively an index), a lower and upper boundary
and some integer parameter. What is contained in the list depends on the
parameter type.

It should then be possible to specify any number of variables, including
their properties, in a comma-separated list.

So I need to dissect a string like the following:

"d(MY_DPAR_01,-10.3,12.8,100), d(0,-10.3,12.8,100), i(SOME_IPAR_17,
0,5), b(SOME_BPAR)"

The first step, as I see it, is to seperate the "outer" list and to
store each variable description in a boost::tuple<char, std::string>,
where the char holds the type identifier and the std::string the part
inside the parantheses. Then, in the second step, I want to parse that
string according to what is expected for this particular type.

I have now run into the problem that the following rule in Boost.Spirit
"swallows" all non-alphanumeric characters.

qi::rule<std::string::const_iterator, std::string(), ascii::space_type>
varSpec = +(alnum | '_' | ',' | '.' | '+' | '-');

varSpec stands for the text inside of the parantheses. I would have
expected this to match any string of at least one of the listed
character types (i.e. alpha-numeric, underscore, etc.).

The rule

qi::rule<std::string::const_iterator, boost::tuple<char,
std::string>(), ascii::space_type> varString = char_("dfib") >> '(' >>
varSpec >> ')';

is then meant to separate the type-descriptor from the description.

Parsing with these yields the output

d: MYDPAR01103128100
d: 0103128100
i: SOMEIPAR1705
b: SOMEBPAR

on a Mac (Mavericks, Boost 1.54) i.e., only the alpha-numeric characters
remain. So clearly my assumption about the "varSpec" rule is wrong.

On a Ubuntu 13.10 System (Boost 1.54, g++ 4.8.1) I get the output

d:
d:
i:
b:

which is equally wrong.

Funnily, if I define varSpec simply as +char_, varSpec gives the correct
result on the Mac (haven't tried Ubuntu), but varString does not match
anything.

So I am at a loss here and would appreciate some help.

Best Regards and thanks for any help you can provide,
Beet




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net