diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-10-19 15:57:25 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-10-19 17:19:27 +0900 |
commit | 1d435bd51aeca75f6e437bc92de2271a716a1ced (patch) | |
tree | 90c085aaf771373c4131a187edfc4ee191d39e21 /ext/ripper/tools/dsl.rb | |
parent | 5c81e19b196e940b3233781b7ef0c5bfcbdee4f5 (diff) | |
download | ruby-1d435bd51aeca75f6e437bc92de2271a716a1ced.tar.gz |
Extend Ripper DSL to set to pseudo variables other than `$$`
Diffstat (limited to 'ext/ripper/tools/dsl.rb')
-rw-r--r-- | ext/ripper/tools/dsl.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/ext/ripper/tools/dsl.rb b/ext/ripper/tools/dsl.rb index 34b435e7c3..925c09b14b 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 |