55 outermost = not bool(heredocstack) |
55 outermost = not bool(heredocstack) |
56 heredocstack.append((match.group(1) in ('<<-', '<<~'), match.group(3))) |
56 heredocstack.append((match.group(1) in ('<<-', '<<~'), match.group(3))) |
57 |
57 |
58 ctx.pos = match.start(5) |
58 ctx.pos = match.start(5) |
59 ctx.end = match.end(5) |
59 ctx.end = match.end(5) |
60 # this may find other heredocs |
60 # this may find other heredocs, so limit the recursion depth |
61 yield from self.get_tokens_unprocessed(context=ctx) |
61 if len(heredocstack) < 100: |
|
62 yield from self.get_tokens_unprocessed(context=ctx) |
|
63 else: |
|
64 yield ctx.pos, String.Heredoc, match.group(5) |
62 ctx.pos = match.end() |
65 ctx.pos = match.end() |
63 |
66 |
64 if outermost: |
67 if outermost: |
65 # this is the outer heredoc again, now we can process them all |
68 # this is the outer heredoc again, now we can process them all |
66 for tolerant, hdname in heredocstack: |
69 for tolerant, hdname in heredocstack: |
105 states = {} |
108 states = {} |
106 states['strings'] = [ |
109 states['strings'] = [ |
107 # easy ones |
110 # easy ones |
108 (r'\:@{0,2}[a-zA-Z_]\w*[!?]?', String.Symbol), |
111 (r'\:@{0,2}[a-zA-Z_]\w*[!?]?', String.Symbol), |
109 (words(RUBY_OPERATORS, prefix=r'\:@{0,2}'), String.Symbol), |
112 (words(RUBY_OPERATORS, prefix=r'\:@{0,2}'), String.Symbol), |
110 (r":'(\\\\|\\'|[^'])*'", String.Symbol), |
113 (r":'(\\\\|\\[^\\]|[^'\\])*'", String.Symbol), |
111 (r':"', String.Symbol, 'simple-sym'), |
114 (r':"', String.Symbol, 'simple-sym'), |
112 (r'([a-zA-Z_]\w*)(:)(?!:)', |
115 (r'([a-zA-Z_]\w*)(:)(?!:)', |
113 bygroups(String.Symbol, Punctuation)), # Since Ruby 1.9 |
116 bygroups(String.Symbol, Punctuation)), # Since Ruby 1.9 |
114 (r'"', String.Double, 'simple-string-double'), |
117 (r'"', String.Double, 'simple-string-double'), |
115 (r"'", String.Single, 'simple-string-single'), |
118 (r"'", String.Single, 'simple-string-single'), |
447 mimetypes = ['text/x-fancysrc'] |
450 mimetypes = ['text/x-fancysrc'] |
448 |
451 |
449 tokens = { |
452 tokens = { |
450 # copied from PerlLexer: |
453 # copied from PerlLexer: |
451 'balanced-regex': [ |
454 'balanced-regex': [ |
452 (r'/(\\\\|\\/|[^/])*/[egimosx]*', String.Regex, '#pop'), |
455 (r'/(\\\\|\\[^\\]|[^/\\])*/[egimosx]*', String.Regex, '#pop'), |
453 (r'!(\\\\|\\!|[^!])*![egimosx]*', String.Regex, '#pop'), |
456 (r'!(\\\\|\\[^\\]|[^!\\])*![egimosx]*', String.Regex, '#pop'), |
454 (r'\\(\\\\|[^\\])*\\[egimosx]*', String.Regex, '#pop'), |
457 (r'\\(\\\\|[^\\])*\\[egimosx]*', String.Regex, '#pop'), |
455 (r'\{(\\\\|\\\}|[^}])*\}[egimosx]*', String.Regex, '#pop'), |
458 (r'\{(\\\\|\\[^\\]|[^}\\])*\}[egimosx]*', String.Regex, '#pop'), |
456 (r'<(\\\\|\\>|[^>])*>[egimosx]*', String.Regex, '#pop'), |
459 (r'<(\\\\|\\[^\\]|[^>\\])*>[egimosx]*', String.Regex, '#pop'), |
457 (r'\[(\\\\|\\\]|[^\]])*\][egimosx]*', String.Regex, '#pop'), |
460 (r'\[(\\\\|\\[^\\]|[^\]\\])*\][egimosx]*', String.Regex, '#pop'), |
458 (r'\((\\\\|\\\)|[^)])*\)[egimosx]*', String.Regex, '#pop'), |
461 (r'\((\\\\|\\[^\\]|[^)\\])*\)[egimosx]*', String.Regex, '#pop'), |
459 (r'@(\\\\|\\@|[^@])*@[egimosx]*', String.Regex, '#pop'), |
462 (r'@(\\\\|\\[^\\]|[^@\\])*@[egimosx]*', String.Regex, '#pop'), |
460 (r'%(\\\\|\\%|[^%])*%[egimosx]*', String.Regex, '#pop'), |
463 (r'%(\\\\|\\[^\\]|[^%\\])*%[egimosx]*', String.Regex, '#pop'), |
461 (r'\$(\\\\|\\\$|[^$])*\$[egimosx]*', String.Regex, '#pop'), |
464 (r'\$(\\\\|\\[^\\]|[^$\\])*\$[egimosx]*', String.Regex, '#pop'), |
462 ], |
465 ], |
463 'root': [ |
466 'root': [ |
464 (r'\s+', Text), |
467 (r'\s+', Text), |
465 |
468 |
466 # balanced delimiters (copied from PerlLexer): |
469 # balanced delimiters (copied from PerlLexer): |
467 (r's\{(\\\\|\\\}|[^}])*\}\s*', String.Regex, 'balanced-regex'), |
470 (r's\{(\\\\|\\[^\\]|[^}\\])*\}\s*', String.Regex, 'balanced-regex'), |
468 (r's<(\\\\|\\>|[^>])*>\s*', String.Regex, 'balanced-regex'), |
471 (r's<(\\\\|\\[^\\]|[^>\\])*>\s*', String.Regex, 'balanced-regex'), |
469 (r's\[(\\\\|\\\]|[^\]])*\]\s*', String.Regex, 'balanced-regex'), |
472 (r's\[(\\\\|\\[^\\]|[^\]\\])*\]\s*', String.Regex, 'balanced-regex'), |
470 (r's\((\\\\|\\\)|[^)])*\)\s*', String.Regex, 'balanced-regex'), |
473 (r's\((\\\\|\\[^\\]|[^)\\])*\)\s*', String.Regex, 'balanced-regex'), |
471 (r'm?/(\\\\|\\/|[^/\n])*/[gcimosx]*', String.Regex), |
474 (r'm?/(\\\\|\\[^\\]|[^///\n])*/[gcimosx]*', String.Regex), |
472 (r'm(?=[/!\\{<\[(@%$])', String.Regex, 'balanced-regex'), |
475 (r'm(?=[/!\\{<\[(@%$])', String.Regex, 'balanced-regex'), |
473 |
476 |
474 # Comments |
477 # Comments |
475 (r'#(.*?)\n', Comment.Single), |
478 (r'#(.*?)\n', Comment.Single), |
476 # Symbols |
479 # Symbols |
477 (r'\'([^\'\s\[\](){}]+|\[\])', String.Symbol), |
480 (r'\'([^\'\s\[\](){}]+|\[\])', String.Symbol), |
478 # Multi-line DoubleQuotedString |
481 # Multi-line DoubleQuotedString |
479 (r'"""(\\\\|\\"|[^"])*"""', String), |
482 (r'"""(\\\\|\\[^\\]|[^\\])*?"""', String), |
480 # DoubleQuotedString |
483 # DoubleQuotedString |
481 (r'"(\\\\|\\"|[^"])*"', String), |
484 (r'"(\\\\|\\[^\\]|[^"\\])*"', String), |
482 # keywords |
485 # keywords |
483 (r'(def|class|try|catch|finally|retry|return|return_local|match|' |
486 (r'(def|class|try|catch|finally|retry|return|return_local|match|' |
484 r'case|->|=>)\b', Keyword), |
487 r'case|->|=>)\b', Keyword), |
485 # constants |
488 # constants |
486 (r'(self|super|nil|false|true)\b', Name.Constant), |
489 (r'(self|super|nil|false|true)\b', Name.Constant), |