Skip to content

Commit 301fa45

Browse files
committed
Remove flip-flop usages from build scripts
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63669 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent bf7a32d commit 301fa45

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

ext/ripper/tools/preproc.rb

+17-10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def main
4141

4242
def prelude(f, out)
4343
@exprs = {}
44+
lex_state_def = false
4445
while line = f.gets
4546
case line
4647
when /\A%%/
@@ -50,19 +51,25 @@ def prelude(f, out)
5051
out << line.sub(/<\w+>/, '<val>')
5152
when /\A%type/
5253
out << line.sub(/<\w+>/, '<val>')
54+
when /^enum lex_state_(?:bits|e) \{/
55+
lex_state_def = true
56+
out << line
57+
when /^\}/
58+
lex_state_def = false
59+
out << line
5360
else
54-
if (/^enum lex_state_(?:bits|e) \{/ =~ line)..(/^\}/ =~ line)
55-
case line
56-
when /^\s*(EXPR_\w+),\s+\/\*(.+)\*\//
57-
@exprs[$1.chomp("_bit")] = $2.strip
58-
when /^\s*(EXPR_\w+)\s+=\s+(.+)$/
59-
name = $1
60-
val = $2.chomp(",")
61-
@exprs[name] = "equals to " + (val.start_with?("(") ? "<tt>#{val}</tt>" : "+#{val}+")
62-
end
63-
end
6461
out << line
6562
end
63+
if lex_state_def
64+
case line
65+
when /^\s*(EXPR_\w+),\s+\/\*(.+)\*\//
66+
@exprs[$1.chomp("_bit")] = $2.strip
67+
when /^\s*(EXPR_\w+)\s+=\s+(.+)$/
68+
name = $1
69+
val = $2.chomp(",")
70+
@exprs[name] = "equals to " + (val.start_with?("(") ? "<tt>#{val}</tt>" : "+#{val}+")
71+
end
72+
end
6673
end
6774
end
6875

template/encdb.h.tmpl

+20-12
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,28 @@ encdirs.each do |encdir|
4040
files[fn] = true
4141
open(File.join(encdir,fn)) do |f|
4242
name = nil
43+
skip_ifndef_ruby = false
44+
encoding_def = false
4345
f.each_line do |line|
44-
if (/^#ifndef RUBY/ =~ line)..(/^#endif/ =~ line)
45-
elsif (/^OnigEncodingDefine/ =~ line)..(/"(.*?)"/ =~ line)
46-
if $1
47-
if name
48-
lines << %[ENC_SET_BASE("#$1", "#{name}");]
49-
else
50-
name = $1
51-
end
52-
check_duplication(defs, $1, fn, $.)
53-
next if BUILTIN_ENCODINGS[name]
54-
encodings << $1
55-
count += 1
46+
case line
47+
when /^#ifndef RUBY/
48+
skip_ifndef_ruby = true
49+
when /^#endif/
50+
skip_ifndef_ruby = false
51+
end
52+
next if skip_ifndef_ruby
53+
encoding_def = true if /^OnigEncodingDefine/ =~ line
54+
if encoding_def && /"(.*?)"/ =~ line
55+
encoding_def = false
56+
if name
57+
lines << %[ENC_SET_BASE("#$1", "#{name}");]
58+
else
59+
name = $1
5660
end
61+
check_duplication(defs, $1, fn, $.)
62+
next if BUILTIN_ENCODINGS[name]
63+
encodings << $1
64+
count += 1
5765
else
5866
case line
5967
when /^\s*rb_enc_register\(\s*"([^"]+)"/

template/transdb.h.tmpl

+11-10
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ transdirs.each do |transdir|
3636
files[fn] = true
3737
path = File.join(transdir,fn)
3838
open(path) do |f|
39+
transcoder_def = false
3940
f.each_line do |line|
40-
if (/^static const rb_transcoder/ =~ line)..(/"(.*?)"\s*,\s*"(.*?)"/ =~ line)
41-
if $1 && $2
42-
from_to = "%s to %s" % [$1, $2]
43-
if converters[from_to]
44-
raise ArgumentError, '%s:%d: transcode "%s" is already registered at %s:%d' %
45-
[path, $., from_to, *converters[from_to].values_at(3, 4)]
46-
else
47-
converters[from_to] = [$1, $2, fn[0..-3], path, $.]
48-
converter_list << from_to
49-
end
41+
transcoder_def = true if /^static const rb_transcoder/ =~ line
42+
if transcoder_def && /"(.*?)"\s*,\s*"(.*?)"/ =~ line
43+
transcoder_def = false
44+
from_to = "%s to %s" % [$1, $2]
45+
if converters[from_to]
46+
raise ArgumentError, '%s:%d: transcode "%s" is already registered at %s:%d' %
47+
[path, $., from_to, *converters[from_to].values_at(3, 4)]
48+
else
49+
converters[from_to] = [$1, $2, fn[0..-3], path, $.]
50+
converter_list << from_to
5051
end
5152
end
5253
end

0 commit comments

Comments
 (0)