summaryrefslogtreecommitdiff
path: root/pygments/lexers/agile.py
diff options
context:
space:
mode:
authorRob Hoelz <rob@hoelz.ro>2012-12-23 01:29:20 +0100
committerRob Hoelz <rob@hoelz.ro>2012-12-23 01:29:20 +0100
commitfd4be7440ff3e1b6240629c34bd69bf7d5ee442b (patch)
treeb8f204b5592d49bcc177d18b2664cb3e686e77dc /pygments/lexers/agile.py
parent295b041de3efe7296b7f5a6dbfbd63ce380f24ef (diff)
downloadpygments-fd4be7440ff3e1b6240629c34bd69bf7d5ee442b.tar.gz
Support nested of bracketing characters
Diffstat (limited to 'pygments/lexers/agile.py')
-rw-r--r--pygments/lexers/agile.py37
1 files changed, 25 insertions, 12 deletions
diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py
index 895b8b40..6e780ba9 100644
--- a/pygments/lexers/agile.py
+++ b/pygments/lexers/agile.py
@@ -2025,20 +2025,33 @@ class Perl6Lexer(ExtendedRegexLexer):
def brackets_callback(token_class):
def callback(lexer, match, context):
- capture = match.group(1)
- n_chars = len(capture)
+ opening_chars = match.group(1)
+ n_chars = len(opening_chars)
+ nesting_level = 1
# XXX this could be more efficient, but is fine for now
- index = Perl6Lexer.PERL6_OPEN_BRACKET_CHARS.index(capture[0])
- closing_char = Perl6Lexer.PERL6_CLOSE_BRACKET_CHARS[index]
- text = context.text
- end_pos = text.find(closing_char * n_chars, match.start() + n_chars)
-
- if end_pos == -1:
- end_pos = len(text)
-
- yield match.start(), token_class, text[match.start() : end_pos + n_chars]
- context.pos = end_pos + n_chars
+ index = Perl6Lexer.PERL6_OPEN_BRACKET_CHARS.index(opening_chars[0])
+ closing_chars = Perl6Lexer.PERL6_CLOSE_BRACKET_CHARS[index] * n_chars
+ text = context.text
+
+ search_pos = match.start(1)
+
+ while nesting_level > 0:
+ next_open_pos = text.find(opening_chars, search_pos + n_chars)
+ next_close_pos = text.find(closing_chars, search_pos + n_chars)
+
+ if next_close_pos == -1:
+ next_close_pos = len(text)
+ nesting_level = 0
+ elif next_open_pos != -1 and next_open_pos < next_close_pos:
+ nesting_level += 1
+ search_pos = next_open_pos
+ else: # next_close_pos < next_open_pos
+ nesting_level -= 1
+ search_pos = next_close_pos
+
+ yield match.start(), token_class, text[match.start() : next_close_pos + n_chars]
+ context.pos = next_close_pos + n_chars
return callback