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
00110
00111
00112
00113
00114
00115 keywords = keywordstable;
00116 endofkeyword = (~identchar) | eol_p | end_p;
00117 keyword = lexeme_d[keywords >> eps_p(endofkeyword)];
00118
00119
00120
00121
00122
00123
00124 idr = lexeme_d[ alpha_p >> *identchar ][assign( lastparsedident )] - keyword;
00125 idlr = lexeme_d[ alpha_p >> *identchar ][assign( lastparsedident )] - keyword;
00126
00127
00128
00129 lexeme_identifier = idlr | keyword[bind( &CommonParser::seenillegalidentifier, this )];
00130 lexeme_notassertingidentifier = idlr;
00131
00132 notassertingidentifier = idr >> !str_p("[]");
00133 identifier = (idr >> !str_p("[]")) | keyword[bind( &CommonParser::seenillegalidentifier, this )];
00134
00135
00136 templ = ch_p('<') >> identifier >> *templ >> '>';
00137 tidentifier = identifier >> *templ;
00138
00139
00140
00141 eos = expect_eos( notassertingeos );
00142 notassertingeos = eol_p | ch_p(';') | eps_p(ch_p('}'));
00143 leos = *(space_p - eol_p) >> (eol_p | ch_p(';') | eps_p(ch_p('}')));
00144
00145 chset<> t_identchar( "a-zA-Z-_0-9/<>." );
00146 type_name = lexeme_d[ alpha_p >> *t_identchar ] - keyword;
00147 }
00148
00149 void CommonParser::seenillegalidentifier()
00150 {
00151 throw parse_exception_illegal_identifier( lastparsedident );
00152 }
00153 }