Module: Y2R

Defined in:
lib/y2r.rb,
lib/y2r/parser.rb,
lib/y2r/ast/ycp.rb,
lib/y2r/version.rb,
lib/y2r/ast/ruby.rb

Defined Under Namespace

Modules: AST Classes: Parser

Constant Summary collapse

VERSION =
File.read(File.dirname(__FILE__) + "/../../VERSION").strip

Class Method Summary collapse

Class Method Details

.compile(input, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/y2r.rb', line 9

def self.compile(input, options = {})
  ast = Parser.new(options).parse(input)

  if !options[:xml]
    ycp_context = AST::YCP::CompilerContext.new(
      :blocks     => [],
      :whitespace => AST::YCP::Comments::Whitespace::DROP_ALL,
      :options    => options,
      :elsif      => false
    )
    ruby_context = AST::Ruby::EmitterContext.new(
      :width    => 80,
      :shift    => 0,
      :priority => AST::Ruby::Priority::NONE
    )

    ast.compile(ycp_context).to_ruby(ruby_context)
  else
    ast
  end
end