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 "async",
00076 "time",
00077 "const",
00078 "nothing",
00079 "yield",
00080 "var",
00081 "set",
00082 "alias",
00083 "sync",
00084 "send",
00085 "call",
00086 "collect",
00087 "collectIfDone",
00088 "return",
00089 "call",
00090 "try",
00091 "catch";
00092
00093 BOOST_SPIRIT_DEBUG_RULE( idr );
00094 BOOST_SPIRIT_DEBUG_RULE( idlr );
00095 BOOST_SPIRIT_DEBUG_RULE( eos );
00096 BOOST_SPIRIT_DEBUG_RULE( notassertingeos );
00097 BOOST_SPIRIT_DEBUG_RULE( leos );
00098 BOOST_SPIRIT_DEBUG_RULE( endofkeyword );
00099 BOOST_SPIRIT_DEBUG_RULE( keywords );
00100 BOOST_SPIRIT_DEBUG_RULE( keyword );
00101 BOOST_SPIRIT_DEBUG_RULE( identifier );
00102 BOOST_SPIRIT_DEBUG_RULE( templ );
00103 BOOST_SPIRIT_DEBUG_RULE( tidentifier );
00104 BOOST_SPIRIT_DEBUG_RULE( identchar );
00105 BOOST_SPIRIT_DEBUG_RULE( notassertingidentifier );
00106 BOOST_SPIRIT_DEBUG_RULE( lexeme_identifier );
00107 BOOST_SPIRIT_DEBUG_RULE( lexeme_notassertingidentifier );
00108 BOOST_SPIRIT_DEBUG_RULE( type_name );
00109 BOOST_SPIRIT_DEBUG_RULE( skipper );
00110
00111
00112
00113
00114
00115
00116 keywords = keywordstable;
00117 endofkeyword = (~identchar) | eol_p | end_p;
00118 keyword = lexeme_d[keywords >> eps_p(endofkeyword)];
00119
00120
00121
00122
00123
00124
00125 idr = lexeme_d[ alpha_p >> *identchar ][assign( lastparsedident )] - keyword;
00126 idlr = lexeme_d[ alpha_p >> *identchar ][assign( lastparsedident )] - keyword;
00127
00128
00129
00130 lexeme_identifier = idlr | keyword[bind( &CommonParser::seenillegalidentifier, this )];
00131 lexeme_notassertingidentifier = idlr;
00132
00133 notassertingidentifier = idr >> !str_p("[]");
00134 identifier = (idr >> !str_p("[]")) | keyword[bind( &CommonParser::seenillegalidentifier, this )];
00135
00136
00137 templ = ch_p('<') >> identifier >> *templ >> '>';
00138 tidentifier = identifier >> *templ;
00139
00140
00141
00142 eos = expect_eos( notassertingeos );
00143 notassertingeos = eol_p | ch_p(';') | eps_p(ch_p('}'));
00144 leos = *(space_p - eol_p) >> (eol_p | ch_p(';') | eps_p(ch_p('}')));
00145
00146 chset<> t_identchar( "a-zA-Z-_0-9/<>." );
00147 type_name = lexeme_d[ alpha_p >> *t_identchar ] - keyword;
00148 }
00149
00150 void CommonParser::seenillegalidentifier()
00151 {
00152 throw parse_exception_illegal_identifier( lastparsedident );
00153 }
00154
00155 }