Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <boost/bind.hpp>
00038
00039 #include "parse_exception.hpp"
00040 #include "parser-debug.hpp"
00041 #include "CommonParser.hpp"
00042
00043 namespace RTT {
00044 using boost::bind;
00045 using namespace detail;
00046
00047 namespace {
00048 boost::spirit::classic::assertion<std::string> expect_eos("End of statement expected. Use a newline or ';' to separate statements.");
00049 }
00050
00051 CommonParser::~CommonParser() {}
00052
00053 CommonParser::CommonParser()
00054 : identchar( "a-zA-Z_0-9" ), skipeol(true),
00055 skipper( eol_skip_functor(skipeol) )
00056 {
00057
00058 keywordstable =
00059 "do",
00060 "until",
00061 "done",
00062 "or",
00063 "and",
00064 "not",
00065 "include",
00066 "if",
00067 "define",
00068 "then",
00069 "else",
00070 "for",
00071 "foreach",
00072 "while",
00073 "true",
00074 "false",
00075 "const",
00076 "nothing",
00077 "yield",
00078 "var",
00079 "set",
00080 "alias",
00081 "send",
00082 "collect",
00083 "collectIfDone",
00084 "return",
00085 "call",
00086 "try",
00087 "catch";
00088
00089 BOOST_SPIRIT_DEBUG_RULE( idr );
00090 BOOST_SPIRIT_DEBUG_RULE( idlr );
00091 BOOST_SPIRIT_DEBUG_RULE( eos );
00092 BOOST_SPIRIT_DEBUG_RULE( notassertingeos );
00093 BOOST_SPIRIT_DEBUG_RULE( leos );
00094 BOOST_SPIRIT_DEBUG_RULE( endofkeyword );
00095 BOOST_SPIRIT_DEBUG_RULE( keywords );
00096 BOOST_SPIRIT_DEBUG_RULE( keyword );
00097 BOOST_SPIRIT_DEBUG_RULE( identifier );
00098 BOOST_SPIRIT_DEBUG_RULE( templ );
00099 BOOST_SPIRIT_DEBUG_RULE( tidentifier );
00100 BOOST_SPIRIT_DEBUG_RULE( identchar );
00101 BOOST_SPIRIT_DEBUG_RULE( notassertingidentifier );
00102 BOOST_SPIRIT_DEBUG_RULE( lexeme_identifier );
00103 BOOST_SPIRIT_DEBUG_RULE( lexeme_notassertingidentifier );
00104 BOOST_SPIRIT_DEBUG_RULE( type_name );
00105 BOOST_SPIRIT_DEBUG_RULE( skipper );
00106
00107
00108
00109
00110
00111
00112 keywords = keywordstable;
00113 endofkeyword = (~identchar) | eol_p | end_p;
00114 keyword = lexeme_d[keywords >> eps_p(endofkeyword)];
00115
00116 idlr = lexeme_d[alpha_p >> *identchar][assign( lastparsedident )];
00117
00118
00119 notassertingidentifier = (idlr >> !str_p("[]")) - keyword;
00120
00121 identifier = keyword[bind( &CommonParser::seenillegalidentifier, this, _1, _2 )] | (idlr >> !str_p("[]") );
00122
00123
00124 templ = ch_p('<') >> identifier >> *templ >> '>';
00125 tidentifier = identifier >> *templ;
00126
00127
00128
00129 eos = expect_eos( notassertingeos );
00130 notassertingeos = eol_p | ch_p(';') | eps_p(ch_p('}'));
00131 leos = *(space_p - eol_p) >> (eol_p | ch_p(';') | eps_p(ch_p('}')));
00132
00133 chset<> t_identchar( "a-zA-Z-_0-9/<>." );
00134 type_name = lexeme_d[ alpha_p >> *t_identchar ] - keyword;
00135 }
00136
00137 void CommonParser::seenillegalidentifier(iter_t begin, iter_t end )
00138 {
00139 std::string ident(begin, end);
00140 throw parse_exception_illegal_identifier( ident );
00141 }
00142
00143 }