Orocos Real-Time Toolkit  2.8.3
ArgumentsParser.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon May 10 19:10:37 CEST 2004 ArgumentsParser.cxx
3 
4  ArgumentsParser.cxx - description
5  -------------------
6  begin : Mon May 10 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@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 Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, *
24  * Suite 330, Boston, MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 #include "parser-debug.hpp"
29 #ifdef ORO_PRAGMA_INTERFACE
30 #pragma implementation
31 #endif
32 #include "ArgumentsParser.hpp"
33 
34 #include <boost/bind.hpp>
35 #include <boost/lexical_cast.hpp>
36 
37 #include "ExpressionParser.hpp"
38 #include "../TaskContext.hpp"
39 
40 
41 namespace RTT
42 {
43  using namespace detail;
44  using boost::bind;
45 
46  namespace {
47  boost::spirit::classic::assertion<std::string> expect_open("Open brace expected.");
48  boost::spirit::classic::assertion<std::string> expect_close("Closing brace expected ( or could not find out what this line means ).");
49  boost::spirit::classic::assertion<std::string> expect_arg("No argument given after comma.");
50  }
51 
53  ExpressionParser& p, TaskContext* peer, Service::shared_ptr tobject, const std::string& o,
54  const std::string& m )
55  : mparsed( false ), expressionparser( p ),
56  mobject( o ), mmethod( m ), _peer(peer), mtobject(tobject)
57  {
58  BOOST_SPIRIT_DEBUG_RULE( argument );
59  BOOST_SPIRIT_DEBUG_RULE( arguments );
60 
61  // a series of arguments; a command-separated list of arguments
62  // between parentheses..
63  arguments = (
64  ch_p('(')
65  >> !( argument >> *( ch_p( ',' ) >> expect_arg( argument ) ) )
66  >> expect_close(ch_p(')')) )[
67  bind( &ArgumentsParser::seenarguments, this ) ];
68 
69  // a single argument is just a normal expression..
70  argument =
71  expressionparser.parser() [
72  bind( &ArgumentsParser::seen_arg, this ) ];
73  }
74 
75  void ArgumentsParser::seen_arg()
76  {
77  margs.push_back( expressionparser.getResult() );
78  expressionparser.dropResult();
79  }
80 
81  void ArgumentsParser::seenarguments()
82  {
83  mparsed = true;
84  }
85 
87  {
88  margs.clear();
89  }
90 }
ArgumentsParser(ExpressionParser &p, TaskContext *peer, Service::shared_ptr tobject, const std::string &object, const std::string &method)
Construct a new ArgumentsParser.
boost::shared_ptr< Service > shared_ptr
Definition: Service.hpp:101
How we parse: this parser works like a stack-based RPN calculator.
base::DataSourceBase::shared_ptr getResult()
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51