From b4ceea54aec4124984df6f8e91b12f35a6a851a9 Mon Sep 17 00:00:00 2001 From: Myun2 Date: Sun, 8 Aug 2010 03:57:00 +0900 Subject: [PATCH] lexical: generate() Add. --- roast/include/roast/lexical/lexical_base.hpp | 14 ---- roast/include/roast/lexical/rule.hpp | 101 ++++++++++++++++++++++++++- roast/include/roast/lexical/string_rule.hpp | 27 +++++++ 3 files changed, 127 insertions(+), 15 deletions(-) delete mode 100644 roast/include/roast/lexical/lexical_base.hpp diff --git a/roast/include/roast/lexical/lexical_base.hpp b/roast/include/roast/lexical/lexical_base.hpp deleted file mode 100644 index 252c0629..00000000 --- a/roast/include/roast/lexical/lexical_base.hpp +++ /dev/null @@ -1,14 +0,0 @@ -// Roast+ License -/* -*/ -#ifndef __SFJP_ROAST__lexical__lexical_base_HPP__ -#define __SFJP_ROAST__lexical__lexical_base_HPP__ - -#include "roast/lexical/base.hpp" - -namespace roast -{ - typedef lexical::base lexical_base; -} - -#endif//__SFJP_ROAST__lexical__lexical_base_HPP__ diff --git a/roast/include/roast/lexical/rule.hpp b/roast/include/roast/lexical/rule.hpp index e53d0c6a..29ab25ee 100644 --- a/roast/include/roast/lexical/rule.hpp +++ b/roast/include/roast/lexical/rule.hpp @@ -22,6 +22,11 @@ namespace roast { return true; } + template + bool generate(const T&, const _Param&) + { + return true; + } }; class _false_analyze @@ -32,6 +37,11 @@ namespace roast { return false; } + template + bool generate(const T&, const _Param&) + { + return false; + } }; template @@ -45,6 +55,11 @@ namespace roast T t; return t.analyze(it, param); } + template + bool generate(const T&, const _Param&) + { + return true; + } }; // Alias : test -> check template class check : public test {}; @@ -106,6 +121,20 @@ namespace roast it = it_work; return true; } + + template + bool generate(_Strm& strm, _Document& doc) + { + T1 t1; + if ( t1.generate(strm, doc) == false ) + return false; + + seq t2; + if ( t2.generate(strm, doc) == false ) + return false; + + return true; + } }; template @@ -124,6 +153,16 @@ namespace roast return true; } + + template + bool generate(_Strm& strm, _Document& doc) + { + T1 t1; + if ( t1.generate(strm, doc) == false ) + return false; + + return true; + } }; ////////////////////////////////////////////////////////////// @@ -152,6 +191,11 @@ namespace roast } return true; } + template + bool generate(const T&, const _Param&) + { + return true; + } }; //////////////// @@ -194,6 +238,25 @@ namespace roast it = it_backup; return false; } + + //---- + + template + bool generate(_Strm& strm, _Document& doc) + { + //_Document doc_work = doc; + T1 t1; + if ( t1.generate(strm, doc) ) + return true; + + //doc = it_backup; + or t2; + if ( t2.generate(strm, doc) ) + return true; + + //doc = it_backup; + return false; + } }; template @@ -211,6 +274,20 @@ namespace roast it = it_backup; return false; } + + //---- + + template + bool generate(_Strm& strm, _Document& doc) + { + //_Document doc_work = doc; + T1 t1; + if ( t1.generate(strm, doc) ) + return true; + + //doc = it_backup; + return false; + } }; template @@ -236,11 +313,25 @@ namespace roast } return true; } + + //---- + + template + bool generate(_Strm& strm, _Document& doc) + { + T t; + for(;;) + { + if ( t.generate(strm, doc) == false ) + break; + } + return true; + } }; //////////////////// - template + template class fixed_repeat { public: @@ -259,6 +350,8 @@ namespace roast return true; } }; + template + class soft_repeat : public fixed_repeat{}; //////////////////// @@ -310,6 +403,12 @@ namespace roast param << N; return true; } + + template + bool generate(_Strm& strm, _Document& doc) + { + return doc << N; + } }; //////////////////////////////////////////////////////////// diff --git a/roast/include/roast/lexical/string_rule.hpp b/roast/include/roast/lexical/string_rule.hpp index db94899f..9f1aba0b 100644 --- a/roast/include/roast/lexical/string_rule.hpp +++ b/roast/include/roast/lexical/string_rule.hpp @@ -34,6 +34,13 @@ namespace roast } return false; } + + template + bool generate(_Strm& strm, _Document& doc) + { + strm << _Char; + return true; + } }; /////////////////////////////////////////////////// @@ -186,6 +193,15 @@ namespace roast { T cant const. } + + //////////////////////////////////////////////// + + template + bool generate(_Strm& strm, _Document& doc) + { + strm << doc.pop_string(); + return true; + } }; ///////////// @@ -222,6 +238,17 @@ namespace roast param << ::std::make_pair( gs.start_it, gs.end_it ); return true; } + + //////////////////////////////////////////////// + + template + bool generate(_Strm& strm, _Document& doc) + { + get_string_end_by_analyze_true gs; + if ( gs.generate(strm, doc) == false ) + return false; + return true; + } }; } -- 2.11.0