class DSL

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);
  • The code must be a single line.

  • The code is basically Ruby code, even if it appears like in C and the result will be processed as C. e.g., comments need to be in Ruby style.

Constants

NAME_PATTERN
NOT_REF_PATTERN
TAG_PATTERN

Attributes

events[R]

Public Class Methods

new(code, options) click to toggle source
# File ripper/tools/dsl.rb, line 21
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\$#{NAME_PATTERN}\z/o)[0] || "$$")
  end
  @vars = 0

  # struct parser_params *p
  p = p = "p"

  @code = ""
  code = code.gsub(%r[\G#{NOT_REF_PATTERN}\K[$@]#{TAG_PATTERN}?#{NAME_PATTERN}]o, '"\&"')
  @last_value = eval(code)
end