From 1fe29b34aae9f7037f0d5795505d42768e3548f6 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Fri, 10 Feb 2012 21:58:35 -0500 Subject: [PATCH] updated highlighting update --HG-- branch : pmacs2 --- mode/scala.py | 53 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/mode/scala.py b/mode/scala.py index 1766854..21baab1 100644 --- a/mode/scala.py +++ b/mode/scala.py @@ -31,7 +31,8 @@ class StringGrammar(Grammar): class SubTypeGrammar(Grammar): pass SubTypeGrammar.rules = [ RegionRule('sub', r'\[', SubTypeGrammar, r'\]'), - PatternRule('scala.type', '(?:[a-zA-Z0-9_.]+| *=> *)+'), + #PatternRule('scala.type', '(?:[a-zA-Z0-9_.]+| *=> *)+'), + PatternRule('scala.type', '[A-Z][a-zA-Z0-9_.]+'), PatternRule('spaces', ' +'), PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_]*'), ] @@ -42,17 +43,17 @@ class ScalaGrammar(Grammar): RegionRule('scala.comment', r'/\*', NestedCommentGrammar, r'\*/'), RegionRule('scala.script', r'#!.+$', ShGrammar, r'!#'), - PatternMatchRule('x', r'(? *)+)', - 'delimiter', 'scala.type'), - PatternMatchRule('x', r'(? *)+)', - 'delimiter', 'spaces', 'scala.type'), - #PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)([a-zA-Z0-9_]+)', + #PatternMatchRule('x', r'(? *)+)', # 'delimiter', 'scala.type'), - #PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)( +)([a-zA-Z0-9_]+)', + #PatternMatchRule('x', r'(? *)+)', # 'delimiter', 'spaces', 'scala.type'), + PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)([a-zA-Z0-9_]+)', + 'delimiter', 'scala.type'), + PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)( +)([a-zA-Z0-9_]+)', + 'delimiter', 'spaces', 'scala.type'), - PatternMatchRule('x', r'(extends|with|new)( +)([a-zA-Z0-9_.]+)', - 'scala.reserved', 'spaces', 'scala.type'), + #PatternMatchRule('x', r'(extends|with|new)( +)([a-zA-Z0-9_.]+)', + # 'scala.reserved', 'spaces', 'scala.type'), #PatternMatchRule('x', r'(with)( +)([a-zA-Z0-9_.]+)', # 'scala.reserved', 'spaces', 'scala.type'), #PatternMatchRule('x', r'(new)( +)([a-zA-Z0-9_.]+)', @@ -92,12 +93,11 @@ class ScalaGrammar(Grammar): PatternRule('scala.symbol', "'[a-zA-Z_][a-zA-Z0-9_]*"), PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_]*'), + PatternRule('scala.type', '[A-Z][a-zA-Z0-9_]*'), PatternRule('scala.bareword', '[a-zA-Z_][a-zA-Z0-9_]*'), ] class ScalaTabber(StackTabber2): - #open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} - #close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}} open_tokens = {'delimiter': {'{': '}', '(': ')'}, 'sub.start': {'[': ']'}} close_tokens = {'delimiter': {'}': '{', ')': '('}, @@ -201,6 +201,7 @@ class ScalaDecompile(Method): } field_re = re.compile('^Field\s+([^:]+):(.+)$') + long_re = re.compile('^long\s+(\d+)[lL]$') sig_re = re.compile('^(\w+)\s+([^:]+):\(([^)]*)\)(.+)$') def _parse_sig(self, line): if line.startswith('class'): @@ -208,19 +209,25 @@ class ScalaDecompile(Method): return "class " + self._abbrev(name) elif line.startswith('String'): - return 'string "%s"' % line + return 'string "%s"' % line[7:] elif line.startswith('Field'): m = self.field_re.match(line) - if not m: raise Exception("failed to match %r" % line) + if not m: raise Exception("failed to match (1) %r" % line) name = self._abbrev(m.group(1)) result = self._parse_args(m.group(2))[0] #return "field %s -> %s" % (name, result) return "field %s %s" % (result, name) + elif line.startswith('long'): + return 'long %s' % line[5:] + + elif line.startswith('int'): + return 'int %s' % line[5:] + else: m = self.sig_re.match(line) - if not m: raise Exception("failed to match %r" % line) + if not m: raise Exception("failed to match (3) %r" % line) typ = self.typs[m.group(1)] name = self._abbrev(m.group(2)) @@ -233,7 +240,7 @@ class ScalaDecompile(Method): def _parse_instruction(self, line): if '//' in line: real, x = line.split('//') - sig = self._parse_sig(x) + sig = self._parse_sig(x.strip()) else: real, sig = line, None @@ -250,8 +257,9 @@ class ScalaDecompile(Method): return "%4s %-22s" % (n, ins + " " + args) def _execute(self, w, **vargs): - cp = 'target/scala-2.9.1.final/classes' #FIXME - argv = ['javap', '-classpath', cp, '-c', vargs['classname']] + clsname = vargs['classname'] + cp = '.:target/scala-2.9.1.final/classes' #FIXME + argv = ['javap', '-classpath', cp, '-c', '-private', clsname] p = Popen(argv, stdout=PIPE, stderr=STDOUT) lines = p.stdout.readlines() @@ -269,7 +277,7 @@ class ScalaDecompile(Method): obj = self._parse_obj(line) elif line == "Code:": continue - elif line == "": + elif line == "" or line == "}": if curr: methods.append((curr, instructions)) curr = None @@ -277,13 +285,14 @@ class ScalaDecompile(Method): elif self.ins_re.match(line): instructions.append(self._parse_instruction(line)) else: + import sys curr = self._parse_method(line) outlines = [] if self.pkg: outlines.append('package ' + self.pkg[:-1]) outlines.append('') - outlines.append(obj + " {") + outlines.append(str(obj) + " {") for method, instructions in methods: if instructions: outlines.append(" " + method + " {") @@ -295,9 +304,9 @@ class ScalaDecompile(Method): outlines.append("}") output = "\n".join(outlines) - - #w.application.data_buffer("*Javap*", output, switch_to=True) - w.application.data_buffer("*Javap*", output, modename='javap', switch_to=True) + + name = "*Javap:%s*" % clsname + w.application.data_buffer(name, output, modename='javap', switch_to=True) # white is for delimiters, operators, numbers default = ('default', 'default')