Sha256: 75ecc94be857bc1651b6f54c6fe4c5c8519b0850a3be2092e154b7006f8acbf3

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

require 'erb'

Duby::AST.defmacro('def_edb') do |transformer, fcall, parent|
  name = fcall.parameters[0].name
  path = fcall.parameters[1].literal
  compiler = ERB::Compiler.new(nil)
  compiler.put_cmd = "_edbout.append"
  compiler.insert_cmd = "__edb_insert__ _edbout.append"
  compiler.pre_cmd = ["def #{name}", "_edbout = StringBuilder.new"]
  compiler.post_cmd = ["_edbout.toString", "end"]
  src = compiler.compile(IO.read(path))
  ast = Duby::AST.parse_ruby(src, path)
  transformer.filename = path
  script = transformer.transform(ast, parent)
  script.body.parent = parent
  script.body
end

Duby::AST.defmacro('__edb_insert__') do |transformer, fcall, parent|
  # ERB sticks in a .to_s that we don't want.
  # the ast is __edb_insert__(_edbout.append(content.to_s))
  append = fcall.parameters[0]
  content = append.parameters[0].target
  content.parent = append
  append.parameters = [content]
  append.parent = parent
  append
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mirah-0.0.4-java lib/mirah/plugin/edb.rb