Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
Whitespace Class Reference

Public Member Functions

def __init__
 
def longest_run_of_spaces
 
def indent_level
 
def equal
 
def not_equal_witness
 
def less
 
def not_less_witness
 

Data Fields

 raw
 
 n
 
 nt
 
 norm
 
 is_simple
 

Detailed Description

Definition at line 106 of file tabnanny.py.

Constructor & Destructor Documentation

def __init__ (   self,
  ws 
)

Definition at line 129 of file tabnanny.py.

130  def __init__(self, ws):
131  self.raw = ws
132  S, T = Whitespace.S, Whitespace.T
133  count = []
134  b = n = nt = 0
135  for ch in self.raw:
136  if ch == S:
137  n = n + 1
138  b = b + 1
139  elif ch == T:
140  n = n + 1
141  nt = nt + 1
142  if b >= len(count):
143  count = count + [0] * (b - len(count) + 1)
144  count[b] = count[b] + 1
145  b = 0
146  else:
147  break
148  self.n = n
149  self.nt = nt
150  self.norm = tuple(count), b
151  self.is_simple = len(count) <= 1

Member Function Documentation

def equal (   self,
  other 
)

Definition at line 181 of file tabnanny.py.

References Whitespace.norm.

182  def equal(self, other):
183  return self.norm == other.norm
def indent_level (   self,
  tabsize 
)

Definition at line 158 of file tabnanny.py.

References Whitespace.norm, and Whitespace.nt.

159  def indent_level(self, tabsize):
160  # count, il = self.norm
161  # for i in range(len(count)):
162  # if count[i]:
163  # il = il + (i/tabsize + 1)*tabsize * count[i]
164  # return il
165 
166  # quicker:
167  # il = trailing + sum (i/ts + 1)*ts*count[i] =
168  # trailing + ts * sum (i/ts + 1)*count[i] =
169  # trailing + ts * sum i/ts*count[i] + count[i] =
170  # trailing + ts * [(sum i/ts*count[i]) + (sum count[i])] =
171  # trailing + ts * [(sum i/ts*count[i]) + num_tabs]
172  # and note that i/ts*count[i] is 0 when i < ts
173 
174  count, trailing = self.norm
175  il = 0
176  for i in range(tabsize, len(count)):
177  il = il + i/tabsize * count[i]
178  return trailing + tabsize * (il + self.nt)
def less (   self,
  other 
)

Definition at line 212 of file tabnanny.py.

References Whitespace.indent_level(), Whitespace.is_simple, Whitespace.longest_run_of_spaces(), sre_parse.max, Whitespace.n, and Whitespace.nt.

213  def less(self, other):
214  if self.n >= other.n:
215  return 0
216  if self.is_simple and other.is_simple:
217  return self.nt <= other.nt
218  n = max(self.longest_run_of_spaces(),
219  other.longest_run_of_spaces()) + 1
220  # the self.n >= other.n test already did it for ts=1
221  for ts in range(2, n+1):
222  if self.indent_level(ts) >= other.indent_level(ts):
223  return 0
224  return 1
def longest_run_of_spaces (   self)

Definition at line 154 of file tabnanny.py.

References sre_parse.max, and Whitespace.norm.

155  def longest_run_of_spaces(self):
156  count, trailing = self.norm
157  return max(len(count)-1, trailing)
def not_equal_witness (   self,
  other 
)

Definition at line 188 of file tabnanny.py.

References Whitespace.indent_level(), Whitespace.longest_run_of_spaces(), and sre_parse.max.

189  def not_equal_witness(self, other):
190  n = max(self.longest_run_of_spaces(),
191  other.longest_run_of_spaces()) + 1
192  a = []
193  for ts in range(1, n+1):
194  if self.indent_level(ts) != other.indent_level(ts):
195  a.append( (ts,
196  self.indent_level(ts),
197  other.indent_level(ts)) )
198  return a
def not_less_witness (   self,
  other 
)

Definition at line 229 of file tabnanny.py.

References Whitespace.indent_level(), Whitespace.longest_run_of_spaces(), and sre_parse.max.

230  def not_less_witness(self, other):
231  n = max(self.longest_run_of_spaces(),
232  other.longest_run_of_spaces()) + 1
233  a = []
234  for ts in range(1, n+1):
235  if self.indent_level(ts) >= other.indent_level(ts):
236  a.append( (ts,
237  self.indent_level(ts),
238  other.indent_level(ts)) )
239  return a

Field Documentation

is_simple

Definition at line 150 of file tabnanny.py.

n

Definition at line 147 of file tabnanny.py.

norm

Definition at line 149 of file tabnanny.py.

nt

Definition at line 148 of file tabnanny.py.

raw

Definition at line 130 of file tabnanny.py.


The documentation for this class was generated from the following file: