Orocos Real-Time Toolkit  2.8.3
parser-types.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 15 11:21:23 CEST 2004 parser-types.hpp
3 
4  parser-types.hpp - description
5  -------------------
6  begin : Thu July 15 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens at mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 #ifndef PARSER_TYPES_HPP
38 #define PARSER_TYPES_HPP
39 
40 #include "rtt-scripting-config.h"
41 
42 #include <boost/version.hpp>
43 
44 #if BOOST_VERSION >= 103800
45 #include <boost/spirit/include/classic.hpp>
46 #include <boost/spirit/include/classic_dynamic.hpp>
47 namespace boost_spirit = boost::spirit::classic;
48 #else
49 #include <boost/spirit.hpp>
50 namespace boost_spirit = boost::spirit;
51 #endif
52 #include "../base/ActionInterface.hpp"
53 #include "rtt-scripting-fwd.hpp"
54 
55 #undef interface // To avoid name clash with namespace interface and Windows SDK objbase.h included through boost/spirit
56 
57 namespace RTT
58 { namespace scripting {
59 
60  using namespace boost_spirit;
61 
62  typedef std::string our_buffer_t;
63  typedef our_buffer_t::iterator our_iterator_t;
64  typedef position_iterator<our_iterator_t> our_pos_iter_t;
65  // this is the iterator type that the parsers have to work with. It
66  // might change some time in the future..
67  typedef our_pos_iter_t iter_t;
68 
69 #if 1
70 
73 #if defined( WIN32 )
74 #ifdef NDEBUG
75  #pragma optimize( "", off)
76  #endif
77 #endif
78 
84  {
85  private:
87  public:
91  eol_skip_functor(bool& skipref) : skipeol(skipref) {}
92  eol_skip_functor(eol_skip_functor const& orig) : skipeol( orig.skipeol ) {}
93  bool& skipeol;
94  typedef nil_t result_t;
95 
96  template <typename ScannerT>
97  std::ptrdiff_t
98  operator()(ScannerT const& scan, result_t& result) const {
99  if (scan.at_end() || skipeol == false )
100  return -1;
101 
102  std::size_t len = 0;
103 
104  if ( *scan == '\r') {
105  ++scan;
106  ++len;
107  }
108 
109  if ( !scan.at_end() && *scan == '\n') {
110  ++scan;
111  ++len;
112  }
113  if ( len > 0 ) {
114  return len;
115  }
116 
117  return -1;
118  }
119  };
120 #if defined( WIN32 )
121 #ifdef NDEBUG
122  #pragma optimize( "", on)
123  #endif
124 #endif
125 
128 # define SKIP_PARSER \
129  ( comment_p( "#" ) | comment_p( "//" ) | \
130  comment_p( "/*", "*/" ) | (space_p - eol_p) | functor_parser<eol_skip_functor>( eol_skip_functor(skipref) ) )
131 
132  // here are the typedef's for the scanner, and the rule types..
133  //typedef __typeof__ ( SKIP_PARSER ) skip_parser_t;
134 
135  //register SKIP_PARSER with typeof system
136  //struct X {};
137  //BOOST_TYPEOF_REGISTER_TYPE(X);
138  //TODO:
139  //typedef alternative<chlit<>, alternative<chlit<>, alternative<chlit<>, alternative<chlit<>, chlit<> > > > > skip_parser_t;
140  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;
141 
142  //typedef BOOST_TYPEOF( SKIP_PARSER ) skip_parser_t;
143  /*typedef
144  alternative<alternative<space_parser, sequence<sequence<
145  strlit<const char*>, kleene_star<difference<anychar_parser,
146  chlit<char> > > >, chlit<char> > >, sequence<sequence<
147  strlit<const char*>, kleene_star<difference<anychar_parser,
148  strlit<const char*> > > >, strlit<const char*> > >
149  skip_parser_t;*/
150 
151 #else
152  // we need to know what type the skip parser will be in order to be
153  // able to know what types the scanner and rule will be exactly.
154  // So we have to put a typedef here, and in order to not put the skip
155  // parser definition in two places, we put it here as a macro, and use
156  // the macro at the appropriate places..
157 
158  // we support shell/perl ( "# comment\n" ), C ( non-nested "/*
159  // comment */" ) and C++ ( "// comment\n" ) style comments.
160  // These are skipped at the scanner level, by using the standard
161  // Boost.Spirit skip_iteration_policy.
162 
163 # define SKIP_PARSER \
164  ( comment_p( "#" ) | comment_p( "//" ) | \
165  comment_p( "/*", "*/" ) | (space_p - eol_p) )
166 
167  // here are the typedef's for the scanner, and the rule types..
168  typedef __typeof__( SKIP_PARSER ) skip_parser_t;
169 #endif
170  typedef skip_parser_iteration_policy<skip_parser_t> iter_pol_t;
171  typedef scanner_policies<iter_pol_t> scanner_pol_t;
172  typedef scanner<iter_t, scanner_pol_t> scanner_t;
173  typedef rule<scanner_t> rule_t;
174  typedef stored_rule<scanner_t> stored_rule_t;
175  typedef rule<lexeme_scanner<scanner_t>::type > lexeme_rule_t;
176 
177 }}
178 
179 #endif
our_buffer_t::iterator our_iterator_t
#define SKIP_PARSER
When using this macro, you must have a boolean variable skipref defined.
std::ptrdiff_t operator()(ScannerT const &scan, result_t &result) const
#define RTT_SCRIPTING_API
eol_skip_functor(eol_skip_functor const &orig)
scanner< iter_t, scanner_pol_t > scanner_t
position_iterator< our_iterator_t > our_pos_iter_t
skip_parser_iteration_policy< skip_parser_t > iter_pol_t
rule< scanner_t > rule_t
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
stored_rule< scanner_t > stored_rule_t
Due to a bug in MSVC 2005, the operator() ends up with a null reference of the skipeol member Tried s...
rule< lexeme_scanner< scanner_t >::type > lexeme_rule_t
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
our_pos_iter_t iter_t
eol_skip_functor(bool &skipref)
By default, eol are skipped.
scanner_policies< iter_pol_t > scanner_pol_t
std::string our_buffer_t