librostlab-blast  1.0.1
blast-parser-location.h
Go to the documentation of this file.
1 // A Bison parser, made by GNU Bison 3.8.2.
2 
3 // Locations for Bison parsers in C++
4 
5 // Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc.
6 
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <https://www.gnu.org/licenses/>.
19 
20 // As a special exception, you may create a larger work that contains
21 // part or all of the Bison parser skeleton and distribute that work
22 // under terms of your choice, so long as that work isn't itself a
23 // parser generator using the skeleton or a modified version thereof
24 // as a parser skeleton. Alternatively, if you modify or redistribute
25 // the parser skeleton itself, you may (at your option) remove this
26 // special exception, which will cause the skeleton and the resulting
27 // Bison output files to be licensed under the GNU General Public
28 // License without this special exception.
29 
30 // This special exception was added by the Free Software Foundation in
31 // version 2.2 of Bison.
32 
38 #ifndef YY_YY_ROSTLAB_BLAST_PARSER_LOCATION_H_INCLUDED
39 # define YY_YY_ROSTLAB_BLAST_PARSER_LOCATION_H_INCLUDED
40 
41 # include <iostream>
42 # include <string>
43 
44 # ifndef YY_NULLPTR
45 # if defined __cplusplus
46 # if 201103L <= __cplusplus
47 # define YY_NULLPTR nullptr
48 # else
49 # define YY_NULLPTR 0
50 # endif
51 # else
52 # define YY_NULLPTR ((void*)0)
53 # endif
54 # endif
55 
56 #line 22 "blast-parser-parser.ypp"
57 namespace rostlab { namespace blast {
58 #line 59 "rostlab/blast-parser-location.h"
59 
61  class position
62  {
63  public:
65  typedef const std::string filename_type;
67  typedef int counter_type;
68 
71  counter_type l = 1,
72  counter_type c = 1)
73  : filename (f)
74  , line (l)
75  , column (c)
76  {}
77 
78 
81  counter_type l = 1,
82  counter_type c = 1)
83  {
84  filename = fn;
85  line = l;
86  column = c;
87  }
88 
92  void lines (counter_type count = 1)
93  {
94  if (count)
95  {
96  column = 1;
97  line = add_ (line, count, 1);
98  }
99  }
100 
102  void columns (counter_type count = 1)
103  {
104  column = add_ (column, count, 1);
105  }
114 
115  private:
117  static counter_type add_ (counter_type lhs, counter_type rhs, counter_type min)
118  {
119  return lhs + rhs < min ? min : lhs + rhs;
120  }
121  };
122 
124  inline position&
126  {
127  res.columns (width);
128  return res;
129  }
130 
132  inline position
134  {
135  return res += width;
136  }
137 
139  inline position&
141  {
142  return res += -width;
143  }
144 
146  inline position
148  {
149  return res -= width;
150  }
151 
156  template <typename YYChar>
157  std::basic_ostream<YYChar>&
158  operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
159  {
160  if (pos.filename)
161  ostr << *pos.filename << ':';
162  return ostr << pos.line << '.' << pos.column;
163  }
164 
166  class location
167  {
168  public:
173 
175  location (const position& b, const position& e)
176  : begin (b)
177  , end (e)
178  {}
179 
181  explicit location (const position& p = position ())
182  : begin (p)
183  , end (p)
184  {}
185 
187  explicit location (filename_type* f,
188  counter_type l = 1,
189  counter_type c = 1)
190  : begin (f, l, c)
191  , end (f, l, c)
192  {}
193 
194 
197  counter_type l = 1,
198  counter_type c = 1)
199  {
200  begin.initialize (f, l, c);
201  end = begin;
202  }
203 
206  public:
208  void step ()
209  {
210  begin = end;
211  }
212 
214  void columns (counter_type count = 1)
215  {
216  end += count;
217  }
218 
220  void lines (counter_type count = 1)
221  {
222  end.lines (count);
223  }
227  public:
232  };
233 
235  inline location&
236  operator+= (location& res, const location& end)
237  {
238  res.end = end.end;
239  return res;
240  }
241 
243  inline location
244  operator+ (location res, const location& end)
245  {
246  return res += end;
247  }
248 
250  inline location&
252  {
253  res.columns (width);
254  return res;
255  }
256 
258  inline location
260  {
261  return res += width;
262  }
263 
265  inline location&
267  {
268  return res += -width;
269  }
270 
272  inline location
274  {
275  return res -= width;
276  }
277 
284  template <typename YYChar>
285  std::basic_ostream<YYChar>&
286  operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
287  {
288  location::counter_type end_col
289  = 0 < loc.end.column ? loc.end.column - 1 : 0;
290  ostr << loc.begin;
291  if (loc.end.filename
292  && (!loc.begin.filename
293  || *loc.begin.filename != *loc.end.filename))
294  ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
295  else if (loc.begin.line < loc.end.line)
296  ostr << '-' << loc.end.line << '.' << end_col;
297  else if (loc.begin.column < end_col)
298  ostr << '-' << end_col;
299  return ostr;
300  }
301 
302 #line 22 "blast-parser-parser.ypp"
303 } } // rostlab::blast
304 #line 305 "rostlab/blast-parser-location.h"
305 
306 #endif // !YY_YY_ROSTLAB_BLAST_PARSER_LOCATION_H_INCLUDED
#define YY_NULLPTR
Two points in a source file.
position begin
Beginning of the located region.
position::filename_type filename_type
Type for file name.
position::counter_type counter_type
Type for line and column numbers.
void lines(counter_type count=1)
Extend the current location to the COUNT next lines.
location(const position &p=position())
Construct a 0-width location in p.
void initialize(filename_type *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
void step()
Reset initial location to final location.
position end
End of the located region.
void columns(counter_type count=1)
Extend the current location to the COUNT next columns.
location(filename_type *f, counter_type l=1, counter_type c=1)
Construct a 0-width location in f, l, c.
location(const position &b, const position &e)
Construct a location from b to e.
A point in a source file.
const std::string filename_type
Type for file name.
counter_type line
Current line number.
void lines(counter_type count=1)
(line related) Advance to the COUNT next lines.
counter_type column
Current column number.
void initialize(filename_type *fn=YY_NULLPTR, counter_type l=1, counter_type c=1)
Initialization.
filename_type * filename
File name to which this position refers.
int counter_type
Type for line and column numbers.
position(filename_type *f=YY_NULLPTR, counter_type l=1, counter_type c=1)
Construct a position.
void columns(counter_type count=1)
(column related) Advance to the COUNT next columns.
position & operator+=(position &res, position::counter_type width)
Add width columns, in place.
position & operator-=(position &res, position::counter_type width)
Subtract width columns, in place.
position operator+(position res, position::counter_type width)
Add width columns.
position operator-(position res, position::counter_type width)
Subtract width columns.
std::basic_ostream< YYChar > & operator<<(std::basic_ostream< YYChar > &ostr, const position &pos)
Intercept output stream redirection.