Code cleanups and refactorings

This commit is contained in:
Holger Rapp 2012-01-14 20:14:51 +01:00
parent 9a7e7603f1
commit 3c8661d4bd
2 changed files with 13 additions and 7 deletions

View File

@ -135,7 +135,7 @@ class _TOParser(object):
if add_ts_zero and 0 not in seen_ts: if add_ts_zero and 0 not in seen_ts:
mark = all_tokens[-1][1].end # Last token is always EndOfText mark = all_tokens[-1][1].end # Last token is always EndOfText
m1 = Position(mark.line, mark.col + 1) m1 = Position(mark.line, mark.col + 1)
self._parent_to._add_tabstop(0, TabStop(self._parent_to, 0, mark, m1)) self._parent_to._add_tabstop(TabStop(self._parent_to, 0, mark, m1))
##################### #####################
# Private Functions # # Private Functions #
@ -146,7 +146,7 @@ class _TOParser(object):
if token.no not in seen_ts: if token.no not in seen_ts:
ts = TabStop(parent, token) ts = TabStop(parent, token)
seen_ts[token.no] = ts seen_ts[token.no] = ts
parent._add_tabstop(token.no,ts) parent._add_tabstop(ts)
else: else:
Mirror(parent, seen_ts[token.no], token) Mirror(parent, seen_ts[token.no], token)
@ -166,7 +166,7 @@ class _TOParser(object):
if isinstance(token, TabStopToken): if isinstance(token, TabStopToken):
ts = TabStop(self._parent_to, token) ts = TabStop(self._parent_to, token)
seen_ts[token.no] = ts seen_ts[token.no] = ts
self._parent_to._add_tabstop(token.no,ts) self._parent_to._add_tabstop(ts)
k = _TOParser(ts, ts.current_text, self._indent) k = _TOParser(ts, ts.current_text, self._indent)
k._do_parse(all_tokens, seen_ts) k._do_parse(all_tokens, seen_ts)
@ -228,8 +228,14 @@ class TextObject(CheapTotalOrdering):
self._childs = [] self._childs = []
self._tabstops = {} self._tabstops = {}
return locals() return locals()
current_text = property(**current_text()) current_text = property(**current_text())
@property
def current_tabstop(self):
if self._cts is None:
return None
return self._tabstops[self._cts]
def abs_start(self): def abs_start(self):
if self._parent: if self._parent:
ps = self._parent.abs_start ps = self._parent.abs_start
@ -389,8 +395,8 @@ class TextObject(CheapTotalOrdering):
self._childs.append(c) self._childs.append(c)
self._childs.sort() self._childs.sort()
def _add_tabstop(self, no, ts): # TODO: should not take no def _add_tabstop(self, ts):
self._tabstops[no] = ts self._tabstops[ts.no] = ts
class EscapedChar(TextObject): class EscapedChar(TextObject):
""" """

View File

@ -1122,7 +1122,7 @@ class SnippetManager(object):
# tabstop and still have the tabstop zero selected. The current tabstop is therefore # tabstop and still have the tabstop zero selected. The current tabstop is therefore
# the one in the latest snippet, but do not overwrite the complete text of the snippet # the one in the latest snippet, but do not overwrite the complete text of the snippet
if self._ctab is None and len(self._csnippets): if self._ctab is None and len(self._csnippets):
self._ctab = self._csnippets[-1]._tabstops[self._csnippets[-1]._cts] # TODO: private parts self._ctab = self._csnippets[-1].current_tabstop
self._ctab.current_text += chars self._ctab.current_text += chars
else: else:
self._ctab.current_text = chars self._ctab.current_text = chars