expected_function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

expected_function

Stefan Dyulgerov
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.

Reply | Threaded
Open this post in threaded view
|

Re: expected_function

Joel de Guzman
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: expected_function

sehe
On 08-05-16 02:26, Joel de Guzman wrote:
> In X3, you can use the expect directive instead:
>
>    expect[a >> b]
In Qi I tend to write `qi::eps > (a > b)` to explicitly expect at the
start of rules

------------------------------------------------------------------------------
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
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general