@@ -164,15 +164,19 @@ def scan_tokens encoder, options
164
164
end
165
165
166
166
elsif match = scan ( / ' (?:(?>[^'\\ ]*) ')? | " (?:(?>[^"\\ \# ]*) ")? /mx )
167
- encoder . begin_group :string
168
167
if match . size == 1
168
+ kind = check ( self . class ::StringState . simple_key_pattern ( match ) ) ? :key : :string
169
+ encoder . begin_group kind
169
170
encoder . text_token match , :delimiter
170
- state = self . class ::StringState . new :string , match == '"' , match # important for streaming
171
+ state = self . class ::StringState . new kind , match == '"' , match # important for streaming
171
172
else
173
+ kind = value_expected == true && scan ( /:/ ) ? :key : :string
174
+ encoder . begin_group kind
172
175
encoder . text_token match [ 0 , 1 ] , :delimiter
173
176
encoder . text_token match [ 1 ..-2 ] , :content if match . size > 2
174
177
encoder . text_token match [ -1 , 1 ] , :delimiter
175
- encoder . end_group :string
178
+ encoder . end_group kind
179
+ encoder . text_token ':' , :operator if kind == :key
176
180
value_expected = false
177
181
end
178
182
@@ -191,11 +195,14 @@ def scan_tokens encoder, options
191
195
encoder . text_token match , :error
192
196
method_call_expected = false
193
197
else
194
- encoder . text_token match , self [ 1 ] ? :float : :integer # TODO: send :hex/:octal/:binary
198
+ kind = self [ 1 ] ? :float : :integer # TODO: send :hex/:octal/:binary
199
+ match << 'r' if match !~ /e/i && scan ( /r/ )
200
+ match << 'i' if scan ( /i/ )
201
+ encoder . text_token match , kind
195
202
end
196
203
value_expected = false
197
204
198
- elsif match = scan ( / [-+!~^\/ ]=? | [:;] | [*|&]{1,2}=? | >>? /x )
205
+ elsif match = scan ( / [-+!~^\/ ]=? | [:;] | & \. | [*|&]{1,2}=? | >>? /x )
199
206
value_expected = true
200
207
encoder . text_token match , :operator
201
208
@@ -208,7 +215,7 @@ def scan_tokens encoder, options
208
215
encoder . end_group kind
209
216
heredocs ||= [ ] # create heredocs if empty
210
217
heredocs << self . class ::StringState . new ( kind , quote != "'" , delim ,
211
- self [ 1 ] == '-' ? :indented : :linestart )
218
+ self [ 1 ] ? :indented : :linestart )
212
219
value_expected = false
213
220
214
221
elsif value_expected && match = scan ( /#{ patterns ::FANCY_STRING_START } /o )
0 commit comments