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