Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: ruby-lex.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb/ruby-lex.rb - ruby lexcal analyzer
[2] Fix | Delete
# $Release Version: 0.9.6$
[3] Fix | Delete
# $Revision$
[4] Fix | Delete
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
[11] Fix | Delete
require "ripper"
[12] Fix | Delete
require "jruby" if RUBY_ENGINE == "jruby"
[13] Fix | Delete
[14] Fix | Delete
# :stopdoc:
[15] Fix | Delete
class RubyLex
[16] Fix | Delete
[17] Fix | Delete
class TerminateLineInput < StandardError
[18] Fix | Delete
def initialize
[19] Fix | Delete
super("Terminate Line Input")
[20] Fix | Delete
end
[21] Fix | Delete
end
[22] Fix | Delete
[23] Fix | Delete
def initialize
[24] Fix | Delete
@exp_line_no = @line_no = 1
[25] Fix | Delete
@indent = 0
[26] Fix | Delete
@continue = false
[27] Fix | Delete
@line = ""
[28] Fix | Delete
@prompt = nil
[29] Fix | Delete
end
[30] Fix | Delete
[31] Fix | Delete
def self.compile_with_errors_suppressed(code)
[32] Fix | Delete
line_no = 1
[33] Fix | Delete
begin
[34] Fix | Delete
result = yield code, line_no
[35] Fix | Delete
rescue ArgumentError
[36] Fix | Delete
code = ";\n#{code}"
[37] Fix | Delete
line_no = 0
[38] Fix | Delete
result = yield code, line_no
[39] Fix | Delete
end
[40] Fix | Delete
result
[41] Fix | Delete
end
[42] Fix | Delete
[43] Fix | Delete
# io functions
[44] Fix | Delete
def set_input(io, p = nil, &block)
[45] Fix | Delete
@io = io
[46] Fix | Delete
if @io.respond_to?(:check_termination)
[47] Fix | Delete
@io.check_termination do |code|
[48] Fix | Delete
code.gsub!(/\s*\z/, '').concat("\n")
[49] Fix | Delete
ltype, indent, continue, code_block_open = check_state(code)
[50] Fix | Delete
if ltype or indent > 0 or continue or code_block_open
[51] Fix | Delete
false
[52] Fix | Delete
else
[53] Fix | Delete
true
[54] Fix | Delete
end
[55] Fix | Delete
end
[56] Fix | Delete
end
[57] Fix | Delete
if @io.respond_to?(:dynamic_prompt)
[58] Fix | Delete
@io.dynamic_prompt do |lines|
[59] Fix | Delete
lines << '' if lines.empty?
[60] Fix | Delete
result = []
[61] Fix | Delete
lines.each_index { |i|
[62] Fix | Delete
c = lines[0..i].map{ |l| l + "\n" }.join
[63] Fix | Delete
ltype, indent, continue, code_block_open = check_state(c)
[64] Fix | Delete
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + i)
[65] Fix | Delete
}
[66] Fix | Delete
result
[67] Fix | Delete
end
[68] Fix | Delete
end
[69] Fix | Delete
if p.respond_to?(:call)
[70] Fix | Delete
@input = p
[71] Fix | Delete
elsif block_given?
[72] Fix | Delete
@input = block
[73] Fix | Delete
else
[74] Fix | Delete
@input = Proc.new{@io.gets}
[75] Fix | Delete
end
[76] Fix | Delete
end
[77] Fix | Delete
[78] Fix | Delete
def set_prompt(p = nil, &block)
[79] Fix | Delete
p = block if block_given?
[80] Fix | Delete
if p.respond_to?(:call)
[81] Fix | Delete
@prompt = p
[82] Fix | Delete
else
[83] Fix | Delete
@prompt = Proc.new{print p}
[84] Fix | Delete
end
[85] Fix | Delete
end
[86] Fix | Delete
[87] Fix | Delete
def ripper_lex_without_warning(code)
[88] Fix | Delete
verbose, $VERBOSE = $VERBOSE, nil
[89] Fix | Delete
tokens = nil
[90] Fix | Delete
self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
[91] Fix | Delete
tokens = Ripper.lex(inner_code, '-', line_no)
[92] Fix | Delete
end
[93] Fix | Delete
$VERBOSE = verbose
[94] Fix | Delete
tokens
[95] Fix | Delete
end
[96] Fix | Delete
[97] Fix | Delete
def set_auto_indent(context)
[98] Fix | Delete
if @io.respond_to?(:auto_indent) and context.auto_indent_mode
[99] Fix | Delete
@io.auto_indent do |lines, line_index, byte_pointer, is_newline|
[100] Fix | Delete
if is_newline
[101] Fix | Delete
md = lines[line_index - 1].match(/(\A +)/)
[102] Fix | Delete
prev_spaces = md.nil? ? 0 : md[1].count(' ')
[103] Fix | Delete
@tokens = ripper_lex_without_warning(lines[0..line_index].join("\n"))
[104] Fix | Delete
depth_difference = check_newline_depth_difference
[105] Fix | Delete
prev_spaces + depth_difference * 2
[106] Fix | Delete
else
[107] Fix | Delete
code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
[108] Fix | Delete
last_line = lines[line_index]&.byteslice(0, byte_pointer)
[109] Fix | Delete
code += last_line if last_line
[110] Fix | Delete
@tokens = ripper_lex_without_warning(code)
[111] Fix | Delete
corresponding_token_depth = check_corresponding_token_depth
[112] Fix | Delete
if corresponding_token_depth
[113] Fix | Delete
corresponding_token_depth
[114] Fix | Delete
else
[115] Fix | Delete
nil
[116] Fix | Delete
end
[117] Fix | Delete
end
[118] Fix | Delete
end
[119] Fix | Delete
end
[120] Fix | Delete
end
[121] Fix | Delete
[122] Fix | Delete
def check_state(code)
[123] Fix | Delete
@tokens = ripper_lex_without_warning(code)
[124] Fix | Delete
ltype = process_literal_type
[125] Fix | Delete
indent = process_nesting_level
[126] Fix | Delete
continue = process_continue
[127] Fix | Delete
code_block_open = check_code_block(code)
[128] Fix | Delete
[ltype, indent, continue, code_block_open]
[129] Fix | Delete
end
[130] Fix | Delete
[131] Fix | Delete
def prompt
[132] Fix | Delete
if @prompt
[133] Fix | Delete
@prompt.call(@ltype, @indent, @continue, @line_no)
[134] Fix | Delete
end
[135] Fix | Delete
end
[136] Fix | Delete
[137] Fix | Delete
def initialize_input
[138] Fix | Delete
@ltype = nil
[139] Fix | Delete
@indent = 0
[140] Fix | Delete
@continue = false
[141] Fix | Delete
@line = ""
[142] Fix | Delete
@exp_line_no = @line_no
[143] Fix | Delete
@code_block_open = false
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
def each_top_level_statement
[147] Fix | Delete
initialize_input
[148] Fix | Delete
catch(:TERM_INPUT) do
[149] Fix | Delete
loop do
[150] Fix | Delete
begin
[151] Fix | Delete
prompt
[152] Fix | Delete
unless l = lex
[153] Fix | Delete
throw :TERM_INPUT if @line == ''
[154] Fix | Delete
else
[155] Fix | Delete
@line_no += l.count("\n")
[156] Fix | Delete
next if l == "\n"
[157] Fix | Delete
@line.concat l
[158] Fix | Delete
if @code_block_open or @ltype or @continue or @indent > 0
[159] Fix | Delete
next
[160] Fix | Delete
end
[161] Fix | Delete
end
[162] Fix | Delete
if @line != "\n"
[163] Fix | Delete
@line.force_encoding(@io.encoding)
[164] Fix | Delete
yield @line, @exp_line_no
[165] Fix | Delete
end
[166] Fix | Delete
break if @io.eof?
[167] Fix | Delete
@line = ''
[168] Fix | Delete
@exp_line_no = @line_no
[169] Fix | Delete
[170] Fix | Delete
@indent = 0
[171] Fix | Delete
rescue TerminateLineInput
[172] Fix | Delete
initialize_input
[173] Fix | Delete
prompt
[174] Fix | Delete
end
[175] Fix | Delete
end
[176] Fix | Delete
end
[177] Fix | Delete
end
[178] Fix | Delete
[179] Fix | Delete
def lex
[180] Fix | Delete
line = @input.call
[181] Fix | Delete
if @io.respond_to?(:check_termination)
[182] Fix | Delete
return line # multiline
[183] Fix | Delete
end
[184] Fix | Delete
code = @line + (line.nil? ? '' : line)
[185] Fix | Delete
code.gsub!(/\s*\z/, '').concat("\n")
[186] Fix | Delete
@tokens = ripper_lex_without_warning(code)
[187] Fix | Delete
@continue = process_continue
[188] Fix | Delete
@code_block_open = check_code_block(code)
[189] Fix | Delete
@indent = process_nesting_level
[190] Fix | Delete
@ltype = process_literal_type
[191] Fix | Delete
line
[192] Fix | Delete
end
[193] Fix | Delete
[194] Fix | Delete
def process_continue
[195] Fix | Delete
# last token is always newline
[196] Fix | Delete
if @tokens.size >= 2 and @tokens[-2][1] == :on_regexp_end
[197] Fix | Delete
# end of regexp literal
[198] Fix | Delete
return false
[199] Fix | Delete
elsif @tokens.size >= 2 and @tokens[-2][1] == :on_semicolon
[200] Fix | Delete
return false
[201] Fix | Delete
elsif @tokens.size >= 2 and @tokens[-2][1] == :on_kw and ['begin', 'else', 'ensure'].include?(@tokens[-2][2])
[202] Fix | Delete
return false
[203] Fix | Delete
elsif !@tokens.empty? and @tokens.last[2] == "\\\n"
[204] Fix | Delete
return true
[205] Fix | Delete
elsif @tokens.size >= 1 and @tokens[-1][1] == :on_heredoc_end # "EOH\n"
[206] Fix | Delete
return false
[207] Fix | Delete
elsif @tokens.size >= 2 and defined?(Ripper::EXPR_BEG) and @tokens[-2][3].anybits?(Ripper::EXPR_BEG | Ripper::EXPR_FNAME)
[208] Fix | Delete
# end of literal except for regexp
[209] Fix | Delete
return true
[210] Fix | Delete
end
[211] Fix | Delete
false
[212] Fix | Delete
end
[213] Fix | Delete
[214] Fix | Delete
def check_code_block(code)
[215] Fix | Delete
return true if @tokens.empty?
[216] Fix | Delete
if @tokens.last[1] == :on_heredoc_beg
[217] Fix | Delete
return true
[218] Fix | Delete
end
[219] Fix | Delete
[220] Fix | Delete
begin # check if parser error are available
[221] Fix | Delete
verbose, $VERBOSE = $VERBOSE, nil
[222] Fix | Delete
case RUBY_ENGINE
[223] Fix | Delete
when 'jruby'
[224] Fix | Delete
JRuby.compile_ir(code)
[225] Fix | Delete
else
[226] Fix | Delete
self.class.compile_with_errors_suppressed(code) do |inner_code, line_no|
[227] Fix | Delete
RubyVM::InstructionSequence.compile(inner_code, nil, nil, line_no)
[228] Fix | Delete
end
[229] Fix | Delete
end
[230] Fix | Delete
rescue EncodingError
[231] Fix | Delete
# This is for a hash with invalid encoding symbol, {"\xAE": 1}
[232] Fix | Delete
rescue SyntaxError => e
[233] Fix | Delete
case e.message
[234] Fix | Delete
when /unterminated (?:string|regexp) meets end of file/
[235] Fix | Delete
# "unterminated regexp meets end of file"
[236] Fix | Delete
#
[237] Fix | Delete
# example:
[238] Fix | Delete
# /
[239] Fix | Delete
#
[240] Fix | Delete
# "unterminated string meets end of file"
[241] Fix | Delete
#
[242] Fix | Delete
# example:
[243] Fix | Delete
# '
[244] Fix | Delete
return true
[245] Fix | Delete
when /syntax error, unexpected end-of-input/
[246] Fix | Delete
# "syntax error, unexpected end-of-input, expecting keyword_end"
[247] Fix | Delete
#
[248] Fix | Delete
# example:
[249] Fix | Delete
# if ture
[250] Fix | Delete
# hoge
[251] Fix | Delete
# if false
[252] Fix | Delete
# fuga
[253] Fix | Delete
# end
[254] Fix | Delete
return true
[255] Fix | Delete
when /syntax error, unexpected keyword_end/
[256] Fix | Delete
# "syntax error, unexpected keyword_end"
[257] Fix | Delete
#
[258] Fix | Delete
# example:
[259] Fix | Delete
# if (
[260] Fix | Delete
# end
[261] Fix | Delete
#
[262] Fix | Delete
# example:
[263] Fix | Delete
# end
[264] Fix | Delete
return false
[265] Fix | Delete
when /syntax error, unexpected '\.'/
[266] Fix | Delete
# "syntax error, unexpected '.'"
[267] Fix | Delete
#
[268] Fix | Delete
# example:
[269] Fix | Delete
# .
[270] Fix | Delete
return false
[271] Fix | Delete
when /unexpected tREGEXP_BEG/
[272] Fix | Delete
# "syntax error, unexpected tREGEXP_BEG, expecting keyword_do or '{' or '('"
[273] Fix | Delete
#
[274] Fix | Delete
# example:
[275] Fix | Delete
# method / f /
[276] Fix | Delete
return false
[277] Fix | Delete
end
[278] Fix | Delete
ensure
[279] Fix | Delete
$VERBOSE = verbose
[280] Fix | Delete
end
[281] Fix | Delete
[282] Fix | Delete
if defined?(Ripper::EXPR_BEG)
[283] Fix | Delete
last_lex_state = @tokens.last[3]
[284] Fix | Delete
if last_lex_state.allbits?(Ripper::EXPR_BEG)
[285] Fix | Delete
return false
[286] Fix | Delete
elsif last_lex_state.allbits?(Ripper::EXPR_DOT)
[287] Fix | Delete
return true
[288] Fix | Delete
elsif last_lex_state.allbits?(Ripper::EXPR_CLASS)
[289] Fix | Delete
return true
[290] Fix | Delete
elsif last_lex_state.allbits?(Ripper::EXPR_FNAME)
[291] Fix | Delete
return true
[292] Fix | Delete
elsif last_lex_state.allbits?(Ripper::EXPR_VALUE)
[293] Fix | Delete
return true
[294] Fix | Delete
elsif last_lex_state.allbits?(Ripper::EXPR_ARG)
[295] Fix | Delete
return false
[296] Fix | Delete
end
[297] Fix | Delete
end
[298] Fix | Delete
[299] Fix | Delete
false
[300] Fix | Delete
end
[301] Fix | Delete
[302] Fix | Delete
def process_nesting_level
[303] Fix | Delete
indent = 0
[304] Fix | Delete
in_oneliner_def = nil
[305] Fix | Delete
@tokens.each_with_index { |t, index|
[306] Fix | Delete
# detecting one-liner method definition
[307] Fix | Delete
if in_oneliner_def.nil?
[308] Fix | Delete
if t[3].allbits?(Ripper::EXPR_ENDFN)
[309] Fix | Delete
in_oneliner_def = :ENDFN
[310] Fix | Delete
end
[311] Fix | Delete
else
[312] Fix | Delete
if t[3].allbits?(Ripper::EXPR_ENDFN)
[313] Fix | Delete
# continuing
[314] Fix | Delete
elsif t[3].allbits?(Ripper::EXPR_BEG)
[315] Fix | Delete
if t[2] == '='
[316] Fix | Delete
in_oneliner_def = :BODY
[317] Fix | Delete
end
[318] Fix | Delete
elsif t[3].allbits?(Ripper::EXPR_END)
[319] Fix | Delete
if in_oneliner_def == :BODY
[320] Fix | Delete
# one-liner method definition
[321] Fix | Delete
indent -= 1
[322] Fix | Delete
end
[323] Fix | Delete
in_oneliner_def = nil
[324] Fix | Delete
else
[325] Fix | Delete
in_oneliner_def = nil
[326] Fix | Delete
end
[327] Fix | Delete
end
[328] Fix | Delete
[329] Fix | Delete
case t[1]
[330] Fix | Delete
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
[331] Fix | Delete
indent += 1
[332] Fix | Delete
when :on_rbracket, :on_rbrace, :on_rparen
[333] Fix | Delete
indent -= 1
[334] Fix | Delete
when :on_kw
[335] Fix | Delete
next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME)
[336] Fix | Delete
case t[2]
[337] Fix | Delete
when 'do'
[338] Fix | Delete
if index > 0 and @tokens[index - 1][3].anybits?(Ripper::EXPR_CMDARG | Ripper::EXPR_ENDFN | Ripper::EXPR_ARG)
[339] Fix | Delete
# method_with_block do; end
[340] Fix | Delete
indent += 1
[341] Fix | Delete
else
[342] Fix | Delete
# while cond do; end # also "until" or "for"
[343] Fix | Delete
# This "do" doesn't increment indent because "while" already
[344] Fix | Delete
# incremented.
[345] Fix | Delete
end
[346] Fix | Delete
when 'def', 'case', 'for', 'begin', 'class', 'module'
[347] Fix | Delete
indent += 1
[348] Fix | Delete
when 'if', 'unless', 'while', 'until'
[349] Fix | Delete
# postfix if/unless/while/until must be Ripper::EXPR_LABEL
[350] Fix | Delete
indent += 1 unless t[3].allbits?(Ripper::EXPR_LABEL)
[351] Fix | Delete
when 'end'
[352] Fix | Delete
indent -= 1
[353] Fix | Delete
end
[354] Fix | Delete
end
[355] Fix | Delete
# percent literals are not indented
[356] Fix | Delete
}
[357] Fix | Delete
indent
[358] Fix | Delete
end
[359] Fix | Delete
[360] Fix | Delete
def check_newline_depth_difference
[361] Fix | Delete
depth_difference = 0
[362] Fix | Delete
open_brace_on_line = 0
[363] Fix | Delete
in_oneliner_def = nil
[364] Fix | Delete
@tokens.each_with_index do |t, index|
[365] Fix | Delete
# detecting one-liner method definition
[366] Fix | Delete
if in_oneliner_def.nil?
[367] Fix | Delete
if t[3].allbits?(Ripper::EXPR_ENDFN)
[368] Fix | Delete
in_oneliner_def = :ENDFN
[369] Fix | Delete
end
[370] Fix | Delete
else
[371] Fix | Delete
if t[3].allbits?(Ripper::EXPR_ENDFN)
[372] Fix | Delete
# continuing
[373] Fix | Delete
elsif t[3].allbits?(Ripper::EXPR_BEG)
[374] Fix | Delete
if t[2] == '='
[375] Fix | Delete
in_oneliner_def = :BODY
[376] Fix | Delete
end
[377] Fix | Delete
elsif t[3].allbits?(Ripper::EXPR_END)
[378] Fix | Delete
if in_oneliner_def == :BODY
[379] Fix | Delete
# one[-liner method definition
[380] Fix | Delete
depth_difference -= 1
[381] Fix | Delete
end
[382] Fix | Delete
in_oneliner_def = nil
[383] Fix | Delete
else
[384] Fix | Delete
in_oneliner_def = nil
[385] Fix | Delete
end
[386] Fix | Delete
end
[387] Fix | Delete
[388] Fix | Delete
case t[1]
[389] Fix | Delete
when :on_ignored_nl, :on_nl, :on_comment
[390] Fix | Delete
if index != (@tokens.size - 1)
[391] Fix | Delete
depth_difference = 0
[392] Fix | Delete
open_brace_on_line = 0
[393] Fix | Delete
end
[394] Fix | Delete
next
[395] Fix | Delete
when :on_sp
[396] Fix | Delete
next
[397] Fix | Delete
end
[398] Fix | Delete
case t[1]
[399] Fix | Delete
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
[400] Fix | Delete
depth_difference += 1
[401] Fix | Delete
open_brace_on_line += 1
[402] Fix | Delete
when :on_rbracket, :on_rbrace, :on_rparen
[403] Fix | Delete
depth_difference -= 1 if open_brace_on_line > 0
[404] Fix | Delete
when :on_kw
[405] Fix | Delete
next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME)
[406] Fix | Delete
case t[2]
[407] Fix | Delete
when 'do'
[408] Fix | Delete
if index > 0 and @tokens[index - 1][3].anybits?(Ripper::EXPR_CMDARG | Ripper::EXPR_ENDFN | Ripper::EXPR_ARG)
[409] Fix | Delete
# method_with_block do; end
[410] Fix | Delete
depth_difference += 1
[411] Fix | Delete
else
[412] Fix | Delete
# while cond do; end # also "until" or "for"
[413] Fix | Delete
# This "do" doesn't increment indent because "while" already
[414] Fix | Delete
# incremented.
[415] Fix | Delete
end
[416] Fix | Delete
when 'def', 'case', 'for', 'begin', 'class', 'module'
[417] Fix | Delete
depth_difference += 1
[418] Fix | Delete
when 'if', 'unless', 'while', 'until', 'rescue'
[419] Fix | Delete
# postfix if/unless/while/until/rescue must be Ripper::EXPR_LABEL
[420] Fix | Delete
unless t[3].allbits?(Ripper::EXPR_LABEL)
[421] Fix | Delete
depth_difference += 1
[422] Fix | Delete
end
[423] Fix | Delete
when 'else', 'elsif', 'ensure', 'when', 'in'
[424] Fix | Delete
depth_difference += 1
[425] Fix | Delete
end
[426] Fix | Delete
end
[427] Fix | Delete
end
[428] Fix | Delete
depth_difference
[429] Fix | Delete
end
[430] Fix | Delete
[431] Fix | Delete
def check_corresponding_token_depth
[432] Fix | Delete
corresponding_token_depth = nil
[433] Fix | Delete
is_first_spaces_of_line = true
[434] Fix | Delete
is_first_printable_of_line = true
[435] Fix | Delete
spaces_of_nest = []
[436] Fix | Delete
spaces_at_line_head = 0
[437] Fix | Delete
open_brace_on_line = 0
[438] Fix | Delete
in_oneliner_def = nil
[439] Fix | Delete
@tokens.each_with_index do |t, index|
[440] Fix | Delete
# detecting one-liner method definition
[441] Fix | Delete
if in_oneliner_def.nil?
[442] Fix | Delete
if t[3].allbits?(Ripper::EXPR_ENDFN)
[443] Fix | Delete
in_oneliner_def = :ENDFN
[444] Fix | Delete
end
[445] Fix | Delete
else
[446] Fix | Delete
if t[3].allbits?(Ripper::EXPR_ENDFN)
[447] Fix | Delete
# continuing
[448] Fix | Delete
elsif t[3].allbits?(Ripper::EXPR_BEG)
[449] Fix | Delete
if t[2] == '='
[450] Fix | Delete
in_oneliner_def = :BODY
[451] Fix | Delete
end
[452] Fix | Delete
elsif t[3].allbits?(Ripper::EXPR_END)
[453] Fix | Delete
if in_oneliner_def == :BODY
[454] Fix | Delete
# one-liner method definition
[455] Fix | Delete
if is_first_printable_of_line
[456] Fix | Delete
corresponding_token_depth = spaces_of_nest.pop
[457] Fix | Delete
else
[458] Fix | Delete
spaces_of_nest.pop
[459] Fix | Delete
corresponding_token_depth = nil
[460] Fix | Delete
end
[461] Fix | Delete
end
[462] Fix | Delete
in_oneliner_def = nil
[463] Fix | Delete
else
[464] Fix | Delete
in_oneliner_def = nil
[465] Fix | Delete
end
[466] Fix | Delete
end
[467] Fix | Delete
[468] Fix | Delete
case t[1]
[469] Fix | Delete
when :on_ignored_nl, :on_nl, :on_comment
[470] Fix | Delete
corresponding_token_depth = nil
[471] Fix | Delete
spaces_at_line_head = 0
[472] Fix | Delete
is_first_spaces_of_line = true
[473] Fix | Delete
is_first_printable_of_line = true
[474] Fix | Delete
open_brace_on_line = 0
[475] Fix | Delete
next
[476] Fix | Delete
when :on_sp
[477] Fix | Delete
spaces_at_line_head = t[2].count(' ') if is_first_spaces_of_line
[478] Fix | Delete
is_first_spaces_of_line = false
[479] Fix | Delete
next
[480] Fix | Delete
end
[481] Fix | Delete
case t[1]
[482] Fix | Delete
when :on_lbracket, :on_lbrace, :on_lparen, :on_tlambeg
[483] Fix | Delete
spaces_of_nest.push(spaces_at_line_head + open_brace_on_line * 2)
[484] Fix | Delete
open_brace_on_line += 1
[485] Fix | Delete
when :on_rbracket, :on_rbrace, :on_rparen
[486] Fix | Delete
if is_first_printable_of_line
[487] Fix | Delete
corresponding_token_depth = spaces_of_nest.pop
[488] Fix | Delete
else
[489] Fix | Delete
spaces_of_nest.pop
[490] Fix | Delete
corresponding_token_depth = nil
[491] Fix | Delete
end
[492] Fix | Delete
open_brace_on_line -= 1
[493] Fix | Delete
when :on_kw
[494] Fix | Delete
next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME)
[495] Fix | Delete
case t[2]
[496] Fix | Delete
when 'def', 'do', 'case', 'for', 'begin', 'class', 'module'
[497] Fix | Delete
spaces_of_nest.push(spaces_at_line_head)
[498] Fix | Delete
when 'rescue'
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function