summaryrefslogtreecommitdiff
path: root/ext/ripper
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-19 15:57:25 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-19 17:19:27 +0900
commit1d435bd51aeca75f6e437bc92de2271a716a1ced (patch)
tree90c085aaf771373c4131a187edfc4ee191d39e21 /ext/ripper
parent5c81e19b196e940b3233781b7ef0c5bfcbdee4f5 (diff)
Extend Ripper DSL to set to pseudo variables other than `$$`
Diffstat (limited to 'ext/ripper')
-rw-r--r--ext/ripper/tools/dsl.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/ext/ripper/tools/dsl.rb b/ext/ripper/tools/dsl.rb
index 34b435e7c36..925c09b14b0 100644
--- a/ext/ripper/tools/dsl.rb
+++ b/ext/ripper/tools/dsl.rb
@@ -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