46 #include "../Logger.hpp" 57 #include "../TaskContext.hpp" 58 #include "../internal/GlobalService.hpp" 61 #include <boost/bind.hpp> 62 #include <boost/lambda/lambda.hpp> 66 #pragma optimize( "", off) 72 using namespace boost;
73 using namespace detail;
78 boost::spirit::classic::assertion<std::string> expect_opencurly(
"Open curly brace '{' expected.");
79 boost::spirit::classic::assertion<std::string> expect_closecurly(
"Closing curly brace '}' expected in statement block (or could not find out what this line means).");
80 boost::spirit::classic::assertion<std::string> expect_closefunction(
"Closing curly brace '}' expected at end of program or function (or could not find out what this line means).");
81 boost::spirit::classic::assertion<std::string> expect_open(
"Open brace '(' expected.");
82 boost::spirit::classic::assertion<std::string> expect_close(
"Closing brace ')' expected.");
83 boost::spirit::classic::assertion<std::string> expect_comma(
"Expected a comma separator.");
84 boost::spirit::classic::assertion<std::string> expect_ident(
"Expected a valid identifier.");
85 boost::spirit::classic::assertion<std::string> expect_semicolon(
"Semicolon ';' expected after statement.");
86 boost::spirit::classic::assertion<std::string> expect_condition(
"Expected a boolean expression ( a condition ).");
87 boost::spirit::classic::assertion<std::string> expect_expression(
"Expected an expression.");
88 boost::spirit::classic::assertion<std::string> expect_command(
"Expected a command after 'do'.");
89 boost::spirit::classic::assertion<std::string> expect_nl(
"Expected a newline after statement.");
90 boost::spirit::classic::assertion<std::string> expect_eof(
"Invalid input in file.");
91 boost::spirit::classic::assertion<std::string> expect_term(
"No valid termination claues found in do ... until { } block.");
96 : rootc( t ),context(), fcontext(), mpositer( positer ),
98 implcond(0), mcondition(0), try_cond(0),
100 conditionparser( rootc, caller, cp ),
101 valuechangeparser( rootc, cp, t->provides(), caller ),
102 expressionparser( rootc, caller, cp ),
104 peerparser(rootc, commonparser),
107 exportf(false),globalf(false),
123 BOOST_SPIRIT_DEBUG_RULE(
newline );
137 BOOST_SPIRIT_DEBUG_RULE(
line );
138 BOOST_SPIRIT_DEBUG_RULE(
content );
139 BOOST_SPIRIT_DEBUG_RULE(
program );
142 BOOST_SPIRIT_DEBUG_RULE(
function );
148 BOOST_SPIRIT_DEBUG_RULE(
callpart );
154 BOOST_SPIRIT_DEBUG_RULE(
ifblock );
155 BOOST_SPIRIT_DEBUG_RULE(
funcargs );
160 opencurly = expect_opencurly( ch_p(
'{') );
162 semicolon = expect_semicolon( ch_p(
';') );
185 funcargs = ch_p(
'(') >> ( !str_p(
"void") >> ch_p(
')') | ((
257 program_text =
"Bug: Program Text to be set by Parser.";
309 std::string def(begin, end);
317 pi->setProgramService(ptsk);
318 pi->setUnloadOnStop(
false );
341 rettype = std::string(begin, end);
347 std::string funcdef(begin, end);
360 if (
mfuncs.count( funcdef ) )
367 throw_(
iter_t(),
"Return type '" +
rettype +
"' for function '"+ funcdef +
"' is an unknown type." );
400 std::map<const DataSourceBase*, DataSourceBase*> dummy;
403 log(
Warning) <<
"Redefining function '"<<
rootc->
getName() <<
"." << mfunc->getName() <<
"': only new programs will use this new function." <<
endlog();
409 std::map<const DataSourceBase*, DataSourceBase*> dummy;
416 std::map<const DataSourceBase*, DataSourceBase*> dummy;
418 if (
rootc->
provides(
"scripting")->hasMember( mfunc->getName() ) )
419 log(
Warning) <<
"Redefining function '"<<
rootc->
getName() <<
".scripting."<< mfunc->getName() <<
"': only new programs will use this new function." <<
endlog();
489 std::string fname(begin, end);
490 if (
mfuncs.count(fname) == 0 )
511 log(
Warning) <<
" 'call' has been deprecated. Please remove this keyword." <<
endlog();
570 std::pair<ActionInterface*, ConditionInterface*> comcon;
593 std::pair<ActionInterface*, ConditionInterface*> comcon;
615 if ( acv.size() == 1) {
618 else if (acv.size() > 1) {
655 std::pair<ActionInterface*, ConditionInterface*> comcon;
693 iter_t begin_copy = begin;
697 scanner_t scanner( begin, end, policies );
715 (*it)->setText( program_text );
717 std::vector<ProgramInterfacePtr> result;
719 result.push_back( *it );
723 catch(
const parser_error<std::string, iter_t>& e )
747 iter_t begin_copy = begin;
752 scanner_t scanner( begin, end, policies );
754 std::vector< ProgramInterfacePtr > function_list;
767 for (funcmap::iterator it=
mfuncs.begin();it!=
mfuncs.end();++it) {
768 it->second->setText( program_text );
769 function_list.push_back( it->second );
773 return function_list;
776 catch(
const parser_error<std::string, iter_t>& e )
827 while ( !
mfuncs.empty() ) {
901 if ( acv.size() == 1) {
904 else if (acv.size() > 1) {
907 if ( conds.size() ==1 ) {
908 cond = conds.front();
910 else if ( conds.size() > 1) {
911 cond = conds.front();
913 while ( i != conds.size() ) {
std::vector< base::DataSourceBase::shared_ptr > callfnargs
std::pair< base::ActionInterface *, ConditionInterface * > getParseResultAsCommand()
std::vector< base::DataSourceBase::shared_ptr > result()
void seenreturnstatement()
This class builds a program consisting of data contained in a program graph tree, based on the Boost ...
void cleanup(bool remove_service)
boost::shared_ptr< FunctionGraph > FunctionGraphPtr
ConditionInterface * getParseResult()
base::AttributeBase * buildAttribute(std::string name, base::DataSourceBase::shared_ptr source=0) const
Service::shared_ptr provides()
void load(Service::shared_ptr source)
virtual AttributeBase * clone() const =0
rule_t & bareDefinitionParser()
ProgramInterfacePtr bodyParserResult()
CommonParser & commonparser
FunctionGraphPtr mcallfunc
void clearParseState()
Clears helper variables of parser.
This interface represents the concept of a condition which can be evaluated and return true or false...
void seenreturntype(iter_t begin, iter_t end)
ArgumentsParser * argsparser
void programtext(iter_t, iter_t)
bool skipeol
Saves eol skipping state.
ConditionInterface * implcond
ConditionInterface * mcondition
boost::shared_ptr< FunctionGraphBuilder > program_builder
void programdef(iter_t begin, iter_t end)
ExpressionParser expressionparser
virtual DataSourceBase::shared_ptr getDataSource() const =0
void seenwhilestatement()
void seencallfunclabel(iter_t begin, iter_t end)
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
virtual parse_exception * copy() const =0
void initBodyParser(const std::string &name, Service::shared_ptr stck, int offset)
ConditionInterface * getCmdResult()
std::stack< base::ActionInterface * > for_incr_command
void seencallfuncstatement()
This class contains some very common parser definitions.
std::vector< scripting::ConditionInterface * > assignConditions()
boost::shared_ptr< Service > shared_ptr
ProgramInterfacePtr programParserResult()
void store(Service::shared_ptr other)
scanner< iter_t, scanner_pol_t > scanner_t
rule_t & functionParser()
ProgramGraphParser(iter_t &positer, TaskContext *context, ExecutionEngine *caller, CommonParser &cp)
skip_parser_iteration_policy< skip_parser_t > iter_pol_t
This class represents a program as an Service in the Orocos TaskContext system.
Service::shared_ptr context
functor_parser< eol_skip_functor > skipper
static std::ostream & endl(std::ostream &__os)
Based on the software pattern 'command', this interface allows execution of action objects...
base::DataSourceBase::shared_ptr getResult()
void setStack(Service::shared_ptr st)
internal::AssignableDataSource< bool >::shared_ptr result()
rule_t & statementParser()
Service::shared_ptr fcontext
ConditionInterface * try_cond
void seenfuncidentifier(iter_t begin, iter_t end)
ValueChangeParser valuechangeparser
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
std::vector< ProgramInterfacePtr > parse(iter_t &begin, iter_t end)
Tries to parse programs, returns the generated programs on success.
std::vector< ProgramInterfacePtr > parseFunction(iter_t &begin, iter_t end)
static shared_ptr Instance()
ConditionParser conditionparser
our_pos_iter_t & mpositer
base::AttributeBase * lastDefinedValue()
base::ActionInterface * for_init_command
std::vector< base::ActionInterface * > assignCommands()
std::vector< FunctionGraphPtr > program_list
boost::intrusive_ptr< DataSourceBase > shared_ptr
rule_t notassertingidentifier
identifier with <template> marks in it
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
void seenbreakstatement()
void functiondef(iter_t begin, iter_t end)
boost::shared_ptr< ProgramService > ProgramServicePtr
scanner_policies< iter_pol_t > scanner_pol_t
Based on the software pattern 'composite', this class RTT_SCRIPTING_API allows composing command obje...
const ExecutionEngine * engine() const
static Logger::LogFunction endlog()
static RTT_API Service::shared_ptr Instance()
virtual const std::string & getName() const