Class: RubyScribe::Runner

Inherits:
Thor
  • Object
show all
Defined in:
lib/ruby_scribe/runner.rb

Instance Method Summary collapse

Instance Method Details

#cat(path) ⇒ Object



7
8
9
10
# File 'lib/ruby_scribe/runner.rb', line 7

def cat(path)
  sexp = RubyParser.new.parse(File.read(path))
  puts RubyScribe::Emitter.new.emit(sexp)
end

#convert(*paths) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_scribe/runner.rb', line 13

def convert(*paths)
  expand_paths(paths).each do |path|
    begin
      sexp = RubyParser.new.parse(File.read(path))
      output = RubyScribe::Emitter.new.emit(sexp)
      
      File.open(path, "w") do |file|
        file.write(output)
        file.flush
      end
    rescue Racc::ParseError, SyntaxError => e
      $stderr.puts "! Failed to parse #{path}:"
      $stderr.puts e.message
    end
  end
end