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