Skip to content

Commit

Permalink
support julia statement (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix authored Jul 31, 2022
1 parent fce2500 commit 96287e1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
4 changes: 3 additions & 1 deletion samples/command/src/julia/sample.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# This file is a "Hello, world!" in Julia language for wandbox.

include("test1.jl")
include("test1.jl"); include("test2.jl");

using .Test1
using .Test2

println("Hello, Wandbox!")

Test1.test()
Test2.test()

# Julia language references:
# https://docs.julialang.org/en/v1/
8 changes: 8 additions & 0 deletions samples/command/src/julia/test2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Test2
function test()
println("Test2: test")
end
function test2()
println("Test2: test2")
end
end
6 changes: 6 additions & 0 deletions tests/test_wandbox_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def test_split_statements(self):
self.assertEqual(". test.sh", statements[0])
self.assertEqual("source \'test data.sh\'", statements[1])

def test_split_statements_2(self):
statements = split_statements("include(\"test1.jl\"); include(\"test2.jl\");")
self.assertEqual(2, len(statements))
self.assertEqual("include ( test1.jl )", statements[0])
self.assertEqual("include ( test2.jl )", statements[1])


if __name__ == '__main__':
test_loader = unittest.defaultTestLoader
Expand Down
11 changes: 7 additions & 4 deletions wandbox/__julia__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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


class JuliaRunner(Runner):
Expand All @@ -16,10 +17,12 @@ def make_code(self, file, filepath, filename):
files = dict()
code = ''
for line in file:
m = self.INCLUDE_REGEX.match(line)
if m:
module = m.group(1).strip('(\'")')
files.update(self.include(os.path.dirname(filepath), module.strip()))
statements = split_statements(line, commenters="#")
for statement in statements:
m = self.INCLUDE_REGEX.match(statement)
if m:
module = m.group(1).strip('(\'")')
files.update(self.include(os.path.dirname(filepath), module.strip()))
code += line
files[filename] = code
return files
Expand Down
17 changes: 12 additions & 5 deletions wandbox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,29 @@ def text_transform(value):
return value


def shlex_join(split_command):
return " ".join([shlex.quote(x) for x in split_command])
def statements_quote(s):
if s in ['(', ')']:
return s
else:
return shlex.quote(s)


def statements_join(split_command):
return " ".join([statements_quote(x) for x in split_command])


def split_statements(line, end_of_statement=";", commenters="#"):
sl = shlex.shlex(line, posix=True, punctuation_chars=True)
sl = shlex.shlex(line, posix=True, punctuation_chars=end_of_statement)
sl.commenters = commenters
sl.source = None
statements = []
statement = []
for s in sl:
if s == end_of_statement:
statements.append(shlex_join(statement))
statements.append(statements_join(statement))
statement = []
else:
statement.append(s)
if len(statement) > 0:
statements.append(shlex_join(statement))
statements.append(statements_join(statement))
return statements

0 comments on commit 96287e1

Please sign in to comment.