parent
7d2720f497
commit
a7a5215bc9
59
mode_perl.py
59
mode_perl.py
|
@ -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]*')
|
||||
]
|
||||
|
||||
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):
|
||||
#tabbercls = tab2.StackTabber
|
||||
tabbercls = tab2.PerlTabber
|
||||
tabbercls = PerlTabber
|
||||
grammar = PerlGrammar()
|
||||
opentoken = 'delimiter'
|
||||
opentags = {'(': ')', '[': ']', '{': '}'}
|
||||
|
|
108
tab2.py
108
tab2.py
|
@ -159,57 +159,57 @@ class StackTabber(Tabber):
|
|||
if self.markers and self.markers[-1].name in names:
|
||||
self.markers.pop(-1)
|
||||
|
||||
class PerlTabber(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 = StackTabber._handle_open_token(self, currlvl, y, i)
|
||||
return currlvl
|
||||
def _handle_close_token(self, currlvl, y, i):
|
||||
self._opt_pop('cont')
|
||||
currlvl = 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 == 'string.start':
|
||||
self._opt_append('string', None)
|
||||
elif fqname == 'string.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('string') and
|
||||
not fqname.startswith('endblock') and
|
||||
not fqname == 'comment' and
|
||||
not fqname == 'null' and
|
||||
token.string not in ('}', ';', '(', '{', '[', ',')):
|
||||
self._opt_append('cont' % fqname, currlvl + 4)
|
||||
return currlvl
|
||||
#class PerlTabber(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 = StackTabber._handle_open_token(self, currlvl, y, i)
|
||||
# return currlvl
|
||||
# def _handle_close_token(self, currlvl, y, i):
|
||||
# self._opt_pop('cont')
|
||||
# currlvl = 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 == 'string.start':
|
||||
# self._opt_append('string', None)
|
||||
# elif fqname == 'string.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('string') and
|
||||
# not fqname.startswith('endblock') and
|
||||
# not fqname == 'comment' and
|
||||
# not fqname == 'null' and
|
||||
# token.string not in ('}', ';', '(', '{', '[', ',')):
|
||||
# self._opt_append('cont' % fqname, currlvl + 4)
|
||||
# return currlvl
|
||||
|
|
Loading…
Reference in New Issue