Skip to content

Instantly share code, notes, and snippets.

@timfel
Created October 21, 2010 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timfel/639637 to your computer and use it in GitHub Desktop.
Save timfel/639637 to your computer and use it in GitHub Desktop.
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