Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61336 - in trunk/libs/spirit/example/scheme: input support
From: joel_at_[hidden]
Date: 2010-04-17 09:20:26


Author: djowel
Date: 2010-04-17 09:20:25 EDT (Sat, 17 Apr 2010)
New Revision: 61336
URL: http://svn.boost.org/trac/boost/changeset/61336

Log:
+ installing the line_pos_iterator
+ error handling tweaks
Text files modified:
   trunk/libs/spirit/example/scheme/input/error_handler.hpp | 47 +++++++++++----------------------------
   trunk/libs/spirit/example/scheme/input/sexpr.hpp | 13 ++++------
   trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp | 14 +++++++++++
   3 files changed, 32 insertions(+), 42 deletions(-)

Modified: trunk/libs/spirit/example/scheme/input/error_handler.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/input/error_handler.hpp (original)
+++ trunk/libs/spirit/example/scheme/input/error_handler.hpp 2010-04-17 09:20:25 EDT (Sat, 17 Apr 2010)
@@ -9,7 +9,6 @@
 
 #include <boost/spirit/home/support/info.hpp>
 #include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/function.hpp>
 #include <iostream>
 
 namespace scheme { namespace input
@@ -17,18 +16,6 @@
     template <typename Iterator>
     struct error_handler
     {
- typedef
- boost::function<
- void(
- Iterator, Iterator, Iterator,
- boost::spirit::info const&
- )>
- errorf_type;
-
- errorf_type errorf;
- error_handler(errorf_type errorf)
- : errorf(errorf) {}
-
         template <typename, typename, typename, typename>
         struct result { typedef void type; };
 
@@ -36,27 +23,19 @@
             Iterator first, Iterator last,
             Iterator err_pos, boost::spirit::info const& what) const
         {
- if (!errorf.empty())
- {
- // "Overridden"
- errorf(first, last, err_pos, what);
- }
- else
- {
- // Default handler
- Iterator eol = err_pos;
- while (eol != last && *eol != '\n' && *eol != '\r')
- ++eol;
-
- std::cerr
- << "Error! Expecting "
- << what
- << " here: \""
- << std::string(err_pos, eol)
- << "\""
- << std::endl
- ;
- }
+ // Default handler
+ Iterator eol = err_pos;
+ while (eol != last && *eol != '\n' && *eol != '\r')
+ ++eol;
+
+ std::cerr
+ << "Error! Expecting "
+ << what
+ << " here: \""
+ << std::string(err_pos, eol)
+ << "\""
+ << std::endl
+ ;
         }
     };
 }}

Modified: trunk/libs/spirit/example/scheme/input/sexpr.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/input/sexpr.hpp (original)
+++ trunk/libs/spirit/example/scheme/input/sexpr.hpp 2010-04-17 09:20:25 EDT (Sat, 17 Apr 2010)
@@ -62,15 +62,12 @@
         rule<Iterator> start;
     };
 
- template <typename Iterator>
+ template <typename Iterator,
+ typename ErrorHandler = input::error_handler<Iterator> >
     struct sexpr : grammar<Iterator, sexpr_white_space<Iterator>, utree()>
     {
- typedef typename
- input::error_handler<Iterator>::errorf_type
- errorf_type;
-
- sexpr(errorf_type errorf = errorf_type())
- : sexpr::base_type(start), error_handler(errorf)
+ sexpr()
+ : sexpr::base_type(start), error_handler(ErrorHandler())
         {
             real_parser<double, strict_real_policies<double> > strict_double;
             uint_parser<unsigned char, 16, 2, 2> hex2;
@@ -113,7 +110,7 @@
         rule<Iterator, binary_string()> byte_str;
         scheme::input::string<Iterator> string;
 
- function<input::error_handler<Iterator> > const error_handler;
+ function<ErrorHandler> const error_handler;
     };
 }}
 

Modified: trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp (original)
+++ trunk/libs/spirit/example/scheme/support/line_pos_iterator.hpp 2010-04-17 09:20:25 EDT (Sat, 17 Apr 2010)
@@ -65,6 +65,7 @@
                     break;
             }
             prev = ref;
+ ++this->base_reference();
         }
 
         std::size_t line;
@@ -75,6 +76,19 @@
     // Utilities
     ///////////////////////////////////////////////////////////////////////////
 
+ // Get the line position. Returns -1 if Iterator is not a line_pos_iterator.
+ template <typename Iterator>
+ inline int get_line(Iterator i)
+ {
+ return -1;
+ }
+
+ template <typename Iterator>
+ inline int get_line(line_pos_iterator<Iterator> i)
+ {
+ return i.position();
+ }
+
     // Get an iterator to the beginning of the line. Applicable to any
     // iterator.
     template <typename Iterator>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk