Methods
|
|
__init__
equal
indent_level
less
longest_run_of_spaces
not_equal_witness
not_less_witness
|
|
__init__
|
__init__ ( self, ws )
|
|
equal
|
equal ( self, other )
return true iff self.indent_level(t) == other.indent_level(t)
for all t >= 1
|
|
indent_level
|
indent_level ( self, tabsize )
count, il = self.norm
for i in range(len(count)):
if count[i]:
il = il + (i/tabsize + 1)tabsize count[i]
return il
|
|
less
|
less ( self, other )
Return true iff self.indent_level(t) < other.indent_level(t)
for all t >= 1.
The algorithm is due to Vincent Broman.
Easy to prove it's correct.
XXXpost that.
Trivial to prove n is sharp (consider T vs ST).
Unknown whether there's a faster general way. I suspected so at
first, but no longer.
For the special (but common!) case where M and N are both of the
form (T)(S), M.less(N) iff M.len() < N.len() and
M.num_tabs() <= N.num_tabs(). Proof is easy but kinda long-winded.
XXXwrite that up.
Note that M is of the form (T)(S) iff len(M.norm[0]) <= 1.
|
|
longest_run_of_spaces
|
longest_run_of_spaces ( self )
return length of longest contiguous run of spaces (whether or not
preceding a tab)
|
|
not_equal_witness
|
not_equal_witness ( self, other )
return a list of tuples (ts, i1, i2) such that
i1 == self.indent_level(ts) != other.indent_level(ts) == i2.
Intended to be used after not self.equal(other) is known, in which
case it will return at least one witnessing tab size.
|
|
not_less_witness
|
not_less_witness ( self, other )
return a list of tuples (ts, i1, i2) such that
i1 == self.indent_level(ts) >= other.indent_level(ts) == i2.
Intended to be used after not self.less(other) is known, in which
case it will return at least one witnessing tab size.
|