Orocos Real-Time Toolkit  2.9.0
parse_exception.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 15 11:21:23 CEST 2004 parse_exception.hpp
3 
4  parse_exception.hpp - description
5  -------------------
6  begin : Thu July 15 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens at mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 #ifndef ORO_PARSE_EXCEPTION_HPP
38 #define ORO_PARSE_EXCEPTION_HPP
39 
40 #include <string>
41 #include <vector>
42 #include "rtt-scripting-config.h"
43 #include "../base/DataSourceBase.hpp"
44 
45 #ifdef ORO_PRAGMA_INTERFACE
46 #pragma interface
47 #endif
48 
49 namespace RTT
50 {
51  class parse_exception;
52 
59  {
60  parse_exception* mpe;
61  std::string mfile;
62  int mline;
63  int mcolumn;
64  // make this private to prevent the compiler from adding it...
65  file_parse_exception& operator=( const file_parse_exception& rhs );
66  public:
68  file_parse_exception( parse_exception* pe, const std::string& file,
69  int line, int column )
70  : mpe( pe ), mfile( file ), mline( line ), mcolumn( column )
71  {
72  }
74 
75  const std::string what() const;
76  };
77 
84  {
85  // make these private
86  parse_exception& operator=( const parse_exception& );
87  protected:
89  public:
90  virtual ~parse_exception() {};
91  virtual const std::string what() const = 0;
92  virtual parse_exception* copy() const = 0;
93  };
94 
95  namespace scripting {
96 
103  : public parse_exception
104  {
105  // make these private
107  protected:
109  };
110 
117  : public parse_exception
118  {
119  // make these private
121  protected:
123  };
124 
132  : public parse_exception
133  {
134  // make these private
136  protected:
138  };
139 
146  : public parse_exception
147  {
148  // make these private
150  protected:
152  };
153 
154 
155 
158  {
159  std::string mident;
160  public:
161  parse_exception_illegal_identifier( const std::string& ident )
162  : mident( ident )
163  {
164  };
165 
166  const std::string what() const
167  {
168  return "The string \"" + mident + "\" cannot be used as an identifer.";
169  }
170 
172  {
173  return new parse_exception_illegal_identifier( *this );
174  }
175 
176  const std::string& identifier() const
177  {
178  return mident;
179  }
180  };
181 
187  : public semantic_parse_exception
188  {
189  std::string mdesc;
190  public:
191  parse_exception_semantic_error( const std::string& desc )
192  : mdesc( desc )
193  {
194  };
195 
196  const std::string what() const
197  {
198  return "Semantic error: " + mdesc;
199  }
200 
202  {
203  return new parse_exception_semantic_error( *this );
204  }
205 
206  const std::string& desc() const
207  {
208  return mdesc;
209  }
210  };
211 
218  {
219  std::string mdesc;
220  public:
221  parse_exception_fatal_semantic_error( const std::string& desc )
222  : mdesc( desc )
223  {
224  };
225 
226  const std::string what() const
227  {
228  return "Fatal Semantic error: " + mdesc;
229  }
230 
232  {
233  return new parse_exception_fatal_semantic_error( *this );
234  }
235 
236  const std::string& desc() const
237  {
238  return mdesc;
239  }
240  };
241 
249  : public parse_exception
250  {
251  std::string mreason;
252  public:
253  parse_exception_parser_fail(const std::string& reason) : mreason(reason)
254  {
255  }
256 
257  const std::string what() const
258  {
259  return "Parse Failure Exception: " + mreason;
260  }
261 
263  {
264  return new parse_exception_parser_fail( *this );
265  }
266  };
267 
274  {
275  std::string mdesc;
276  public:
277  parse_exception_syntactic_error( const std::string& desc )
278  : mdesc( desc )
279  {
280  };
281 
282  const std::string what() const
283  {
284  return "Syntactic error: " + mdesc;
285  }
286 
288  {
289  return new parse_exception_syntactic_error( *this );
290  }
291 
292  const std::string& desc() const
293  {
294  return mdesc;
295  }
296  };
297 
299  : public semantic_parse_exception
300  {
301  std::string mname;
302  std::string mmeth;
303  public:
304  parse_exception_no_such_component( const std::string& name, const std::string& meth )
305  : mname( name ), mmeth(meth)
306  {
307  }
308 
309  const std::string what() const
310  {
311  return "Service or Task \"" + mname + "\" has no Peer or Service "+mmeth+" (or "+mname+" was not found at all).";
312  }
313 
315  {
316  return new parse_exception_no_such_component( *this );
317  }
318 
319  const std::string& componentName() const
320  {
321  return mname;
322  }
323  };
324 
326  : public semantic_parse_exception
327  {
328  std::string mcomponentname;
329  std::string mmethodname;
330  public:
332  const std::string& componentname, const std::string& methodname )
333  : mcomponentname( componentname ), mmethodname( methodname )
334  {
335  };
336 
337  const std::string what() const
338  {
339  return "No method \"" + mmethodname + "\" registered for the object or task \"" + mcomponentname + "\".";
340  }
341 
343  {
345  }
346 
347  const std::string& componentName() const
348  {
349  return mcomponentname;
350  }
351 
352  const std::string& methodName() const
353  {
354  return mmethodname;
355  }
356  };
357 
360  {
361  std::string mcomponentname;
362  std::string mmethodname;
363  int mexpectednumber;
364  int mreceivednumber;
365  public:
367  const std::string& componentname, const std::string& methodname,
368  int expectednumber, int receivednumber )
369  : mcomponentname( componentname ), mmethodname( methodname ),
370  mexpectednumber( expectednumber ),
371  mreceivednumber( receivednumber )
372  {
373  };
374 
375  const std::string what() const;
376 
378  {
379  return new parse_exception_wrong_number_of_arguments( *this );
380  }
381 
382  const std::string& componentName() const
383  {
384  return mcomponentname;
385  }
386 
387  const std::string& methodName() const
388  {
389  return mmethodname;
390  }
391 
392  int expectedNumber() const
393  {
394  return mexpectednumber;
395  }
396 
397  int receivedNumber() const
398  {
399  return mreceivednumber;
400  }
401  };
402 
405  {
406  std::string mcomponentname;
407  std::string mmethodname;
408  int margnumber;
409  std::string mexpected;
410  std::string mreceived;
411  public:
413  const std::string& componentname, const std::string& methodname,
414  int argnumber, const std::string& expected, const std::string& received )
415  : mcomponentname( componentname ), mmethodname( methodname ),
416  margnumber( argnumber ), mexpected( expected), mreceived( received )
417  {
418  };
419 
420  const std::string what() const;
421 
423  {
424  return new parse_exception_wrong_type_of_argument( *this );
425  }
426 
427  const std::string& componentName() const
428  {
429  return mcomponentname;
430  }
431 
432  const std::string& methodName() const
433  {
434  return mmethodname;
435  }
436 
437  int argumentNumber() const
438  {
439  return margnumber;
440  }
441  };
442 
445  {
446  std::string mname;
447  public:
448  parse_exception_undefined_value( const std::string& name )
449  : mname( name )
450  {
451  }
452 
453  const std::string what() const throw()
454  {
455  return "Use of undefined value: \"" + mname + "\".";
456  }
457 
459  {
460  return new parse_exception_undefined_value( *this );
461  }
462 
463  const std::string& name() {
464  return mname;
465  }
466  };
467 
470  {
471  std::string margsig;
472  public:
473  parse_exception_no_such_constructor(const std::string& tname,
474  std::vector<base::DataSourceBase::shared_ptr> args);
475 
476  const std::string what() const { return margsig; }
477 
479  {
480  return new parse_exception_no_such_constructor( *this );
481  }
482  };
483  }
484 }
485 
486 #endif
A Semantic parse exception means the parser recognised a part of the string, but got into trouble lat...
parse_exception_wrong_number_of_arguments(const std::string &componentname, const std::string &methodname, int expectednumber, int receivednumber)
parse_exception_wrong_type_of_argument(const std::string &componentname, const std::string &methodname, int argnumber, const std::string &expected, const std::string &received)
parse_exception_parser_fail(const std::string &reason)
parse_exception_wrong_type_of_argument * copy() const
parse_exception class that is used for various semantic errors for which it was not worth defining a ...
This is an exception class that keeps a parse_exception pointer along with the location in the file a...
parse_exception class that is used for various syntactic errors for which it was not worth defining a...
file_parse_exception(parse_exception *pe, const std::string &file, int line, int column)
parse_exception_undefined_value * copy() const
parse_exception_no_such_constructor * copy() const
This is the uppermost exception class in the parser system.
parse_exception_semantic_error * copy() const
parse_exception_no_such_method_on_component * copy() const
A normal syntactic parse exception means the parser recognised the input, but got stuck later due to ...
parse_exception_syntactic_error * copy() const
#define RTT_SCRIPTING_EXPORT
parse_exception_fatal_semantic_error * copy() const
A Fatal Syntactic parse exception means the parser knows the input is plain wrong and no further atte...
parse_exception class that is used for fatal semantic errors for which it was not worth defining a pr...
parse_exception_parser_fail * copy() const
An exception which a parser may throw to indicate that it failed to understand the input...
parse_exception_no_such_component(const std::string &name, const std::string &meth)
parse_exception_no_such_component * copy() const
parse_exception_illegal_identifier * copy() const
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
parse_exception_wrong_number_of_arguments * copy() const
parse_exception_no_such_method_on_component(const std::string &componentname, const std::string &methodname)
A Fatal Semantic parse exception means the parser knows that the parsing failed dramatically and shou...