Re: expected_function

Joel de Guzman <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
On 30/04/2016 1:04 AM, Stefan Dyulgerov wrote:
> Hello,
>
> does any one know why the expect_function has a member first?
>
> I was trying to see why i do not get on_error<fail> code and it seems, that
> the expect_function class has a logic that prevents some of the exceptions.
> Most notably there is a member called first, which eats all the exceptions
> in the beginning.
>
> I am trying to parse the word
>
> imports,
>
>     qi::rule < iterator, std::string(), ascii::space_type >
> m_identifier;
>     m_identifier = raw[ lexeme[(alpha | '_') > *( alpha | digit | '_')] ];
>
> imports is parsed
> 1imports is not parsed, however this code is not called:
> boost::throw_exception(Exception(first, last, component.what(context)));
>
> If i comment the logic seems to work fine. I see this is connected with some
> multipass parsing, which i do not use.

The expression a > b, is specified as:

Match a followed by b. If a fails, no-match. If b fails, throw an expectation_failure<Iter>

Hence, only b matters. If a does not match, then it is simply a parse
error, not an expectation failure.

In X3, you can use the expect directive instead:

   expect[a >> b]

HTH

reference: 
http://www.boost.org/doc/libs/1_60_0/libs/spirit/doc/html/spirit/qi/reference/operator/expect.html

Regards,
-- 
Joel de Guzman
http://www.ciere.com
http://boost-spirit.com
http://www.cycfi.com/


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.