lib/sibilant.rb in sibilant-0.0.3 vs lib/sibilant.rb in sibilant-0.0.4
- old
+ new
@@ -1,9 +1,12 @@
require "sibilant/version"
require 'json'
+require 'open3'
module Sibilant
+ class CompilationError < RuntimeError; end
+
class << self
def [](sibilant_code)
Sibilant::Compiler.new.translate sibilant_code
end
end
@@ -28,13 +31,18 @@
def sibilant_cli
File.join sibilant_js_root, 'bin', 'sibilant'
end
def translate(sibilant_code)
- IO.popen("#{sibilant_cli} -i", 'r+') do |sibilant|
- sibilant.puts sibilant_code
- sibilant.close_write
- sibilant.read
- end.strip
+ Open3.popen3 sibilant_cli, '-i' do |i,o,e,t|
+ i.puts sibilant_code
+ i.close_write
+
+ if t.value.success?
+ o.read.strip
+ else
+ raise Sibilant::CompilationError.new(e.read.strip)
+ end
+ end
end
end
end