81 """ |
81 """ |
82 self.lineno, self.msg, self.line = lineno, msg, line |
82 self.lineno, self.msg, self.line = lineno, msg, line |
83 |
83 |
84 def get_lineno(self): |
84 def get_lineno(self): |
85 """ |
85 """ |
86 Method to retrieve the line number. |
86 Public method to retrieve the line number. |
87 |
87 |
88 @return The line number (integer) |
88 @return The line number (integer) |
89 """ |
89 """ |
90 return self.lineno |
90 return self.lineno |
91 |
91 |
92 def get_msg(self): |
92 def get_msg(self): |
93 """ |
93 """ |
94 Method to retrieve the message. |
94 Public method to retrieve the message. |
95 |
95 |
96 @return The error message (string) |
96 @return The error message (string) |
97 """ |
97 """ |
98 return self.msg |
98 return self.msg |
99 |
99 |
100 def get_line(self): |
100 def get_line(self): |
101 """ |
101 """ |
102 Method to retrieve the offending line. |
102 Public method to retrieve the offending line. |
103 |
103 |
104 @return The line of code (string) |
104 @return The line of code (string) |
105 """ |
105 """ |
106 return self.line |
106 return self.line |
107 |
107 |
202 |
202 |
203 # return length of longest contiguous run of spaces (whether or not |
203 # return length of longest contiguous run of spaces (whether or not |
204 # preceding a tab) |
204 # preceding a tab) |
205 def longest_run_of_spaces(self): |
205 def longest_run_of_spaces(self): |
206 """ |
206 """ |
207 Method to calculate the length of longest contiguous run of spaces. |
207 Public method to calculate the length of longest contiguous run of |
|
208 spaces. |
208 |
209 |
209 @return The length of longest contiguous run of spaces (whether or not |
210 @return The length of longest contiguous run of spaces (whether or not |
210 preceding a tab) |
211 preceding a tab) |
211 """ |
212 """ |
212 count, trailing = self.norm |
213 count, trailing = self.norm |
213 return max(len(count) - 1, trailing) |
214 return max(len(count) - 1, trailing) |
214 |
215 |
215 def indent_level(self, tabsize): |
216 def indent_level(self, tabsize): |
216 """ |
217 """ |
217 Method to determine the indentation level. |
218 Public method to determine the indentation level. |
218 |
219 |
219 @param tabsize The length of a tab stop. (integer) |
220 @param tabsize The length of a tab stop. (integer) |
220 @return indentation level (integer) |
221 @return indentation level (integer) |
221 """ |
222 """ |
222 # count, il = self.norm |
223 # count, il = self.norm |
241 |
242 |
242 # return true iff self.indent_level(t) == other.indent_level(t) |
243 # return true iff self.indent_level(t) == other.indent_level(t) |
243 # for all t >= 1 |
244 # for all t >= 1 |
244 def equal(self, other): |
245 def equal(self, other): |
245 """ |
246 """ |
246 Method to compare the indentation levels of two Whitespace objects for |
247 Public method to compare the indentation levels of two Whitespace |
247 equality. |
248 objects for equality. |
248 |
249 |
249 @param other Whitespace object to compare against. |
250 @param other Whitespace object to compare against. |
250 @return True, if we compare equal against the other Whitespace object. |
251 @return True, if we compare equal against the other Whitespace object. |
251 """ |
252 """ |
252 return self.norm == other.norm |
253 return self.norm == other.norm |
255 # i1 == self.indent_level(ts) != other.indent_level(ts) == i2. |
256 # i1 == self.indent_level(ts) != other.indent_level(ts) == i2. |
256 # Intended to be used after not self.equal(other) is known, in which |
257 # Intended to be used after not self.equal(other) is known, in which |
257 # case it will return at least one witnessing tab size. |
258 # case it will return at least one witnessing tab size. |
258 def not_equal_witness(self, other): |
259 def not_equal_witness(self, other): |
259 """ |
260 """ |
260 Method to calculate a tuple of witnessing tab size. |
261 Public method to calculate a tuple of witnessing tab size. |
261 |
262 |
262 Intended to be used after not self.equal(other) is known, in which |
263 Intended to be used after not self.equal(other) is known, in which |
263 case it will return at least one witnessing tab size. |
264 case it will return at least one witnessing tab size. |
264 |
265 |
265 @param other Whitespace object to calculate against. |
266 @param other Whitespace object to calculate against. |
289 # M.num_tabs() <= N.num_tabs(). Proof is easy but kinda long-winded. |
290 # M.num_tabs() <= N.num_tabs(). Proof is easy but kinda long-winded. |
290 # XXXwrite that up. |
291 # XXXwrite that up. |
291 # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1. |
292 # Note that M is of the form (T*)(S*) iff len(M.norm[0]) <= 1. |
292 def less(self, other): |
293 def less(self, other): |
293 """ |
294 """ |
294 Method to compare the indentation level against another Whitespace |
295 Public method to compare the indentation level against another |
295 objects to be smaller. |
296 Whitespace objects to be smaller. |
296 |
297 |
297 @param other Whitespace object to compare against. |
298 @param other Whitespace object to compare against. |
298 @return True, if we compare less against the other Whitespace object. |
299 @return True, if we compare less against the other Whitespace object. |
299 """ |
300 """ |
300 if self.n >= other.n: |
301 if self.n >= other.n: |
313 # i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. |
314 # i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. |
314 # Intended to be used after not self.less(other) is known, in which |
315 # Intended to be used after not self.less(other) is known, in which |
315 # case it will return at least one witnessing tab size. |
316 # case it will return at least one witnessing tab size. |
316 def not_less_witness(self, other): |
317 def not_less_witness(self, other): |
317 """ |
318 """ |
318 Method to calculate a tuple of witnessing tab size. |
319 Public method to calculate a tuple of witnessing tab size. |
319 |
320 |
320 Intended to be used after not self.less(other is known, in which |
321 Intended to be used after not self.less(other is known, in which |
321 case it will return at least one witnessing tab size. |
322 case it will return at least one witnessing tab size. |
322 |
323 |
323 @param other Whitespace object to calculate against. |
324 @param other Whitespace object to calculate against. |