From 16cc059837eb83f96f35caf207c1e0778673f63c Mon Sep 17 00:00:00 2001 From: Gaurav Jain Date: Fri, 2 May 2014 00:35:08 -0400 Subject: Allow default state transitions to allow for state strings as well as tuples --- pygments/lexer.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pygments/lexer.py b/pygments/lexer.py index 3ef1c8d1..205b7495 100644 --- a/pygments/lexer.py +++ b/pygments/lexer.py @@ -383,11 +383,14 @@ def using(_other, **kwargs): return callback -class default(str): +class default: """ - Indicates that a state should include rules from another state. + Indicates a state or state action (e.g. #pop) to apply. + For example default('#pop') is equivalent to ('', Token, '#pop') + Note that state tuples may be used as well """ - pass + def __init__(self, state): + self.state = state class RegexLexerMeta(LexerMeta): @@ -460,8 +463,7 @@ class RegexLexerMeta(LexerMeta): # processed already continue if isinstance(tdef, default): - new_state = cls._process_new_state(str(tdef), - unprocessed, processed) + new_state = cls._process_new_state(tdef.state, unprocessed, processed) tokens.append((re.compile('').match, None, new_state)) continue -- cgit v1.2.1