summaryrefslogtreecommitdiff
path: root/pygments/lexer.py
diff options
context:
space:
mode:
authorAnteru <bitbucket@ca.sh13.net>2019-05-21 16:32:04 +0000
committerAnteru <bitbucket@ca.sh13.net>2019-05-21 16:32:04 +0000
commit9c84bc6450663888e243268621dcf71eab18ed11 (patch)
tree15231faf42954c633413b5c06369da6b05949ed7 /pygments/lexer.py
parentc0db1e260ea7e399a1f34bc9966914298e1b6b17 (diff)
parent8202e648945351366bd0c465d72953fae40f4783 (diff)
downloadpygments-9c84bc6450663888e243268621dcf71eab18ed11.tar.gz
Merged in lucatorella/pygments-main (pull request #813)
Add support for @import keyword in Objective-C
Diffstat (limited to 'pygments/lexer.py')
-rw-r--r--pygments/lexer.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/pygments/lexer.py b/pygments/lexer.py
index 90905ba5..62d66318 100644
--- a/pygments/lexer.py
+++ b/pygments/lexer.py
@@ -639,14 +639,20 @@ class RegexLexer(Lexer):
if isinstance(new_state, tuple):
for state in new_state:
if state == '#pop':
- statestack.pop()
+ if len(statestack) > 1:
+ statestack.pop()
elif state == '#push':
statestack.append(statestack[-1])
else:
statestack.append(state)
elif isinstance(new_state, int):
- # pop
- del statestack[new_state:]
+ # pop, but keep at least one state on the stack
+ # (random code leading to unexpected pops should
+ # not allow exceptions)
+ if abs(new_state) >= len(statestack):
+ del statestack[1:]
+ else:
+ del statestack[new_state:]
elif new_state == '#push':
statestack.append(statestack[-1])
else:
@@ -724,14 +730,18 @@ class ExtendedRegexLexer(RegexLexer):
if isinstance(new_state, tuple):
for state in new_state:
if state == '#pop':
- ctx.stack.pop()
+ if len(ctx.stack) > 1:
+ ctx.stack.pop()
elif state == '#push':
ctx.stack.append(ctx.stack[-1])
else:
ctx.stack.append(state)
elif isinstance(new_state, int):
- # pop
- del ctx.stack[new_state:]
+ # see RegexLexer for why this check is made
+ if abs(new_state) >= len(ctx.stack):
+ del ctx.state[1:]
+ else:
+ del ctx.stack[new_state:]
elif new_state == '#push':
ctx.stack.append(ctx.stack[-1])
else: