7 #include "../TaskContext.hpp" 8 #include "../internal/Exceptions.hpp" 14 #include <boost/bind.hpp> 15 #include <boost/lambda/lambda.hpp> 16 #include <boost/call_traits.hpp> 19 #include "../internal/mystd.hpp" 20 #include "../internal/GlobalEngine.hpp" 25 using namespace boost;
26 using namespace detail;
32 boost::spirit::classic::assertion<std::string> expect_eof(
"Invalid input in file.");
33 guard<std::string> no_function_guard;
37 error_status<> ScriptParser::handle_no_function(
scanner_t const& scan, parser_error<std::string, iter_t>&e )
40 if ( programparser->parserUsed() == false )
41 return error_status<>( error_status<>::fail );
43 return error_status<>( error_status<>::rethrow );
48 context(tc), caller(tcaller), storage(
Service::Create(
"stack") ),
49 mpositer(positer), ln_offset(0),
52 stateparser(new
StateGraphParser(mpositer, context, context->engine(), commonparser)),
53 programparser(new
ProgramGraphParser(mpositer, context, context->engine(), *commonparser)),
57 BOOST_SPIRIT_DEBUG_RULE( production );
58 BOOST_SPIRIT_DEBUG_RULE( statemachine );
59 BOOST_SPIRIT_DEBUG_RULE( program );
60 BOOST_SPIRIT_DEBUG_RULE(
function );
61 BOOST_SPIRIT_DEBUG_RULE( statement );
65 statemachine[bind(&ScriptParser::seenstatemachine,
this)]
66 | program[bind(&ScriptParser::seenprogram,
this)]
67 | no_function_guard(
function[bind(&ScriptParser::seenfunction,
this)])[boost::bind(&ScriptParser::handle_no_function,
this,_1,_2)]
68 | statement[bind(&ScriptParser::seenstatement,
this)]
73 statemachine = stateparser->
parser();
85 void ScriptParser::seenstatement()
92 while (ret->execute() && ret->isRunning())
97 <<
"Script encountered an error during execution of line " 98 << ret->getLineNumber() << endlog();
104 <<
"Parser refuses to execute more than 10000 yield statements. Fix your program." 115 void ScriptParser::seenprogram()
118 assert( context->
provides()->hasService(
"scripting"));
126 log(
Info) <<
"Loading Program '"<< ret->getName() <<
"'" <<endlog();
127 if ( ss->loadProgram( ret ) ==
false)
128 throw program_load_exception(
"Could not load Program '"+ ret->getName() +
"' :\n failed to load in ScriptingService.\n");
130 log(
Error) <<
"Could not load Program '"<< ret->getName() <<
"' :" << endlog();
139 void ScriptParser::seenfunction()
146 void ScriptParser::seenstatemachine()
149 assert( context->
provides()->hasService(
"scripting"));
155 log(
Info) <<
"Loading StateMachine '"<< ret->getName() <<
"'" <<endlog();
156 ss->loadStateMachine( ret );
158 log(
Error) <<
"Could not load StateMachine'"<< ret->getName() <<
"' :" << endlog();
174 | comment_p(
"/*",
"*/")
182 ln_offset = mpositer.get_position().line - 1;
183 program_text = std::string( begin, end );
188 if (!production.parse(scanner))
194 "Syntax error"), mpositer.get_position().file,
195 mpositer.get_position().line,
196 mpositer.get_position().column);
199 }
catch (
const parser_error<std::string, iter_t>& e)
205 e.descriptor), mpositer.get_position().file,
206 mpositer.get_position().line,
207 mpositer.get_position().column);
214 mpositer.get_position().line,
215 mpositer.get_position().column);
225 delete statementparser;
226 delete programparser;
231 void ScriptParser::clear()
rule_t notassertingeos
End Of Statement Parser.
boost::shared_ptr< ScriptingService > shared_ptr
boost::shared_ptr< ParsedStateMachine > ParsedStateMachinePtr
const char * what() const
boost::shared_ptr< FunctionGraph > FunctionGraphPtr
Service::shared_ptr provides()
Returns this Service.
This is not a parser in the Boost.spirit sense of the word, it's just a class used to hold the parser...
ProgramInterfacePtr bodyParserResult()
void parse(iter_t &begin, iter_t end)
Parses and executes the script from begin to end.
A Parser for Orocos Program Scripts.
boost::shared_ptr< ProgramInterface > ProgramInterfacePtr
virtual parse_exception * copy() const =0
void initBodyParser(const std::string &name, Service::shared_ptr stck, int offset)
Initialize the bodyParser to parse and store each statement it sees.
This is an exception class that keeps a parse_exception pointer along with the location in the file a...
This class contains some very common parser definitions.
void storeOffset()
Stores the current position in the input stream (iterator received from the constructor) in order to ...
parse_exception class that is used for various syntactic errors for which it was not worth defining a...
An execution engine serialises (executes one after the other) the execution of all commands...
ProgramInterfacePtr programParserResult()
Returns the last program parsed by programParser()
This class allows storage and retrieval of operations, ports, attributes and properties provided by a...
rule_t & programParser()
Returns a program foo {} parser.
ScriptParser(iter_t &positer, TaskContext *tc, ExecutionEngine *caller)
Initialize with an initial position, the TaskContext in which context to parse the scripts and the Ta...
scanner< iter_t, scanner_pol_t > scanner_t
rule_t & functionParser()
Parses a function foo {} definition.
ParsedStateMachinePtr getParserResult()
Returns the last state machine instantiation of parser() or null if no instantiations were seen...
skip_parser_iteration_policy< skip_parser_t > iter_pol_t
static RTT_API ExecutionEngine * Instance()
This is an overloaded member function, provided for convenience. It differs from the above function o...
functor_parser< eol_skip_functor > skipper
End Of Statement Parser.
This is the uppermost exception class in the parser system.
rule_t & statementParser()
Parses a single-line statement.
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
This exception is thrown when a program or state machine could not be loaded into a ProgramProcessor ...
The TaskContext is the C++ representation of an Orocos component.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
This interface allows to load program scripts and state machines and allows execution of code...
rule_t & parser()
Returns the top-level parser for state machines.
This class represents a function.
scanner_policies< iter_pol_t > scanner_pol_t
void setText(const std::string &t)
Set the program text.