From dd3151d3545e99a2017bcf01a88cba97bd8c0311 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Wed, 11 Aug 2010 23:16:48 -0400 Subject: [PATCH] first stab at scala indenter... by no means complete or correct --HG-- branch : pmacs2 --- mode/scala.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/mode/scala.py b/mode/scala.py index deff0b1..6519c22 100644 --- a/mode/scala.py +++ b/mode/scala.py @@ -1,5 +1,5 @@ #import commands -#from tab import StackTabber +from tab import StackTabber2 #from method import Method from mode import Fundamental from lex import Grammar, PatternRule, RegionRule, PatternMatchRule @@ -54,11 +54,25 @@ class ScalaGrammar(Grammar): PatternRule('scala.null', 'null'), ] +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',)) + def is_base(self, y): return y == 0 + class Scala(Fundamental): name = 'Scala' extensions = ['.scala'] + tabwidth = 2 + tabbercls = ScalaTabber grammar = ScalaGrammar - commentc = '--' + commentc = '//' opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) @@ -75,9 +89,9 @@ class Scala(Fundamental): } _bindings = { - 'close-paren': (')',), - 'close-brace': ('}',), - 'close-bracket': (']',), + 'close-paren': (')',), + 'close-brace': ('}',), + 'close-bracket': (']',), } def install(*args):