nilac 0.0.4.3.9.6 → 0.0.4.3.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +2 -0
- data/examples/decBin.js +2 -2
- data/examples/repl.js +31 -0
- data/examples/repl.nila +24 -0
- data/lib/nilac/add_semicolons.rb +1 -1
- data/lib/nilac/compile_blocks.rb +20 -2
- data/lib/nilac/compile_case_statement.rb +1 -1
- data/lib/nilac/compile_conditional_structures.rb +20 -8
- data/lib/nilac/compile_custom_function_map.rb +3 -1
- data/lib/nilac/compile_default_values.rb +15 -1
- data/lib/nilac/compile_integers.rb +147 -2
- data/lib/nilac/compile_lambdas.rb +22 -6
- data/lib/nilac/compile_loops.rb +1 -1
- data/lib/nilac/compile_monkey_patching.rb +189 -0
- data/lib/nilac/compile_named_functions.rb +44 -70
- data/lib/nilac/compile_parallel_assignment.rb +2 -2
- data/lib/nilac/compile_ruby_methods.rb +3 -1
- data/lib/nilac/compile_strings.rb +4 -4
- data/lib/nilac/friendly_errors.rb +95 -0
- data/lib/nilac/get_variables.rb +29 -18
- data/lib/nilac/lexical_scoped_function_variables.rb +6 -0
- data/lib/nilac/output_javascript.rb +9 -7
- data/lib/nilac/paranthesis_compactor.rb +37 -0
- data/lib/nilac/pretty_print_javascript.rb +53 -61
- data/lib/nilac/replace_multiline_comments.rb +6 -2
- data/lib/nilac/replace_named_functions.rb +41 -65
- data/lib/nilac/replace_strings.rb +40 -17
- data/lib/nilac/rollblocks.rb +86 -13
- data/lib/nilac/version.rb +1 -1
- data/lib/nilac.rb +46 -13
- data/shark/features/blocks.feature +11 -0
- data/shark/features/monkey_patch.feature +11 -0
- data/shark/test_files/blocks.nila +18 -0
- data/shark/test_files/correct_blocks.js +25 -0
- data/shark/test_files/correct_case.js +1 -1
- data/shark/test_files/correct_monkey_patch.js +24 -0
- data/shark/test_files/correct_multiple_return.js +2 -2
- data/shark/test_files/correct_splats.js +3 -3
- data/shark/test_files/lambda.nila +9 -1
- data/shark/test_files/monkey_patch.nila +18 -0
- data/shark/test_files/multiple_return.nila +8 -8
- data/shark/test_files/sample_class.nila +1 -1
- metadata +13 -7
- data/LICENSE +0 -20
- data/examples/countdown.nila +0 -31
- data/lib/nilac/compile_classes.rb +0 -19
- data/shark/test_files/array_sugar.nila +0 -3
- data/shark/test_files/class.nila +0 -7
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'find_all_matching_indices'
|
2
|
-
|
3
2
|
require_relative 'read_file_line_by_line'
|
3
|
+
require_relative 'replace_strings'
|
4
4
|
|
5
5
|
def pretty_print_javascript(javascript_file_contents, temporary_nila_file,declarable_variables)
|
6
6
|
|
@@ -42,105 +42,93 @@ require_relative 'read_file_line_by_line'
|
|
42
42
|
|
43
43
|
end
|
44
44
|
|
45
|
-
def fix_newlines(file_contents)
|
45
|
+
def fix_newlines(file_contents,main_block_numbers)
|
46
46
|
|
47
|
-
def
|
47
|
+
def block_compactor(input_block)
|
48
48
|
|
49
|
-
|
49
|
+
modified_block = input_block.reject {|element| element.strip.eql?("")}
|
50
50
|
|
51
|
-
|
51
|
+
modified_block = modified_block.collect {|element| element.rstrip + "\n"}
|
52
52
|
|
53
|
-
|
53
|
+
return modified_block
|
54
54
|
|
55
|
-
|
55
|
+
end
|
56
56
|
|
57
|
-
|
57
|
+
main_block_numbers = [ ] if main_block_numbers.nil?
|
58
58
|
|
59
|
-
|
59
|
+
unless main_block_numbers.empty?
|
60
60
|
|
61
|
-
|
61
|
+
javascript_regexp = /(if |for |while |case |default:|switch\(|,function\(|\(function\(|= function\(|((=|:)\s+\{))/
|
62
62
|
|
63
|
-
|
63
|
+
starting_locations = []
|
64
64
|
|
65
|
-
|
65
|
+
file_contents.each_with_index do |line, index|
|
66
66
|
|
67
|
-
|
67
|
+
if line.index(javascript_regexp) != nil
|
68
68
|
|
69
|
-
|
69
|
+
starting_locations << index
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
starting_index = starting_line_indices[0]
|
71
|
+
end
|
74
72
|
|
75
|
-
|
73
|
+
end
|
76
74
|
|
77
|
-
|
75
|
+
remaining_contents, blocks = roll_blocks(file_contents,starting_locations)
|
78
76
|
|
79
|
-
|
77
|
+
modified_block = []
|
80
78
|
|
81
|
-
|
79
|
+
blocks.each do |block|
|
82
80
|
|
83
|
-
|
81
|
+
while block.join.include?("--block")
|
84
82
|
|
85
|
-
|
83
|
+
nested_blocks = block.reject {|element| !replace_strings(element).include?("--block")}
|
86
84
|
|
87
|
-
|
85
|
+
block_numbers = nested_blocks.collect {|element| element.strip.split("--block")[1].to_i}
|
88
86
|
|
89
|
-
|
87
|
+
block_numbers.each_with_index do |number,index|
|
90
88
|
|
91
|
-
|
89
|
+
location = block.index(nested_blocks[index])
|
92
90
|
|
93
|
-
|
91
|
+
block[location] = blocks[number]
|
94
92
|
|
95
93
|
end
|
96
94
|
|
97
|
-
|
98
|
-
|
99
|
-
starting_index = starting_line_indices[0]
|
95
|
+
block = block.flatten
|
100
96
|
|
101
97
|
end
|
102
98
|
|
103
|
-
|
104
|
-
##
|
105
|
-
# puts "Whitespace was left unfixed!"
|
106
|
-
##
|
107
|
-
#rescue ArgumentError
|
108
|
-
##
|
109
|
-
# puts "Whitespace was left unfixed!"
|
99
|
+
modified_block << block
|
110
100
|
|
111
101
|
end
|
112
102
|
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
compact_contents = file_contents.reject { |element| element.lstrip.eql? "" }
|
103
|
+
main_block_numbers = main_block_numbers.collect {|element| element.strip.to_i}
|
118
104
|
|
119
|
-
|
105
|
+
remaining_contents = remaining_contents.reject {|element| element.strip.eql?("")}
|
120
106
|
|
121
|
-
|
107
|
+
remaining_contents = [remaining_contents[0]] + remaining_contents[1...-1].collect {|element| element + "\n"} + [remaining_contents[-1]]
|
122
108
|
|
123
|
-
|
109
|
+
main_block_numbers.each do |number|
|
124
110
|
|
125
|
-
|
111
|
+
correct_block = block_compactor(modified_block[number])
|
126
112
|
|
127
|
-
|
113
|
+
correct_block << "\n"
|
128
114
|
|
129
|
-
|
115
|
+
remaining_contents[remaining_contents.index("--block#{number}\n\n")] = correct_block
|
130
116
|
|
131
|
-
|
117
|
+
end
|
132
118
|
|
133
|
-
|
119
|
+
remaining_contents = remaining_contents.flatten
|
134
120
|
|
135
|
-
|
121
|
+
else
|
136
122
|
|
137
|
-
|
123
|
+
remaining_contents = block_compactor(file_contents)
|
138
124
|
|
139
|
-
|
125
|
+
remaining_contents = [remaining_contents[0]] + remaining_contents[1...-1].collect {|element| element + "\n"} + [remaining_contents[-1]]
|
140
126
|
|
141
127
|
end
|
142
128
|
|
143
|
-
|
129
|
+
remaining_contents[-1] = remaining_contents[-1].rstrip
|
130
|
+
|
131
|
+
return remaining_contents
|
144
132
|
|
145
133
|
end
|
146
134
|
|
@@ -176,7 +164,7 @@ require_relative 'read_file_line_by_line'
|
|
176
164
|
|
177
165
|
current_block = []
|
178
166
|
|
179
|
-
possible_blocks.
|
167
|
+
possible_blocks.each do |block|
|
180
168
|
|
181
169
|
if !block[0].eql?(current_block[-1])
|
182
170
|
|
@@ -190,7 +178,7 @@ require_relative 'read_file_line_by_line'
|
|
190
178
|
|
191
179
|
current_block.each_with_index do |line, index|
|
192
180
|
|
193
|
-
if line.
|
181
|
+
if line.strip.eql? "}" or line.strip.eql?("};") or line.strip.include?("_!;") or line.strip.eql?("});")
|
194
182
|
|
195
183
|
end_counter += 1
|
196
184
|
|
@@ -234,7 +222,7 @@ require_relative 'read_file_line_by_line'
|
|
234
222
|
|
235
223
|
current_block.each_with_index do |line, index|
|
236
224
|
|
237
|
-
if line.
|
225
|
+
if line.strip.eql? "}" or line.strip.eql?("};") or line.strip.include?("_!;") or line.strip.eql?("});")
|
238
226
|
|
239
227
|
end_counter += 1
|
240
228
|
|
@@ -306,6 +294,8 @@ require_relative 'read_file_line_by_line'
|
|
306
294
|
|
307
295
|
javascript_file_contents = javascript_file_contents.collect { |element| element.sub("whaaleskey", "while") }
|
308
296
|
|
297
|
+
javascript_file_contents = javascript_file_contents.collect { |element| element.sub("}#@$", "}") }
|
298
|
+
|
309
299
|
javascript_file_contents = reset_tabs(javascript_file_contents)
|
310
300
|
|
311
301
|
starting_locations = []
|
@@ -408,14 +398,16 @@ require_relative 'read_file_line_by_line'
|
|
408
398
|
|
409
399
|
remaining_file_contents = ["(function() {\n", remaining_file_contents, "\n}).call(this);"].flatten
|
410
400
|
|
411
|
-
joined_file_contents = remaining_file_contents.join
|
412
|
-
|
413
401
|
main_blocks.each_with_index do |block_id, index|
|
414
402
|
|
415
|
-
|
403
|
+
remaining_file_contents[remaining_file_contents.index(block_id)] = modified_blocks[index]
|
416
404
|
|
417
405
|
end
|
418
406
|
|
407
|
+
remaining_file_contents = remaining_file_contents.reject {|element| element.eql?(" ")}
|
408
|
+
|
409
|
+
joined_file_contents = remaining_file_contents.join
|
410
|
+
|
419
411
|
else
|
420
412
|
|
421
413
|
remaining_file_contents = remaining_file_contents.collect { |element| " " + element }
|
@@ -436,7 +428,7 @@ require_relative 'read_file_line_by_line'
|
|
436
428
|
|
437
429
|
line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("%$%$ {","")}
|
438
430
|
|
439
|
-
line_by_line_contents = fix_newlines(line_by_line_contents)
|
431
|
+
line_by_line_contents = fix_newlines(line_by_line_contents,main_block_numbers)
|
440
432
|
|
441
433
|
removable_indices = line_by_line_contents.each_index.select {|index| line_by_line_contents[index].strip == "%$%$;" }
|
442
434
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require_relative "find_file_name"
|
2
|
-
|
3
2
|
require_relative "find_file_path"
|
4
|
-
|
5
3
|
require_relative "read_file_line_by_line"
|
6
4
|
|
7
5
|
def replace_multiline_comments(input_file_contents, nila_file_path, *output_js_file_path)
|
@@ -63,6 +61,12 @@
|
|
63
61
|
|
64
62
|
temporary_nila_file = find_file_path(nila_file_path, ".nila") + "temp_nila.nila"
|
65
63
|
|
64
|
+
if File.exist?(temporary_nila_file)
|
65
|
+
|
66
|
+
File.delete(temporary_nila_file)
|
67
|
+
|
68
|
+
end
|
69
|
+
|
66
70
|
if output_js_file_path.empty?
|
67
71
|
|
68
72
|
output_js_file = find_file_path(nila_file_path, ".nila") + find_file_name(nila_file_path, ".nila") + ".js"
|
@@ -1,108 +1,81 @@
|
|
1
1
|
require_relative 'read_file_line_by_line'
|
2
|
+
require_relative 'rollblocks'
|
3
|
+
require_relative 'replace_strings'
|
4
|
+
|
2
5
|
|
3
6
|
def replace_named_functions(nila_file_contents, temporary_nila_file)
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
return input_array[start_index..end_index]
|
8
|
-
|
9
|
-
end
|
8
|
+
final_modified_file_contents = nila_file_contents.clone
|
10
9
|
|
11
|
-
|
10
|
+
joined_file_contents = final_modified_file_contents.join
|
12
11
|
|
13
|
-
|
12
|
+
modified_file_contents = []
|
14
13
|
|
15
|
-
|
14
|
+
rand_number = []
|
16
15
|
|
17
|
-
|
16
|
+
nila_file_contents.each do |content|
|
18
17
|
|
19
|
-
|
18
|
+
if replace_strings(content).include?("def ")
|
20
19
|
|
21
|
-
|
20
|
+
rand_num = rand(1..25)
|
22
21
|
|
23
|
-
|
22
|
+
while rand_number.include?(rand_num)
|
24
23
|
|
25
|
-
|
24
|
+
rand_num = rand(1..10)
|
26
25
|
|
27
|
-
|
26
|
+
end
|
28
27
|
|
29
|
-
|
28
|
+
modified_file_contents << content.sub("def ","#{" "*rand_num}def ")
|
30
29
|
|
31
|
-
|
30
|
+
rand_number << rand_num
|
32
31
|
|
33
|
-
|
32
|
+
else
|
34
33
|
|
34
|
+
modified_file_contents << content
|
35
35
|
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
38
|
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
modified_file_contents = nila_file_contents.dup
|
44
|
-
|
45
|
-
for y in 0...end_locations.length
|
46
|
-
|
47
|
-
current_location = end_locations[y]
|
48
|
-
|
49
|
-
current_string = modified_file_contents[current_location]
|
50
|
-
|
51
|
-
finder_location = current_location
|
52
|
-
|
53
|
-
begin
|
54
|
-
|
55
|
-
while current_string.index(nila_regexp) == nil
|
56
|
-
|
57
|
-
finder_location -= 1
|
40
|
+
nila_file_contents = modified_file_contents.clone
|
58
41
|
|
59
|
-
|
42
|
+
possible_function_blocks = nila_file_contents.reject {|element| !replace_strings(element).include?("def ")}
|
60
43
|
|
61
|
-
|
44
|
+
function_block_locations = []
|
62
45
|
|
63
|
-
|
46
|
+
possible_function_blocks.each do |block_start|
|
64
47
|
|
65
|
-
|
48
|
+
function_block_locations << nila_file_contents.clone.each_index.select {|index| nila_file_contents[index] == block_start }
|
66
49
|
|
67
|
-
|
68
|
-
|
69
|
-
end_blocks << code_block_end
|
70
|
-
|
71
|
-
code_block_begin_string_split = modified_file_contents[code_block_begin].split(" ")
|
72
|
-
|
73
|
-
code_block_begin_string_split[0] = code_block_begin_string_split[0].reverse
|
74
|
-
|
75
|
-
code_block_begin_string = code_block_begin_string_split.join(" ")
|
50
|
+
end
|
76
51
|
|
77
|
-
|
52
|
+
function_block_locations = function_block_locations.flatten
|
78
53
|
|
79
|
-
|
80
|
-
|
81
|
-
puts "Function compilation failed!"
|
54
|
+
function_block_locations = [0,function_block_locations,-1].flatten.uniq
|
82
55
|
|
83
|
-
|
56
|
+
file_remains, code_blocks = extract_blocks(function_block_locations,final_modified_file_contents)
|
84
57
|
|
85
|
-
|
58
|
+
modified_code_blocks = []
|
86
59
|
|
87
|
-
|
60
|
+
code_blocks.each do |block|
|
88
61
|
|
89
|
-
|
62
|
+
modified_code_blocks << block.collect {|element| element.gsub("\n\t\nend\n\t\n","}#@$")}
|
90
63
|
|
91
|
-
|
64
|
+
end
|
92
65
|
|
93
|
-
|
66
|
+
code_blocks = modified_code_blocks.clone
|
94
67
|
|
95
|
-
|
68
|
+
named_code_blocks = code_blocks.clone.reject {|element| !replace_strings(element[0]).include?("def ")}
|
96
69
|
|
97
|
-
|
70
|
+
modified_code_blocks = []
|
98
71
|
|
99
|
-
|
72
|
+
code_blocks.each do |block|
|
100
73
|
|
101
|
-
|
74
|
+
modified_code_blocks << block.collect {|element| element.gsub("")}
|
102
75
|
|
103
|
-
|
76
|
+
end
|
104
77
|
|
105
|
-
|
78
|
+
unless named_code_blocks.empty?
|
106
79
|
|
107
80
|
codeblock_counter = 1
|
108
81
|
|
@@ -148,7 +121,10 @@ require_relative 'read_file_line_by_line'
|
|
148
121
|
|
149
122
|
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
150
123
|
|
151
|
-
|
124
|
+
named_functions = named_functions.reject {|element| element.empty?}
|
125
|
+
|
126
|
+
nested_functions = nested_functions.reject {|element| element.empty?}
|
152
127
|
|
128
|
+
return line_by_line_contents, named_functions, nested_functions
|
153
129
|
|
154
130
|
end
|
@@ -1,35 +1,58 @@
|
|
1
|
-
|
1
|
+
# This is the simplest and most important method on the whole Nilac source code. This protects user written
|
2
|
+
# strings from being overwritten during the compilation
|
2
3
|
|
3
|
-
|
4
|
+
def replace_strings(input_string)
|
4
5
|
|
5
|
-
|
6
|
+
element = input_string.gsub("==", "equalequal")
|
6
7
|
|
7
|
-
|
8
|
+
element = element.gsub("!=", "notequal")
|
8
9
|
|
9
|
-
|
10
|
+
element = element.gsub("+=", "plusequal")
|
10
11
|
|
11
|
-
|
12
|
+
element = element.gsub("-=", "minusequal")
|
12
13
|
|
13
|
-
|
14
|
+
element = element.gsub("*=", "multiequal")
|
14
15
|
|
15
|
-
|
16
|
+
element = element.gsub("/=", "divequal")
|
16
17
|
|
17
|
-
|
18
|
+
element = element.gsub("%=", "modequal")
|
18
19
|
|
19
|
-
|
20
|
+
element = element.gsub("=~", "matchequal")
|
20
21
|
|
21
|
-
|
22
|
+
element = element.gsub(">=", "greatequal")
|
22
23
|
|
23
|
-
|
24
|
+
input_string = element.gsub("<=", "lessyequal")
|
24
25
|
|
25
|
-
|
26
|
+
string_counter = 0
|
26
27
|
|
27
|
-
|
28
|
+
if input_string.count("\"") % 2 == 0
|
28
29
|
|
29
|
-
|
30
|
+
while input_string.include?("\"")
|
30
31
|
|
31
|
-
|
32
|
+
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
32
33
|
|
33
|
-
|
34
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
35
|
+
|
36
|
+
string_counter += 1
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
if input_string.count("'") % 2 == 0
|
43
|
+
|
44
|
+
while input_string.include?("'")
|
45
|
+
|
46
|
+
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
47
|
+
|
48
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
49
|
+
|
50
|
+
string_counter += 1
|
34
51
|
|
35
52
|
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
return input_string
|
57
|
+
|
58
|
+
end
|
data/lib/nilac/rollblocks.rb
CHANGED
@@ -1,16 +1,36 @@
|
|
1
|
-
|
1
|
+
require_relative 'replace_strings'
|
2
2
|
|
3
|
-
|
3
|
+
def extract_blocks(statement_indexes, input_file_contents,options = [])
|
4
4
|
|
5
|
-
|
5
|
+
possible_blocks = []
|
6
|
+
|
7
|
+
block_counter = 0
|
6
8
|
|
7
9
|
extracted_blocks = []
|
8
10
|
|
9
|
-
|
11
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("}#@$","\n\t\nend\n\t\n")}
|
12
|
+
|
13
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("};","\t\t}\n\t")} if options.length.eql?(5)
|
14
|
+
|
15
|
+
controlregexp = /(if |Euuf |while |for |def | do |class )/ if options.empty?
|
16
|
+
|
17
|
+
controlregexp = /(if |while |class |= function)/ if options.length.eql?(1)
|
18
|
+
|
19
|
+
controlregexp = /(if |while |def | do |class )/ if options.length.eql?(2)
|
20
|
+
|
21
|
+
controlregexp = /(Euuf |while |for | do |function )/ if options.length.eql?(5)
|
10
22
|
|
11
|
-
|
23
|
+
endexpr = "end" if options.empty?
|
12
24
|
|
13
|
-
|
25
|
+
endexpr = "};" if options.length.eql?(1)
|
26
|
+
|
27
|
+
endexpr = "end" if options.length.eql?(2)
|
28
|
+
|
29
|
+
endexpr = "}" if options.length.eql?(5)
|
30
|
+
|
31
|
+
for x in 0...statement_indexes.length-1
|
32
|
+
|
33
|
+
possible_blocks << input_file_contents[statement_indexes[x]..statement_indexes[x+1]]
|
14
34
|
|
15
35
|
end
|
16
36
|
|
@@ -20,7 +40,7 @@ def extract_blocks(statement_indexes, input_file_contents)
|
|
20
40
|
|
21
41
|
current_block = []
|
22
42
|
|
23
|
-
|
43
|
+
possible_blocks.each_with_index do |block|
|
24
44
|
|
25
45
|
unless current_block[-1] == block[0]
|
26
46
|
|
@@ -32,10 +52,9 @@ def extract_blocks(statement_indexes, input_file_contents)
|
|
32
52
|
|
33
53
|
end
|
34
54
|
|
35
|
-
|
36
55
|
current_block.each_with_index do |line, index|
|
37
56
|
|
38
|
-
if line.strip.eql?
|
57
|
+
if line.strip.eql? endexpr
|
39
58
|
|
40
59
|
end_counter += 1
|
41
60
|
|
@@ -55,7 +74,7 @@ def extract_blocks(statement_indexes, input_file_contents)
|
|
55
74
|
|
56
75
|
array_extract.each_with_index do |line|
|
57
76
|
|
58
|
-
break if (line.lstrip.index(controlregexp) != nil
|
77
|
+
break if (line.lstrip.index(controlregexp) != nil)
|
59
78
|
|
60
79
|
index_counter += 1
|
61
80
|
|
@@ -69,9 +88,9 @@ def extract_blocks(statement_indexes, input_file_contents)
|
|
69
88
|
|
70
89
|
block_end = current_block.index(block_extract[-1])
|
71
90
|
|
72
|
-
current_block[block_start..block_end] = "--
|
91
|
+
current_block[block_start..block_end] = "--block#{block_counter}"
|
73
92
|
|
74
|
-
|
93
|
+
block_counter += 1
|
75
94
|
|
76
95
|
end_counter = 0
|
77
96
|
|
@@ -79,7 +98,7 @@ def extract_blocks(statement_indexes, input_file_contents)
|
|
79
98
|
|
80
99
|
current_block.each_with_index do |line, index|
|
81
100
|
|
82
|
-
if line.strip.eql?
|
101
|
+
if line.strip.eql? endexpr
|
83
102
|
|
84
103
|
end_counter += 1
|
85
104
|
|
@@ -95,6 +114,60 @@ def extract_blocks(statement_indexes, input_file_contents)
|
|
95
114
|
|
96
115
|
end
|
97
116
|
|
117
|
+
modified_blocks = extracted_blocks.clone
|
118
|
+
|
119
|
+
modified_blocks.each_with_index do |block,index|
|
120
|
+
|
121
|
+
extracted_blocks[index] = block.collect {|element| element.gsub("\n\t\nend\n\t\n","}#@$")}
|
122
|
+
|
123
|
+
extracted_blocks[index] = block.collect {|element| element.gsub("\t\t}\n\t","};")}
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
if options.length == 5
|
128
|
+
|
129
|
+
output_blocks = extracted_blocks
|
130
|
+
|
131
|
+
main_block = extracted_blocks.reject {|element| !replace_strings(element[0]).index(/function /)}
|
132
|
+
|
133
|
+
return main_block.flatten,output_blocks
|
134
|
+
|
135
|
+
else
|
136
|
+
|
137
|
+
modified_rolled_blocks = []
|
138
|
+
|
139
|
+
rolled_blocks = extracted_blocks.reject {|element| !replace_strings(element.join).include?("--block")}
|
140
|
+
|
141
|
+
rolled_blocks.each do |block|
|
142
|
+
|
143
|
+
included_blocks = block.reject {|element| !replace_strings(element).include?("--block")}
|
144
|
+
|
145
|
+
matching_blocks = included_blocks.collect {|element| element.split("--block")[1].to_i}
|
146
|
+
|
147
|
+
while block.join.include?("--block")
|
148
|
+
|
149
|
+
block[block.index(included_blocks[0])] = extracted_blocks[matching_blocks[0]]
|
150
|
+
|
151
|
+
included_blocks.delete_at(0)
|
152
|
+
|
153
|
+
matching_blocks.delete_at(0)
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
modified_rolled_blocks << block
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
rolled_blocks.each_with_index do |block,index|
|
162
|
+
|
163
|
+
extracted_blocks[extracted_blocks.index(block)] = modified_rolled_blocks[index]
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
extracted_blocks = extracted_blocks.collect {|element| element.flatten}
|
168
|
+
|
98
169
|
return current_block, extracted_blocks
|
99
170
|
|
171
|
+
end
|
172
|
+
|
100
173
|
end
|
data/lib/nilac/version.rb
CHANGED