parent
2dcac2c1f1
commit
155044696f
29
tab.py
29
tab.py
|
@ -240,7 +240,8 @@ class Marker2(object):
|
||||||
class StackTabber2(Tabber):
|
class StackTabber2(Tabber):
|
||||||
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
||||||
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
||||||
scope_tokens = {'delimiter': set(['{'])}
|
open_scope_tokens = {'delimiter': set(['{'])}
|
||||||
|
close_scope_tokens = {'delimiter': set(['}'])}
|
||||||
control_tokens = {'keyword': set(['if', 'else', 'while', 'do', 'for'])}
|
control_tokens = {'keyword': set(['if', 'else', 'while', 'do', 'for'])}
|
||||||
end_at_eof = True
|
end_at_eof = True
|
||||||
end_at_tokens = {}
|
end_at_tokens = {}
|
||||||
|
@ -376,14 +377,17 @@ class StackTabber2(Tabber):
|
||||||
|
|
||||||
# add implicit continuation XYZYXYZY
|
# add implicit continuation XYZYXYZY
|
||||||
name, s = t.fqname(), t.string
|
name, s = t.fqname(), t.string
|
||||||
top = self._peek()
|
top = self._peek()
|
||||||
if (i + start == end and
|
atscope = True
|
||||||
(not top or top.name in self.scope_tokens.get(top.type_, {}))):
|
if top:
|
||||||
|
d = self.open_scope_tokens.get(top.type_, set())
|
||||||
|
atscope = top.name in d
|
||||||
|
if (atscope and i + start == end):
|
||||||
d = self.nocontinue_tokens.get(name)
|
d = self.nocontinue_tokens.get(name)
|
||||||
if d is None or d != 1 and s not in d:
|
if d is None or d != 1 and s not in d:
|
||||||
if s == '}':
|
if s not in self.close_scope_tokens.get(name, set()):
|
||||||
raise Exception, "foog: %r %r %r" % (s not in d, s, d)
|
nextlvl = self._get_next_level()
|
||||||
self._append_unless('continue', name, self._get_next_level())
|
self._append_unless('continue', name, nextlvl)
|
||||||
#XYZYZYXYXY
|
#XYZYZYXYXY
|
||||||
|
|
||||||
def _is_open_token(self, t):
|
def _is_open_token(self, t):
|
||||||
|
@ -392,12 +396,15 @@ class StackTabber2(Tabber):
|
||||||
def _handle_open_token(self, y, tokens, start, end, i, t):
|
def _handle_open_token(self, y, tokens, start, end, i, t):
|
||||||
if i == 0 and self.stack and self.stack[-1].name == 'continue':
|
if i == 0 and self.stack and self.stack[-1].name == 'continue':
|
||||||
self.stack.pop()
|
self.stack.pop()
|
||||||
if t.string in self.scope_tokens.get(t.name, {}):
|
if t.string in self.open_scope_tokens.get(t.name, set()):
|
||||||
self._pop_while('continue', 'control')
|
self._pop_while('continue', 'control')
|
||||||
|
if i == 0 and t.string in self.open_scope_tokens.get(t.name, set()):
|
||||||
|
self._save_curr_level()
|
||||||
|
|
||||||
if i == end - start:
|
if i == end - start:
|
||||||
level = self._get_next_level()
|
level = self._get_next_level()
|
||||||
else:
|
else:
|
||||||
level = tokens[i + 1].x + 1
|
level = tokens[i + 1].x + 1
|
||||||
self._append(t.string, t.name, level)
|
self._append(t.string, t.name, level)
|
||||||
|
|
||||||
def _handle_other_token(self, y, tokens, start, end, i, t):
|
def _handle_other_token(self, y, tokens, start, end, i, t):
|
||||||
|
@ -427,7 +434,9 @@ class StackTabber2(Tabber):
|
||||||
|
|
||||||
# add implicit continuation
|
# add implicit continuation
|
||||||
top = self._peek()
|
top = self._peek()
|
||||||
if i + start == end and (top and top.name in self.scope_tokens.get(top.type_, {}) or not top):
|
if (i + start == end and
|
||||||
|
(top and top.name in self.open_scope_tokens.get(top.type_, {}) or
|
||||||
|
not top)):
|
||||||
if self.continue_tokens:
|
if self.continue_tokens:
|
||||||
if s in self.continue_tokens.get(name, {}):
|
if s in self.continue_tokens.get(name, {}):
|
||||||
self._append_unless('continue', name, self._get_next_level())
|
self._append_unless('continue', name, self._get_next_level())
|
||||||
|
|
Loading…
Reference in New Issue