parse_exception.hpp
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 #ifndef ORO_PARSE_EXCEPTION_HPP
00038 #define ORO_PARSE_EXCEPTION_HPP
00039
00040 #include <string>
00041 #include <vector>
00042 #include "../DataSourceBase.hpp"
00043 #include "../rtt-config.h"
00044
00045 #ifdef ORO_PRAGMA_INTERFACE
00046 #pragma interface
00047 #endif
00048
00049 namespace RTT
00050 {
00051 class parse_exception;
00052
00058 class RTT_EXPORT file_parse_exception
00059 {
00060 parse_exception* mpe;
00061 std::string mfile;
00062 int mline;
00063 int mcolumn;
00064
00065 file_parse_exception& operator=( const file_parse_exception& rhs );
00066 public:
00067 file_parse_exception( const file_parse_exception& rhs );
00068 file_parse_exception( parse_exception* pe, const std::string& file,
00069 int line, int column )
00070 : mpe( pe ), mfile( file ), mline( line ), mcolumn( column )
00071 {
00072 }
00073 ~file_parse_exception();
00074
00075 const std::string what() const;
00076 };
00077
00083 class RTT_EXPORT parse_exception
00084 {
00085
00086 parse_exception& operator=( const parse_exception& );
00087 protected:
00088 parse_exception() {};
00089 public:
00090 virtual ~parse_exception() {};
00091 virtual const std::string what() const = 0;
00092 virtual parse_exception* copy() const = 0;
00093 };
00094
00095 namespace detail {
00096
00102 class RTT_EXPORT semantic_parse_exception
00103 : public parse_exception
00104 {
00105
00106 semantic_parse_exception& operator=( const semantic_parse_exception& );
00107 protected:
00108 semantic_parse_exception() {};
00109 };
00110
00116 class RTT_EXPORT fatal_syntactic_parse_exception
00117 : public parse_exception
00118 {
00119
00120 fatal_syntactic_parse_exception& operator=( const fatal_syntactic_parse_exception& );
00121 protected:
00122 fatal_syntactic_parse_exception() {};
00123 };
00124
00131 class RTT_EXPORT fatal_semantic_parse_exception
00132 : public parse_exception
00133 {
00134
00135 fatal_semantic_parse_exception& operator=( const fatal_syntactic_parse_exception& );
00136 protected:
00137 fatal_semantic_parse_exception() {};
00138 };
00139
00145 class RTT_EXPORT syntactic_parse_exception
00146 : public parse_exception
00147 {
00148
00149 syntactic_parse_exception& operator=( const syntactic_parse_exception& );
00150 protected:
00151 syntactic_parse_exception() {};
00152 };
00153
00154
00155
00156 class RTT_EXPORT parse_exception_illegal_identifier
00157 : public syntactic_parse_exception
00158 {
00159 std::string mident;
00160 public:
00161 parse_exception_illegal_identifier( const std::string& ident )
00162 : mident( ident )
00163 {
00164 };
00165
00166 const std::string what() const
00167 {
00168 return "The string \"" + mident + "\" cannot be used as an identifer.";
00169 }
00170
00171 parse_exception_illegal_identifier* copy() const
00172 {
00173 return new parse_exception_illegal_identifier( *this );
00174 }
00175
00176 const std::string& identifier() const
00177 {
00178 return mident;
00179 }
00180 };
00181
00186 class RTT_EXPORT parse_exception_semantic_error
00187 : public semantic_parse_exception
00188 {
00189 std::string mdesc;
00190 public:
00191 parse_exception_semantic_error( const std::string& desc )
00192 : mdesc( desc )
00193 {
00194 };
00195
00196 const std::string what() const
00197 {
00198 return "Semantic error: " + mdesc;
00199 }
00200
00201 parse_exception_semantic_error* copy() const
00202 {
00203 return new parse_exception_semantic_error( *this );
00204 }
00205
00206 const std::string& desc() const
00207 {
00208 return mdesc;
00209 }
00210 };
00211
00216 class RTT_EXPORT parse_exception_fatal_semantic_error
00217 : public fatal_semantic_parse_exception
00218 {
00219 std::string mdesc;
00220 public:
00221 parse_exception_fatal_semantic_error( const std::string& desc )
00222 : mdesc( desc )
00223 {
00224 };
00225
00226 const std::string what() const
00227 {
00228 return "Fatal Semantic error: " + mdesc;
00229 }
00230
00231 parse_exception_fatal_semantic_error* copy() const
00232 {
00233 return new parse_exception_fatal_semantic_error( *this );
00234 }
00235
00236 const std::string& desc() const
00237 {
00238 return mdesc;
00239 }
00240 };
00241
00248 class RTT_EXPORT parse_exception_parser_fail
00249 : public parse_exception
00250 {
00251 public:
00252 parse_exception_parser_fail()
00253 {
00254 }
00255
00256 const std::string what() const
00257 {
00258 return "Parse Failure Exception ( This _specific_ parser could not parse the input )";
00259 }
00260
00261 parse_exception_parser_fail* copy() const
00262 {
00263 return new parse_exception_parser_fail( *this );
00264 }
00265 };
00266
00271 class RTT_EXPORT parse_exception_syntactic_error
00272 : public syntactic_parse_exception
00273 {
00274 std::string mdesc;
00275 public:
00276 parse_exception_syntactic_error( const std::string& desc )
00277 : mdesc( desc )
00278 {
00279 };
00280
00281 const std::string what() const
00282 {
00283 return "Syntactic error: " + mdesc;
00284 }
00285
00286 parse_exception_syntactic_error* copy() const
00287 {
00288 return new parse_exception_syntactic_error( *this );
00289 }
00290
00291 const std::string& desc() const
00292 {
00293 return mdesc;
00294 }
00295 };
00296
00297 class RTT_EXPORT parse_exception_no_such_component
00298 : public semantic_parse_exception
00299 {
00300 std::string mname;
00301 std::string mmeth;
00302 public:
00303 parse_exception_no_such_component( const std::string& name, const std::string& meth )
00304 : mname( name ), mmeth(meth)
00305 {
00306 }
00307
00308 const std::string what() const
00309 {
00310 return "Object or task \"" + mname + "\" registered no method "+mmeth+" (or "+mname+" was not found at all).";
00311 }
00312
00313 parse_exception_no_such_component* copy() const
00314 {
00315 return new parse_exception_no_such_component( *this );
00316 }
00317
00318 const std::string& componentName() const
00319 {
00320 return mname;
00321 }
00322 };
00323
00324 class RTT_EXPORT parse_exception_no_such_method_on_component
00325 : public semantic_parse_exception
00326 {
00327 std::string mcomponentname;
00328 std::string mmethodname;
00329 public:
00330 parse_exception_no_such_method_on_component(
00331 const std::string& componentname, const std::string& methodname )
00332 : mcomponentname( componentname ), mmethodname( methodname )
00333 {
00334 };
00335
00336 const std::string what() const
00337 {
00338 return "No method \"" + mmethodname + "\" registered for the object or task \"" + mcomponentname + "\".";
00339 }
00340
00341 parse_exception_no_such_method_on_component* copy() const
00342 {
00343 return new parse_exception_no_such_method_on_component( *this );
00344 }
00345
00346 const std::string& componentName() const
00347 {
00348 return mcomponentname;
00349 }
00350
00351 const std::string& methodName() const
00352 {
00353 return mmethodname;
00354 }
00355 };
00356
00357 class RTT_EXPORT parse_exception_wrong_number_of_arguments
00358 : public fatal_semantic_parse_exception
00359 {
00360 std::string mcomponentname;
00361 std::string mmethodname;
00362 int mexpectednumber;
00363 int mreceivednumber;
00364 public:
00365 parse_exception_wrong_number_of_arguments(
00366 const std::string& componentname, const std::string& methodname,
00367 int expectednumber, int receivednumber )
00368 : mcomponentname( componentname ), mmethodname( methodname ),
00369 mexpectednumber( expectednumber ),
00370 mreceivednumber( receivednumber )
00371 {
00372 };
00373
00374 const std::string what() const;
00375
00376 parse_exception_wrong_number_of_arguments* copy() const
00377 {
00378 return new parse_exception_wrong_number_of_arguments( *this );
00379 }
00380
00381 const std::string& componentName() const
00382 {
00383 return mcomponentname;
00384 }
00385
00386 const std::string& methodName() const
00387 {
00388 return mmethodname;
00389 }
00390
00391 int expectedNumber() const
00392 {
00393 return mexpectednumber;
00394 }
00395
00396 int receivedNumber() const
00397 {
00398 return mreceivednumber;
00399 }
00400 };
00401
00402 class RTT_EXPORT parse_exception_wrong_type_of_argument
00403 : public fatal_semantic_parse_exception
00404 {
00405 std::string mcomponentname;
00406 std::string mmethodname;
00407 int margnumber;
00408 std::string mexpected;
00409 std::string mreceived;
00410 public:
00411 parse_exception_wrong_type_of_argument(
00412 const std::string& componentname, const std::string& methodname,
00413 int argnumber, const std::string& expected, const std::string& received )
00414 : mcomponentname( componentname ), mmethodname( methodname ),
00415 margnumber( argnumber ), mexpected( expected), mreceived( received )
00416 {
00417 };
00418
00419 const std::string what() const;
00420
00421 parse_exception_wrong_type_of_argument* copy() const
00422 {
00423 return new parse_exception_wrong_type_of_argument( *this );
00424 }
00425
00426 const std::string& componentName() const
00427 {
00428 return mcomponentname;
00429 }
00430
00431 const std::string& methodName() const
00432 {
00433 return mmethodname;
00434 }
00435
00436 int argumentNumber() const
00437 {
00438 return margnumber;
00439 }
00440 };
00441
00442 class RTT_EXPORT parse_exception_undefined_value
00443 : public fatal_semantic_parse_exception
00444 {
00445 std::string mname;
00446 public:
00447 parse_exception_undefined_value( const std::string& name )
00448 : mname( name )
00449 {
00450 }
00451
00452 const std::string what() const throw()
00453 {
00454 return "Use of undefined value: \"" + mname + "\".";
00455 }
00456
00457 parse_exception_undefined_value* copy() const throw()
00458 {
00459 return new parse_exception_undefined_value( *this );
00460 }
00461
00462 const std::string& name() {
00463 return mname;
00464 }
00465 };
00466
00467 class RTT_EXPORT parse_exception_no_such_constructor
00468 : public fatal_semantic_parse_exception
00469 {
00470 std::string margsig;
00471 public:
00472 parse_exception_no_such_constructor(const std::string& tname,
00473 std::vector<DataSourceBase::shared_ptr> args);
00474
00475 const std::string what() const { return margsig; }
00476
00477 parse_exception_no_such_constructor* copy() const
00478 {
00479 return new parse_exception_no_such_constructor( *this );
00480 }
00481 };
00482 }
00483 }
00484
00485 #endif