2010-08-11 08:55:30 -04:00
|
|
|
#import commands
|
2010-08-11 23:16:48 -04:00
|
|
|
from tab import StackTabber2
|
2010-08-11 08:55:30 -04:00
|
|
|
#from method import Method
|
2010-08-11 08:42:43 -04:00
|
|
|
from mode import Fundamental
|
|
|
|
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
|
|
|
|
from mode.python import StringGrammar1, StringGrammar2
|
2010-08-11 08:55:30 -04:00
|
|
|
#from mode.pipe import Pipe
|
|
|
|
#from method.shell import Interact
|
2010-08-11 08:42:43 -04:00
|
|
|
|
|
|
|
chr1 = '[a-zA-Z_]'
|
|
|
|
chr2 = '[a-zA-Z_0-9]'
|
|
|
|
word = chr1 + chr2 + '*'
|
|
|
|
|
|
|
|
class NestedCommentGrammar(Grammar): pass
|
|
|
|
NestedCommentGrammar.rules = [
|
|
|
|
RegionRule('comment', r'/\*', NestedCommentGrammar, r'\*/'),
|
|
|
|
PatternRule('data', r'(?:[^\*]|\*(?!/))+'),
|
|
|
|
]
|
|
|
|
|
2010-08-11 08:55:30 -04:00
|
|
|
class StringGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule('escaped', r"\\u[0-9A-Fa-f]{4}|\\[0-7]{1,3}|\\[btnfr\"'\\]"),
|
|
|
|
PatternRule('data', r'[^\\"]+'),
|
|
|
|
]
|
|
|
|
|
2010-08-11 08:42:43 -04:00
|
|
|
class ScalaGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule('scala.comment', '//.*$'),
|
|
|
|
RegionRule('scala.comment', r'/\*', NestedCommentGrammar, r'\*/'),
|
|
|
|
|
|
|
|
PatternRule('spaces', r'(?:\t| )+'),
|
|
|
|
PatternRule('eol', r'\n'),
|
|
|
|
|
2010-08-11 10:19:12 -04:00
|
|
|
PatternRule('delimiter', r'(?:;|{|}|\[|\]|\(|\)|,|\.|<|>|:|/|\+|-|\*|=)'),
|
|
|
|
|
2010-08-12 07:40:07 -04:00
|
|
|
PatternRule('scala.def', '(?<=(?<![a-zA-Z0-9_])def )[a-zA-Z_][a-zA-Z0-9_]*'),
|
|
|
|
PatternRule('scala.class', '(?<=(?<![a-zA-Z0-9_])class )[a-zA-Z_][a-zA-Z0-9_]*'),
|
|
|
|
PatternRule('scala.class', '(?<=(?<![a-zA-Z0-9_])object )[a-zA-Z_][a-zA-Z0-9_]*'),
|
|
|
|
|
2010-08-11 08:42:43 -04:00
|
|
|
PatternRule('scala.reserved', '(?:yield|with|while|var|val|type|true|try|trait|throw|this|super|sealed|return|protected|private|package|override|object|null|new|match|lazy|import|implicit|if|forSome|for|finally|final|false|extends|else|do|def|class|catch|case|abstract)(?!%s)' % word),
|
|
|
|
|
|
|
|
PatternRule('scala.integer', '-?(?:0|[1-9])[0-9]*[Ll]?'),
|
|
|
|
PatternRule('scala.integer', '-?0x[0-9A-Fa-f]+[Ll]?'),
|
|
|
|
PatternRule('scala.integer', '-?0[0-7]+[Ll]?'),
|
|
|
|
|
|
|
|
PatternRule('scala.float', r'-?[0-9]+\.[0-9]*'), # FIXME
|
|
|
|
|
|
|
|
PatternRule('scala.bool', '(?:true|false)(?![a-zA-Z0-9_])'),
|
|
|
|
|
|
|
|
PatternRule('scala.char', r"'(?:[^'\\]|\\u[0-9A-Fa-f]{4}|\\[0-7]{1,3}|\\[btnfr\"'\\])'"),
|
2010-08-11 08:55:30 -04:00
|
|
|
RegionRule('scala.string', '"', StringGrammar, '"'),
|
|
|
|
PatternRule('scala.symbol', "'[a-zA-Z_][a-zA-Z0-9_]*"),
|
2010-08-11 10:19:12 -04:00
|
|
|
|
|
|
|
PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_]*'),
|
|
|
|
|
|
|
|
PatternRule('scala.bareword', '[a-zA-Z_][a-zA-Z0-9_]*'),
|
|
|
|
|
|
|
|
PatternRule('scala.null', 'null'),
|
2010-08-11 08:42:43 -04:00
|
|
|
]
|
|
|
|
|
2010-08-11 23:16:48 -04:00
|
|
|
class ScalaTabber(StackTabber2):
|
|
|
|
open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}}
|
|
|
|
close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}}
|
|
|
|
control_tokens = {'scala.reserved': set(('if', 'else', 'while', 'do', 'for'))}
|
|
|
|
end_at_eof = True
|
|
|
|
start_free_tokens = {'string.start': 'string.end'}
|
|
|
|
end_free_tokens = {'string.end': 'string.start'}
|
|
|
|
is_ignored_tokens = set(('spaces', 'eol', 'comment', 'comment.start',
|
|
|
|
'comment.data', 'comment.null', 'comment.end'))
|
|
|
|
is_indent_tokens = set(('spaces',))
|
2010-08-12 00:01:47 -04:00
|
|
|
def _is_base(self, y):
|
|
|
|
# the first line is always safe
|
|
|
|
if y == 0: return True
|
|
|
|
|
|
|
|
# if there are no tokens we don't really have any info
|
|
|
|
tokens = self._get_tokens(y)
|
|
|
|
if not tokens: return False
|
|
|
|
|
|
|
|
# if it looks like a top-level class, object or function, then say ok
|
|
|
|
t = tokens[0]
|
|
|
|
if t.fqmatchs('scala.reserved', ('class', 'object', 'def')):
|
|
|
|
return True
|
|
|
|
|
|
|
|
# the default is to assume no
|
|
|
|
return False
|
2010-08-11 23:16:48 -04:00
|
|
|
|
2010-08-11 08:42:43 -04:00
|
|
|
class Scala(Fundamental):
|
|
|
|
name = 'Scala'
|
|
|
|
extensions = ['.scala']
|
2010-08-11 23:16:48 -04:00
|
|
|
tabwidth = 2
|
|
|
|
tabbercls = ScalaTabber
|
2010-08-11 08:42:43 -04:00
|
|
|
grammar = ScalaGrammar
|
2010-08-11 23:16:48 -04:00
|
|
|
commentc = '//'
|
2010-08-11 08:42:43 -04:00
|
|
|
opentokens = ('delimiter',)
|
|
|
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
|
|
|
closetokens = ('delimiter',)
|
|
|
|
closetags = {')': '(', ']': '[', '}': '{'}
|
2010-08-11 10:19:12 -04:00
|
|
|
|
|
|
|
colors = {
|
|
|
|
'scala.annotation': ('magenta', 'default'),
|
|
|
|
'scala.bool': ('magenta', 'default'),
|
|
|
|
'scala.null': ('magenta', 'default'),
|
|
|
|
|
|
|
|
'scala.integer': ('default', 'default'),
|
|
|
|
'scala.float': ('default', 'default'),
|
|
|
|
'scala.bareword': ('default', 'default'),
|
2010-08-12 07:40:07 -04:00
|
|
|
|
|
|
|
'scala.class': ('yellow', 'default'),
|
|
|
|
'scala.def': ('blue', 'default'),
|
2010-08-11 10:19:12 -04:00
|
|
|
}
|
|
|
|
|
2010-08-11 08:42:43 -04:00
|
|
|
_bindings = {
|
2010-08-11 23:16:48 -04:00
|
|
|
'close-paren': (')',),
|
|
|
|
'close-brace': ('}',),
|
|
|
|
'close-bracket': (']',),
|
2010-08-11 08:42:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
def install(*args):
|
|
|
|
Scala.install(*args)
|