Datasets:
Upload scripts/check_syntax.rb with huggingface_hub
Browse files- scripts/check_syntax.rb +14 -0
scripts/check_syntax.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env ruby
|
| 2 |
+
# frozen_string_literal: true
|
| 3 |
+
|
| 4 |
+
require 'parser/current'
|
| 5 |
+
|
| 6 |
+
# Reads code from stdin and exits with 0 if syntax is valid, 1 otherwise.
|
| 7 |
+
begin
|
| 8 |
+
code = $stdin.read
|
| 9 |
+
Parser::CurrentRuby.parse(code)
|
| 10 |
+
exit 0
|
| 11 |
+
rescue Parser::SyntaxError => e
|
| 12 |
+
$stderr.puts e.message
|
| 13 |
+
exit 1
|
| 14 |
+
end
|