parent
05d0f86c93
commit
41a8a5d9a2
|
@ -1,7 +1,7 @@
|
|||
import color, mode, tab
|
||||
from lex import Grammar, PatternRule, RegionRule
|
||||
from mode.python import StringGrammar2
|
||||
from mode.c import CTabber
|
||||
from mode.c import CTabber2
|
||||
|
||||
class JavaGrammar(Grammar):
|
||||
rules = [
|
||||
|
@ -30,7 +30,7 @@ class JavaGrammar(Grammar):
|
|||
PatternRule(r"eol", r"\n$"),
|
||||
]
|
||||
|
||||
class JavaTabber(CTabber):
|
||||
class JavaTabber(CTabber2):
|
||||
def is_base(self, y):
|
||||
if y == 0:
|
||||
return True
|
||||
|
|
18
tab.py
18
tab.py
|
@ -243,6 +243,8 @@ class StackTabber2(Tabber):
|
|||
nocontinue_tokens = {}
|
||||
start_free_tokens = {'string.start': 'string.end'}
|
||||
end_free_tokens = {'string.end': 'string.start'}
|
||||
start_macro_tokens = {}
|
||||
end_macro_tokens = {}
|
||||
def __init__(self, m):
|
||||
self.mode = m
|
||||
self.name = m.name()
|
||||
|
@ -377,17 +379,30 @@ class StackTabber2(Tabber):
|
|||
|
||||
def _handle_other_token(self, y, tokens, start, end, i, t):
|
||||
name, s = t.fqname(), t.string
|
||||
# handle "free" tokens (strings, heredocs, etc)
|
||||
if name in self.start_free_tokens:
|
||||
self._append('free', name, None)
|
||||
return
|
||||
elif name in self.end_free_tokens:
|
||||
self._pop('free')
|
||||
|
||||
# handle macros
|
||||
if name in self.start_macro_tokens:
|
||||
self._append('macro', name, 0)
|
||||
if i == 0:
|
||||
self._save_curr_level()
|
||||
return
|
||||
elif name in self.end_macro_tokens:
|
||||
self._pop('macro')
|
||||
return
|
||||
|
||||
# remove implicit continuation
|
||||
if self.end_at_eof and i + start == end:
|
||||
self._pop_while('continue', 'control')
|
||||
elif self.end_at_tokens.get(name, {}).get(s):
|
||||
self._pop_while('continue', 'control')
|
||||
|
||||
# add implicit continuation
|
||||
top = self._peek()
|
||||
if top and top.name in self.scope_tokens.get(top.type_, {}):
|
||||
if self.continue_tokens:
|
||||
|
@ -397,9 +412,12 @@ class StackTabber2(Tabber):
|
|||
if s not in self.nocontinue_tokens.get(name, {}):
|
||||
self._append_unless('continue', name, self._get_next_level())
|
||||
|
||||
|
||||
if name == 'continuation':
|
||||
# handle explicit continuation
|
||||
self._append_unless('continue', name, self._get_next_level())
|
||||
elif s in self.control_tokens.get(name, {}):
|
||||
# handle control keywords
|
||||
if i == start:
|
||||
self._save_curr_level()
|
||||
self._append_unless('control', name, self._get_next_level())
|
||||
|
|
Loading…
Reference in New Issue