a bunch of fixes to c-tabber and stacktabber2

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-08-19 23:25:47 -04:00
parent 16d55b4bc9
commit 72bdc0915a
2 changed files with 20 additions and 8 deletions

View File

@ -100,15 +100,19 @@ class CTabber2(tab.StackTabber2):
end_free_tokens = {'c.string.end': 'c.string.start'} end_free_tokens = {'c.string.end': 'c.string.start'}
start_macro_tokens = {'c.macro.start': 'c.macro.end'} start_macro_tokens = {'c.macro.start': 'c.macro.end'}
end_macro_tokens = {'c.macro.end': 'c.macro.start'} end_macro_tokens = {'c.macro.end': 'c.macro.start'}
def is_base(self, y): def _is_base(self, y):
if y == 0: if y == 0:
return True return True
# if there are no tokens we don't really have any info
tokens = self._get_tokens(y) tokens = self._get_tokens(y)
if not tokens:
return False
# this assumes that people aren't gonna use these macros inside of # this assumes that people aren't gonna use these macros inside of
# blocks, which is probably ok. # blocks, which is probably ok.
t = tokens[0] t = tokens[0]
if t.fqmatchs('c.macro.start', '#define', '#include'): if t.fqmatchs('c.macro.start', ('#define', '#include')):
return True return True
# detecting function declarations is annoying; this assumes that people # detecting function declarations is annoying; this assumes that people
@ -116,13 +120,14 @@ class CTabber2(tab.StackTabber2):
# might do that for function return type and name. # might do that for function return type and name.
# #
# unfortunately, valid function return types might include any of the # unfortunately, valid function return types might include any of the
# four types of tokens below # types of tokens below
decl = False decl = False
for t in tokens: for t in tokens:
if t.isa('c.keyword', 'c.identifier', 'c.type'): if decl and self._is_ignored(t):
pass
elif t.isa('c.keyword', 'c.identifier', 'c.type'):
decl = True decl = True
continue elif decl and t.name == 'c.function':
if decl and t.name == 'c.function':
break break
else: else:
decl = False decl = False

9
tab.py
View File

@ -386,6 +386,11 @@ class StackTabber2(Tabber):
if self.end_at_eof: if self.end_at_eof:
return return
# ok, if we are closing a block then this will end a "single-statement"
# block. e.g. else switch() { ... }
if t.string in self.close_scope_tokens.get(t.fqname(), set()):
self._pop('control')
# if we do want implicit continuation, see if we need it. # if we do want implicit continuation, see if we need it.
name, s = t.fqname(), t.string name, s = t.fqname(), t.string
top = self._peek() top = self._peek()
@ -406,7 +411,8 @@ class StackTabber2(Tabber):
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.open_scope_tokens.get(t.name, set()): if t.string in self.open_scope_tokens.get(t.name, set()):
self._pop_while('continue', 'control') #self._pop_while('continue', 'control')
self._pop_while('continue')
if i == 0 and t.string in self.open_scope_tokens.get(t.name, set()): if i == 0 and t.string in self.open_scope_tokens.get(t.name, set()):
self._save_curr_level() self._save_curr_level()
@ -465,4 +471,5 @@ class StackTabber2(Tabber):
# handle control keywords # handle control keywords
if i == start: if i == start:
self._save_curr_level() self._save_curr_level()
self._pop_while('continue');
self._append('control', name, self._get_next_level(), y) self._append('control', name, self._get_next_level(), y)