Created
October 21, 2010 23:52
-
-
Save timfel/639637 to your computer and use it in GitHub Desktop.
Simple Syntax checking for Ruby in Redcar?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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