ThirdParty/Pygments/pygments/lexers/ruby.py

changeset 5713
6762afd9f963
parent 4697
c2e9bf425554
child 6651
e8f3b5568b21
equal deleted inserted replaced
5712:f0d08bdeacf4 5713:6762afd9f963
3 pygments.lexers.ruby 3 pygments.lexers.ruby
4 ~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for Ruby and related languages. 6 Lexers for Ruby and related languages.
7 7
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
45 # okay, this is the hardest part of parsing Ruby... 45 # okay, this is the hardest part of parsing Ruby...
46 # match: 1 = <<-?, 2 = quote? 3 = name 4 = quote? 5 = rest of line 46 # match: 1 = <<-?, 2 = quote? 3 = name 4 = quote? 5 = rest of line
47 47
48 start = match.start(1) 48 start = match.start(1)
49 yield start, Operator, match.group(1) # <<-? 49 yield start, Operator, match.group(1) # <<-?
50 yield match.start(2), String.Heredoc, match.group(2) # quote ", ', ` 50 yield match.start(2), String.Heredoc, match.group(2) # quote ", ', `
51 yield match.start(3), Name.Constant, match.group(3) # heredoc name 51 yield match.start(3), String.Delimiter, match.group(3) # heredoc name
52 yield match.start(4), String.Heredoc, match.group(4) # quote again 52 yield match.start(4), String.Heredoc, match.group(4) # quote again
53 53
54 heredocstack = ctx.__dict__.setdefault('heredocstack', []) 54 heredocstack = ctx.__dict__.setdefault('heredocstack', [])
55 outermost = not bool(heredocstack) 55 outermost = not bool(heredocstack)
56 heredocstack.append((match.group(1) == '<<-', match.group(3))) 56 heredocstack.append((match.group(1) == '<<-', match.group(3)))
57 57
72 else: 72 else:
73 check = match.group().rstrip() 73 check = match.group().rstrip()
74 if check == hdname: 74 if check == hdname:
75 for amatch in lines: 75 for amatch in lines:
76 yield amatch.start(), String.Heredoc, amatch.group() 76 yield amatch.start(), String.Heredoc, amatch.group()
77 yield match.start(), Name.Constant, match.group() 77 yield match.start(), String.Delimiter, match.group()
78 ctx.pos = match.end() 78 ctx.pos = match.end()
79 break 79 break
80 else: 80 else:
81 lines.append(match) 81 lines.append(match)
82 else: 82 else:

eric ide

mercurial