parser-types.hpp

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-config.h"
00041 
00042 #include <boost/version.hpp>
00043 
00044 #if BOOST_VERSION >= 103800
00045 #include <boost/spirit/include/classic.hpp>
00046 namespace boost_spirit = boost::spirit::classic;
00047 #else
00048 #include <boost/spirit.hpp>
00049 namespace boost_spirit = boost::spirit;
00050 #endif
00051 #include "../CommandInterface.hpp"
00052 
00053 namespace RTT
00054 {
00055   class ProgramGraph;
00056   class VertexNode;
00057   class EdgeCondition;
00058 }
00059 
00060 namespace RTT
00061 {
00062   template< class T>
00063   class Property;
00064   class PropertyBag;
00065   class PropertyBase;
00066   class ConditionInterface;
00067 }
00068 
00069 namespace RTT
00070 {
00071     class TaskContext;
00072 
00073     namespace detail {
00074         class ExpressionParser;
00075         class ArgumentsParser;
00076     }
00077 
00078 
00079 
00080 
00081 
00082 
00083        using namespace boost_spirit;
00084 
00085   typedef std::string our_buffer_t;
00086   typedef our_buffer_t::iterator our_iterator_t;
00087   typedef position_iterator<our_iterator_t> our_pos_iter_t;
00088   // this is the iterator type that the parsers have to work with.  It
00089   // might change some time in the future..
00090   typedef our_pos_iter_t iter_t;
00091 
00092   // a macro using GCC's C++ extension typeof that is used to not have
00093   // to specify impossibly long type names..  See the Boost.Spirit
00094   // documentation for more details, as that's where I got it from..
00095   // we use __typeof__ instead of typeof because it is not disabled by
00096   // using gcc -ansi
00097 
00098   //TODO: this typeof replaced by boost header might not work.
00099 #   define RULE( name, def ) \
00100        boost_spirit::contiguous<boost_spirit::sequence<boost_spirit::alpha_parser,boost_spirit::kleene_star<boost_spirit::chset<char> > > > name = (def)
00101       //BOOST_TYPE_OF(( (def) ) name = (def)
00102   // typeof is not a native c/c++ construct and is gcc specific
00103   //__typeof__( (def) ) name = (def)
00104   
00105 
00106 
00107 #if 1
00108 
00111 #if defined( WIN32 )
00112 #ifdef NDEBUG
00113         #pragma optimize( "", off)
00114     #endif
00115 #endif
00116 
00121     struct RTT_API eol_skip_functor
00122     {
00123     private:
00124         eol_skip_functor();
00125     public:
00129         eol_skip_functor(bool& skipref) : skipeol(skipref) {}
00130         eol_skip_functor(eol_skip_functor const& orig) : skipeol( orig.skipeol ) {}
00131         bool& skipeol;
00132         typedef nil_t result_t;
00133 
00134         template <typename ScannerT>
00135         std::ptrdiff_t
00136         operator()(ScannerT const& scan, result_t& result) const {
00137             if (scan.at_end() || skipeol == false )
00138                 return -1;
00139 
00140             std::size_t len = 0;
00141 
00142             if ( *scan == '\r') {
00143                 ++scan;
00144                 ++len;
00145             }
00146 
00147             if ( !scan.at_end() && *scan == '\n') {
00148                 ++scan;
00149                 ++len;
00150             }
00151             if ( len > 0 ) {
00152                 return len;
00153             }
00154 
00155             return -1;
00156         }
00157     };
00158 #if defined( WIN32 )
00159 #ifdef NDEBUG
00160         #pragma optimize( "", on)
00161     #endif
00162 #endif
00163 
00166 #   define SKIP_PARSER \
00167       ( comment_p( "#" ) | comment_p( "//" ) | \
00168         comment_p( "/*", "*/" ) | (space_p - eol_p) | functor_parser<eol_skip_functor>( eol_skip_functor(skipref) ) )
00169 
00170   // here are the typedef's for the scanner, and the rule types..
00171   //typedef __typeof__ ( SKIP_PARSER ) skip_parser_t;
00172     
00173     //register SKIP_PARSER with typeof system 
00174     //struct X {};
00175     //BOOST_TYPEOF_REGISTER_TYPE(X);
00176     //TODO:
00177     //typedef alternative<chlit<>, alternative<chlit<>, alternative<chlit<>, alternative<chlit<>, chlit<> > > > > skip_parser_t;
00178     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<RTT::eol_skip_functor> > skip_parser_t;
00179     //typedef BOOST_TYPEOF( SKIP_PARSER ) skip_parser_t;
00180     /*typedef
00181         alternative<alternative<space_parser, sequence<sequence<
00182                strlit<const char*>, kleene_star<difference<anychar_parser,
00183                chlit<char> > > >, chlit<char> > >, sequence<sequence<
00184                strlit<const char*>, kleene_star<difference<anychar_parser,
00185                strlit<const char*> > > >, strlit<const char*> > >
00186     skip_parser_t;*/
00187 
00188 #else
00189   // we need to know what type the skip parser will be in order to be
00190   // able to know what types the scanner and rule will be exactly.
00191   // So we have to put a typedef here, and in order to not put the skip
00192   // parser definition in two places, we put it here as a macro, and use
00193   // the macro at the appropriate places..
00194 
00195   // we support shell/perl ( "# comment\n" ), C ( non-nested "/*
00196   // comment */" ) and C++ ( "// comment\n" ) style comments.
00197   // These are skipped at the scanner level, by using the standard
00198   // Boost.Spirit skip_iteration_policy.
00199 
00200 #   define SKIP_PARSER \
00201       ( comment_p( "#" ) | comment_p( "//" ) | \
00202         comment_p( "/*", "*/" ) | (space_p - eol_p) )
00203 
00204   // here are the typedef's for the scanner, and the rule types..
00205   typedef __typeof__( SKIP_PARSER ) skip_parser_t;
00206 #endif
00207   typedef skip_parser_iteration_policy<skip_parser_t> iter_pol_t;
00208   typedef scanner_policies<iter_pol_t> scanner_pol_t;
00209   typedef scanner<iter_t, scanner_pol_t> scanner_t;
00210   typedef rule<scanner_t> rule_t;
00211   typedef rule<lexeme_scanner<scanner_t>::type > lexeme_rule_t;
00212 
00213 }
00214 
00215 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3