Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Syntax checking for Ruby in Redcar?
require 'java'
module Java::IO
import 'java.io.File'
import 'java.io.FileInputStream'
end
module JRuby
import 'org.jruby.Ruby'
end
class RubySyntaxChecker
# Why this *args here? Well, this forces a ManyVarsDynamicScope for the Parser
def check(path, *args)
begin
runtime = JRuby::Ruby.global_runtime
io = Java::IO::FileInputStream.new(Java::IO::File.new(path))
runtime.parse_from_main(io, File.basename(path))
rescue SyntaxError => e
e.exception.message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment