00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00039 #ifndef BISON_POSITION_HH
00040 # define BISON_POSITION_HH
00041 
00042 # include <iostream>
00043 # include <string>
00044 # include <algorithm>
00045 
00046 
00047 
00048 #line 1 "[Bison:b4_percent_define_default]"
00049 
00050 namespace example {
00051 
00052 
00053 #line 54 "position.hh"
00055   class position
00056   {
00057   public:
00058 
00060     position ()
00061       : filename (0), line (1), column (1)
00062     {
00063     }
00064 
00065 
00067     inline void initialize (std::string* fn)
00068     {
00069       filename = fn;
00070       line = 1;
00071       column = 1;
00072     }
00073 
00076   public:
00078     inline void lines (int count = 1)
00079     {
00080       column = 1;
00081       line += count;
00082     }
00083 
00085     inline void columns (int count = 1)
00086     {
00087       column = std::max (1u, column + count);
00088     }
00091   public:
00093     std::string* filename;
00095     unsigned int line;
00097     unsigned int column;
00098   };
00099 
00101   inline const position&
00102   operator+= (position& res, const int width)
00103   {
00104     res.columns (width);
00105     return res;
00106   }
00107 
00109   inline const position
00110   operator+ (const position& begin, const int width)
00111   {
00112     position res = begin;
00113     return res += width;
00114   }
00115 
00117   inline const position&
00118   operator-= (position& res, const int width)
00119   {
00120     return res += -width;
00121   }
00122 
00124   inline const position
00125   operator- (const position& begin, const int width)
00126   {
00127     return begin + -width;
00128   }
00129 
00131   inline bool
00132   operator== (const position& pos1, const position& pos2)
00133   {
00134     return
00135       (pos1.filename == pos2.filename
00136        || (pos1.filename && pos2.filename && *pos1.filename == *pos2.filename))
00137       && pos1.line == pos2.line && pos1.column == pos2.column;
00138   }
00139 
00141   inline bool
00142   operator!= (const position& pos1, const position& pos2)
00143   {
00144     return !(pos1 == pos2);
00145   }
00146 
00151   inline std::ostream&
00152   operator<< (std::ostream& ostr, const position& pos)
00153   {
00154     if (pos.filename)
00155       ostr << *pos.filename << ':';
00156     return ostr << pos.line << '.' << pos.column;
00157   }
00158 
00159 
00160 
00161 #line 1 "[Bison:b4_percent_define_default]"
00162 
00163 } 
00164 
00165 
00166 #line 167 "position.hh"
00167 #endif // not BISON_POSITION_HH