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 <boost/spirit.hpp> 00041 #include "../CommandInterface.hpp" 00042 00043 namespace RTT 00044 { 00045 class ProgramGraph; 00046 class VertexNode; 00047 class EdgeCondition; 00048 } 00049 00050 namespace RTT 00051 { 00052 template< class T> 00053 class Property; 00054 class PropertyBag; 00055 class PropertyBase; 00056 class ConditionInterface; 00057 } 00058 00059 namespace RTT 00060 { 00061 class TaskContext; 00062 00063 namespace detail { 00064 class ExpressionParser; 00065 class ArgumentsParser; 00066 } 00067 00068 00069 00070 00071 00072 00073 using namespace boost::spirit; 00074 00075 typedef std::string our_buffer_t; 00076 typedef our_buffer_t::iterator our_iterator_t; 00077 typedef position_iterator<our_iterator_t> our_pos_iter_t; 00078 // this is the iterator type that the parsers have to work with. It 00079 // might change some time in the future.. 00080 typedef our_pos_iter_t iter_t; 00081 00082 // a macro using GCC's C++ extension typeof that is used to not have 00083 // to specify impossibly long type names.. See the Boost.Spirit 00084 // documentation for more details, as that's where I got it from.. 00085 // we use __typeof__ instead of typeof because it is not disabled by 00086 // using gcc -ansi 00087 # define RULE( name, def ) \ 00088 __typeof__( (def) ) name = (def) 00089 00090 00091 #if 1 00092 00096 struct eol_skip_functor 00097 { 00101 static bool skipeol; 00102 typedef nil_t result_t; 00103 00104 template <typename ScannerT> 00105 std::ptrdiff_t 00106 operator()(ScannerT const& scan, result_t& result) const { 00107 if (scan.at_end() || skipeol == false ) 00108 return -1; 00109 00110 std::size_t len = 0; 00111 00112 if ( *scan == '\r') { 00113 ++scan; 00114 ++len; 00115 } 00116 00117 if ( !scan.at_end() && *scan == '\n') { 00118 ++scan; 00119 ++len; 00120 } 00121 if ( len > 0 ) { 00122 return len; 00123 } 00124 00125 return -1; 00126 } 00127 }; 00128 00132 extern functor_parser<eol_skip_functor> eol_skip_p; 00133 00134 # define SKIP_PARSER \ 00135 ( comment_p( "#" ) | comment_p( "//" ) | \ 00136 comment_p( "/*", "*/" ) | (space_p - eol_p) | eol_skip_p ) 00137 00138 // here are the typedef's for the scanner, and the rule types.. 00139 typedef __typeof__( SKIP_PARSER ) skip_parser_t; 00140 #else 00141 // we need to know what type the skip parser will be in order to be 00142 // able to know what types the scanner and rule will be exactly. 00143 // So we have to put a typedef here, and in order to not put the skip 00144 // parser definition in two places, we put it here as a macro, and use 00145 // the macro at the appropriate places.. 00146 00147 // we support shell/perl ( "# comment\n" ), C ( non-nested "/* 00148 // comment */" ) and C++ ( "// comment\n" ) style comments. 00149 // These are skipped at the scanner level, by using the standard 00150 // Boost.Spirit skip_iteration_policy. 00151 00152 # define SKIP_PARSER \ 00153 ( comment_p( "#" ) | comment_p( "//" ) | \ 00154 comment_p( "/*", "*/" ) | (space_p - eol_p) ) 00155 00156 // here are the typedef's for the scanner, and the rule types.. 00157 typedef __typeof__( SKIP_PARSER ) skip_parser_t; 00158 #endif 00159 typedef skip_parser_iteration_policy<skip_parser_t> iter_pol_t; 00160 typedef scanner_policies<iter_pol_t> scanner_pol_t; 00161 typedef scanner<iter_t, scanner_pol_t> scanner_t; 00162 typedef rule<scanner_t> rule_t; 00163 typedef rule<lexeme_scanner<scanner_t>::type > lexeme_rule_t; 00164 00165 } 00166 00167 #endif
1.5.8