parent
2dcac2c1f1
commit
155044696f
25
tab.py
25
tab.py
|
@ -240,7 +240,8 @@ class Marker2(object):
|
|||
class StackTabber2(Tabber):
|
||||
open_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'])}
|
||||
end_at_eof = True
|
||||
end_at_tokens = {}
|
||||
|
@ -377,13 +378,16 @@ class StackTabber2(Tabber):
|
|||
# add implicit continuation XYZYXYZY
|
||||
name, s = t.fqname(), t.string
|
||||
top = self._peek()
|
||||
if (i + start == end and
|
||||
(not top or top.name in self.scope_tokens.get(top.type_, {}))):
|
||||
atscope = True
|
||||
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)
|
||||
if d is None or d != 1 and s not in d:
|
||||
if s == '}':
|
||||
raise Exception, "foog: %r %r %r" % (s not in d, s, d)
|
||||
self._append_unless('continue', name, self._get_next_level())
|
||||
if s not in self.close_scope_tokens.get(name, set()):
|
||||
nextlvl = self._get_next_level()
|
||||
self._append_unless('continue', name, nextlvl)
|
||||
#XYZYZYXYXY
|
||||
|
||||
def _is_open_token(self, t):
|
||||
|
@ -392,8 +396,11 @@ class StackTabber2(Tabber):
|
|||
def _handle_open_token(self, y, tokens, start, end, i, t):
|
||||
if i == 0 and self.stack and self.stack[-1].name == 'continue':
|
||||
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')
|
||||
if i == 0 and t.string in self.open_scope_tokens.get(t.name, set()):
|
||||
self._save_curr_level()
|
||||
|
||||
if i == end - start:
|
||||
level = self._get_next_level()
|
||||
else:
|
||||
|
@ -427,7 +434,9 @@ class StackTabber2(Tabber):
|
|||
|
||||
# add implicit continuation
|
||||
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 s in self.continue_tokens.get(name, {}):
|
||||
self._append_unless('continue', name, self._get_next_level())
|
||||
|
|
Loading…
Reference in New Issue