Orocos Real-Time Toolkit
2.5.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Mon May 10 19:10:37 CEST 2004 ArgumentsParser.cxx 00003 00004 ArgumentsParser.cxx - description 00005 ------------------- 00006 begin : Mon May 10 2004 00007 copyright : (C) 2004 Peter Soetens 00008 email : peter.soetens@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 Lesser General Public * 00013 * License as published by the Free Software Foundation; either * 00014 * version 2.1 of the License, or (at your option) any later version. * 00015 * * 00016 * This library is distributed in the hope that it will be useful, * 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00019 * Lesser General Public License for more details. * 00020 * * 00021 * You should have received a copy of the GNU Lesser General Public * 00022 * License along with this library; if not, write to the Free Software * 00023 * Foundation, Inc., 59 Temple Place, * 00024 * Suite 330, Boston, MA 02111-1307 USA * 00025 * * 00026 ***************************************************************************/ 00027 00028 #include "parser-debug.hpp" 00029 #ifdef ORO_PRAGMA_INTERFACE 00030 #pragma implementation 00031 #endif 00032 #include "ArgumentsParser.hpp" 00033 00034 #include <boost/bind.hpp> 00035 #include <boost/lexical_cast.hpp> 00036 00037 #include "ExpressionParser.hpp" 00038 #include "../TaskContext.hpp" 00039 00040 00041 namespace RTT 00042 { 00043 using namespace detail; 00044 using boost::bind; 00045 00046 namespace { 00047 boost::spirit::classic::assertion<std::string> expect_open("Open brace expected."); 00048 boost::spirit::classic::assertion<std::string> expect_close("Closing brace expected ( or could not find out what this line means )."); 00049 boost::spirit::classic::assertion<std::string> expect_arg("No argument given after comma."); 00050 } 00051 00052 ArgumentsParser::ArgumentsParser( 00053 ExpressionParser& p, TaskContext* peer, Service::shared_ptr tobject, const std::string& o, 00054 const std::string& m ) 00055 : mparsed( false ), expressionparser( p ), 00056 mobject( o ), mmethod( m ), _peer(peer), mtobject(tobject) 00057 { 00058 BOOST_SPIRIT_DEBUG_RULE( argument ); 00059 BOOST_SPIRIT_DEBUG_RULE( arguments ); 00060 00061 // a series of arguments; a command-separated list of arguments 00062 // between parentheses.. 00063 arguments = ( 00064 ch_p('(') 00065 >> !( argument >> *( ch_p( ',' ) >> expect_arg( argument ) ) ) 00066 >> expect_close(ch_p(')')) )[ 00067 bind( &ArgumentsParser::seenarguments, this ) ]; 00068 00069 // a single argument is just a normal expression.. 00070 argument = 00071 expressionparser.parser() [ 00072 bind( &ArgumentsParser::seen_arg, this ) ]; 00073 } 00074 00075 void ArgumentsParser::seen_arg() 00076 { 00077 margs.push_back( expressionparser.getResult() ); 00078 expressionparser.dropResult(); 00079 } 00080 00081 void ArgumentsParser::seenarguments() 00082 { 00083 mparsed = true; 00084 } 00085 00086 ArgumentsParser::~ArgumentsParser() 00087 { 00088 margs.clear(); 00089 } 00090 }