|
Boost Users : |
From: Todd Day (today_at_[hidden])
Date: 2006-02-23 09:34:33
There has got to be a very very easy problem, but I've been knocking
around for the better part of 12 hours in the docs and the examples and
in google groups and the spirit list, and I've not made any progress.
There must be some basic concept I'm totally missing out on. This is my
first cut at using Spirit.
I have the following, which is a simplified version of what I'm really
after. Basically, I have to look for strings of the form (including the
quotes)
"ParmName: ParmValue"
I'm looking for certain ParmNames, and I have to grab the associated
ParmValue. This is what the code below is supposed to do.
list<string> sl;
rule<> parm_string = ch_p('"') >> str_p("DeviceName") >> ch_p(':') >>
*blank_p >> (*~ch_p('"'))[push_back_a(sl)] >> ch_p('"');
rule<> r = *~ch_p('"') >> parm_string;
parse(str, *r);
This works just find when
str = " (text \"DeviceName: Altera in Controller\" (blah))";
It properly returns to me only the value, which is
Altera in Controller
However, inserting the quoted word "broken" is enough to break it, like
so
str = "\"broken\" (text \"DeviceName: Altera in Controller\" (blah))";
In other words, it doesn't work if non-matching random quoted text is
found. The problem in my rule r is the *~ch_p('"'). I thought this
rule would mean, (a) eat all non-quoted characters until followed by (b)
my parm match. But the rule really says, (a) eat all non-quoted
characters, then stop working if it isn't followed by (b) my parm match.
I think I might be screwed here since *anychar_p is greedy and I can't
figure out how to otherwise skip over bad stuff.
It still doesn't make sense to me that the simpler
parse(str, *parm_string)
does not work. I'm not sure why I have to specify the characters I want
to skip if I've specified the characters I want to match.
Perplexed, and thanking you profusely in advance for any help,
-todd-
PS - hopefully, any solution does not involve a skip rule. These don't
seem to work when parsing file_iterators, which is what I'm really
trying to do. I get compile errors that I don't get when using the
simple string version of parse(). Also, don't skip rules run *after* a
match has first been made?
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