diff --git a/application.py b/application.py index 7c3c93e..71d38d1 100755 --- a/application.py +++ b/application.py @@ -748,8 +748,10 @@ class Application(object): # for debugging things like lexing/relexing/etc. if token._debug: attr = color.build('blue', 'green') - else: + elif token.color: attr = color.build(*token.color) + else: + attr = color.build("default", "default") k = slot.y_offset + count self.win.addstr(k, x_offset + lm, s[:swidth - x_offset], attr) diff --git a/lex.py b/lex.py index 8363e03..0b6fe24 100755 --- a/lex.py +++ b/lex.py @@ -221,7 +221,14 @@ class RegionRule(Rule): # now we will loop over the different pairs of grammars/stop-patterns in # this region, and return the resulting token; we start at i - for tok in self._lex_loop(lexer, toresume, toresume[0].matchd, i): + matchd = toresume[0].matchd + if not matchd and toresume[0].parent: + p = toresume[0].parent + while not p.matchd and p.parent: + p = p.parent + matchd = p.matchd + #for tok in self._lex_loop(lexer, toresume, toresume[0].matchd, i): + for tok in self._lex_loop(lexer, toresume, matchd, i): yield tok raise StopIteration def _lex_loop(self, lexer, toresume, matchd, i): @@ -249,7 +256,10 @@ class RegionRule(Rule): lexer.mstack.append(mode) if self.pairs[i][1]: - stopre = re.compile(self.pairs[i][1] % matchd, self.reflags) + try: + stopre = re.compile(self.pairs[i][1] % matchd, self.reflags) + except: + raise Exception, "%r\n%r\n%r" % (self.pairs[i][1], matchd, self.reflags) else: stopre = None if i == len(self.pairs) - 1: diff --git a/mode/perl.py b/mode/perl.py index df980ed..d6f5409 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -45,7 +45,7 @@ class QuotedGrammar4(Grammar): class PerlGrammar(Grammar): rules = [ - RegionRule(r'heredoc', r"<<(?P[a-zA-Z0-9_]+) *;", StringGrammar, r'^%(heredoc)s$'), + RegionRule(r'heredoc', r"<<(?P[a-zA-Z_][a-zA-Z0-9_]+)", None, ';\n', StringGrammar, r'^%(heredoc)s$'), RegionRule(r'heredoc', r'<< *"(?P[a-zA-Z0-9_]+)" *;', StringGrammar, r'^%(heredoc)s$'), RegionRule(r'heredoc', r"<< *'(?P[a-zA-Z0-9_]+)' *;", Grammar, r'^%(heredoc)s$'), RegionRule(r'evaldoc', r"<< *`(?P[a-zA-Z0-9_]+)` *;", StringGrammar, r'^%(heredoc)s$'), diff --git a/mode/sh.py b/mode/sh.py index 74718ae..f55c910 100644 --- a/mode/sh.py +++ b/mode/sh.py @@ -47,7 +47,7 @@ class TestGrammar(Grammar): class ShGrammar(Grammar): rules = [ - RegionRule(r'heredoc', r"<<(?P[a-zA-Z0-9_]+)", StringGrammar, r'^%(heredoc)s$'), + RegionRule(r'heredoc', r"<<(?P[a-zA-Z][a-zA-Z0-9_]*)", None, "\n", StringGrammar, r'^%(heredoc)s$'), PatternRule(r'sh_function', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\(\))'), PatternRule(r'sh_reserved', r"(?:done|do|elif|else|esac|fi|for|function|if|in|select|then|until|while|time)(?![a-zA-Z0-9_=/])"), RegionRule(r'case', r'case', Grammar, 'in', CaseGrammar, r'esac'),