fixed nested grammars

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-02-21 04:24:14 +00:00
parent b134fed9e9
commit f6c0e57e11
1 changed files with 6 additions and 2 deletions

8
lex.py
View File

@ -128,8 +128,9 @@ class NocasePatternRule(PatternRule):
reflags = re.IGNORECASE
class FakeWindow(object):
def __init__(self, app):
def __init__(self, app, b):
self.application = app
self.buffer = b
class OverrideError(Exception):
pass
class OverridePatternRule(PatternRule):
@ -139,13 +140,16 @@ class OverridePatternRule(PatternRule):
if lexer.action == 'lex':
a = lexer.mode.window.application
try:
b = lexer.mode.window.buffer
modecls = a.modes[d['mode']]
mode = modecls(FakeWindow(lexer.mode.window.application))
mode = modecls(FakeWindow(lexer.mode.window.application, b))
if hasattr(mode, 'grammar') and hasattr(mode, 'colors'):
lexer.mode.gstack['%s' % d['token']] = mode
else:
raise OverrideError("argh: %r" % mode)
except (KeyError, AttributeError, OverrideError):
# uncomment raise to fix dynamic highlighting
#raise
pass
yield self.make_token(lexer, m.group(0), self.name, parent, d)
raise StopIteration