Re: [Spirit & Karma] #2: Implement error handling

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

Re: [Spirit & Karma] #2: Implement error handling

Hartmut Kaiser
#2: Implement error handling
----------------------+-----------------------------------------------------
  Reporter:  hkaiser  |       Owner:  djowel  
      Type:  todo     |      Status:  new      
  Priority:  major    |   Milestone:  Spirit V2
 Component:  Spirit   |     Version:  Spirit V2
Resolution:           |    Keywords:          
----------------------+-----------------------------------------------------
Comment (by djowel):

 Done. We now have a cool error handling facility, thanks to Tobias
 suggestions. Sample:

 {{{
         rule<char const*> r;
         r = '(' > int_ > ',' > int_ > ')';
 }}}

 Notice the use of a > b. Unlike a >> b, a > b is a hard expectation. That
 is, if a is matched, b '''must''' match. Otherwise, an exception is
 thrown. The exception is then caught by the enclosing rule if an error
 handler is installed. Example:

 {{{
         r.on_error
         ((
             std::cout
                 << val("Error! Expecting: ")
                 << _4
                 << val(" Here: \"")
                 << construct<std::string>(_3, _2)
                 << val("\"")
                 << std::endl
         ));
 }}}

 Example results:

 {{{
     "(123,456)"        ok
     "(abc,def)"        Error! Expecting: integer Here: "abc,def)"
     "(123,456]"        Error! Expecting: ')' Here: "]"
     "(123;456)"        Error! Expecting: ',' Here: ";456)"
     "[123,456]"        the rule will fail parsing but should not throw
 }}}

--
Ticket URL: <http://fortytwo.cct.lsu.edu:8000/SpiritKarma/ticket/2#comment:1>
Spirit &amp; Karma <http://spirit.sourceforge.net>
Development of the Boost::Spirit V2 libraries
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel
Reply | Threaded
Open this post in threaded view
|

Re: [Spirit & Karma] #2: Implement error handling

Hartmut Kaiser
#2: Implement error handling
----------------------+-----------------------------------------------------
  Reporter:  hkaiser  |       Owner:  djowel  
      Type:  todo     |      Status:  closed  
  Priority:  major    |   Milestone:  Spirit V2
 Component:  Spirit   |     Version:  Spirit V2
Resolution:  fixed    |    Keywords:          
----------------------+-----------------------------------------------------
Changes (by djowel):

  * status:  new => closed
  * resolution:  => fixed

--
Ticket URL: <http://fortytwo.cct.lsu.edu:8000/SpiritKarma/ticket/2#comment:2>
Spirit &amp; Karma <http://spirit.sourceforge.net>
Development of the Boost::Spirit V2 libraries
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Spirit-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-devel