From c47fca63d61776fb2fdbee73d87591b99ea56d80 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Tue, 16 Mar 2010 01:02:52 -0400 Subject: [PATCH] indentation support --HG-- branch : pmacs2 --- mode/inform6.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/mode/inform6.py b/mode/inform6.py index 25f9a69..3c62d4f 100644 --- a/mode/inform6.py +++ b/mode/inform6.py @@ -1,5 +1,7 @@ from mode import Fundamental from lex import Grammar, PatternRule, RegionRule, NocaseKeywordRule +from tab import StackTabber +import regex directives = '''abbreviate array attribute btrace class constant default dictionary end endif etrace extend fake_action global ifdef ifndef iftrue @@ -64,9 +66,45 @@ class Inform6Grammar(Grammar): PatternRule('continuation', r'\\\n$'), ] +class Inform6Tabber(StackTabber): + def is_base(self, y): + if y == 0: + return True + h = self.mode.window.buffer.highlights[self.mode.name] + if not h.tokens[y]: + return False + t = h.tokens[y][0] + if t.name != 'inform6.directive': + return False + return t.string.lower() in ('constant', 'include', 'object') + def _handle_open_token(self, currlvl, y, i): + t = self.get_token(y, i) + l = self.get_curr_level() + self.mode.tabwidth + self._append(t.string, l, y) + return currlvl + def _handle_other_token(self, currlvl, y, i): + w = self.mode.tabwidth + t = self.get_token(y, i) + s = t.string.lower() + n = t.fqname() + if n == 'inform6.directive': + if s == 'object': + self._append('object', currlvl + w, y) + if n == 'inform6.keyword': + if s in ('with', 'has'): + if self._peek_name() == 'keyword': + self._pop() + currlvl -= w + self._append('keyword', currlvl + w, y) + elif n == 'delimiter': + self._opt_pop('keyword') + self._opt_pop('object') + return currlvl + class Inform6(Fundamental): name = 'inform6' extensions = ['.inf'] + tabbercls = Inform6Tabber grammar = Inform6Grammar commentc = '!' opentokens = ('delimiter',)