File: syntax.hh

package info (click to toggle)
scalc 0.2.4-1
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,692 kB
  • ctags: 811
  • sloc: sh: 10,131; cpp: 1,572; makefile: 32
file content (58 lines) | stat: -rw-r--r-- 1,891 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
  syntax.hh, copyright (c) 2006 by Vincent Fourmond: 
  The class for describing syntax errors
  
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details (in the COPYING file).
  
*/

namespace SCalc {

  /**
     \brief A syntax error
     This class represents a syntax error. You can get several informations
     about this error, such as the original_string(), the error_message(),
     the exact location of the error in the string
     (start_pos() and end_pos()).
   */
  class SyntaxError : public  ParserResult {
  protected:
    std::string original;
    std::string message;
    int start;
    int end;
  public:

    /// Yes, this is a syntax error
    virtual int is_syntax_error() { return 1;};

    SyntaxError(Session * s, const char * str, 
		const char *error, int st, int en);

    /// The original string on which the error occured
    std::string original_string() { return original;};
    /// The error message
    std::string error_message() { return message;};
    /// The starting position
    int start_pos() { return start;};
    /// The end position
    int end_pos() { return end;};
    
    /**
       \brief Pretty prints the error message
       Returns a std::string containing a nice display of
       the error message, with a series of ^^^^ showing
       where the error occurred. This function assumes that
       all characters have the same display size. 
    */
    virtual std::string pretty_print();
  };
};