nilac 0.0.4.3.9.2 → 0.0.4.3.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/nilac +9 -5748
- data/examples/StringMagic.nila +23 -0
- data/examples/countdown.nila +31 -0
- data/examples/decBin.nila +3 -3
- data/examples/marky.js +30 -0
- data/examples/marky.nila +23 -0
- data/lib/nilac/ErrorDeclarations.rb +11 -0
- data/lib/nilac/add_semicolons.rb +57 -0
- data/lib/nilac/compile_arrays.rb +266 -0
- data/lib/nilac/compile_blocks.rb +137 -0
- data/lib/nilac/compile_case_statement.rb +168 -0
- data/lib/nilac/compile_classes.rb +18 -0
- data/lib/nilac/compile_comments.rb +79 -0
- data/lib/nilac/compile_conditional_structures.rb +1378 -0
- data/lib/nilac/compile_custom_function_map.rb +45 -0
- data/lib/nilac/compile_default_values.rb +160 -0
- data/lib/nilac/compile_hashes.rb +123 -0
- data/lib/nilac/compile_heredocs.rb +62 -0
- data/lib/nilac/compile_integers.rb +23 -0
- data/lib/nilac/compile_interpolated_strings.rb +133 -0
- data/lib/nilac/compile_loops.rb +211 -0
- data/lib/nilac/compile_named_functions.rb +690 -0
- data/lib/nilac/compile_operators.rb +83 -0
- data/lib/nilac/compile_parallel_assignment.rb +103 -0
- data/lib/nilac/compile_ruby_methods.rb +58 -0
- data/lib/nilac/compile_special_keywords.rb +44 -0
- data/lib/nilac/compile_strings.rb +145 -0
- data/lib/nilac/compile_whitespace_delimited_functions.rb +97 -0
- data/lib/nilac/create_mac_executable.rb +25 -0
- data/lib/nilac/extract_parsable_file.rb +23 -0
- data/lib/nilac/find_all_matching_indices.rb +18 -0
- data/lib/nilac/find_file_name.rb +13 -0
- data/lib/nilac/find_file_path.rb +13 -0
- data/lib/nilac/get_variables.rb +123 -0
- data/lib/nilac/output_javascript.rb +13 -0
- data/lib/nilac/parse_arguments.rb +41 -0
- data/lib/nilac/pretty_print_javascript.rb +457 -0
- data/lib/nilac/read_file_line_by_line.rb +11 -0
- data/lib/nilac/remove_question_marks.rb +46 -0
- data/lib/nilac/replace_multiline_comments.rb +92 -0
- data/lib/nilac/replace_named_functions.rb +154 -0
- data/lib/nilac/replace_singleline_comments.rb +45 -0
- data/lib/nilac/replace_strings.rb +35 -0
- data/lib/nilac/split_semicolon_seperated_expressions.rb +39 -0
- data/lib/nilac/strToArray.rb +15 -0
- data/lib/nilac/version.rb +1 -1
- data/lib/nilac.rb +324 -1
- data/nilac.gemspec +0 -1
- data/shark/features/add_auto_return_statement.feature +1 -1
- data/shark/features/array_and_string_indexing.feature +1 -1
- data/shark/features/barebones_compilation.feature +1 -1
- data/shark/features/case_when.feature +1 -1
- data/shark/features/default_method_parameters.feature +1 -1
- data/shark/features/fix_newlines.feature +1 -1
- data/shark/features/hashes.feature +1 -1
- data/shark/features/heredoc.feature +1 -1
- data/shark/features/if_then_else.feature +1 -1
- data/shark/features/loop.feature +1 -1
- data/shark/features/method_multiple_return.feature +1 -1
- data/shark/features/multiline_array.feature +1 -1
- data/shark/features/multiple_variable_initialization.feature +1 -1
- data/shark/features/numbers.feature +1 -1
- data/shark/features/regular_for.feature +1 -1
- data/shark/features/regular_if.feature +1 -1
- data/shark/features/regular_while.feature +1 -1
- data/shark/features/ruby_methods.feature +1 -1
- data/shark/features/ruby_operators.feature +1 -1
- data/shark/features/splats.feature +1 -1
- data/shark/features/string_interpolation.feature +1 -1
- data/shark/features/strings.feature +1 -1
- data/shark/features/times.feature +1 -1
- data/shark/features/unless_until.feature +1 -1
- data/shark/features/whitespace_delimitation.feature +1 -1
- metadata +46 -18
- data/src/nilac.rb +0 -5753
@@ -0,0 +1,83 @@
|
|
1
|
+
def compile_operators(input_file_contents)
|
2
|
+
|
3
|
+
def compile_power_operator(input_string)
|
4
|
+
|
5
|
+
matches = input_string.scan(/(\w{1,}\*\*\w{1,})/).to_a.flatten
|
6
|
+
|
7
|
+
unless matches.empty?
|
8
|
+
|
9
|
+
matches.each do |match|
|
10
|
+
|
11
|
+
left, right = match.split("**")
|
12
|
+
|
13
|
+
input_string = input_string.sub(match, "Math.pow(#{left},#{right})")
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
return input_string
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def compile_match_operator(input_string)
|
24
|
+
|
25
|
+
rejection_exp = /( aannddy | orriioo |nnoottyy )/
|
26
|
+
|
27
|
+
if input_string.include?("=~")
|
28
|
+
|
29
|
+
input_string = input_string.gsub(" && "," aannddy ").gsub(" || "," orriioo ").gsub("!","nnoottyy")
|
30
|
+
|
31
|
+
left, right = input_string.split("=~")
|
32
|
+
|
33
|
+
if left.index(rejection_exp) != nil
|
34
|
+
|
35
|
+
left = left[left.index(rejection_exp)..-1]
|
36
|
+
|
37
|
+
elsif left.index(/\(/)
|
38
|
+
|
39
|
+
left = left[left.index(/\(/)+1..-1]
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
if right.index(rejection_exp) != nil
|
44
|
+
|
45
|
+
right = right[0...right.index(rejection_exp)]
|
46
|
+
|
47
|
+
elsif right.index(/\)/)
|
48
|
+
|
49
|
+
right = right[0...right.index(/\)/)]
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
original_string = "#{left}=~#{right}"
|
54
|
+
|
55
|
+
replacement_string = "#{left.rstrip} = #{left.rstrip}.match(#{right.lstrip.rstrip})"
|
56
|
+
|
57
|
+
input_string = input_string.sub(original_string,replacement_string)
|
58
|
+
|
59
|
+
input_string = input_string.gsub(" aannddy "," && ").gsub(" orriioo "," || ").gsub("nnoottyy","!")
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
return input_string
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
input_file_contents = input_file_contents.collect { |element| element.sub("==", "===") }
|
68
|
+
|
69
|
+
input_file_contents = input_file_contents.collect { |element| element.sub("!=", "!==") }
|
70
|
+
|
71
|
+
input_file_contents = input_file_contents.collect { |element| element.sub("equequ", "==") }
|
72
|
+
|
73
|
+
input_file_contents = input_file_contents.collect { |element| element.sub("elsuf", "else if") }
|
74
|
+
|
75
|
+
input_file_contents = input_file_contents.collect { |element| compile_power_operator(element) }
|
76
|
+
|
77
|
+
input_file_contents = input_file_contents.collect {|element| compile_match_operator(element)}
|
78
|
+
|
79
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("_!;",";")}
|
80
|
+
|
81
|
+
return input_file_contents
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative 'replace_strings'
|
2
|
+
|
3
|
+
require_relative 'read_file_line_by_line'
|
4
|
+
|
5
|
+
def compile_parallel_assignment(input_file_contents, temporary_nila_file)
|
6
|
+
|
7
|
+
def arrayify_right_side(input_string)
|
8
|
+
|
9
|
+
modified_input_string = input_string.dup
|
10
|
+
|
11
|
+
input_string = replace_strings(input_string)
|
12
|
+
|
13
|
+
javascript_regexp = /(if |while |for |function |function\()/
|
14
|
+
|
15
|
+
if input_string.include?("=") and input_string.index(javascript_regexp) == nil and input_string.strip[0..3] != "_ref" and !input_string.split("=")[1].include?("[")
|
16
|
+
|
17
|
+
right_side = input_string.split("=")[1]
|
18
|
+
|
19
|
+
if right_side.include?(",")
|
20
|
+
|
21
|
+
splits = right_side.split(",")
|
22
|
+
|
23
|
+
replacement_string = []
|
24
|
+
|
25
|
+
splits.each do |str|
|
26
|
+
|
27
|
+
unless str.include?(")") and !str.include?("(")
|
28
|
+
|
29
|
+
replacement_string << str
|
30
|
+
|
31
|
+
else
|
32
|
+
|
33
|
+
replacement_string[-1] = replacement_string[-1]+ "," +str
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
replacement_string = " [#{replacement_string.join(",").strip}]\n"
|
40
|
+
|
41
|
+
modified_input_string = modified_input_string.sub(right_side,replacement_string)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
return modified_input_string
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
input_file_contents = input_file_contents.collect {|element| arrayify_right_side(element)}
|
52
|
+
|
53
|
+
possible_variable_lines = input_file_contents.clone.reject { |element| !element.include? "=" }
|
54
|
+
|
55
|
+
possible_parallel_assignment = possible_variable_lines.reject { |element| !element.split("=")[0].include? "," }
|
56
|
+
|
57
|
+
parallel_assignment_index = []
|
58
|
+
|
59
|
+
possible_parallel_assignment.each do |statement|
|
60
|
+
|
61
|
+
location_array = input_file_contents.each_index.select { |index| input_file_contents[index] == statement }
|
62
|
+
|
63
|
+
parallel_assignment_index << location_array[0]
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
modified_file_contents = input_file_contents.dup
|
68
|
+
|
69
|
+
parallel_assignment_counter = 1
|
70
|
+
|
71
|
+
possible_parallel_assignment.each_with_index do |line, index|
|
72
|
+
|
73
|
+
line_split = line.split(" = ")
|
74
|
+
|
75
|
+
right_side_variables = line_split[0].split(",")
|
76
|
+
|
77
|
+
replacement_string = "_ref#{parallel_assignment_counter} = #{line_split[1]}\n\n"
|
78
|
+
|
79
|
+
variable_string = ""
|
80
|
+
|
81
|
+
right_side_variables.each_with_index do |variable, var_index|
|
82
|
+
|
83
|
+
variable_string = variable_string + variable.rstrip + " = _ref#{parallel_assignment_counter}[#{var_index}]\n\n"
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
replacement_string = replacement_string + variable_string
|
88
|
+
|
89
|
+
modified_file_contents[parallel_assignment_index[index]] = replacement_string
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
file_id = open(temporary_nila_file, 'w')
|
94
|
+
|
95
|
+
file_id.write(modified_file_contents.join)
|
96
|
+
|
97
|
+
file_id.close()
|
98
|
+
|
99
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
100
|
+
|
101
|
+
return line_by_line_contents
|
102
|
+
|
103
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
def compile_ruby_methods(input_file_contents)
|
2
|
+
|
3
|
+
# These are some interesting methods that we really miss in Javascript.
|
4
|
+
# So we have made these methods available
|
5
|
+
|
6
|
+
method_map_replacement = {
|
7
|
+
|
8
|
+
".split" => ".split(\" \")",
|
9
|
+
|
10
|
+
".join" => ".join()",
|
11
|
+
|
12
|
+
".strip" => ".replace(/^\\s+|\\s+$/g,'')",
|
13
|
+
|
14
|
+
".lstrip" => ".replace(/^\\s+/g,\"\")",
|
15
|
+
|
16
|
+
".rstrip" => ".replace(/\\s+$/g,\"\")",
|
17
|
+
|
18
|
+
".to_s" => ".toString()",
|
19
|
+
|
20
|
+
".reverse" => ".reverse()",
|
21
|
+
|
22
|
+
".empty?" => ".length == 0",
|
23
|
+
|
24
|
+
".upcase" => ".toUpperCase()",
|
25
|
+
|
26
|
+
".downcase" => ".toLowerCase()",
|
27
|
+
|
28
|
+
}
|
29
|
+
|
30
|
+
method_map = method_map_replacement.keys
|
31
|
+
|
32
|
+
method_map_regex = method_map.collect {|name| name.gsub(".","\\.")}
|
33
|
+
|
34
|
+
method_map_regex = Regexp.new(method_map_regex.join("|"))
|
35
|
+
|
36
|
+
modified_file_contents = input_file_contents.clone
|
37
|
+
|
38
|
+
input_file_contents.each_with_index do |line, index|
|
39
|
+
|
40
|
+
if line.match(method_map_regex)
|
41
|
+
|
42
|
+
method_match = line.match(method_map_regex).to_a[0]
|
43
|
+
|
44
|
+
unless line.include?(method_match + "(")
|
45
|
+
|
46
|
+
line = line.sub(method_match,method_map_replacement[method_match])
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
modified_file_contents[index] = line
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
return modified_file_contents
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'replace_strings'
|
2
|
+
|
3
|
+
def compile_special_keywords(input_file_contents)
|
4
|
+
|
5
|
+
# This method compiles some Ruby specific keywords to Javascript to make it easy to port
|
6
|
+
# Ruby code into Javascript
|
7
|
+
|
8
|
+
keyword_replacement_map = {
|
9
|
+
|
10
|
+
"nil" => "null",
|
11
|
+
|
12
|
+
"Array.new" => "new Array()"
|
13
|
+
|
14
|
+
}
|
15
|
+
|
16
|
+
special_keywords = keyword_replacement_map.keys
|
17
|
+
|
18
|
+
keyword_map_regex = special_keywords.collect {|name| name.gsub(".","\\.")}
|
19
|
+
|
20
|
+
keyword_map_regex = Regexp.new(keyword_map_regex.join("|"))
|
21
|
+
|
22
|
+
modified_file_contents = input_file_contents.clone
|
23
|
+
|
24
|
+
input_file_contents.each_with_index do |line, index|
|
25
|
+
|
26
|
+
if replace_strings(line).match(keyword_map_regex)
|
27
|
+
|
28
|
+
method_match = line.match(keyword_map_regex).to_a[0]
|
29
|
+
|
30
|
+
if line.split(keyword_map_regex)[0].include?("=")
|
31
|
+
|
32
|
+
line = line.sub(method_match,keyword_replacement_map[method_match])
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
modified_file_contents[index] = line
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
return modified_file_contents
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
def compile_strings(input_file_contents)
|
2
|
+
|
3
|
+
def compile_small_q_syntax(input_file_contents)
|
4
|
+
|
5
|
+
possible_syntax_usage = input_file_contents.reject { |element| !element.include?("%q") }
|
6
|
+
|
7
|
+
possible_syntax_usage.each do |line|
|
8
|
+
|
9
|
+
modified_line = line.dup
|
10
|
+
|
11
|
+
line_split = line.split("+").collect { |element| element.lstrip.rstrip }
|
12
|
+
|
13
|
+
line_split.each do |str|
|
14
|
+
|
15
|
+
delimiter = str[str.index("%q")+2]
|
16
|
+
|
17
|
+
string_extract = str[str.index("%q")..-1]
|
18
|
+
|
19
|
+
delimiter = "}" if delimiter.eql?("{")
|
20
|
+
|
21
|
+
delimiter = ")" if delimiter.eql?("(")
|
22
|
+
|
23
|
+
delimiter = ">" if delimiter.eql?("<")
|
24
|
+
|
25
|
+
if string_extract[-1].eql?(delimiter)
|
26
|
+
|
27
|
+
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract, "'#{string_extract[3...-1]}'")
|
28
|
+
|
29
|
+
modified_line = modified_line.sub(string_extract, "'#{string_extract[3...-1]}'")
|
30
|
+
|
31
|
+
elsif delimiter.eql?(" ")
|
32
|
+
|
33
|
+
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract, "'#{string_extract[3..-1]}'")
|
34
|
+
|
35
|
+
modified_line = modified_line.sub(string_extract, "'#{string_extract[3..-1]}'")
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
return input_file_contents
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def compile_big_q_syntax(input_file_contents)
|
48
|
+
|
49
|
+
possible_syntax_usage = input_file_contents.reject { |element| !element.include?("%Q") }
|
50
|
+
|
51
|
+
possible_syntax_usage.each do |line|
|
52
|
+
|
53
|
+
modified_line = line.dup
|
54
|
+
|
55
|
+
line_split = line.split("+").collect { |element| element.lstrip.rstrip }
|
56
|
+
|
57
|
+
line_split.each do |str|
|
58
|
+
|
59
|
+
delimiter = str[str.index("%Q")+2]
|
60
|
+
|
61
|
+
string_extract = str[str.index("%Q")..-1]
|
62
|
+
|
63
|
+
delimiter = "}" if delimiter.eql?("{")
|
64
|
+
|
65
|
+
delimiter = ")" if delimiter.eql?("(")
|
66
|
+
|
67
|
+
delimiter = ">" if delimiter.eql?("<")
|
68
|
+
|
69
|
+
if string_extract[-1].eql?(delimiter)
|
70
|
+
|
71
|
+
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract, "\"#{string_extract[3...-1]}\"")
|
72
|
+
|
73
|
+
modified_line = modified_line.sub(string_extract, "\"#{string_extract[3...-1]}\"")
|
74
|
+
|
75
|
+
elsif delimiter.eql?(" ")
|
76
|
+
|
77
|
+
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract, "\"#{string_extract[3..-1]}\"")
|
78
|
+
|
79
|
+
modified_line = modified_line.sub(string_extract, "\"#{string_extract[3..-1]}\"")
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
return input_file_contents
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def compile_percentage_syntax(input_file_contents)
|
92
|
+
|
93
|
+
possible_syntax_usage = input_file_contents.reject { |element| !element.include?("%") }
|
94
|
+
|
95
|
+
possible_syntax_usage = possible_syntax_usage.reject { |element| element.index(/(\%(\W|\s)\w{1,})/).nil? }
|
96
|
+
|
97
|
+
possible_syntax_usage.each do |line|
|
98
|
+
|
99
|
+
modified_line = line.dup
|
100
|
+
|
101
|
+
line_split = line.split("+").collect { |element| element.lstrip.rstrip }
|
102
|
+
|
103
|
+
line_split.each do |str|
|
104
|
+
|
105
|
+
delimiter = str[str.index("%")+1]
|
106
|
+
|
107
|
+
string_extract = str[str.index("%")..-1]
|
108
|
+
|
109
|
+
delimiter = "}" if delimiter.eql?("{")
|
110
|
+
|
111
|
+
delimiter = ")" if delimiter.eql?("(")
|
112
|
+
|
113
|
+
delimiter = ">" if delimiter.eql?("<")
|
114
|
+
|
115
|
+
if string_extract[-1].eql?(delimiter)
|
116
|
+
|
117
|
+
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract, "\"#{string_extract[2...-1]}\"")
|
118
|
+
|
119
|
+
modified_line = modified_line.sub(string_extract, "\"#{string_extract[2...-1]}\"")
|
120
|
+
|
121
|
+
elsif delimiter.eql?(" ")
|
122
|
+
|
123
|
+
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract, "\"#{string_extract[2..-1]}\"")
|
124
|
+
|
125
|
+
modified_line = modified_line.sub(string_extract, "\"#{string_extract[2..-1]}\"")
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
return input_file_contents
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
file_contents = compile_small_q_syntax(input_file_contents)
|
138
|
+
|
139
|
+
file_contents = compile_big_q_syntax(file_contents)
|
140
|
+
|
141
|
+
file_contents = compile_percentage_syntax(file_contents)
|
142
|
+
|
143
|
+
return file_contents
|
144
|
+
|
145
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative 'read_file_line_by_line'
|
2
|
+
|
3
|
+
def compile_whitespace_delimited_functions(input_file_contents, function_names, temporary_nila_file)
|
4
|
+
|
5
|
+
def extract(input_string, pattern_start, pattern_end)
|
6
|
+
|
7
|
+
def find_all_matching_indices(input_string, pattern)
|
8
|
+
|
9
|
+
locations = []
|
10
|
+
|
11
|
+
index = input_string.index(pattern)
|
12
|
+
|
13
|
+
while index != nil
|
14
|
+
|
15
|
+
locations << index
|
16
|
+
|
17
|
+
index = input_string.index(pattern, index+1)
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
return locations
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
all_start_locations = find_all_matching_indices(input_string, pattern_start)
|
28
|
+
|
29
|
+
pattern = []
|
30
|
+
|
31
|
+
all_start_locations.each do |location|
|
32
|
+
|
33
|
+
extracted_string = input_string[location..-1]
|
34
|
+
|
35
|
+
string_extract = extracted_string[0..extracted_string.index(pattern_end)]
|
36
|
+
|
37
|
+
if !string_extract.include?(" = function(")
|
38
|
+
|
39
|
+
pattern << string_extract
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
return pattern
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
|
51
|
+
input_file_contents[-1] = input_file_contents[-1] + "\n" if !input_file_contents[-1].include?("\n")
|
52
|
+
|
53
|
+
joined_file_contents = input_file_contents.join
|
54
|
+
|
55
|
+
function_names.each do |list_of_functions|
|
56
|
+
|
57
|
+
list_of_functions.each do |function|
|
58
|
+
|
59
|
+
matching_strings = extract(joined_file_contents, function+" ", "\n")
|
60
|
+
|
61
|
+
matching_strings.each do |string|
|
62
|
+
|
63
|
+
modified_string = string.dup
|
64
|
+
|
65
|
+
modified_string = modified_string.rstrip + modified_string.split(modified_string.rstrip)[1].gsub(" ", "")
|
66
|
+
|
67
|
+
modified_string = modified_string.sub(function+" ", function+"(")
|
68
|
+
|
69
|
+
modified_string = modified_string.split("#{function}(")[0] + "#{function}(" + modified_string.split("#{function}(")[1].lstrip
|
70
|
+
|
71
|
+
modified_string = modified_string.sub("\n", ")\n")
|
72
|
+
|
73
|
+
joined_file_contents = joined_file_contents.sub(string, modified_string)
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
rescue NoMethodError
|
82
|
+
|
83
|
+
puts "Whitespace delimitation exited with errors!"
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
file_id = open(temporary_nila_file, 'w')
|
88
|
+
|
89
|
+
file_id.write(joined_file_contents)
|
90
|
+
|
91
|
+
file_id.close()
|
92
|
+
|
93
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
94
|
+
|
95
|
+
return line_by_line_contents
|
96
|
+
|
97
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
def create_mac_executable(input_file)
|
2
|
+
|
3
|
+
def read_file_line_by_line(input_path)
|
4
|
+
|
5
|
+
file_id = open(input_path)
|
6
|
+
|
7
|
+
file_line_by_line = file_id.readlines()
|
8
|
+
|
9
|
+
file_id.close
|
10
|
+
|
11
|
+
return file_line_by_line
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
mac_file_contents = ["#!/usr/bin/env ruby\n\n"] + read_file_line_by_line(input_file)
|
16
|
+
|
17
|
+
mac_file_path = input_file.sub(".rb", "")
|
18
|
+
|
19
|
+
file_id = open(mac_file_path, "w")
|
20
|
+
|
21
|
+
file_id.write(mac_file_contents.join)
|
22
|
+
|
23
|
+
file_id.close
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
def extract_parsable_file(input_file_contents)
|
2
|
+
|
3
|
+
reversed_file_contents = input_file_contents.reverse
|
4
|
+
|
5
|
+
line_counter = 0
|
6
|
+
|
7
|
+
if input_file_contents.join.include?("__END__")
|
8
|
+
|
9
|
+
while !reversed_file_contents[line_counter].strip.include?("__END__")
|
10
|
+
|
11
|
+
line_counter += 1
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
return_contents = input_file_contents[0...-1*line_counter-1]
|
16
|
+
|
17
|
+
else
|
18
|
+
|
19
|
+
input_file_contents
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
def find_all_matching_indices(input_string, pattern)
|
2
|
+
|
3
|
+
locations = []
|
4
|
+
|
5
|
+
index = input_string.index(pattern)
|
6
|
+
|
7
|
+
while index != nil
|
8
|
+
|
9
|
+
locations << index
|
10
|
+
|
11
|
+
index = input_string.index(pattern, index+1)
|
12
|
+
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
return locations
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
def find_file_name(input_path, file_extension)
|
2
|
+
|
3
|
+
extension_remover = input_path.split(file_extension)
|
4
|
+
|
5
|
+
remaining_string = extension_remover[0].reverse
|
6
|
+
|
7
|
+
path_finder = remaining_string.index("/")
|
8
|
+
|
9
|
+
remaining_string = remaining_string.reverse
|
10
|
+
|
11
|
+
return remaining_string[remaining_string.length-path_finder..-1]
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
def find_file_path(input_path, file_extension)
|
2
|
+
|
3
|
+
extension_remover = input_path.split(file_extension)
|
4
|
+
|
5
|
+
remaining_string = extension_remover[0].reverse
|
6
|
+
|
7
|
+
path_finder = remaining_string.index("/")
|
8
|
+
|
9
|
+
remaining_string = remaining_string.reverse
|
10
|
+
|
11
|
+
return remaining_string[0...remaining_string.length-path_finder]
|
12
|
+
|
13
|
+
end
|