1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Extend Ripper DSL to set to pseudo variables other than $$

This commit is contained in:
Nobuyoshi Nakada 2019-10-19 15:57:25 +09:00
parent 5c81e19b19
commit 1d435bd51a
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -12,7 +12,11 @@ class DSL
@events = {}
@error = options.include?("error")
@brace = options.include?("brace")
@final = options.include?("final")
if options.include?("final")
@final = "p->result"
else
@final = (options.grep(/\A\$[$\d]\z/)[0] || "$$")
end
@vars = 0
# create $1 == "$1", $2 == "$2", ...
@ -37,9 +41,7 @@ class DSL
undef class
def generate
s = "$$"
s = "p->result" if @final
s = "#@code#{ s }=#@last_value;"
s = "#@code#@final=#@last_value;"
s = "{VALUE #{ (1..@vars).map {|v| "v#{ v }" }.join(",") };#{ s }}" if @vars > 0
s << "ripper_error(p);" if @error
s = "{#{ s }}" if @brace