#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/lexical2/lexical2_util.hpp"
+#include <string>
#include "roast/stream/string_stream.hpp"
#include "roast/stream/console_stream.hpp"
-//#include <iostream>
namespace roast
{
{
//////////////////////////////////////////////////////////////////////////////////
- template <typename _Rule, typename _It, typename _Param>
- bool str_analyze(const _It& it, _Param& param)
+ template <typename Lexer, typename Param>
+ ::std::string& to_string(const Lexer &lexer, ::std::string& buffer, Param& param = EmptyType())
{
- 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); }
-
- //////////////////////////////////////////////////////////////////////////////////
-
- 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>();
- }
+ ::roast::string_output_stream sos(buffer);
- ///
- 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);
+ //if ( r.generate(sos,doc) == false )
+ lexer.generate(sos, param);
+ return buffer;
}
- //////////
- 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)
+ template <typename Lexer, typename Param>
+ ::std::string to_string(const Lexer &lexer, Param& param = EmptyType())
{
-
- ::std::string s;
- ::roast::string_output_stream ss(s);
- //generate(ss,r);
-
- //if ( r.generate(ss,doc) == false )
- r.generate(ss,r);
- return s;
+ ::std::string str;
+ return to_string(lexer, str, param);
}
//////////////////////////////////////////////////////////////////////////////////
- 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 Lexer, typename Param>
+ void print(const Lexer &lexer, Param& param = EmptyType())
+ {
+ lexer.generate(::roast::stream::cout, param);
}
-
- template <typename _Rule>
- void println(_Rule& r){
- //r.generate(::std::cout, doc);
- r.generate(::roast::stream::cout, null_document);
+
+ template <typename Lexer, typename Param>
+ void println(const Lexer &lexer, Param& param = EmptyType())
+ {
+ lexer.generate(::roast::stream::cout, param);
::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__