start working on support classpath in mode.scala

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2012-09-10 15:24:47 -06:00
parent 733d522314
commit bd90421ddc
1 changed files with 24 additions and 21 deletions

View File

@ -31,10 +31,10 @@ class StringGrammar(Grammar):
class SubTypeGrammar(Grammar): pass class SubTypeGrammar(Grammar): pass
SubTypeGrammar.rules = [ SubTypeGrammar.rules = [
RegionRule('sub', r'\[', SubTypeGrammar, r'\]'), RegionRule('sub', r'\[', SubTypeGrammar, r'\]'),
#PatternRule('scala.type', '(?:[a-zA-Z0-9_.]+| *=> *)+'),
PatternRule('scala.type', '[A-Z][a-zA-Z0-9_.]*'), PatternRule('scala.type', '[A-Z][a-zA-Z0-9_.]*'),
PatternRule('spaces', ' +'), PatternRule('spaces', ' +'),
PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_]*'),
RegionRule('scala.string', '"', StringGrammar, '"'),
] ]
class ScalaGrammar(Grammar): class ScalaGrammar(Grammar):
@ -43,25 +43,13 @@ class ScalaGrammar(Grammar):
RegionRule('scala.comment', r'/\*', NestedCommentGrammar, r'\*/'), RegionRule('scala.comment', r'/\*', NestedCommentGrammar, r'\*/'),
RegionRule('scala.script', r'#!.+$', ShGrammar, r'!#'), RegionRule('scala.script', r'#!.+$', ShGrammar, r'!#'),
#PatternMatchRule('x', r'(?<!:)(:)((?:[a-zA-Z0-9_.]+| *=> *)+)',
# 'delimiter', 'scala.type'),
#PatternMatchRule('x', r'(?<!:)(:)( +)((?:[a-zA-Z0-9_.]+| *=> *)+)',
# 'delimiter', 'spaces', 'scala.type'),
PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)([a-zA-Z0-9_]+)', PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)([a-zA-Z0-9_]+)',
'delimiter', 'scala.type'), 'delimiter', 'scala.type'),
PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)( +)([a-zA-Z0-9_]+)', PatternMatchRule('x', r'(?<=[a-zA-Z0-9_ ])(:)( +)([a-zA-Z0-9_]+)',
'delimiter', 'spaces', 'scala.type'), 'delimiter', '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_.]+)',
# 'scala.reserved', 'spaces', 'scala.type'),
PatternRule('scala.def', '(?<=(?<![a-zA-Z0-9_])def )[^0-9:\[\( ][^:\[\( ]*'), PatternRule('scala.def', '(?<=(?<![a-zA-Z0-9_])def )[^0-9:\[\( ][^:\[\( ]*'),
#PatternRule('delimiter', r'(?:;|{|}|\[|\]|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=)'),
RegionRule('sub', r'(?<=:)\(', SubTypeGrammar, r'\)'), RegionRule('sub', r'(?<=:)\(', SubTypeGrammar, r'\)'),
PatternRule('delimiter', r'(?:;|{|}|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=)'), PatternRule('delimiter', r'(?:;|{|}|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=)'),
RegionRule('sub', r'\[', SubTypeGrammar, r'\]'), RegionRule('sub', r'\[', SubTypeGrammar, r'\]'),
@ -70,9 +58,6 @@ class ScalaGrammar(Grammar):
PatternRule('spaces', r'(?:\t| )+'), PatternRule('spaces', r'(?:\t| )+'),
PatternRule('eol', r'\n'), PatternRule('eol', r'\n'),
#PatternRule('scala.def', '(?<=(?<![a-zA-Z0-9_])def )[a-zA-Z_][a-zA-Z0-9_]*'),
#PatternRule('scala.def', '(?<=(?<![a-zA-Z0-9_])def )[^0-9\[\( ][^\[\( ]*'),
PatternRule('scala.class', '(?<=(?<![a-zA-Z0-9_])class )[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule('scala.class', '(?<=(?<![a-zA-Z0-9_])class )[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule('scala.object', '(?<=(?<![a-zA-Z0-9_])object )[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule('scala.object', '(?<=(?<![a-zA-Z0-9_])object )[a-zA-Z_][a-zA-Z0-9_]*'),
PatternRule('scala.trait', '(?<=(?<![a-zA-Z0-9_])trait )[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule('scala.trait', '(?<=(?<![a-zA-Z0-9_])trait )[a-zA-Z_][a-zA-Z0-9_]*'),
@ -117,9 +102,8 @@ class ScalaTabber(StackTabber2):
tokens = self._get_tokens(y) tokens = self._get_tokens(y)
if not tokens: return False if not tokens: return False
# if it looks like a top-level class, object or function, then say ok # if it looks like a top-level class or object, then say ok
t = tokens[0] if tokens[0].fqmatchs('scala.reserved', ('class', 'object')):
if t.fqmatchs('scala.reserved', ('class', 'object', 'def')):
return True return True
# the default is to assume no # the default is to assume no
@ -315,6 +299,23 @@ class ScalaDecompile(Method):
name = "*Javap:%s*" % clsname name = "*Javap:%s*" % clsname
w.application.data_buffer(name, output, modename='javap', switch_to=True) w.application.data_buffer(name, output, modename='javap', switch_to=True)
class ScalaSetClasspath(Method):
'''Set Scala's classpath'''
args = [arg("lib", dt='path', p="Lib: ", dv=lambda w: '.')]
def _execute(self, w, **vargs):
w.application.config['scala.cp'] = vargs['lib'].split(':')
class ScalaAddClasspath(ScalaSetClasspath):
'''Add path(s) to Scala's classpath'''
def _execute(self, w, **vargs):
w.application.config['scala.cp'].extend(vargs['lib'].split(':'))
class ScalaShowClasspath(ScalaSetClasspath):
'''Display Scala's classpath'''
def _execute(self, w, **vargs):
w.set_error(w.application.config.get('scala.cp'))
w.application.config['scala.cp'].extend(vargs['lib'].split(':'))
# white is for delimiters, operators, numbers # white is for delimiters, operators, numbers
default = ('default', 'default') default = ('default', 'default')
@ -353,8 +354,10 @@ class Scala(Fundamental):
tabbercls = ScalaTabber tabbercls = ScalaTabber
grammar = ScalaGrammar grammar = ScalaGrammar
commentc = '//' commentc = '//'
#actions = [ScalaStart, ScalaDocBrowse, ScalaDocLookup, ScalaGetType, ScalaGotoDefinition]
actions = [ScalaStart, ScalaDecompile] actions = [ScalaStart, ScalaDecompile, ScalaSetClasspath,
ScalaAddClasspath, ScalaShowClasspath]
opentokens = ('delimiter', 'sub.start', 'sub.sub.start', 'sub.sub.sub.start') opentokens = ('delimiter', 'sub.start', 'sub.sub.start', 'sub.sub.sub.start')
opentags = {'(': ')', '[': ']', '{': '}'} opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter', 'sub.end', 'sub.sub.end', 'sub.sub.sub.end') closetokens = ('delimiter', 'sub.end', 'sub.sub.end', 'sub.sub.sub.end')