summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rwxr-xr-xext/ripper/tools/generate.rb25
1 files changed, 14 insertions, 11 deletions
diff --git a/ext/ripper/tools/generate.rb b/ext/ripper/tools/generate.rb
index 48ad9e1d25..fc30e775bb 100755
--- a/ext/ripper/tools/generate.rb
+++ b/ext/ripper/tools/generate.rb
@@ -68,15 +68,22 @@ end
def generate_eventids1(ids)
buf = ""
+ buf << %Q[static struct {\n]
ids.each do |id, arity|
- buf << %Q[static ID ripper_id_#{id};\n]
+ buf << %Q[ ID id_#{id};\n]
+ end
+ buf << %Q[} ripper_parser_ids;\n]
+ buf << %Q[\n]
+ ids.each do |id, arity|
+ buf << %Q[#define ripper_id_#{id} ripper_parser_ids.id_#{id}\n]
end
buf << %Q[\n]
buf << %Q[static void\n]
buf << %Q[ripper_init_eventids1(void)\n]
buf << %Q[{\n]
+ buf << %Q[#define set_id1(name) ripper_id_##name = rb_intern_const("on_"#name)\n]
ids.each do |id, arity|
- buf << %Q[ ripper_id_#{id} = rb_intern_const("on_#{id}");\n]
+ buf << %Q[ set_id1(#{id});\n]
end
buf << %Q[}\n]
buf << %Q[\n]
@@ -84,11 +91,9 @@ def generate_eventids1(ids)
buf << %Q[ripper_init_eventids1_table(VALUE self)\n]
buf << %Q[{\n]
buf << %Q[ VALUE h = rb_hash_new();\n]
- buf << %Q[ ID id;\n]
buf << %Q[ rb_define_const(self, "PARSER_EVENT_TABLE", h);\n]
ids.each do |id, arity|
- buf << %Q[ id = rb_intern_const("#{id}");\n]
- buf << %Q[ rb_hash_aset(h, ID2SYM(id), INT2NUM(#{arity}));\n]
+ buf << %Q[ rb_hash_aset(h, intern_sym("#{id}"), INT2FIX(#{arity}));\n]
end
buf << %Q[}\n]
buf
@@ -100,11 +105,9 @@ def generate_eventids2_table(ids)
buf << %Q[ripper_init_eventids2_table(VALUE self)\n]
buf << %Q[{\n]
buf << %Q[ VALUE h = rb_hash_new();\n]
- buf << %Q[ ID id;\n]
buf << %Q[ rb_define_const(self, "SCANNER_EVENT_TABLE", h);\n]
ids.each do |id|
- buf << %Q[ id = rb_intern_const("#{id}");\n]
- buf << %Q[ rb_hash_aset(h, ID2SYM(id), INT2NUM(1));\n]
+ buf << %Q[ rb_hash_aset(h, intern_sym("#{id}"), INT2FIX(1));\n]
end
buf << %Q[}\n]
buf
@@ -135,9 +138,9 @@ def read_ids1_with_locations(path)
h = {}
File.open(path) {|f|
f.each do |line|
- next if /\A\#\s*define\s+s?dispatch/ =~ line
+ next if /\A\#\s*define\s+dispatch/ =~ line
next if /ripper_dispatch/ =~ line
- line.scan(/dispatch(\d)\((\w+)/) do |arity, event|
+ line.scan(/\bdispatch(\d)\((\w+)/) do |arity, event|
(h[event] ||= []).push [f.lineno, arity.to_i]
end
end
@@ -147,7 +150,7 @@ end
def read_ids2(path)
File.open(path) {|f|
- return f.read.scan(/ripper_id_(\w+)/).flatten.uniq.sort
+ return f.read.scan(/ID\s+ripper_id_(\w+)/).flatten.uniq.sort
}
end