00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef BISON_LOCATION_HH
00027 # define BISON_LOCATION_HH
00028
00029 # include <iostream>
00030 # include <string>
00031 # include "position.hh"
00032
00033 namespace yy
00034 {
00035
00037 class Location
00038 {
00041 public:
00043 Location (void) :
00044 begin (),
00045 end ()
00046 {
00047 }
00053 public:
00055 inline void step (void)
00056 {
00057 begin = end;
00058 }
00059
00061 inline void columns (unsigned int count = 1)
00062 {
00063 end += count;
00064 }
00065
00067 inline void lines (unsigned int count = 1)
00068 {
00069 end.lines (count);
00070 }
00074 public:
00076 Position begin;
00078 Position end;
00079 };
00080
00082 inline const Location operator+ (const Location& begin, const Location& end)
00083 {
00084 Location res = begin;
00085 res.end = end.end;
00086 return res;
00087 }
00088
00090 inline const Location operator+ (const Location& begin, unsigned int width)
00091 {
00092 Location res = begin;
00093 res.columns (width);
00094 return res;
00095 }
00096
00098 inline Location &operator+= (Location& res, unsigned int width)
00099 {
00100 res.columns (width);
00101 return res;
00102 }
00103
00110 inline std::ostream& operator<< (std::ostream& ostr, const Location& loc)
00111 {
00112 Position last = loc.end - 1;
00113 ostr << loc.begin;
00114 if (loc.begin.filename != last.filename)
00115 ostr << '-' << last;
00116 else if (loc.begin.line != last.line)
00117 ostr << '-' << last.line << '.' << last.column;
00118 else if (loc.begin.column != last.column)
00119 ostr << '-' << last.column;
00120 return ostr;
00121 }
00122
00123 }
00124
00125 #endif // not BISON_LOCATION_HH