Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit] This parser hang
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-12-01 12:02:41


> Yes, I'm targeting V2. Actually I try to make parser that match string
> that doesn't contain several characters. Is this the right way to do it :
>
> +(~(char_(':')|'*'|'?'))

Use character classes: http://tinyurl.com/32ttlm9
(http://www.boost.org/doc/libs/1_45_0/libs/spirit/doc/html/spirit/qi/referen
ce/char/char.html#spirit.qi.reference.char.char.char__def_):

    +~char_(":*?")

> Is there any mention in spirit documentation that mention char parser must
> use operator~() instead of operator !()? I don't see any operator ~() in
> parser operators section in doc, what it is mean anyway ?

See here: http://tinyurl.com/374udfb
(http://www.boost.org/doc/libs/1_45_0/libs/spirit/doc/html/spirit/qi/referen
ce/char/char.html#spirit.qi.reference.char.char.expression_semantics)

Beware the operator!() is wrong in this situation in any case. It does not
stand for 'not' but for the 'not predicate': http://tinyurl.com/3abjhsr
(http://www.boost.org/doc/libs/1_45_0/libs/spirit/doc/html/spirit/qi/referen
ce/operator/not_predicate.html).

Regards Hartmut
---------------
http://boost-spirit.com

>
> Thanks for your quick response.
>
> --- Pada Rab, )1/12/10, Hartmut Kaiser <hartmut.kaiser_at_[hidden]> menulis:
>
> Dari: Hartmut Kaiser <hartmut.kaiser_at_[hidden]>
> Judul: Re: [Boost-users] [spirit] This parser hang
> Kepada: boost-users_at_[hidden]
> Tanggal: Rabu, 1 Desember, 2010, 8:49 AM
> > This code:
> >
> > std::string s("blablabla");
> >
> > std::string::iterator start = s.begin(); std::string::iterator finish
> > = s.end();
> >
> > bool result = phrase_parse(start, finish, +(!char_(':')), space);
> >
> > It's just a simple parser that match string which doesn't have ':'
> > character in it right ? But when I run it, function phrase_parse is
> > hang, it never return anything.
> > I'm using boost 1.44 with VC 2008
>
> Are you using Spirit V2.x or Spirit.Classic? I'm asking as the meaning for
> the operator '!' has changed. In Spirit.Classic it stands for 'optional',
> while in Spirit V2.x it stands for the 'not predicate' (which is
> different).
>
>
> I assume you're targeting V2.x, therefore it has to be:
>
>     +(~char_(':'))
>
> instead. Note, the operator~() is applicable to character parsers only. If
> you need 'A but not B' in the general case, use:
>
>    +(char_ - char_(':'))
>
> (but for character parsers the first is much more efficient).
>
> Regards Hartmut
> ---------------
> http://boost-spirit.com
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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