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 () :
00044 begin (),
00045 end ()
00046 {
00047 }
00053 public:
00055 inline void step ()
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 (last.filename
00115 && (!loc.begin.filename
00116 || *loc.begin.filename != *last.filename))
00117 ostr << '-' << last;
00118 else if (loc.begin.line != last.line)
00119 ostr << '-' << last.line << '.' << last.column;
00120 else if (loc.begin.column != last.column)
00121 ostr << '-' << last.column;
00122 return ostr;
00123 }
00124
00125 }
00126
00127 #endif // not BISON_LOCATION_HH