Skip to content

Commit 39cbd37

Browse files
committed
add support for Ruby 2.2 quoted hash keys
KNOWN ISSUE: string interpolation will not work!
1 parent 080f8a8 commit 39cbd37

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/coderay/scanners/ruby.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,18 @@ def scan_tokens encoder, options
164164
end
165165

166166
elsif match = scan(/ ' (?:(?>[^'\\]*) ')? | " (?:(?>[^"\\\#]*) ")? /mx)
167-
encoder.begin_group :string
168167
if match.size == 1
168+
encoder.begin_group :string
169169
encoder.text_token match, :delimiter
170170
state = self.class::StringState.new :string, match == '"', match # important for streaming
171171
else
172+
kind = value_expected == true && scan(/:/) ? :key : :string
173+
encoder.begin_group kind
172174
encoder.text_token match[0,1], :delimiter
173175
encoder.text_token match[1..-2], :content if match.size > 2
174176
encoder.text_token match[-1,1], :delimiter
175-
encoder.end_group :string
177+
encoder.end_group kind
178+
encoder.text_token ':', :operator if kind == :key
176179
value_expected = false
177180
end
178181

0 commit comments

Comments
 (0)