Get rid of use of special variables

Use `"\n"` and `IO#fileno` instead of `$/` and `$.` respectively.
[Feature #14240]
This commit is contained in:
Jeremy Evans 2020-01-20 16:53:31 +09:00 committed by Nobuyoshi Nakada
parent f31b90f2b9
commit 9f99760daf
No known key found for this signature in database
GPG Key ID: 4BC7D6DF58D8DF60
3 changed files with 12 additions and 12 deletions

View File

@ -45,7 +45,7 @@ def prelude(f, out)
while line = f.gets while line = f.gets
case line case line
when /\A%%/ when /\A%%/
out << '%%' << $/ out << "%%\n"
return return
when /\A%token/ when /\A%token/
out << line.sub(/<\w+>/, '<val>') out << line.sub(/<\w+>/, '<val>')
@ -79,15 +79,15 @@ def grammar(f, out)
while line = f.gets while line = f.gets
case line case line
when %r</\*% *ripper(?:\[(.*?)\])?: *(.*?) *%\*/> when %r</\*% *ripper(?:\[(.*?)\])?: *(.*?) *%\*/>
out << DSL.new($2, ($1 || "").split(",")).generate << $/ out << DSL.new($2, ($1 || "").split(",")).generate << "\n"
when %r</\*%%%\*/> when %r</\*%%%\*/>
out << '#if 0' << $/ out << "#if 0\n"
when %r</\*%> when %r</\*%>
out << '#endif' << $/ out << "#endif\n"
when %r<%\*/> when %r<%\*/>
out << $/ out << "\n"
when /\A%%/ when /\A%%/
out << '%%' << $/ out << "%%\n"
return return
else else
out << line out << line

View File

@ -58,7 +58,7 @@ encdirs.each do |encdir|
else else
name = $1 name = $1
end end
check_duplication(defs, $1, fn, $.) check_duplication(defs, $1, fn, f.lineno)
next if BUILTIN_ENCODINGS[name] next if BUILTIN_ENCODINGS[name]
encodings << $1 encodings << $1
count += 1 count += 1
@ -71,18 +71,18 @@ encdirs.each do |encdir|
when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/ when /^ENC_REPLICATE\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
raise ArgumentError, raise ArgumentError,
'%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' % '%s:%d: ENC_REPLICATE: %s is not defined yet. (replica %s)' %
[fn, $., $2, $1] unless defs[$2.upcase] [fn, f.lineno, $2, $1] unless defs[$2.upcase]
count += 1 count += 1
when /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/ when /^ENC_ALIAS\(\s*"([^"]+)"\s*,\s*"([^"]+)"/
raise ArgumentError, raise ArgumentError,
'%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' % '%s:%d: ENC_ALIAS: %s is not defined yet. (alias %s)' %
[fn, $., $2, $1] unless defs[$2.upcase] [fn, f.lineno, $2, $1] unless defs[$2.upcase]
when /^ENC_DUMMY\w*\(\s*"([^"]+)"/ when /^ENC_DUMMY\w*\(\s*"([^"]+)"/
count += 1 count += 1
else else
next next
end end
check_duplication(defs, $1, fn, $.) check_duplication(defs, $1, fn, f.lineno)
lines << line.sub(/;.*/m, "").chomp + ";" if line lines << line.sub(/;.*/m, "").chomp + ";" if line
end end
end end

View File

@ -44,9 +44,9 @@ transdirs.each do |transdir|
from_to = "%s to %s" % [$1, $2] from_to = "%s to %s" % [$1, $2]
if converters[from_to] if converters[from_to]
raise ArgumentError, '%s:%d: transcode "%s" is already registered at %s:%d' % raise ArgumentError, '%s:%d: transcode "%s" is already registered at %s:%d' %
[path, $., from_to, *converters[from_to].values_at(3, 4)] [path, f.lineno, from_to, *converters[from_to].values_at(3, 4)]
else else
converters[from_to] = [$1, $2, fn[0..-3], path, $.] converters[from_to] = [$1, $2, fn[0..-3], path, f.lineno]
converter_list << from_to converter_list << from_to
end end
end end