00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef BISON_POSITION_HH
00027 # define BISON_POSITION_HH
00028
00029 # include <iostream>
00030 # include <string>
00031
00032 namespace yy
00033 {
00035 class Position
00036 {
00037 public:
00039 static const unsigned int initial_column = 0;
00041 static const unsigned int initial_line = 1;
00042
00045 public:
00047 Position () :
00048 filename (),
00049 line (initial_line),
00050 column (initial_column)
00051 {
00052 }
00058 public:
00060 inline void lines (int count = 1)
00061 {
00062 column = initial_column;
00063 line += count;
00064 }
00065
00067 inline void columns (int count = 1)
00068 {
00069 int leftmost = initial_column;
00070 int current = column;
00071 if (leftmost <= current + count)
00072 column += count;
00073 else
00074 column = initial_column;
00075 }
00078 public:
00080 std::string filename;
00082 unsigned int line;
00084 unsigned int column;
00085 };
00086
00088 inline const Position&
00089 operator+= (Position& res, const int width)
00090 {
00091 res.columns (width);
00092 return res;
00093 }
00094
00096 inline const Position
00097 operator+ (const Position& begin, const int width)
00098 {
00099 Position res = begin;
00100 return res += width;
00101 }
00102
00104 inline const Position&
00105 operator-= (Position& res, const int width)
00106 {
00107 return res += -width;
00108 }
00109
00111 inline const Position
00112 operator- (const Position& begin, const int width)
00113 {
00114 return begin + -width;
00115 }
00116
00121 inline std::ostream&
00122 operator<< (std::ostream& ostr, const Position& pos)
00123 {
00124 if (!pos.filename.empty ())
00125 ostr << pos.filename << ':';
00126 return ostr << pos.line << '.' << pos.column;
00127 }
00128
00129 }
00130 #endif // not BISON_POSITION_HH