Skip to content

Commit

Permalink
Merge pull request #119 from srz-zumix/feature/support_statement_ruby
Browse files Browse the repository at this point in the history
support Ruby statement
  • Loading branch information
srz-zumix authored Aug 3, 2022
2 parents c72eb09 + 6c0f7ba commit 3aa6510
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion samples/command/src/ruby/sample.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# This file is a "Hello, world!" in Ruby language by ruby for wandbox.

require './test1'
require_relative 'test2'
require_relative 'test2'; require './test3'

puts "Hello, Wandbox!"
test1
test2
test3

# Ruby reference:
# https://docs.ruby-lang.org/
4 changes: 4 additions & 0 deletions samples/command/src/ruby/test3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

def test3
puts "Test3"
end
23 changes: 13 additions & 10 deletions wandbox/__ruby__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

from .cli import CLI
from .runner import Runner
from .utils import split_statements


class RubyRunner(Runner):

REQUIRE_REGEX = re.compile(r'^\s*require\s+(.*?)$')
REQUIRE_RELATIVE_REGEX = re.compile(r'^\s*require_relative\s+(.*?)$')
REQUIRE_REGEX = re.compile(r'^\s*require\s+(.*?)\s*(;|)\s*$')
REQUIRE_RELATIVE_REGEX = re.compile(r'^\s*require_relative\s+(.*?)\s*(;|)\s*$')

def reset(self):
self.required = []
Expand All @@ -17,16 +18,18 @@ def make_code(self, file, filepath, filename):
files = dict()
code = ''
for line in file:
m = self.REQUIRE_REGEX.match(line)
if m:
module = m.group(1).strip('\'"')
if module.startswith('.'):
files.update(self.require(os.path.dirname(filepath), module.strip()))
else:
m = self.REQUIRE_RELATIVE_REGEX.match(line)
statements = split_statements(line, commenters="#")
for statement in statements:
m = self.REQUIRE_REGEX.match(statement)
if m:
module = m.group(1).strip('\'"')
files.update(self.require(os.path.dirname(filepath), module.strip()))
if module.startswith('.'):
files.update(self.require(os.path.dirname(filepath), module.strip()))
else:
m = self.REQUIRE_RELATIVE_REGEX.match(statement)
if m:
module = m.group(1).strip('\'"')
files.update(self.require(os.path.dirname(filepath), module.strip()))
code += line
files[filename] = code
return files
Expand Down

0 comments on commit 3aa6510

Please sign in to comment.