as2js: /home/snapwebsites/snapcpp/contrib/as2js/lib/position.cpp Source File

as2js  0.1.14
AlexScript to JavaScript
position.cpp
Go to the documentation of this file.
1 /* lib/position.cpp
2 
3 Copyright (c) 2005-2019 Made to Order Software Corp. All Rights Reserved
4 
6 
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16 
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31 
32 */
33 
34 #include "as2js/position.h"
35 
36 #include "as2js/exceptions.h"
37 
38 
39 namespace as2js
40 {
41 
42 
52 void Position::set_filename(String const& filename)
53 {
54  f_filename = filename;
55 }
56 
57 
68 void Position::set_function(String const& function)
69 {
70  f_function = function;
71 }
72 
73 
85 {
86  if(line < 1)
87  {
88  throw exception_internal_error("the line parameter of the position object cannot be less than 1");
89  }
90 
94  f_line = line;
95 }
96 
97 
104 {
105  ++f_page;
108 }
109 
110 
117 {
118  ++f_paragraph;
119 }
120 
121 
128 {
129  ++f_page_line;
130  ++f_line;
131 }
132 
133 
144 {
145  return f_filename;
146 }
147 
148 
159 {
160  return f_function;
161 }
162 
163 
172 {
173  return f_page;
174 }
175 
176 
186 {
187  return f_page_line;
188 }
189 
190 
200 {
201  return f_paragraph;
202 }
203 
204 
215 {
216  return f_line;
217 }
218 
219 
236 std::ostream& operator << (std::ostream& out, Position const& pos)
237 {
238  if(pos.get_filename().empty())
239  {
240  out << "line " << pos.get_line() << ":";
241  }
242  else
243  {
244  out << pos.get_filename() << ":" << pos.get_line() << ":";
245  }
246 
247  return out;
248 }
249 
250 
251 }
252 // namespace as2js
253 
254 // vim: ts=4 sw=4 et
counter_t f_page
Definition: position.h:72
counter_t f_page_line
Definition: position.h:73
counter_t f_line
Definition: position.h:75
counter_t get_page() const
Retrieve the current page counter.
Definition: position.cpp:171
void new_paragraph()
Increments the paragraph counter by 1.
Definition: position.cpp:116
counter_t get_paragraph() const
Retrieve the current paragraph counter.
Definition: position.cpp:199
String f_filename
Definition: position.h:70
String f_function
Definition: position.h:71
counter_t get_page_line() const
Retrieve the current page line counter.
Definition: position.cpp:185
void reset_counters(counter_t line=DEFAULT_COUNTER)
Reset the counter.
Definition: position.cpp:84
int32_t counter_t
Definition: position.h:47
counter_t get_line() const
Retrieve the current line counter.
Definition: position.cpp:214
void new_page()
Increment the page counter by 1.
Definition: position.cpp:103
void set_function(String const &function)
Set the function being read.
Definition: position.cpp:68
void new_line()
Increment the line counter by 1.
Definition: position.cpp:127
static counter_t const DEFAULT_COUNTER
Definition: position.h:48
std::ostream & operator<<(std::ostream &out, Node const &node)
Send a node to the specified output stream.
String get_filename() const
Retrieve the filename.
Definition: position.cpp:143
counter_t f_paragraph
Definition: position.h:74
The AlexScript to JavaScript namespace.
Definition: compiler.cpp:37
String get_function() const
Retrieve the function name.
Definition: position.cpp:158
void set_filename(String const &filename)
Set the filename being read.
Definition: position.cpp:52

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly