--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-03 21:52:23 +00:00
parent 998e836873
commit 3f86cd6ea3
1 changed files with 26 additions and 42 deletions

View File

@ -1,12 +1,13 @@
import color, mode, tab import color, mode, tab
import context import context
from lex import Grammar, PatternRule, RegionRule from lex import Grammar, PatternRule, RegionRule, PatternGroupRule
from mode.python import StringGrammar2 from mode.python import StringGrammar2
from mode.c import CTabber2 from mode.c import CTabber2
from parse import Any, And, Or, Optional, Name, Match, Matchs from parse import Any, And, Or, Optional, Name, Match, Matchs
class CommentGrammar(Grammar): class CommentGrammar(Grammar):
rules = [ rules = [
PatternGroupRule(r'xyz', 'javadoc', r'@[a-z]+', r'spaces', r' +', r'javaname', r'[^ ]+'),
PatternRule(r"javadoc", r"@[a-z]+"), PatternRule(r"javadoc", r"@[a-z]+"),
PatternRule(r"data", r"(?:[^@*]|\*(?!/))+"), PatternRule(r"data", r"(?:[^@*]|\*(?!/))+"),
] ]
@ -69,10 +70,7 @@ class JavaTabber2(tab.StackTabber2):
start_free_tokens = {'string.start': 'string.end'} start_free_tokens = {'string.start': 'string.end'}
end_free_tokens = {'string.end': 'string.start'} end_free_tokens = {'string.end': 'string.start'}
def is_base(self, y): def is_base(self, y):
if y == 0: return y == 0
return True
else:
return False
def _is_indent(self, t): def _is_indent(self, t):
return t.name == 'spaces' return t.name == 'spaces'
def _is_ignored(self, t): def _is_ignored(self, t):
@ -91,43 +89,31 @@ class JavaContext(context.Context):
return [] return []
def _build_name_map(self, y1, y2, last, curr, stack): def _build_name_map(self, y1, y2, last, curr, stack):
blen = len(self.mode.window.buffer.lines)
highlights = self.mode.window.get_highlighter() highlights = self.mode.window.get_highlighter()
i = y1
i = y1
while i < y2: while i < y2:
if not stack: if not stack: curr = None
curr = None tokens = highlights.tokens[i]
g = highlights.tokens[i] result = self.class_match.match(tokens)
gl = len(g) if result: curr = tokens[result[0] - self.class_offset].string
result = self.method_match.match(tokens)
if result: curr = tokens[result[0] - self.method_offset].string
result = self.class_match.match(g) if curr is not None: self.names.setdefault(curr, i)
if result:
n = result[0] - self.class_offset
curr = g[n].string
result = self.method_match.match(g) for t in tokens:
if result:
n = result[0] - self.method_offset
curr = g[n].string
if curr is not None and curr not in self.names:
self.names[curr] = i
for t in g:
if t.match('delimiter', '{'): if t.match('delimiter', '{'):
stack.append(curr) stack.append(curr)
elif t.match('delimiter', '}'): elif t.match('delimiter', '}'):
if stack: if stack: stack.pop(-1)
stack.pop(-1)
if stack: if stack:
curr = stack[-1] curr = stack[-1]
else: else:
curr = None curr = None
if curr: if curr: self.namelines[i] = (curr, tuple(stack))
self.namelines[i] = (curr, tuple(stack))
i += 1 i += 1
class Java(mode.Fundamental): class Java(mode.Fundamental):
@ -135,32 +121,30 @@ class Java(mode.Fundamental):
extensions = ['.java'] extensions = ['.java']
tabbercls = JavaTabber2 tabbercls = JavaTabber2
grammar = JavaGrammar grammar = JavaGrammar
opentokens = ('delimiter',) opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'} opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',) closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'} closetags = {')': '(', ']': '[', '}': '{'}
colors = { colors = {
'java_comment.start': ('red', 'default', 'bold'), 'java_comment.start': ('red', 'default', 'bold'),
'java_comment.end': ('red', 'default', 'bold'), 'java_comment.end': ('red', 'default', 'bold'),
'java_comment.javadoc': ('magenta', 'default', 'bold'), 'java_comment.javadoc': ('magenta', 'default', 'bold'),
'java_comment.data': ('red', 'default', 'bold'), 'java_comment.javaname': ('yellow', 'default', 'bold'),
'java_comment.null': ('red', 'default', 'bold'), 'java_comment.data': ('red', 'default', 'bold'),
'import': ('blue', 'default', 'bold'), 'java_comment.null': ('red', 'default', 'bold'),
'java_label': ('magenta', 'default', 'bold'), 'import': ('blue', 'default', 'bold'),
'java_builtin': ('magenta', 'default', 'bold'), 'java_label': ('magenta', 'default', 'bold'),
'java_char': ('green', 'default', 'bold'), 'java_builtin': ('magenta', 'default', 'bold'),
'java_integer': ('green', 'default', 'bold'), 'java_char': ('green', 'default', 'bold'),
'java_float': ('green', 'default', 'bold'), 'java_integer': ('green', 'default', 'bold'),
'java_float': ('green', 'default', 'bold'),
} }
format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]" format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]"
#format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(first)s %(perc)s [%(func)s]"
def get_status_names(self): def get_status_names(self):
names = mode.Fundamental.get_status_names(self) names = mode.Fundamental.get_status_names(self)
c = self.window.logical_cursor() c = self.window.logical_cursor()
names['func'] = self.get_line_function(c.y) names['func'] = self.get_line_function(c.y)
#names['first'] = self.window.first.xy()
return names return names
def __init__(self, w): def __init__(self, w):