@@ -64,38 +64,32 @@ def get_squashed_tk
6464 end
6565 return nil if tk . nil?
6666 case tk [ :kind ]
67- when :on_symbeg then
67+ when :on_symbeg
6868 tk = get_symbol_tk ( tk )
69- when :on_tstring_beg then
69+ when :on_tstring_beg
7070 tk = get_string_tk ( tk )
71- when :on_backtick then
71+ when :on_backtick
7272 if ( tk [ :state ] & ( EXPR_FNAME | EXPR_ENDFN ) ) != 0
7373 tk [ :kind ] = :on_ident
7474 tk [ :state ] = EXPR_ARG
7575 else
7676 tk = get_string_tk ( tk )
7777 end
78- when :on_regexp_beg then
78+ when :on_regexp_beg
7979 tk = get_regexp_tk ( tk )
80- when :on_embdoc_beg then
80+ when :on_embdoc_beg
8181 tk = get_embdoc_tk ( tk )
82- when :on_heredoc_beg then
82+ when :on_heredoc_beg
8383 @heredoc_queue << retrieve_heredoc_info ( tk )
84- when :on_nl , :on_ignored_nl , :on_comment , :on_heredoc_end then
84+ when :on_nl , :on_ignored_nl , :on_comment , :on_heredoc_end
8585 if !@heredoc_queue . empty?
8686 get_heredoc_tk ( *@heredoc_queue . shift )
8787 elsif tk [ :text ] . nil? # :on_ignored_nl sometimes gives nil
8888 tk [ :text ] = ''
8989 end
90- when :on_words_beg then
90+ when :on_words_beg , :on_qwords_beg , :on_symbols_beg , :on_qsymbols_beg
9191 tk = get_words_tk ( tk )
92- when :on_qwords_beg then
93- tk = get_words_tk ( tk )
94- when :on_symbols_beg then
95- tk = get_words_tk ( tk )
96- when :on_qsymbols_beg then
97- tk = get_words_tk ( tk )
98- when :on_op then
92+ when :on_op
9993 if '&.' == tk [ :text ]
10094 tk [ :kind ] = :on_period
10195 else
@@ -116,31 +110,10 @@ def get_symbol_tk(tk)
116110 symbol_tk [ :state ] = tk1 [ :state ]
117111 else
118112 case ( tk1 = get_squashed_tk ) [ :kind ]
119- when :on_ident
120- symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
121- symbol_tk [ :state ] = tk1 [ :state ]
122113 when :on_tstring_content
123114 symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
124115 symbol_tk [ :state ] = get_squashed_tk [ :state ] # skip :on_tstring_end
125- when :on_tstring_end
126- symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
127- symbol_tk [ :state ] = tk1 [ :state ]
128- when :on_op
129- symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
130- symbol_tk [ :state ] = tk1 [ :state ]
131- when :on_ivar
132- symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
133- symbol_tk [ :state ] = tk1 [ :state ]
134- when :on_cvar
135- symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
136- symbol_tk [ :state ] = tk1 [ :state ]
137- when :on_gvar
138- symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
139- symbol_tk [ :state ] = tk1 [ :state ]
140- when :on_const
141- symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
142- symbol_tk [ :state ] = tk1 [ :state ]
143- when :on_kw
116+ when :on_ident , :on_tstring_end , :on_op , :on_ivar , :on_cvar , :on_const , :on_kw
144117 symbol_tk [ :text ] = ":#{ tk1 [ :text ] } "
145118 symbol_tk [ :state ] = tk1 [ :state ]
146119 else
@@ -173,7 +146,7 @@ def get_string_tk(tk)
173146 break
174147 else
175148 string = string + inner_str_tk [ :text ]
176- if :on_embexpr_beg == inner_str_tk [ :kind ] then
149+ if :on_embexpr_beg == inner_str_tk [ :kind ]
177150 kind = :on_dstring if :on_tstring == kind
178151 end
179152 end
@@ -209,15 +182,15 @@ def get_embdoc_tk(tk)
209182 end
210183
211184 def get_heredoc_tk ( heredoc_name , indent )
212- string = ''
185+ string = + ''
213186 start_tk = nil
214187 prev_tk = nil
215188 until heredoc_end? ( heredoc_name , indent , tk = @tokens . shift ) do
216189 start_tk = tk unless start_tk
217190 if ( prev_tk . nil? or "\n " == prev_tk [ :text ] [ -1 ] ) and 0 != tk [ :char_no ]
218- string = string + ( ' ' * tk [ :char_no ] )
191+ string << ( ' ' * tk [ :char_no ] )
219192 end
220- string = string + tk [ :text ]
193+ string << tk [ :text ]
221194 prev_tk = tk
222195 end
223196 start_tk = tk unless start_tk
@@ -235,7 +208,7 @@ def retrieve_heredoc_info(tk)
235208
236209 def heredoc_end? ( name , indent , tk )
237210 result = false
238- if :on_heredoc_end == tk [ :kind ] then
211+ if :on_heredoc_end == tk [ :kind ]
239212 tk_name = tk [ :text ] . chomp
240213 tk_name . lstrip! if indent
241214 if name == tk_name
@@ -246,7 +219,7 @@ def heredoc_end?(name, indent, tk)
246219 end
247220
248221 def get_words_tk ( tk )
249- string = ''
222+ string = + ''
250223 start_token = tk [ :text ]
251224 start_quote = tk [ :text ] . rstrip [ -1 ]
252225 line_no = tk [ :line_no ]
@@ -266,35 +239,31 @@ def get_words_tk(tk)
266239 if tk . nil?
267240 end_token = end_quote
268241 break
269- elsif :on_tstring_content == tk [ :kind ] then
270- string += tk [ :text ]
271- elsif :on_words_sep == tk [ :kind ] or :on_tstring_end == tk [ :kind ] then
272- if end_quote == tk [ :text ] . strip then
242+ elsif :on_tstring_content == tk [ :kind ]
243+ string << tk [ :text ]
244+ elsif :on_words_sep == tk [ :kind ] or :on_tstring_end == tk [ :kind ]
245+ if end_quote == tk [ :text ] . strip
273246 end_token = tk [ :text ]
274247 break
275248 else
276- string += tk [ :text ]
249+ string << tk [ :text ]
277250 end
278251 else
279- string += tk [ :text ]
252+ string << tk [ :text ]
280253 end
281254 end
282255 text = "#{ start_token } #{ string } #{ end_token } "
283256 Token . new ( line_no , char_no , :on_dstring , text , state )
284257 end
285258
286259 def get_op_tk ( tk )
287- if REDEFINABLE_OPERATORS . include? ( tk [ :text ] ) and tk [ :state ] == EXPR_ARG then
260+ if REDEFINABLE_OPERATORS . include? ( tk [ :text ] ) and tk [ :state ] == EXPR_ARG
288261 tk [ :state ] = EXPR_ARG
289262 tk [ :kind ] = :on_ident
290- elsif tk [ :text ] =~ /^[-+]$/ then
263+ elsif tk [ :text ] =~ /^[-+]$/
291264 tk_ahead = get_squashed_tk
292265 case tk_ahead [ :kind ]
293- when :on_int , :on_float , :on_rational , :on_imaginary then
294- tk [ :text ] += tk_ahead [ :text ]
295- tk [ :kind ] = tk_ahead [ :kind ]
296- tk [ :state ] = tk_ahead [ :state ]
297- when :on_heredoc_beg , :on_tstring , :on_dstring # frozen/non-frozen string literal
266+ when :on_int , :on_float , :on_rational , :on_imaginary , :on_heredoc_beg , :on_tstring , :on_dstring
298267 tk [ :text ] += tk_ahead [ :text ]
299268 tk [ :kind ] = tk_ahead [ :kind ]
300269 tk [ :state ] = tk_ahead [ :state ]
0 commit comments