parent
0d009bfa8c
commit
e7c656de45
|
@ -1,10 +1,9 @@
|
||||||
package TBB::Reporting2;
|
package TBB::Reporting2;
|
||||||
|
|
||||||
{
|
my $foo = {
|
||||||
'foo',
|
'foo',
|
||||||
'bar',
|
'bar',
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
foo();
|
foo();
|
||||||
|
|
||||||
|
|
|
@ -447,10 +447,12 @@ class DumpMarkers(Method):
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
lines = []
|
lines = []
|
||||||
if w.mode.tabber:
|
if w.mode.tabber:
|
||||||
for i in range(0, len(w.mode.tabber.lines)):
|
keys = w.mode.tabber.lines.keys()
|
||||||
|
keys.sort()
|
||||||
|
for i in keys:
|
||||||
line = w.mode.tabber.lines[i]
|
line = w.mode.tabber.lines[i]
|
||||||
lines.append("LINE %d: %r" % (i, line))
|
lines.append("LINE %d: %r" % (i, line))
|
||||||
lines.append(" %s" % repr(w.mode.tabber.markers[i]))
|
lines.append(" %s" % repr(w.mode.tabber.record[i]))
|
||||||
else:
|
else:
|
||||||
lines.append("no tokens")
|
lines.append("no tokens")
|
||||||
output = "\n".join(lines)
|
output = "\n".join(lines)
|
||||||
|
@ -531,7 +533,7 @@ class InsertTab(Method):
|
||||||
j = w.buffer.count_leading_whitespace(cursor.y)
|
j = w.buffer.count_leading_whitespace(cursor.y)
|
||||||
if i != j:
|
if i != j:
|
||||||
KillWhitespace().execute(w)
|
KillWhitespace().execute(w)
|
||||||
w.insert_string(Point(0, cursor.y), ' ' * i * 4)
|
w.insert_string(Point(0, cursor.y), ' ' * i)
|
||||||
else:
|
else:
|
||||||
w.goto(Point(j, cursor.y))
|
w.goto(Point(j, cursor.y))
|
||||||
class KillWhitespace(Method):
|
class KillWhitespace(Method):
|
||||||
|
|
12
mode_perl.py
12
mode_perl.py
|
@ -101,11 +101,13 @@ class PerlGrammar(Grammar):
|
||||||
]
|
]
|
||||||
|
|
||||||
class Perl(mode2.Fundamental):
|
class Perl(mode2.Fundamental):
|
||||||
#tabbercls = tab2.Tabber
|
#tabbercls = tab2.StackTabber
|
||||||
tabbercls = tab2.StackTabber
|
tabbercls = tab2.PerlTabber
|
||||||
grammar = PerlGrammar()
|
grammar = PerlGrammar()
|
||||||
opentags = {'(': ')', '[': ']', '{': '}'}
|
opentoken = 'delimiter'
|
||||||
closetags = {')': '(', ']': '[', '}': '{'}
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
||||||
|
closetoken = 'delimiter'
|
||||||
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
mode2.Fundamental.__init__(self, w)
|
mode2.Fundamental.__init__(self, w)
|
||||||
|
|
||||||
|
|
89
tab2.py
89
tab2.py
|
@ -13,32 +13,28 @@ class Tabber:
|
||||||
self.mode = m
|
self.mode = m
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
|
|
||||||
def is_leftmost_token(self, y, i):
|
def get_next_left_token(self, y, i):
|
||||||
tokens = self.get_tokens(y)
|
tokens = self.get_tokens(y)
|
||||||
assert i >= 0 and i < len(tokens)
|
assert i >= 0 and i < len(tokens)
|
||||||
for j in range(0, i):
|
for j in range(0, i):
|
||||||
|
m = regex.whitespace.match(tokens[i - j].string)
|
||||||
|
if not m:
|
||||||
|
return tokens[i - j]
|
||||||
|
return None
|
||||||
|
def get_next_right_token(self, y, i):
|
||||||
|
tokens = self.get_tokens(y)
|
||||||
|
assert i >= 0 and i < len(tokens)
|
||||||
|
for j in range(i + 1, len(tokens)):
|
||||||
m = regex.whitespace.match(tokens[j].string)
|
m = regex.whitespace.match(tokens[j].string)
|
||||||
if not m:
|
if not m:
|
||||||
return False
|
return tokens[j]
|
||||||
return True
|
return None
|
||||||
|
def is_leftmost_token(self, y, i):
|
||||||
|
return self.get_next_left_token(y, i) is None
|
||||||
def is_rightmost_token(self, y, i):
|
def is_rightmost_token(self, y, i):
|
||||||
tokens = self.get_tokens(y)
|
return self.get_next_right_token(y, i) is None
|
||||||
assert i >= 0 and i < len(tokens)
|
|
||||||
for j in range(i, len(tokens)):
|
|
||||||
m = regex.whitespace.match(highlighter.tokens[y][j].string)
|
|
||||||
if not m:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
def is_only_token(self, y, i):
|
def is_only_token(self, y, i):
|
||||||
tokens = self.get_tokens(y)
|
return self.is_leftmost_token(y, i) and self.is_rightmost_token(y, i)
|
||||||
assert i >= 0 and i < len(tokens)
|
|
||||||
for j in range(0, len(tokens)):
|
|
||||||
if j == i:
|
|
||||||
continue
|
|
||||||
m = regex.whitespace.match(highlighter.tokens[y][j].string)
|
|
||||||
if not m:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def region_added(self, p, newlines):
|
def region_added(self, p, newlines):
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
|
@ -76,6 +72,8 @@ class StackTabber(Tabber):
|
||||||
return 0
|
return 0
|
||||||
def get_tokens(self, y):
|
def get_tokens(self, y):
|
||||||
return self.mode.window.buffer.highlights[self.mode.name()].tokens[y]
|
return self.mode.window.buffer.highlights[self.mode.name()].tokens[y]
|
||||||
|
def get_token(self, y, i):
|
||||||
|
return self.mode.window.buffer.highlights[self.mode.name()].tokens[y][i]
|
||||||
|
|
||||||
def region_added(self, p, newlines):
|
def region_added(self, p, newlines):
|
||||||
self.lines = {}
|
self.lines = {}
|
||||||
|
@ -110,22 +108,41 @@ class StackTabber(Tabber):
|
||||||
y += 1
|
y += 1
|
||||||
|
|
||||||
def _handle_token(self, currlvl, y, i):
|
def _handle_token(self, currlvl, y, i):
|
||||||
highlighter = self.mode.window.buffer.highlights[self.mode.name()]
|
token = self.get_token(y, i)
|
||||||
token = highlighter.tokens[y][i]
|
s = token.string
|
||||||
s = token.string
|
|
||||||
|
|
||||||
if token.name == 'delimiter':
|
if token.name == self.mode.closetoken and s in self.mode.closetags:
|
||||||
if s in self.mode.closetags:
|
currlvl = self._handle_open_token(currlvl, y, i)
|
||||||
if not self.markers:
|
elif token.name == self.mode.opentoken and s in self.mode.opentags:
|
||||||
raise Exception, "unmatched closing token %r" % s
|
currlvl = self._handle_close_token(currlvl, y, i)
|
||||||
nam = self.markers[-1].name
|
else:
|
||||||
if s == self.mode.opentags[nam]:
|
currlvl = self._handle_other_token(currlvl, y, i)
|
||||||
del self.markers[-1]
|
|
||||||
if self.is_leftmost_token(y, i):
|
|
||||||
currlvl = self.get_curr_level()
|
|
||||||
else:
|
|
||||||
raise Exception, "mismatched closing tag %r vs %r" % (nam, s)
|
|
||||||
elif s in self.mode.opentags:
|
|
||||||
level = self.get_curr_level() + 1
|
|
||||||
self.markers.append(Marker(s, level))
|
|
||||||
return currlvl
|
return currlvl
|
||||||
|
|
||||||
|
def _handle_open_token(self, currlvl, y, i):
|
||||||
|
token = self.get_token(y, i)
|
||||||
|
s1 = token.string
|
||||||
|
if not self.markers:
|
||||||
|
raise Exception, "unmatched closing token %r" % s1
|
||||||
|
s2 = self.markers[-1].name
|
||||||
|
if s1 == self.mode.opentags[s2]:
|
||||||
|
del self.markers[-1]
|
||||||
|
if self.is_leftmost_token(y, i):
|
||||||
|
currlvl = self.get_curr_level()
|
||||||
|
else:
|
||||||
|
raise Exception, "mismatched closing tag %r vs %r" % (s2, s1)
|
||||||
|
return currlvl
|
||||||
|
def _handle_close_token(self, currlvl, y, i):
|
||||||
|
token = self.get_token(y, i)
|
||||||
|
rtoken = self.get_next_right_token(y, i)
|
||||||
|
if rtoken is None:
|
||||||
|
level = self.get_curr_level() + 4
|
||||||
|
else:
|
||||||
|
level = rtoken.x
|
||||||
|
self.markers.append(Marker(token.string, level))
|
||||||
|
return currlvl
|
||||||
|
def _handle_other_token(self, currlvl, y, i):
|
||||||
|
return currlvl
|
||||||
|
|
||||||
|
class PerlTabber(StackTabber):
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue