$search
00001 /*************************************************************************** 00002 tag: Peter Soetens Thu Jul 15 11:21:23 CEST 2004 parser-types.hpp 00003 00004 parser-types.hpp - description 00005 ------------------- 00006 begin : Thu July 15 2004 00007 copyright : (C) 2004 Peter Soetens 00008 email : peter.soetens at mech.kuleuven.ac.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 #ifndef PARSER_TYPES_HPP 00038 #define PARSER_TYPES_HPP 00039 00040 #include "rtt-scripting-config.h" 00041 00042 #include <boost/version.hpp> 00043 00044 #if BOOST_VERSION >= 103800 00045 #include <boost/spirit/include/classic.hpp> 00046 #include <boost/spirit/include/classic_dynamic.hpp> 00047 namespace boost_spirit = boost::spirit::classic; 00048 #else 00049 #include <boost/spirit.hpp> 00050 namespace boost_spirit = boost::spirit; 00051 #endif 00052 #include "../base/ActionInterface.hpp" 00053 #include "rtt-scripting-fwd.hpp" 00054 00055 #undef interface // To avoid name clash with namespace interface and Windows SDK objbase.h included through boost/spirit 00056 00057 namespace RTT 00058 { namespace scripting { 00059 00060 using namespace boost_spirit; 00061 00062 typedef std::string our_buffer_t; 00063 typedef our_buffer_t::iterator our_iterator_t; 00064 typedef position_iterator<our_iterator_t> our_pos_iter_t; 00065 // this is the iterator type that the parsers have to work with. It 00066 // might change some time in the future.. 00067 typedef our_pos_iter_t iter_t; 00068 00069 #if 1 00070 00073 #if defined( WIN32 ) 00074 #ifdef NDEBUG 00075 #pragma optimize( "", off) 00076 #endif 00077 #endif 00078 00083 struct RTT_SCRIPTING_API eol_skip_functor 00084 { 00085 private: 00086 eol_skip_functor(); 00087 public: 00091 eol_skip_functor(bool& skipref) : skipeol(skipref) {} 00092 eol_skip_functor(eol_skip_functor const& orig) : skipeol( orig.skipeol ) {} 00093 bool& skipeol; 00094 typedef nil_t result_t; 00095 00096 template <typename ScannerT> 00097 std::ptrdiff_t 00098 operator()(ScannerT const& scan, result_t& result) const { 00099 if (scan.at_end() || skipeol == false ) 00100 return -1; 00101 00102 std::size_t len = 0; 00103 00104 if ( *scan == '\r') { 00105 ++scan; 00106 ++len; 00107 } 00108 00109 if ( !scan.at_end() && *scan == '\n') { 00110 ++scan; 00111 ++len; 00112 } 00113 if ( len > 0 ) { 00114 return len; 00115 } 00116 00117 return -1; 00118 } 00119 }; 00120 #if defined( WIN32 ) 00121 #ifdef NDEBUG 00122 #pragma optimize( "", on) 00123 #endif 00124 #endif 00125 00128 # define SKIP_PARSER \ 00129 ( comment_p( "#" ) | comment_p( "//" ) | \ 00130 comment_p( "/*", "*/" ) | (space_p - eol_p) | functor_parser<eol_skip_functor>( eol_skip_functor(skipref) ) ) 00131 00132 // here are the typedef's for the scanner, and the rule types.. 00133 //typedef __typeof__ ( SKIP_PARSER ) skip_parser_t; 00134 00135 //register SKIP_PARSER with typeof system 00136 //struct X {}; 00137 //BOOST_TYPEOF_REGISTER_TYPE(X); 00138 //TODO: 00139 //typedef alternative<chlit<>, alternative<chlit<>, alternative<chlit<>, alternative<chlit<>, chlit<> > > > > skip_parser_t; 00140 typedef boost_spirit::alternative<boost_spirit::alternative<boost_spirit::alternative<boost_spirit::alternative<boost_spirit::confix_parser<boost_spirit::impl::string_as_parser::type,boost_spirit::kleene_star<boost_spirit::anychar_parser>,boost_spirit::alternative<boost_spirit::eol_parser,boost_spirit::end_parser>,boost_spirit::unary_parser_category,boost_spirit::non_nested,boost_spirit::is_lexeme>,boost_spirit::confix_parser<boost_spirit::impl::string_as_parser::type,boost_spirit::kleene_star<boost_spirit::anychar_parser>,boost_spirit::alternative<boost_spirit::eol_parser,boost_spirit::end_parser>,boost_spirit::unary_parser_category,boost_spirit::non_nested,boost_spirit::is_lexeme> >,boost_spirit::confix_parser<boost_spirit::impl::string_as_parser::type,boost_spirit::kleene_star<boost_spirit::anychar_parser>,boost_spirit::impl::string_as_parser::type,boost_spirit::unary_parser_category,boost_spirit::non_nested,boost_spirit::is_lexeme> >,boost_spirit::difference<boost_spirit::space_parser,boost_spirit::eol_parser> >,boost_spirit::functor_parser<eol_skip_functor> > skip_parser_t; 00141 00142 //typedef BOOST_TYPEOF( SKIP_PARSER ) skip_parser_t; 00143 /*typedef 00144 alternative<alternative<space_parser, sequence<sequence< 00145 strlit<const char*>, kleene_star<difference<anychar_parser, 00146 chlit<char> > > >, chlit<char> > >, sequence<sequence< 00147 strlit<const char*>, kleene_star<difference<anychar_parser, 00148 strlit<const char*> > > >, strlit<const char*> > > 00149 skip_parser_t;*/ 00150 00151 #else 00152 // we need to know what type the skip parser will be in order to be 00153 // able to know what types the scanner and rule will be exactly. 00154 // So we have to put a typedef here, and in order to not put the skip 00155 // parser definition in two places, we put it here as a macro, and use 00156 // the macro at the appropriate places.. 00157 00158 // we support shell/perl ( "# comment\n" ), C ( non-nested "/* 00159 // comment */" ) and C++ ( "// comment\n" ) style comments. 00160 // These are skipped at the scanner level, by using the standard 00161 // Boost.Spirit skip_iteration_policy. 00162 00163 # define SKIP_PARSER \ 00164 ( comment_p( "#" ) | comment_p( "//" ) | \ 00165 comment_p( "/*", "*/" ) | (space_p - eol_p) ) 00166 00167 // here are the typedef's for the scanner, and the rule types.. 00168 typedef __typeof__( SKIP_PARSER ) skip_parser_t; 00169 #endif 00170 typedef skip_parser_iteration_policy<skip_parser_t> iter_pol_t; 00171 typedef scanner_policies<iter_pol_t> scanner_pol_t; 00172 typedef scanner<iter_t, scanner_pol_t> scanner_t; 00173 typedef rule<scanner_t> rule_t; 00174 typedef stored_rule<scanner_t> stored_rule_t; 00175 typedef rule<lexeme_scanner<scanner_t>::type > lexeme_rule_t; 00176 00177 }} 00178 00179 #endif