--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-06-19 18:45:51 +00:00
parent 0d009bfa8c
commit e7c656de45
4 changed files with 69 additions and 49 deletions

View File

@ -1,10 +1,9 @@
package TBB::Reporting2; package TBB::Reporting2;
{ my $foo = {
'foo', 'foo',
'bar', 'bar',
} };
foo(); foo();

View File

@ -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):

View File

@ -101,10 +101,12 @@ 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()
opentoken = 'delimiter'
opentags = {'(': ')', '[': ']', '{': '}'} opentags = {'(': ')', '[': ']', '{': '}'}
closetoken = 'delimiter'
closetags = {')': '(', ']': '[', '}': '{'} closetags = {')': '(', ']': '[', '}': '{'}
def __init__(self, w): def __init__(self, w):
mode2.Fundamental.__init__(self, w) mode2.Fundamental.__init__(self, w)

77
tab2.py
View File

@ -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)
elif token.name == self.mode.opentoken and s in self.mode.opentags:
currlvl = self._handle_close_token(currlvl, y, i)
else:
currlvl = self._handle_other_token(currlvl, y, i)
return currlvl
def _handle_open_token(self, currlvl, y, i):
token = self.get_token(y, i)
s1 = token.string
if not self.markers: if not self.markers:
raise Exception, "unmatched closing token %r" % s raise Exception, "unmatched closing token %r" % s1
nam = self.markers[-1].name s2 = self.markers[-1].name
if s == self.mode.opentags[nam]: if s1 == self.mode.opentags[s2]:
del self.markers[-1] del self.markers[-1]
if self.is_leftmost_token(y, i): if self.is_leftmost_token(y, i):
currlvl = self.get_curr_level() currlvl = self.get_curr_level()
else: else:
raise Exception, "mismatched closing tag %r vs %r" % (nam, s) raise Exception, "mismatched closing tag %r vs %r" % (s2, s1)
elif s in self.mode.opentags:
level = self.get_curr_level() + 1
self.markers.append(Marker(s, level))
return currlvl 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