x3::error_handler<std::u32string::const_iterator>?

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

x3::error_handler<std::u32string::const_iterator>?

Mario Lang
Hi.

In my project, I am parsing std::wstring or even std::u32string.
Looking at x3::error_handler::err_out, I see std::ostream is assumed.
From what I understand, this is not going to work for me.
Are there any plans to make x3::error_handler a bit more generic, so
that for instance, boost::locale::conv::utf_to_utf can be hooked up to it?
As far as I can see, error_handler<Iterator>::print_line() is going to
do the wrong thing if Iterator::value_type is not a simple char.

--
CYa,
  ⡍⠁⠗⠊⠕

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: x3::error_handler<std::u32string::const_iterator>?

Mario Lang
Mario Lang <[hidden email]> writes:

> In my project, I am parsing std::wstring or even std::u32string.
> Looking at x3::error_handler::err_out, I see std::ostream is assumed.
> From what I understand, this is not going to work for me.
> Are there any plans to make x3::error_handler a bit more generic, so
> that for instance, boost::locale::conv::utf_to_utf can be hooked up to it?
> As far as I can see, error_handler<Iterator>::print_line() is going to
> do the wrong thing if Iterator::value_type is not a simple char.

Replying to self.  Maybe something along the lines of the following
change?

--- a/include/boost/spirit/home/x3/support/utility/error_reporting.hpp
+++ b/include/boost/spirit/home/x3/support/utility/error_reporting.hpp
@@ -11,6 +11,7 @@
 #include <boost/filesystem/path.hpp>
 #endif
 
+#include <boost/locale/encoding_utf.hpp>
 #include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
 #include <ostream>
 
@@ -92,16 +89,19 @@ namespace boost { namespace spirit { namespace x3
     template <typename Iterator>
     void error_handler<Iterator>::print_line(Iterator start, Iterator last) const
     {
-        for (; start != last; ++start)
+        auto end = start;
+        while (end != last)
         {
             auto c = *start;
             if (c == '\r' || c == '\n')
                 break;
             else
-                err_out << c;
+                ++end;
         }
-        err_out << std::endl;
-   }
+        typedef typename std::iterator_traits<Iterator>::value_type char_type;
+        std::basic_string<char_type> line{start, end};
+        err_out << locale::conv::utf_to_utf<char>(line) << std::endl;
+    }
 
     template <typename Iterator>
     void error_handler<Iterator>::print_indicator(Iterator& start, Iterator last, char ind) const

--
CYa,
  ⡍⠁⠗⠊⠕

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: x3::error_handler<std::u32string::const_iterator>?

Joel de Guzman
On 5/16/15 7:05 PM, Mario Lang wrote:

> Mario Lang <[hidden email]> writes:
>
>> In my project, I am parsing std::wstring or even std::u32string.
>> Looking at x3::error_handler::err_out, I see std::ostream is assumed.
>>  From what I understand, this is not going to work for me.
>> Are there any plans to make x3::error_handler a bit more generic, so
>> that for instance, boost::locale::conv::utf_to_utf can be hooked up to it?
>> As far as I can see, error_handler<Iterator>::print_line() is going to
>> do the wrong thing if Iterator::value_type is not a simple char.
>
> Replying to self.  Maybe something along the lines of the following
> change?

Could you do a pull request?

https://github.com/boostorg/spirit/tree/develop

While you are at it, please make sure all the examples are also updated.
Thanks!

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


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general