aboutsummaryrefslogtreecommitdiffstats
path: root/ext/ripper/tools/preproc.rb
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-19 10:48:08 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-19 10:48:08 +0000
commit9b7fe0a25012d615f1cae8da1f5c444f61ffb7c7 (patch)
treee46613a0689272c609dd1e41ebe1ca9e5b7faa50 /ext/ripper/tools/preproc.rb
parent9eb4344a16ec37eb5660099c1aad12f9a8dc914d (diff)
downloadruby-9b7fe0a25012d615f1cae8da1f5c444f61ffb7c7.tar.gz
ext/ripper: Introduce a simple DSL for ripper.y code generation
Currently, parse.y actions are hard to read and write because the code has double meaning (for core parser and for ripper). I think that, if it is easy to write ripper's code shortly and simply, the double meaning trick is not needed. For the sake, this change adds a simple DSL for ripper's code. For example, in parse.y, we can write: /*% ripper: stmts_add(stmts_new, void_stmt) %*/ instead of: $$ = dispatch2(stmts_add, dispatch0(stmts_new), dispatch0(void_stmt)); git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/ripper/tools/preproc.rb')
-rwxr-xr-xext/ripper/tools/preproc.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/ext/ripper/tools/preproc.rb b/ext/ripper/tools/preproc.rb
index 8b68579164..560a82e54f 100755
--- a/ext/ripper/tools/preproc.rb
+++ b/ext/ripper/tools/preproc.rb
@@ -72,9 +72,13 @@ def prelude(f, out)
end
end
+require_relative "dsl"
+
def grammar(f, out)
while line = f.gets
case line
+ when %r</\*% *ripper(?:\[(.*?)\])?: *(.*?) *%\*/>
+ out << DSL.new($2, ($1 || "").split(",")).generate << $/
when %r</\*%%%\*/>
out << '#if 0' << $/
when %r</\*%c%\*/>