52 #include "../TaskContext.hpp" 56 #include "../internal/Exceptions.hpp" 57 #include "../base/AttributeBase.hpp" 66 #include <boost/bind.hpp> 67 #include <boost/lambda/lambda.hpp> 68 #include <boost/call_traits.hpp> 71 #include "../internal/mystd.hpp" 75 using namespace boost;
76 using namespace detail;
89 boost::spirit::classic::assertion<GraphSyntaxErrors> expect_state(state_expected);
90 boost::spirit::classic::assertion<GraphSyntaxErrors> expect_handle(handle_expected);
91 boost::spirit::classic::assertion<GraphSyntaxErrors> expect_transition(transition_expected);
92 boost::spirit::classic::assertion<std::string> expect_end(
"Ending '}' expected ( or could not find out what this line means ).");
93 boost::spirit::classic::assertion<std::string> expect_end_of_state(
"Exptected ending '}' at end of state ( or could not find out what this line means ).");
94 boost::spirit::classic::assertion<std::string> expect_if(
"Wrongly formatted \"if ... then select\" clause.");
95 boost::spirit::classic::assertion<std::string> expect_select(
"'select' statement required after emty transition program.");
96 boost::spirit::classic::assertion<std::string> expect_select_ident(
"'select' requires a valid state name.");
97 boost::spirit::classic::assertion<std::string> expect_comma(
"Expected a comma separator.");
98 boost::spirit::classic::assertion<std::string> expect_ident(
"Expected a valid identifier.");
99 boost::spirit::classic::assertion<std::string> expect_event_or_if(
"Expected an event name or an if clause in transition statement.");
100 boost::spirit::classic::assertion<std::string> expect_open(
"Open brace expected.");
101 boost::spirit::classic::assertion<std::string> expect_eof(
"Invalid input in file.");
102 boost::spirit::classic::assertion<std::string> expect_eol(
"Newline expected at end of statement.");
103 boost::spirit::classic::assertion<std::string> expect_semicolon(
"Semi colon expected after statement.");
104 boost::spirit::classic::assertion<std::string> expect_open_parenth(
"Open parenthesis expected." );
105 boost::spirit::classic::assertion<std::string> expect_close_parenth(
"Open parenthesis expected." );
106 boost::spirit::classic::assertion<std::string> expect_eventselect(
"'select' statement required after event or transition program.");
107 boost::spirit::classic::assertion<std::string> expect_eventargs(
"Could not parse arguments after event.");
118 curinstantiatedmachine(),
119 curmachinebuilder( 0 ),
120 curinitialstateflag( false ),
121 curfinalstateflag( false ),
123 curnonprecstate( 0 ),
131 conditionparser( new
ConditionParser( context, caller, *commonparser ) ),
132 valuechangeparser( new
ValueChangeParser(context, *commonparser, context->provides(), caller) ),
135 peerparser( new
PeerParser(context, *commonparser, true) )
138 BOOST_SPIRIT_DEBUG_RULE(
body );
143 BOOST_SPIRIT_DEBUG_RULE(
varline );
144 BOOST_SPIRIT_DEBUG_RULE(
state );
145 BOOST_SPIRIT_DEBUG_RULE(
vardec );
149 BOOST_SPIRIT_DEBUG_RULE(
entry );
152 BOOST_SPIRIT_DEBUG_RULE(
handle );
155 BOOST_SPIRIT_DEBUG_RULE(
exit );
158 BOOST_SPIRIT_DEBUG_RULE(
ifbranch );
161 BOOST_SPIRIT_DEBUG_RULE(
program );
162 BOOST_SPIRIT_DEBUG_RULE(
selector );
187 >> expect_open( ch_p(
'{' ) )
189 >> expect_end( ch_p(
'}' ) );
228 >> expect_open(ch_p(
'{' ))
251 >> expect_open( ch_p(
'{' ))
253 >> expect_end( ch_p(
'}' ) )[
257 >> expect_open(ch_p(
'{'))>>
programBody >> expect_end(ch_p(
'}'))[
261 >> expect_open(ch_p(
'{'))>>
programBody >> expect_end(ch_p(
'}'))[
265 >> expect_open(ch_p(
'{')) >>
programBody >> expect_end(ch_p(
'}'))[
269 >> expect_open(ch_p(
'{'))>>
programBody >> expect_end(ch_p(
'}'))[
292 >> expect_open(ch_p(
'{'))
294 >> expect_end(ch_p(
'}')) );
355 std::string def(s, f);
358 assert( dynamic_cast<StateDescription*>(
curtemplate->getState( def ) ) );
480 if (peer->hasOperation(
evname) ) {
486 if ( peer->hasService(
evname) ==
false || peer->getService(
evname)->hasOperation(
"read") ==
false) {
518 std::string state_id(s,f);
525 if ( !state_id.empty() ) {
535 assert( next_state );
590 assert(
peer->provides()->hasMember(
evname) );
677 vector<string> states =
curtemplate->getStateList();
678 for( vector<string>::const_iterator it = states.begin(); it != states.end(); ++it)
680 assert( dynamic_cast<StateDescription*>(
curtemplate->getState( *it ) ) );
697 for ( std::vector<ActionInterface*>::iterator i =
varinitcommands.begin();
708 for( StateMachine::ChildList::const_iterator it=
curtemplate->getChildren().begin();
740 scanner_t scanner( begin, end, policies );
762 catch(
const parser_error<std::string, iter_t>& e )
772 catch(
const parser_error<GraphSyntaxErrors, iter_t>& )
831 for( StateMachine::ChildList::const_iterator it=
curtemplate->getChildren().begin();
845 for ( std::vector<ActionInterface*>::iterator i =
varinitcommands.begin();
956 "\" already used as object name in task '"+
context->
getName()+
"'." ));
971 std::string name( begin, end );
986 std::string name( begin, end );
1020 machineparams_t::iterator j = params.find( i->first );
1021 if ( j == params.end() )
1025 for ( machineparams_t::iterator i = params.begin(); i != params.end(); ++i )
1030 "No value given for argument \"" + i->first +
"\" in instantiation of this StateMachine." ));
1031 #ifndef ORO_EMBEDDED 1033 paraminitcommands.push_back( i->second->getDataSource()->updateAction( j->second.get() ) );
1040 ActionInterface* ret = i->second->getDataSource()->updateAction( j->second.get());
1074 for(std::vector<ActionInterface*>::iterator it = acv.begin(); it!=acv.end(); ++it)
1083 assert( pnames.size() == tbases.size() );
1084 for (
unsigned int i = 0; i < pnames.size(); ++i)
1085 curtemplate->addParameter( pnames[i] , tbases[i] );
ProgramInterface * getHandleProgram() const
std::vector< base::DataSourceBase::shared_ptr > result()
unsigned int selectln
are we instantiating a rootmachine ?
ValueChangeParser * valuechangeparser
void setEntryProgram(ProgramInterfacePtr entry)
std::vector< base::AttributeBase * > definedValues()
void seenmachineinstargumentname(iter_t begin, iter_t end)
void saveText(iter_t begin, iter_t end)
ConditionInterface * getParseResult()
rule_t statemachinecontent
void seensubMachineinstantiation()
Service::shared_ptr provides()
rule_t & aliasDefinitionParser()
std::string curmachineinstargumentname
std::string curmachinename
void setHandleProgram(ProgramInterfacePtr handle)
ProgramInterfacePtr bodyParserResult()
void setRunProgram(ProgramInterfacePtr run)
void setEntryPoint(int line)
rule_t machineinstantiation
This interface represents the concept of a condition which can be evaluated and return true or false...
const std::string & getName() const
const std::string & getName() const
Get the name of this state.
std::string curinstmachinename
StateDescription * curstate
bool skipeol
Saves eol skipping state.
This class represents a state with all actions stored in an external program.
StateDescription * postponeState()
rule_t rootmachineinstantiation
StateGraphParser(iter_t &positer, TaskContext *tc, ExecutionEngine *caller, CommonParser *cp)
void statedef(iter_t s, iter_t f)
void seenstatemachineend()
virtual ConditionInterface * clone() const =0
void seenmachinevariable()
ProgramGraphParser * progParser
rule_t machineinstarguments
A Parser for Orocos Program Scripts.
ConditionParser * conditionparser
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
virtual parse_exception * copy() const =0
void initBodyParser(const std::string &name, Service::shared_ptr stck, int offset)
machinenamemap_t rootmachines
rule_t subMachinevarchange
This class contains some very common parser definitions.
machineparamvalues_t curinstmachineparams
std::map< std::string, base::AttributeBase * > machineparams_t
void doselect(const std::string &name)
std::map< std::string, ConditionCache * > global_port_events
ParsedStateMachinePtr curinstantiatedmachine
void store(Service::shared_ptr other)
scanner< iter_t, scanner_pol_t > scanner_t
ProgramInterface * getEntryProgram() const
ParsedStateMachinePtr getParserResult()
std::vector< base::ActionInterface * > varinitcommands
void seenmachineinstargumentvalue()
void inprogram(const std::string &name)
void setExitProgram(ProgramInterfacePtr exit)
skip_parser_iteration_policy< skip_parser_t > iter_pol_t
boost::shared_ptr< StateMachineService > getService() const
rule_t machineinstargument
functor_parser< eol_skip_functor > skipper
void startrootmachineinstantiation()
Based on the software pattern 'command', this interface allows execution of action objects...
std::vector< std::string > definedNames()
base::DataSourceBase::shared_ptr getResult()
StateMachineBuilder * curmachinebuilder
void seenmachinetypename(iter_t begin, iter_t end)
std::vector< base::DataSourceBase::shared_ptr > evargs
store line number of select's 'if' statement.
boost::shared_ptr< StateMachineService > curobject
void seenrootmachineinstantiation()
boost::shared_ptr< ProgramInterface > transProgram
std::map< std::string, ConditionCache * > cur_port_events
ProgramInterface * getRunProgram() const
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
ExpressionParser * expressionparser
ParsedStateMachinePtr curtemplate
boost::shared_ptr< ProgramInterface > elseProgram
rule_t & paramDefinitionParser()
rule_t & constantDefinitionParser()
ArgumentsParser * argsparser
void seeneventname(iter_t s, iter_t f)
rule_t & variableDefinitionParser()
virtual void add(base::ActionInterface *com)
void seenstatemachinename(iter_t begin, iter_t end)
std::vector< base::ActionInterface * > assignCommands()
ParsedStateMachinePtr build(bool instantiate)
CommonParser * commonparser
std::vector< typename MapT::mapped_type > values(const MapT &map)
boost::intrusive_ptr< DataSourceBase > shared_ptr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
StateDescription * curnonprecstate
std::vector< base::ActionInterface * > paraminitcommands
our_pos_iter_t & mpositer
machinebuilders_t machinebuilders
void seeninstmachinename(iter_t begin, iter_t end)
boost::shared_ptr< ProgramInterface > finishProgram()
our_pos_iter_t saveStartPos
boost::shared_ptr< ParsedStateMachine > ParsedStateMachinePtr
StateDescription * elsestate
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
ProgramInterface * getExitProgram() const
This class represents a stateMachine as a Service in the Orocos TaskContext system.
std::vector< ParsedStateMachinePtr > parse(iter_t &begin, iter_t end)
ConditionInterface * curcondition
virtual const std::string & getName() const
void seenselect(iter_t s, iter_t f)
void seenmachineinstantiation()