fixed some perl tab issues

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-06-21 03:34:31 +00:00
parent 7d2720f497
commit a7a5215bc9
2 changed files with 111 additions and 56 deletions

View File

@ -100,9 +100,64 @@ class PerlGrammar(Grammar):
PatternRule(name=r'bareword', pattern=r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*') PatternRule(name=r'bareword', pattern=r'(?:[a-zA-Z_][a-zA-Z_0-9]*::)*[a-zA-Z_][a-zA-Z_0-9]*')
] ]
class PerlTabber(tab2.StackTabber):
def is_base(self, y):
if y == 0:
return True
highlighter = self.mode.window.buffer.highlights[self.mode.name()]
if not highlighter.tokens[y]:
return False
t = highlighter.tokens[y][0]
if t.name == 'keyword' and t.string == 'sub':
return True
return False
def _handle_open_token(self, currlvl, y, i):
currlvl = tab2.StackTabber._handle_open_token(self, currlvl, y, i)
return currlvl
def _handle_close_token(self, currlvl, y, i):
self._opt_pop('cont')
currlvl = tab2.StackTabber._handle_close_token(self, currlvl, y, i)
token = self.get_token(y, i)
if token.string == '}':
self._opt_pop('cont')
elif self.is_rightmost_token(y, i):
self._opt_append('cont', currlvl + 4)
return currlvl
def _handle_other_token(self, currlvl, y, i):
token = self.get_token(y, i)
fqname = token.fqname()
if fqname == 'delimiter' and token.string == ';':
self._opt_pop('cont')
elif fqname == 'heredoc.start':
self._opt_append('heredoc', None)
elif fqname == 'heredoc.end':
self._opt_pop('heredoc')
self._opt_pop('cont')
elif fqname == 'pod.start':
self._opt_append('pod', None)
elif fqname == 'pod.end':
self._opt_pop('pod')
currlvl = 0
elif fqname == 'string1.start' or fqname == 'string2.start':
self._opt_append('string', None)
elif fqname == 'string1.end' or fqname == 'string2.end':
self._opt_pop('string')
if self.is_rightmost_token(y, i):
self._opt_append('cont', currlvl + 4)
if self.is_rightmost_token(y, i):
if(not fqname.startswith('pod') and
not fqname.startswith('heredoc') and
not fqname.startswith('string1') and
not fqname.startswith('string2') and
not fqname.startswith('endblock') and
not fqname == 'comment' and
not fqname == 'null' and
token.string not in ('}', ';', '(', '{', '[', ',')):
self._opt_append('cont', currlvl + 4)
return currlvl
class Perl(mode2.Fundamental): class Perl(mode2.Fundamental):
#tabbercls = tab2.StackTabber tabbercls = PerlTabber
tabbercls = tab2.PerlTabber
grammar = PerlGrammar() grammar = PerlGrammar()
opentoken = 'delimiter' opentoken = 'delimiter'
opentags = {'(': ')', '[': ']', '{': '}'} opentags = {'(': ')', '[': ']', '{': '}'}

108
tab2.py
View File

@ -159,57 +159,57 @@ class StackTabber(Tabber):
if self.markers and self.markers[-1].name in names: if self.markers and self.markers[-1].name in names:
self.markers.pop(-1) self.markers.pop(-1)
class PerlTabber(StackTabber): #class PerlTabber(StackTabber):
def is_base(self, y): # def is_base(self, y):
if y == 0: # if y == 0:
return True # return True
highlighter = self.mode.window.buffer.highlights[self.mode.name()] # highlighter = self.mode.window.buffer.highlights[self.mode.name()]
if not highlighter.tokens[y]: # if not highlighter.tokens[y]:
return False # return False
t = highlighter.tokens[y][0] # t = highlighter.tokens[y][0]
if t.name == 'keyword' and t.string == 'sub': # if t.name == 'keyword' and t.string == 'sub':
return True # return True
return False # return False
def _handle_open_token(self, currlvl, y, i): # def _handle_open_token(self, currlvl, y, i):
currlvl = StackTabber._handle_open_token(self, currlvl, y, i) # currlvl = StackTabber._handle_open_token(self, currlvl, y, i)
return currlvl # return currlvl
def _handle_close_token(self, currlvl, y, i): # def _handle_close_token(self, currlvl, y, i):
self._opt_pop('cont') # self._opt_pop('cont')
currlvl = StackTabber._handle_close_token(self, currlvl, y, i) # currlvl = StackTabber._handle_close_token(self, currlvl, y, i)
token = self.get_token(y, i) # token = self.get_token(y, i)
if token.string == '}': # if token.string == '}':
self._opt_pop('cont') # self._opt_pop('cont')
elif self.is_rightmost_token(y, i): # elif self.is_rightmost_token(y, i):
self._opt_append('cont', currlvl + 4) # self._opt_append('cont', currlvl + 4)
return currlvl # return currlvl
def _handle_other_token(self, currlvl, y, i): # def _handle_other_token(self, currlvl, y, i):
token = self.get_token(y, i) # token = self.get_token(y, i)
fqname = token.fqname() # fqname = token.fqname()
if fqname == 'delimiter' and token.string == ';': # if fqname == 'delimiter' and token.string == ';':
self._opt_pop('cont') # self._opt_pop('cont')
elif fqname == 'heredoc.start': # elif fqname == 'heredoc.start':
self._opt_append('heredoc', None) # self._opt_append('heredoc', None)
elif fqname == 'heredoc.end': # elif fqname == 'heredoc.end':
self._opt_pop('heredoc') # self._opt_pop('heredoc')
self._opt_pop('cont') # self._opt_pop('cont')
elif fqname == 'pod.start': # elif fqname == 'pod.start':
self._opt_append('pod', None) # self._opt_append('pod', None)
elif fqname == 'pod.end': # elif fqname == 'pod.end':
self._opt_pop('pod') # self._opt_pop('pod')
currlvl = 0 # currlvl = 0
elif fqname == 'string.start': # elif fqname == 'string.start':
self._opt_append('string', None) # self._opt_append('string', None)
elif fqname == 'string.end': # elif fqname == 'string.end':
self._opt_pop('string') # self._opt_pop('string')
if self.is_rightmost_token(y, i): # if self.is_rightmost_token(y, i):
self._opt_append('cont', currlvl + 4) # self._opt_append('cont', currlvl + 4)
if self.is_rightmost_token(y, i): # if self.is_rightmost_token(y, i):
if(not fqname.startswith('pod') and # if(not fqname.startswith('pod') and
not fqname.startswith('heredoc') and # not fqname.startswith('heredoc') and
not fqname.startswith('string') and # not fqname.startswith('string') and
not fqname.startswith('endblock') and # not fqname.startswith('endblock') and
not fqname == 'comment' and # not fqname == 'comment' and
not fqname == 'null' and # not fqname == 'null' and
token.string not in ('}', ';', '(', '{', '[', ',')): # token.string not in ('}', ';', '(', '{', '[', ',')):
self._opt_append('cont' % fqname, currlvl + 4) # self._opt_append('cont' % fqname, currlvl + 4)
return currlvl # return currlvl