hauns | 1 Feb 11:50
Picon

name() and on_error

i now have spent already more time on this than i should, so i might as well ask. i noticed that in all published
examples on the use of the on_error<fail> clause that a preceding section of statements names the rules
within the grammar elaboratively:

  term.name("term");
  factor.name("factor");

however, i cannot see where that name is actually used (i.e., calling rule.name()). in our standard error
handler, how would i go about accessing the name of the rule that failed? i am thinking of something like:

struct error_handler_phx
  {
    template <typename, typename, typename>
    struct result { typedef void type; };

    template <typename Iterator>
    void operator()(qi::info const& what, Iterator pos, Iterator last) const
    {
      std::cout << "error in rule " << HOW_TO_ACCESS_RULE.NAME()_HERE? << ": expecting " << what << " at " <<
std::string(pos,last) << std::endl;
    }
  };

passing in an extra string with the rule name appears awkward as the rule was already named, so it should be
somehow available to the handler. thanks!

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
(Continue reading)

Joel de Guzman | 1 Feb 12:42
Picon
Favicon

Re: name() and on_error

On 2/1/2010 6:50 PM, hauns <at> mac.com wrote:
> i now have spent already more time on this than i should, so i might as well ask. i noticed that in all
published examples on the use of the on_error<fail>  clause that a preceding section of statements names
the rules within the grammar elaboratively:
>
>    term.name("term");
>    factor.name("factor");
>
> however, i cannot see where that name is actually used (i.e., calling rule.name()). in our standard error
handler, how would i go about accessing the name of the rule that failed? i am thinking of something like:
>
> struct error_handler_phx
>    {
>      template<typename, typename, typename>
>      struct result { typedef void type; };
>
>      template<typename Iterator>
>      void operator()(qi::info const&  what, Iterator pos, Iterator last) const
>      {
>        std::cout<<  "error in rule "<<  HOW_TO_ACCESS_RULE.NAME()_HERE?<<  ": expecting "<<  what<<  " at "<< 
std::string(pos,last)<<  std::endl;
>      }
>    };
>
> passing in an extra string with the rule name appears awkward as the rule was already named, so it should be
somehow available to the handler. thanks!

qi::info const& what gives you the name of the rule. That is evident in the
examples, e.g (mini_c.hpp):

(Continue reading)

hauns | 1 Feb 13:06
Picon

Re: name() and on_error

Joel de Guzman <joel <at> boost-consulting.com> writes:

> qi::info const& what gives you the name of the rule. That is evident in the
> examples, e.g (mini_c.hpp):
> 
>      std::cout
>          << "Error! Expecting "
>          << what                         // what failed?
>          << " here: \""
>          << std::string(err_pos, last)   // iterators to error-pos, end
>          << "\""
>          << std::endl
>      ;

thanks for the prompt reply. to illustrate my case, if rule "upper" fails,

  upper %= raw[lexeme[ char_("A-Z") > *char_("A-Z_") ]];

while parsing string "CamelBackExpression" i get the following output:

  error: expecting <char-set> at amelBackExpression

i.e., yes it failed in enclosed rule "char-set" (= char_), but no mention of 
"upper". how can i access the name of the enclosing rule? is it a matter
of correct usage of >>/> operators? thanks

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
(Continue reading)

Joel de Guzman | 1 Feb 13:32
Picon
Favicon

Re: name() and on_error

On 2/1/2010 8:06 PM, hauns wrote:
> Joel de Guzman<joel<at>  boost-consulting.com>  writes:
>
>> qi::info const&  what gives you the name of the rule. That is evident in the
>> examples, e.g (mini_c.hpp):
>>
>>       std::cout
>>           <<  "Error! Expecting"
>>           <<  what                         // what failed?
>>           <<  " here: \""
>>           <<  std::string(err_pos, last)   // iterators to error-pos, end
>>           <<  "\""
>>           <<  std::endl
>>       ;
>
> thanks for the prompt reply. to illustrate my case, if rule "upper" fails,
>
>    upper %= raw[lexeme[ char_("A-Z")>  *char_("A-Z_") ]];
>
> while parsing string "CamelBackExpression" i get the following output:
>
>    error: expecting<char-set>  at amelBackExpression
>
> i.e., yes it failed in enclosed rule "char-set" (= char_), but no mention of
> "upper". how can i access the name of the enclosing rule? is it a matter
> of correct usage of>>/>  operators? thanks

Ah, no, that will only be the case if it is 'upper' that actually triggered
the error. E.g.:

(Continue reading)

Hartmut Kaiser | 1 Feb 13:35
Picon
Gravatar

Re: name() and on_error

> > qi::info const& what gives you the name of the rule. That is evident
> in the
> > examples, e.g (mini_c.hpp):
> >
> >      std::cout
> >          << "Error! Expecting "
> >          << what                         // what failed?
> >          << " here: \""
> >          << std::string(err_pos, last)   // iterators to error-pos,
> end
> >          << "\""
> >          << std::endl
> >      ;
> 
> thanks for the prompt reply. to illustrate my case, if rule "upper"
> fails,
> 
>   upper %= raw[lexeme[ char_("A-Z") > *char_("A-Z_") ]];
> 
> while parsing string "CamelBackExpression" i get the following output:
> 
>   error: expecting <char-set> at amelBackExpression
> 
> i.e., yes it failed in enclosed rule "char-set" (= char_), but no
> mention of
> "upper". how can i access the name of the enclosing rule? is it a
> matter
> of correct usage of >>/> operators? thanks

Since you know which handler got called you can deduce to what rule it
(Continue reading)

hauns | 1 Feb 14:08
Picon

Re: name() and on_error

Joel de Guzman <joel <at> boost-consulting.com> writes:

> Ah, no, that will only be the case if it is 'upper' that actually triggered
> the error. E.g.:
> 
>      xxx > upper
> 
> Then, your outer error handler will get that. There is no way to get
> the name of the outer rule from an arbitrary inner expression. The data
> is not available in the error handler.
> 
> It is possible to provide you with that information. We can do that
> if there's enough interest in it. OTOH, it is also easy to write
> your own on_error function that attaches the rules name through
> bind, so I'm not sure if that's really needed...

thanks, this is exaaactly what i meant! so passing in the rule's name is the 
way to go for now.

it is true that the violation was triggered by the nested char_ rule, however,
the handler was registered on the outer rule originally. so it would maybe not 
be a bad idea that the handler retains a link to the rule it is attached as 
well. 

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
(Continue reading)

Georg Fritzsche | 1 Feb 18:09
Gravatar

Re: storing line numbers of expressions with Qi

Chris Hoeppler wrote:
> Have you seen the iter_pos-parser:
> 
> http://boost-spirit.com/home/articles/qi-example/creating-your-own-parser-component-for-spirit-qi
> 
> There's a position iterator in Spirit.Classic that can also be 
> used with Qi:
> 
> http://www.boost.org/doc/libs/1_41_0/libs/spirit/classic/doc/position_iterator.html

Thank you, i managed to miss the article as well that position iterators 
can be used with Qi too.

Regards,
Georg

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Chris Hoeppler | 1 Feb 21:20
Picon

Re: Comment parsers

> >>>> Are there any comment parsers in 2.1 like there are in Classic??
> >>>
> >>> There is the confix parser component in the repository:
> >>> http://tinyurl.com/yz9wa3l. The docs show how you can use it to
> >>> build your
> >>> own comment parsers.
> >>
> >> I followed the instruction on the website, however, I'm not getting
> >> the right parsing results. In particular, the C++ comment parser is
> >> not detecting C++ style comments
> >
> > I would like to see the usual: minimal, self-contained code I can
> > compile
> > and run.
>
> Sure, I will get that to you. Have to strip out a LOT of stuff from
> the code.
>
> >> and the both the C and C++ comment
> >> parser are removing *spaces* from the comment. So for example, the
> >> following comment:
> >>
> >>   /* This is a C comment */
> >>
> >> is returned as
> >>
> >>  ThisisaCcomment
> >
> > That's probably because you are using a skipper eating the
> > whitespace. In
(Continue reading)

John Wilkinson | 1 Feb 21:44
Picon
Favicon

variant containing double and int

Hi I am starting a port from classic to Spirit2. I am impressed by how attributes work but am now stuck after
adding doubles to a variant already parsing ints and strings. The problem seems to be that it always
prefers to parse an int in preference to a double, i.e. is reads "123.345" as int 123 and stops at the dot. I
have tried implementing a "strict double", i.e. ( double_ - int_ ), but inlining it doesn't make and
difference, it still finds an int. If I move the strict double parse into a rule there is a compilation error
variant.hpp. I have included the full code, any help would be appreciated,

Thanks
John W

#include "stdafx.h"
#include <vector>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/spirit/include/qi_core.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_list.hpp>
#include <boost/spirit/repository/include/qi_confix.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/cstdint.hpp> 
#include <boost/variant.hpp> 

using namespace std;
using namespace boost;

namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;

namespace
{
(Continue reading)

Joel de Guzman | 2 Feb 00:38
Picon
Favicon

Re: variant containing double and int

On 2/2/2010 4:44 AM, John Wilkinson wrote:
> Hi I am starting a port from classic to Spirit2. I am impressed by how attributes work
> but am now stuck after adding doubles to a variant already parsing ints and strings.
> The problem seems to be that it always prefers to parse an int in preference to a
> double, i.e. is reads "123.345" as int 123 and stops at the dot. I have tried
> implementing a "strict double", i.e. ( double_ - int_ ), but inlining it doesn't make
> and difference, it still finds an int. If I move the strict double parse into a rule
> there is a compilation error variant.hpp. I have included the full code, any help would
> be appreciated,
>

Spirit provides the strict_real_policies. Use it. Try this:

     qi::real_parser<double, qi::strict_real_policies<double> > strict_double;

     start_ = quoted_str_ >> ':' >> value_;
     value_ = quoted_str_ | strict_double | qi::int_;
     quoted_str_ = lexeme[ '"' >> *(char_ - '"') >> '"' ];

Regards,
--

-- 
Joel de Guzman
http://www.boostpro.com
http://spirit.sf.net
http://www.facebook.com/djowel

Meet me at BoostCon
http://www.boostcon.com/home
http://www.facebook.com/boostcon

(Continue reading)


Gmane