From: myun2 Date: Tue, 29 May 2012 20:00:20 +0000 (+0900) Subject: lexical2_test Add. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=6bbd842f79dc30577cc4609b52543f175d15ba37;p=roast%2Froast.git lexical2_test Add. --- diff --git a/roast/test/lexical2_test/big_xml.zip b/roast/test/lexical2_test/big_xml.zip new file mode 100644 index 00000000..7fddf105 Binary files /dev/null and b/roast/test/lexical2_test/big_xml.zip differ diff --git a/roast/test/lexical2_test/css_test.cpp b/roast/test/lexical2_test/css_test.cpp new file mode 100644 index 00000000..d2a051e0 --- /dev/null +++ b/roast/test/lexical2_test/css_test.cpp @@ -0,0 +1,65 @@ +#include "roast/web/css.hpp" +#include + +using namespace roast; + +class printer +{ +public: + void operator << (char c){ putc(c,stdout); } + void operator << (const char* s){ printf(s); } + + int pop_string(){ return 0; }; +}; + +ROAST_LEXICAL_FIXSTR(hoge, "hoge") +ROAST_LEXICAL_FIXSTR(hoge2, "hoge2") + +ROAST_LEXICAL_FIXSTR(_Family, "_Family") +ROAST_LEXICAL_FIXSTR(_Size, "_Size") +ROAST_LEXICAL_FIXSTR(_Style, "_Style") +ROAST_LEXICAL_FIXSTR(_Weight, "_Weight") +ROAST_LEXICAL_FIXSTR(_Variant, "_Variant") +ROAST_LEXICAL_FIXSTR(_Height, "_Height") + +int main() +{ + using namespace roast::css; + using namespace roast::css::attr; + using namespace roast::css::attr::unit; + using namespace roast::lexical::rule; + +// ::roast::css::lexical::parser_rule cssa; +// cssa.analyze("/*ZZZ*//*ZZZ*/ /*ZZZ*//*ZZZ*/ /*ZZZ*/ hoge/*ZZZ*/ {aa /*ZZZ*/ :/*ZZZ*/ bb/*ZZZ*/; /*ZZZ*/ee:ss /*ZZZ*/}\n" +// "/*ZZZ*/hoge2,2#dd{cc:dd; aa : bb ; aa : bb}",printer()); + + //padding_, px_<10>, px_<10> > a; + //color_ > a; + //border_color_ a; + //line_height_ a; + //vertical_align_ a; + text_decoration_ a; + //padding_px_<10,20,30,8> a; + //color_<0xFF88DA> + //top_ > a; + //float_string<132,58,2> a; + //num_string<592116> a; + font_<_Family, _Size/*, _Style, _Weight*/, _Variant, _Height> b; + //font_style_ c; + //font_style_ d; + //font_variant_ c; + //font_size_ d; + font_family_ c; + font_family_ d; + //unit::px_<10> a; + a.generate(printer(),printer()); + printf(";\n"); + b.generate(printer(),printer()); + printf(";\n"); + c.generate(printer(),printer()); + printf(";\n"); + d.generate(printer(),printer()); + printf(";\n"); + + return 0; +} diff --git a/roast/test/lexical2_test/dom_test.cpp b/roast/test/lexical2_test/dom_test.cpp new file mode 100644 index 00000000..ec4f0461 --- /dev/null +++ b/roast/test/lexical2_test/dom_test.cpp @@ -0,0 +1,246 @@ +#include "roast/xml/roast_xml/dom3.hpp" +#include +#include +#include +#include +#include +#include "roast_xml/sax_test.hpp" + +using namespace std; +using namespace roast; +using namespace roast::roast_xml; + +#pragma warning(disable:4996) +#pragma warning(disable:4102) + +/////////////////////////////////////////////////////////// +const bool g_detail = false; + +#define BUF_SIZE (64*1024*1024) // 32MB + +class A +{ +public: + vector& aa; + A(vector& a_):aa(a_){} + + //A& operator = (A& a){ return *this; } +}; + +bool sax_error_test_detail(const char* xml_text, const char* expect_msg) +{ + try + { + printf("text: \"%s\"\n", xml_text); + sax(xml_text, speed_test_sax_impl); + } + catch(::std::string& e) + { + printf("message: %s\n", e.c_str()); + printf("expect: %s\n", expect_msg); + + if ( e.compare(expect_msg) == 0 ) + { + printf( " ** OK! **\n\n"); + return true; + } + else + { + printf( " ** NG! **\n\n"); + return false; + } + } + printf( " ** Not cause exception. (NG) **\n\n"); + return false; +} + +bool sax_error_test(const char* xml_text, const char* expect_msg) +{ + if ( g_detail ) + return sax_error_test_detail(xml_text, expect_msg); + try + { + //printf("text: \"%s\"\n", xml_text); + sax(xml_text, speed_test_sax_impl); + } + catch(::std::string& e) + { + /*printf("message: %s\n", e.c_str()); + printf("expect: %s\n", expect_msg); + + if ( e.compare(expect_msg) == 0 ) + { + printf( " ** OK! **\n\n"); + return true; + } + else + { + printf( " ** NG! **\n\n"); + return false; + }*/ + if ( e.compare(expect_msg) == 0 ) + { + printf("[o] \"%s\"\n", xml_text); + return true; + } + else + { + printf("[x] \"%s\"\n", xml_text); + printf(" message: %s\n", e.c_str()); + printf(" expect: %s\n", expect_msg); + return false; + } + } + //printf( " ** Not cause exception. (NG) **\n\n"); + printf("[x] \"%s\" (Not cause exception.)\n", xml_text); + return false; +} + +int main() +{ + document doc; + try + { + FILE* fp = fopen("temp.xml","rb"); + char* work = new char [BUF_SIZE]; + memset(work,0,BUF_SIZE); + fread(work,1,BUF_SIZE,fp); + + ////////////////////////////////////////////// + + //document doc = dom_parse(work); + printf("%d\n", clock()); + //sax((const char*)work, speed_test_sax_impl); + //dom_parse(work, doc); + + //const char* root_cant_have_text_test = " a"; + //sax(root_cant_have_text_test, speed_test_sax_impl); + + using namespace roast::roast_xml::rule; + + goto LABEL1; + + // root_cant_have_text + sax_error_test("<", illegal_term_exception().c_str() ); + sax_error_test(" ", invalid_comment_start_exception().c_str() ); + sax_error_test(" ", illegal_term_in_comment_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() );// X + //goto END; + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", illegal_term_in_comment_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test("", no_root_element_exception().c_str() );// X + + sax_error_test(" ", invalid_comment_start_exception().c_str() ); + sax_error_test(" ", illegal_term_in_comment_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", illegal_term_in_comment_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() ); + + sax_error_test(" ", invalid_comment_start_exception().c_str() ); + sax_error_test(" ", illegal_term_in_comment_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", illegal_term_in_comment_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", no_root_element_exception().c_str() );// X + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", invalid_comment_end_exception().c_str() ); + sax_error_test(" ", no_root_element_exception().c_str() ); +END: + ; + } + catch(sax_exception& e) + { + printf("%d\n", clock()); + printf("\n\n#############################################################################" + "\n%s\n", e.c_str()); + //printf("Error!!\n"); + } + catch(::std::string& e) + { + printf("%d\n", clock()); + printf("\n\n#############################################################################" + "\n%s\n", e.c_str()); + //printf("Error!!\n"); + } + return 0; + + try + { + if ( !doc.is_empty() ) + { + element& e = doc.get_root_element(); + //element& e2 = e.get_first_element(); + + printf("%s\n", e.name.c_str()); + //printf("%s\n", e2.name.c_str()); + for(element_iterator it=e.get_element_iterator(); it.is_valid(); it++) + { + printf(" %s\n", it->name.c_str()); + for(element_iterator it2=it->get_element_iterator(); it2.is_valid(); it2++) + { + printf(" %s\n", it2->name.c_str()); + + for(element_iterator it3=it2->get_element_iterator(); it3.is_valid(); it3++) + { + printf(" %s\n", it3->name.c_str()); + } + } + } + } + } + catch(::std::string& e) + { + printf("\n\n#############################################################################" + "\n%s\n", e.c_str()); + //printf("Error!!\n"); + } + + return 0; +} diff --git a/roast/test/lexical2_test/html_test.cpp b/roast/test/lexical2_test/html_test.cpp new file mode 100644 index 00000000..9eb16444 --- /dev/null +++ b/roast/test/lexical2_test/html_test.cpp @@ -0,0 +1,20 @@ +#include "roast/web/html.hpp" +#include "roast/web/css.hpp" +#include + +using namespace roast; + +int main() +{ + using namespace roast::web::css; + + printf("%s\n", color("red").to_string().c_str() ); + printf("%s\n", background_color(0x11223344).to_string().c_str() ); + printf("%s\n", background_repeat(background_repeat::repeat).to_string().c_str() ); + printf("%s\n", background_position(background_position::left, background_position::top).to_string().c_str() ); + + printf("%s\n", font_size(unit::px(10)).to_string().c_str() ); + printf("%s\n", font_size(font_size::larger).to_string().c_str() ); + + return 0; +} diff --git a/roast/test/lexical2_test/lex_var_test.cpp b/roast/test/lexical2_test/lex_var_test.cpp new file mode 100644 index 00000000..a353a56f --- /dev/null +++ b/roast/test/lexical2_test/lex_var_test.cpp @@ -0,0 +1,49 @@ +#include "roast/std/any.hpp" +#include "roast/lexical.hpp" + +using namespace ::roast; +using namespace ::roast::lexical; +using namespace ::roast::lexical::variable; + +int main() +{ + int_ aa(33); + char_ aa2(33); + short_ aa3(33); + long_ aa4(33); + + ::roast::any hoge(2.5); + //printf("%f\n", *((double*)hoge.get()) ); + printf("%f\n", hoge.get() ); + hoge = 100; + //printf("%d\n", *((int*)hoge.get()) ); + printf("%d\n", hoge.get() ); + + int aaa = 200; + + ::roast::any_ref hugi(aaa); + printf("%d\n", hugi.get() ); + hugi = 4000; + printf("%d\n", aaa ); + printf("%d\n", hugi.get() ); + + int_array<4> ia; + + any2 an2; + an2 = aa; + + ::roast::lexical::print(aa); + + //////////////////////////////////////////////// + + //avector av; + ::roast::any_vector avec; + avec.push_back(100); + avec.push_back(::std::string("aaaaa")); + + printf("======================\n"); + printf("%d\n", any_cast(avec[0]) ); + printf("%s\n", any_cast<::std::string>(avec[1]).c_str() ); + + return 0; +} diff --git a/roast/test/lexical2_test/lexical_test_vc2010.sln b/roast/test/lexical2_test/lexical_test_vc2010.sln new file mode 100644 index 00000000..28a99782 --- /dev/null +++ b/roast/test/lexical2_test/lexical_test_vc2010.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C++ Express 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lexical_test_vc2010", "lexical_test_vc2010.vcxproj", "{75F2DCA9-E904-47A9-A62E-FE8659548B0D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Debug|Win32.ActiveCfg = Debug|Win32 + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Debug|Win32.Build.0 = Debug|Win32 + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Release|Win32.ActiveCfg = Release|Win32 + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/roast/test/lexical2_test/lexical_test_vc2010.vcxproj b/roast/test/lexical2_test/lexical_test_vc2010.vcxproj new file mode 100644 index 00000000..792d6ce8 --- /dev/null +++ b/roast/test/lexical2_test/lexical_test_vc2010.vcxproj @@ -0,0 +1,95 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {75F2DCA9-E904-47A9-A62E-FE8659548B0D} + lexical_test_vc2010 + Win32Proj + + + + Application + Unicode + true + + + Application + Unicode + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + true + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + false + + + + Disabled + ../../include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + EditAndContinue + + + %(AdditionalLibraryDirectories) + true + Console + MachineX86 + + + + + MaxSpeed + true + ../../include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + true + + + Level3 + ProgramDatabase + + + %(AdditionalLibraryDirectories) + true + Console + true + true + MachineX86 + + + + + + + + + \ No newline at end of file diff --git a/roast/test/lexical2_test/lexical_test_vc2010.vcxproj.filters b/roast/test/lexical2_test/lexical_test_vc2010.vcxproj.filters new file mode 100644 index 00000000..73dcd1d2 --- /dev/null +++ b/roast/test/lexical2_test/lexical_test_vc2010.vcxproj.filters @@ -0,0 +1,18 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + + + ソース ファイル + + + \ No newline at end of file diff --git a/roast/test/lexical2_test/mbstring_test.cpp b/roast/test/lexical2_test/mbstring_test.cpp new file mode 100644 index 00000000..365e8e3d --- /dev/null +++ b/roast/test/lexical2_test/mbstring_test.cpp @@ -0,0 +1,24 @@ +#include "roast/str/multibyte/utf8_lexical.hpp" +#include +#include + +using namespace roast; +using namespace roast::lexical; + +#define BUFF_SIZE 200*1024*1024 + +int main() +{ + FILE* fp = fopen("temp.xml","r"); + //FILE* fp = fopen("MIDIƒfƒoƒCƒXƒ}ƒl[ƒWƒƒ3.xml","r"); + //char work[256]; + //fread(work,sizeof(work),1,fp); + char *work = new char [BUFF_SIZE]; + fread(work,BUFF_SIZE,1,fp); + + //printf("%d\n", clock()); + + //printf("%d\n", clock()); + + return 0; +} diff --git a/roast/test/lexical2_test/roast_test_2nc.sln b/roast/test/lexical2_test/roast_test_2nc.sln new file mode 100644 index 00000000..da9ea354 --- /dev/null +++ b/roast/test/lexical2_test/roast_test_2nc.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "roast_test_2nc", "roast_test_2nc.vcproj", "{75F2DCA9-E904-47A9-A62E-FE8659548B0D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Debug|Win32.ActiveCfg = Debug|Win32 + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Debug|Win32.Build.0 = Debug|Win32 + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Release|Win32.ActiveCfg = Release|Win32 + {75F2DCA9-E904-47A9-A62E-FE8659548B0D}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/roast/test/lexical2_test/roast_test_2nc.vcproj b/roast/test/lexical2_test/roast_test_2nc.vcproj new file mode 100644 index 00000000..fc74ca5c --- /dev/null +++ b/roast/test/lexical2_test/roast_test_2nc.vcproj @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/roast/test/lexical2_test/roast_xml/sax_test.hpp b/roast/test/lexical2_test/roast_xml/sax_test.hpp new file mode 100644 index 00000000..1c27fd3a --- /dev/null +++ b/roast/test/lexical2_test/roast_xml/sax_test.hpp @@ -0,0 +1,80 @@ +#include "roast/xml/roast_xml/sax.hpp" + +using namespace std; +using namespace roast; +using namespace roast::roast_xml; + + +class _test_sax_impl +{ +private: + ::std::string m_indent; +public: + void start_xml_declaration() + { + printf("=XML Declaration : start=\n" ); + m_indent += " "; + } + + void end_xml_declaration() + { + printf("=XML Declaration : end=\n\n" ); + m_indent = m_indent.substr(2); + } + + void attribute( const sized_ccharbuf &attr_name, const sized_ccharbuf &attr_value ) + { + printf("%sattr: %s=\"%s\"\n", + m_indent.c_str(), + attr_name.to_string().c_str(), + attr_value.to_string().c_str() ); + } + + void comment( const sized_ccharbuf &s ) + { + printf("%scomment: \"%s\"\n", + m_indent.c_str(), + s.to_string().c_str() ); + } + + void text( const sized_ccharbuf &s ) + { + printf("%stext: \"%s\"\n", + m_indent.c_str(), + s.to_string().c_str() ); + } + void start_element( const sized_ccharbuf &s ) + { + printf("%s\n", m_indent.c_str(), m_indent.c_str()); + } + void end_element( const sized_ccharbuf &s ){ + m_indent = m_indent.substr(2); + printf(" %s/%s end of element.\n%s>\n", m_indent.c_str(), s.to_string().c_str(), m_indent.c_str()); + } +}; + + +class _speed_test_sax_impl +{ +private: + ::std::string m_indent; +public: + void start_xml_declaration(){} + void end_xml_declaration(){} + void attribute( const sized_ccharbuf &attr_name, const sized_ccharbuf &attr_value ){} + void comment( const sized_ccharbuf &s ){} + void text( const sized_ccharbuf &s ){} + void start_element( const sized_ccharbuf &s ){} + void end_element(){} + void end_element( const sized_ccharbuf &s ){} +}; + +//typedef sax_impl_<_test_sax_impl> test_sax_impl; +//typedef sax_impl_<_speed_test_sax_impl> speed_test_sax_impl; +static sax_impl_<_test_sax_impl> test_sax_impl; +static sax_impl_<_speed_test_sax_impl> speed_test_sax_impl; diff --git a/roast/test/lexical2_test/roast_xml_test.cpp b/roast/test/lexical2_test/roast_xml_test.cpp new file mode 100644 index 00000000..e3fa64fe --- /dev/null +++ b/roast/test/lexical2_test/roast_xml_test.cpp @@ -0,0 +1,51 @@ +#include "roast/xml/roast_xml.hpp" +#include +#include +#include + +using namespace roast; +using namespace roast::lexical; + +int main() +{ + FILE* fp = fopen("temp.xml","r"); + char* work = new char [20*1024*1024]; + memset(work,0,20*1024*1024); + fread(work,(20*1024*1024),1,fp); + + roast_xml::dom_parser xml(work); + roast_xml::document* pdoc = xml.analyze(); + + using namespace roast_xml; + using namespace roast_xml::rxpath; + + element *e = pdoc->get_root_element(); + printf("%s\n", e->get_attribute("date")->value.to_string().c_str() ); + //printf("%s\n", *(*e / "version") [0].get_attribute("date")->value.to_string().c_str() ); + printf("%s\n", (*e / el("version")) [2]->get_attribute("module")->value.to_string().c_str() ); + //printf("%s\n", (*e / el("dev")[at("type")="SYSTEM"]) [0]->get_attribute("name")->value.to_string().c_str() ); + printf("%s\n", (*e / el("dev")[at("type")="SYSTEM"][0] / at("title") )->value.to_string().c_str() ); + printf("%s\n", (*e / el("dev")[at("type")="SYSTEM"][0] / (at("name")="product") / 0 / xpath::text).c_str() ); + printf("%s\n", (*e / el("dev")[at("type")=="SYSTEM"][0] / atval("name","product") / 0 / rxpath::text).c_str() ); + + //printf("%s\n", *e [el("dev",at("type")="SYSTEM")] [0] [at("title")] ->value.to_string().c_str() ); + + /* + element_list_t el = e->get_child_elements(); + for(int i=0; iname.to_string().c_str() ); + }*/ + /* + for(int i=0; inode_list.size(); i++) + { + node *n = e->node_list[i]; + }*/ + /*roast_xml::dom_generator gen; + gen.generate(::std::cout, *pdoc); + + delete pdoc;*/ + + return 0; +} diff --git a/roast/test/lexical2_test/sax_test.cpp b/roast/test/lexical2_test/sax_test.cpp new file mode 100644 index 00000000..abb70dcb --- /dev/null +++ b/roast/test/lexical2_test/sax_test.cpp @@ -0,0 +1,82 @@ +#include "roast/xml/roast_xml/sax.hpp" +#include "roast/xml/roast_xml/rxpath.hpp" +#include "roast/xml/roast_xml/sax_generator.hpp" +#include "roast_xml/sax_test.hpp" +#include +#include +#include +#include +#include + +using namespace std; +using namespace roast; +using namespace roast::roast_xml; +using namespace roast::roast_xml::rxpath; + +/////////////////////////////////////////////////////////// + +#define BUF_SIZE (32*1024*1024) // 32MB + +int main() +{ + try + { + FILE* fp = fopen("temp.xml","rb"); + char* work = new char [BUF_SIZE]; + memset(work,0,BUF_SIZE); + fread(work,1,BUF_SIZE,fp); + + ////////////////////////////////////////////// + + map tl; + int id; + + ::std::string s; + + printf("start:%d\n", clock()); + sax sx; + sx.analyze((const char*)work, speed_test_sax_impl); + printf("end:%d\n", clock()); + printf("lines:%d\n", speed_test_sax_impl.get_line()); + + /* + //printf(work); + sax_parser saxpar; + saxpar.analyze((const char*)work, + rax + / "hoge" + / "hoge" + / text2print() ); + /* saxpar.analyze((const char*)work, + rax /"statuses"/"status"/ + text2int(id) && + ( el("user")/aster/text/user_append_functor(id,tl) + || aster/text/status_append_functor(id,tl) + ) + );*/ + //saxgen /"statuses"/"status"/ ( el("!user")/status_append_o || el("user")/user ) ); + //saxgen / el("statuses") / el("status") / ( ); + //printf("%s\n", s.c_str()); + } + catch(::roast::lexical::rule::eoi_exception& e) + { + printf("Invalid XML Term\n"); + printf("lines:%d\n", speed_test_sax_impl.get_line()); + //printf("Error!!\n"); + } + catch(::std::string& e) + { + printf("\n\n#############################################################################" + "\n%s\n", e.c_str()); + printf("lines:%d\n", speed_test_sax_impl.get_line()); + //printf("Error!!\n"); + } + /*catch(rax_parse_error& e) + { + printf("%s\n", e.c_str()); + //printf("Error!!\n"); + }*/ + + + return 0; +} diff --git a/roast/test/lexical2_test/static_map.cpp b/roast/test/lexical2_test/static_map.cpp new file mode 100644 index 00000000..9e752017 --- /dev/null +++ b/roast/test/lexical2_test/static_map.cpp @@ -0,0 +1,26 @@ +#include "roast/tp/static_map.hpp" +#include +#include + +using namespace roast; +using namespace roast::lexical; + + +int main() +{ + //static_map, pair<2,20>, pair<3,40> > > sm; + //printf("%d\n", sm::get<1>::value ); + using namespace std; + static_map sm( make_ul_tuple( make_pair(1,"hoge"), make_pair(4,"huge"), make_pair(6,"hige") ) ); + printf("%s\n", sm.get<4>() ); + + map mp; + mp[1] = "hoge"; + mp[4] = "huge"; + mp[6] = "hige"; + printf("%s\n", mp[4] ); + + //(long long)'hoge'; + + return 0; +} diff --git a/roast/test/lexical2_test/temp.xml b/roast/test/lexical2_test/temp.xml new file mode 100644 index 00000000..e8705a96 --- /dev/null +++ b/roast/test/lexical2_test/temp.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/roast/test/lexical2_test/twitter_parser.cpp b/roast/test/lexical2_test/twitter_parser.cpp new file mode 100644 index 00000000..af3e2765 --- /dev/null +++ b/roast/test/lexical2_test/twitter_parser.cpp @@ -0,0 +1,133 @@ +#include "roast/xml/roast_xml/roast_xml_dom_parser.hpp" +#include "roast/xml/roast_xml/roast_xml_sax_parser.hpp" +#include +#include + +using namespace roast; +using namespace roast::lexical; + +#define BUFF_SIZE 200*1024*1024 + +namespace myun2 +{ + namespace twitter + { + //template + class timeline_sax_parser_impl + { + private: + //::std::string m_tagname; + sized_ccharbuf m_tagname; + bool m_on_user; + + public: + virtual void on_next_status()=0; + virtual void status_value( const sized_ccharbuf &name, const sized_ccharbuf &value )=0; + virtual void user_value( const sized_ccharbuf &name, const sized_ccharbuf &value )=0; + + protected: + timeline_sax_parser_impl(){ + m_tagname.ptr = 0; + m_tagname.size = 0; + m_on_user = false; + } + + // nothing... + void start_xml_declaration(){} + void end_xml_declaration(){} + void attribute( const sized_ccharbuf &attr_name, const sized_ccharbuf &attr_value ){} + void comment( const sized_ccharbuf &s ){} + + //////////////////////////////////////////////////////// + + void text( const sized_ccharbuf &s ) + { + if ( m_tagname.ptr != 0 ) + { + if ( m_on_user ) + user_value( m_tagname, s ); + else + status_value( m_tagname, s ); + } + } + void start_element( const sized_ccharbuf &s ) + { + if ( s == "statuses" ) + ; + else if ( s == "status" ) + on_next_status(); + else if ( s == "user" ) + m_on_user = true; + else + m_tagname = s; + //m_tagname = ::std::string(s.ptr, s.size); + } + void end_element(){ + /*if ( m_on_user ) + { + if ( m_tagname.ptr != 0 ) + m_tagname = sized_ccharbuf(); + else + m_on_user = false; + }*/ + if ( m_tagname.ptr != 0 ) + m_tagname = sized_ccharbuf(0,0); + else if ( m_on_user ) + m_on_user = false; + } + }; + } +} + +using namespace myun2::twitter; +using namespace roast::roast_xml; + +class tl_test : public timeline_sax_parser_impl +{ +public: + void on_next_status() + { + printf("==============================================\n"); + } + void status_value( const sized_ccharbuf &name, const sized_ccharbuf &value ) + { + printf("%s: \"%s\"\n", name.to_string().c_str(), value.to_string().c_str() ); + } + void user_value( const sized_ccharbuf &name, const sized_ccharbuf &value ) + { + printf("user/%s: \"%s\"\n", name.to_string().c_str(), value.to_string().c_str() ); + } +}; + + +int main() +{ + sized_ccharbuf a("abcde", 3); + sized_ccharbuf b("abcff", 3); + sized_ccharbuf c("abdff", 3); + sized_ccharbuf d("abcde", 4); + sized_ccharbuf e("abcde", 2); + printf("%d\n", a == a ); + printf("%d\n", a == b ); + printf("%d\n", a == c ); + printf("%d\n", a == d ); + printf("%d\n", d == a ); + printf("%d\n", a == e ); + printf("\n"); + printf("%d\n", a == "abc" ); + printf("%d\n", a == "aba" ); + printf("%d\n", a == "ab" ); + printf("%d\n", a == "abcd" ); + printf("\n"); + + //////////////////////////////////////////////////// + + FILE* fp = fopen("temp.xml","r"); + char *work = new char [BUFF_SIZE]; + fread(work,BUFF_SIZE,1,fp); + + sax_parser bb(work); + bb.analyze(); + + return 0; +} \ No newline at end of file diff --git a/roast/test/lexical2_test/xml_gen_test.cpp b/roast/test/lexical2_test/xml_gen_test.cpp new file mode 100644 index 00000000..7ed49fad --- /dev/null +++ b/roast/test/lexical2_test/xml_gen_test.cpp @@ -0,0 +1,28 @@ +#include "roast/xml/roast_xml/rule_xml.hpp" + +using namespace roast::lexical; +using namespace roast::lexical::rule; +using namespace roast::roast_xml::rule; + +#pragma warning(disable:4996) +#pragma warning(disable:4102) + +/////////////////////////////////////////////////////////// + +ROAST_LEXICAL_FIXSTR(aaa, "aaa"); +ROAST_LEXICAL_FIXSTR(bbb, "bbb"); + +int main() +{ + printf("%s\n", str_generate >(null_document).c_str() ); + printf("%s\n", str_generate >(null_document).c_str() ); + + printf("%s\n", str_generate >(null_document).c_str() ); + printf("%s\n", str_generate >(null_document).c_str() ); + + printf("%s\n", str_generate >(null_document).c_str() ); + printf("%s\n", str_generate >(null_document).c_str() ); + printf("%s\n", str_generate >(null_document).c_str() ); + + return 0; +}