Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit] parsing keyword or identifier
From: Brian Budge (brian.budge_at_[hidden])
Date: 2011-05-03 16:28:30


On Mon, May 2, 2011 at 7:18 PM, Hartmut Kaiser <hartmut.kaiser_at_[hidden]> wrote:

> Spirit grammars are still C++ and still obey the default C++ operator
> preferences. Use this instead:
>
>    BOOST_AUTO(fileName, *(char_ - keywordSym));
>
> and it will work.
>

Hi Hartmut -

Thanks for the input. I had tried this precedence before, and during
my mucking about I guess I forgot to put the parens back in. In any
case, the above production still doesn't work, because it continues
parsing until the end of the file...

TILT=foobar
1
2...

will eat everything. I'm not sure how to make it stop at the end of
the line, because I'm using the space-eating parser, which seems to
eat whitespace before checking the rules.

Additionally, I'm having trouble getting the parsed value into a
string. I can get the above example to work like this:

BOOST_AUTO(fileName, *((char_ - keywordSym) -
qi::digit))[ref(tiltFileName) = _1]);

I used digit because I know that a digit will follow the filename, but
if the filename contains a digit, of course this will fail. That's
one problem. The other problem is that tiltFileName only contains 'r'
after parsing. My hunch is that this is because the char_ parser
parses one character at a time, so only the last one is there. I
tried wrapping the production as (*((char_ -
keywordSym)-qi::digit))[...], but now I can't get the code to compile.

Any further ideas are much appreciated.

  Brian


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