Simple DSL implementation for Ripper code generation
input: % ripper: stmts_add(stmts_new, void_stmt) %
output:
VALUE v1, v2; v1 = dispatch0(stmts_new); v2 = dispatch0(void_stmt); $$ = dispatch2(stmts_add, v1, v2);
# File ripper/tools/dsl.rb, line 11 def initialize(code, options) @events = {} @error = options.include?("error") @brace = options.include?("brace") if options.include?("final") @final = "p->result" else @final = (options.grep(/\A\$(?:\$|\d+)\z/)[0] || "$$") end @vars = 0 # create $1 == "$1", $2 == "$2", ... s = (1..20).map {|n| "$#{n}"} re = Array.new(s.size, "([^\0]+)") /#{re.join("\0")}/ =~ s.join("\0") # struct parser_params *p p = p = "p" @code = "" @last_value = eval(code) end