@@ -164,15 +164,19 @@ def scan_tokens encoder, options
164164 end
165165
166166 elsif match = scan ( / ' (?:(?>[^'\\ ]*) ')? | " (?:(?>[^"\\ \# ]*) ")? /mx )
167- encoder . begin_group :string
168167 if match . size == 1
168+ kind = check ( self . class ::StringState . simple_key_pattern ( match ) ) ? :key : :string
169+ encoder . begin_group kind
169170 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
171172 else
173+ kind = value_expected == true && scan ( /:/ ) ? :key : :string
174+ encoder . begin_group kind
172175 encoder . text_token match [ 0 , 1 ] , :delimiter
173176 encoder . text_token match [ 1 ..-2 ] , :content if match . size > 2
174177 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
176180 value_expected = false
177181 end
178182
@@ -191,11 +195,14 @@ def scan_tokens encoder, options
191195 encoder . text_token match , :error
192196 method_call_expected = false
193197 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
195202 end
196203 value_expected = false
197204
198- elsif match = scan ( / [-+!~^\/ ]=? | [:;] | [*|&]{1,2}=? | >>? /x )
205+ elsif match = scan ( / [-+!~^\/ ]=? | [:;] | & \. | [*|&]{1,2}=? | >>? /x )
199206 value_expected = true
200207 encoder . text_token match , :operator
201208
@@ -208,7 +215,7 @@ def scan_tokens encoder, options
208215 encoder . end_group kind
209216 heredocs ||= [ ] # create heredocs if empty
210217 heredocs << self . class ::StringState . new ( kind , quote != "'" , delim ,
211- self [ 1 ] == '-' ? :indented : :linestart )
218+ self [ 1 ] ? :indented : :linestart )
212219 value_expected = false
213220
214221 elsif value_expected && match = scan ( /#{ patterns ::FANCY_STRING_START } /o )
0 commit comments