Re: lexeme_d converse?
Jeff Flinn <TriumphSprint2000 <at> hotmail.com>
2007-08-01 12:42:49 GMT
Another correction inline.
Jeff Flinn wrote:
> CARL BARRON wrote:
>> On Jul 31, 2007, at 9:28 AM, Jeff Flinn wrote:
>>
>>> Below is an exemplary snippet of what I'm trying to accomplish. I'd
>>> like
>>> to skip "-" and "--" anywhere in the string. I'm stumped on how to
>>> accomplish this using spirit symbols. Would I need to write a filtering
>>> input iterator? Or would I need to add all combinations "AAA", "A-AA",
>>> "A--AA", "AA-", ... to the symbol table? This could become unruly.
>>>
>>> All ideas appreciated, Jeff
>
> ...
>
>> you can use a skipper to skip one or two -'s.
>> parse_info<> lOk1 = parse( lTxt.c_str
>> , *sym[push_back_a(out)] >> !end_p
>> ,ch_p('-') >> !ch_p('-')
>> );
>
> This results in:
>
> lOk1 = {stop=0x00357714 "B-BB---CC--C" hit=true full=false...}
>
> "B-BB" is not matched by sym. This also would prevent "---" from
> matching sym as well. Hence the title "Lexeme_d converse". I need the
> single and double dashes to be skipped by the skipper, but triples to be
> passed through to the symbol parser as a completed entity.
>
> Here is the fully compilable code that distills my issue, correcting a
> few ommisions/errors in the previous posting.
>
> #include <boost/spirit.hpp>
> #include <vector>
> #include <string>
>
> using namespace boost::spirit;
>
> int main()
> {
> symbols<std::string> sym;
>
> sym.add("AAA","xxx") ("BBB","yyy") ("CCC","zzz") ("---"," ");
>
> std::string lTxt = "AAA-B-BB---CC--C";
>
> std::vector<std::string> out; // "xxx", "yyy", "---", "zzz"
and the desired output should be:
> std::vector<std::string> out; // "xxx", "yyy", " ", "zzz"
>
> parse_info<> lOk1 = parse( lTxt.c_str()
> , *sym[push_back_a(out)] >> !end_p
> ,ch_p('-') >> !ch_p('-')
> //, (str_p("--")>>~eps_p('-'))
> //| (str_p("-") >>~eps_p('-'))
> );
>
> //lOk1= {stop=0x00357714 "B-BB---CC--C" hit=true full=false...}
>
> return 0;
> }
>
> Thanks, Jeff
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/