summaryrefslogtreecommitdiff
path: root/ext/ripper
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-20 17:45:25 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-20 17:45:25 +0000
commit5db289422981ca7108a443b1ce46fb4dbe7ab46b (patch)
tree7c2e2d1270a4f8688ee13b471c32cbc218bdf370 /ext/ripper
parentd24f1fddd770ca5ac488602207649ac678fb10ad (diff)
parse.y: Remove double meaning of new_qcall/new_command_qcall
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61992 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/ripper')
-rw-r--r--ext/ripper/tools/dsl.rb30
1 files changed, 20 insertions, 10 deletions
diff --git a/ext/ripper/tools/dsl.rb b/ext/ripper/tools/dsl.rb
index 44a8f42..3c4c11c 100644
--- a/ext/ripper/tools/dsl.rb
+++ b/ext/ripper/tools/dsl.rb
@@ -50,18 +50,28 @@ class DSL
"v#{ @vars += 1 }"
end
+ def opt_event(event, default, addend)
+ add_event(event, [default, addend], true)
+ end
+
+ def add_event(event, args, qundef_check = false)
+ event = event.to_s.delete_suffix("!")
+ @events[event] = args.size
+ vars = []
+ args.each do |arg|
+ vars << v = new_var
+ @code << "#{ v }=#{ arg };"
+ end
+ v = new_var
+ d = "dispatch#{ args.size }(#{ [event, *vars].join(",") })"
+ d = "#{ vars.last }==Qundef ? #{ vars.first } : #{ d }" if qundef_check
+ @code << "#{ v }=#{ d };"
+ v
+ end
+
def method_missing(event, *args)
if event.to_s =~ /!\z/
- event = $`
- @events[event] = args.size
- vars = []
- args.each do |arg|
- vars << v = new_var
- @code << "#{ v }=#{ arg };"
- end
- v = new_var
- @code << "#{ v }=dispatch#{ args.size }(#{ [event, *vars].join(",") });"
- v
+ add_event(event, args)
elsif args.empty? and /\Aid[A-Z]/ =~ event.to_s
event
else