--- /dev/null
+// Roast+ License
+/*
+*/
+#ifndef __SFJP_ROAST__lexical2__to_string_HPP__
+#define __SFJP_ROAST__lexical2__to_string_HPP__
+
+//#include <string> // str_generate()
+#include "roast/lexical/iterator_util.hpp"
+#include "roast/stream/string_stream.hpp"
+#include "roast/stream/console_stream.hpp"
+//#include <iostream>
+
+namespace roast
+{
+ namespace lexical
+ {
+ //////////////////////////////////////////////////////////////////////////////////
+
+ // Null Document Class (for Not Used Document Only!!)
+
+ template <typename>
+ class null_document_
+ {
+ public:
+ template <typename T>
+ bool operator << (T){ return true; }
+ };
+ /*static*/ null_document_<int> null_document;
+
+ //////////////////////////////////////////////////////////////////////////////////
+
+ // Analyze Utility Functions.
+
+ template <typename _Rule, typename _It, typename _Param>
+ bool analyze(const _It& it, _Param& param)
+ {
+ ::roast::lexical::rule::work_iterator<_Rule> r;
+ return r.analyze(it, param);
+ }
+
+ template <typename _Rule, typename _It, typename _Param>
+ bool parse(const _It& it, _Param& param){ return analyze<_Rule>(it, param); }
+
+ /////
+
+ template <typename _Rule, typename _It, typename _Param>
+ bool str_analyze(const _It& it, _Param& param)
+ {
+ using namespace ::roast::lexical::rule;
+ typedef work_iterator<seq<_Rule, zeroterm> > _StrRule;
+ return analyze<_StrRule>(it, param);
+ }
+
+ template <typename _Rule, typename _It, typename _Param>
+ bool str_parse(const _It& it, _Param& param){ return str_analyze<_Rule>(it, param); }
+
+ //////////////////////////////////////////////////////////////////////////////////
+
+ // Generate Utility Functions.
+
+ template <typename _Rule, typename _Strm, typename _Document>
+ bool generate(_Strm& strm, _Document& doc = null_document)
+ {
+ _Rule r;
+ return r.generate(strm,doc);
+ }
+ /////
+
+ template <typename _Rule>
+ ::std::string str_generate()
+ {
+ ::std::string s;
+ ::roast::string_output_stream ss(s);
+ rule::false_ret_to_exception<_Rule> r;
+ r.generate(ss, null_document);
+ return s;
+ }
+ template <typename _Rule, typename _Document>
+ ::std::string to_string(){
+ return str_generate<_Rule, _Document>();
+ }
+
+ ///
+ template <typename _Rule, typename _Document>
+ ::std::string str_generate(_Document& doc)
+ {
+ ::std::string s;
+ ::roast::string_output_stream ss(s);
+ rule::false_ret_to_exception<_Rule> r;
+ r.generate(ss,doc);
+ return s;
+ }
+ template <typename _Rule, typename _Document>
+ ::std::string to_string(_Document& doc){
+ return str_generate<_Rule>(doc);
+ }
+
+ //////////
+ template <typename _Rule, typename _Document>
+ ::std::string to_string(_Rule& r, _Document& doc){
+ ::std::string s;
+ ::roast::string_output_stream ss(s);
+ //if ( r.generate(ss,doc) == false )
+ r.generate(ss,doc);
+ return s;
+ }
+
+ template <typename _Rule>
+ ::std::string to_string(_Rule& r){
+ return to_string(r, null_document);
+ }
+
+ template <typename _Rule>
+ ::std::string to_string2(_Rule& r)
+ {
+
+ ::std::string s;
+ ::roast::string_output_stream ss(s);
+ //generate(ss,r);
+
+ //if ( r.generate(ss,doc) == false )
+ r.generate(ss,r);
+ return s;
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////
+
+ template <typename _Rule, typename _Document>
+ void print(_Rule& r, _Document& doc){
+ //r.generate(::std::cout, doc);
+ r.generate(::roast::stream::cout, doc);
+ }
+
+ template <typename _Rule>
+ void print(_Rule& r){
+ //r.generate(::std::cout, doc);
+ r.generate(::roast::stream::cout, null_document);
+ }
+
+ template <typename _Rule>
+ void println(_Rule& r){
+ //r.generate(::std::cout, doc);
+ r.generate(::roast::stream::cout, null_document);
+ ::roast::stream::cout << '\n';
+ }
+
+ //////////////////////////////////////////////////////////////////////////////////
+ }
+
+ template <typename _Rule>
+ ::std::string lex_to_string(_Rule& r)
+ {
+ return lexical::to_string2(r);
+ }
+}
+
+#endif//__SFJP_ROAST__lexical2__to_string_HPP__