summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaurav Jain <gaurav@gauravjain.org>2014-05-02 00:35:08 -0400
committerGaurav Jain <gaurav@gauravjain.org>2014-05-02 00:35:08 -0400
commit16cc059837eb83f96f35caf207c1e0778673f63c (patch)
treeab6781e3111a1738a06e122d9b7889ad6942c44c
parent93c7b130ad8712bff29c98ce619914cbc803f3f3 (diff)
downloadpygments-16cc059837eb83f96f35caf207c1e0778673f63c.tar.gz
Allow default state transitions to allow for state strings as well as tuples
-rw-r--r--pygments/lexer.py12
1 files 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