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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/README.md +2 -0
  4. data/examples/decBin.js +2 -2
  5. data/examples/repl.js +31 -0
  6. data/examples/repl.nila +24 -0
  7. data/lib/nilac/add_semicolons.rb +1 -1
  8. data/lib/nilac/compile_blocks.rb +20 -2
  9. data/lib/nilac/compile_case_statement.rb +1 -1
  10. data/lib/nilac/compile_conditional_structures.rb +20 -8
  11. data/lib/nilac/compile_custom_function_map.rb +3 -1
  12. data/lib/nilac/compile_default_values.rb +15 -1
  13. data/lib/nilac/compile_integers.rb +147 -2
  14. data/lib/nilac/compile_lambdas.rb +22 -6
  15. data/lib/nilac/compile_loops.rb +1 -1
  16. data/lib/nilac/compile_monkey_patching.rb +189 -0
  17. data/lib/nilac/compile_named_functions.rb +44 -70
  18. data/lib/nilac/compile_parallel_assignment.rb +2 -2
  19. data/lib/nilac/compile_ruby_methods.rb +3 -1
  20. data/lib/nilac/compile_strings.rb +4 -4
  21. data/lib/nilac/friendly_errors.rb +95 -0
  22. data/lib/nilac/get_variables.rb +29 -18
  23. data/lib/nilac/lexical_scoped_function_variables.rb +6 -0
  24. data/lib/nilac/output_javascript.rb +9 -7
  25. data/lib/nilac/paranthesis_compactor.rb +37 -0
  26. data/lib/nilac/pretty_print_javascript.rb +53 -61
  27. data/lib/nilac/replace_multiline_comments.rb +6 -2
  28. data/lib/nilac/replace_named_functions.rb +41 -65
  29. data/lib/nilac/replace_strings.rb +40 -17
  30. data/lib/nilac/rollblocks.rb +86 -13
  31. data/lib/nilac/version.rb +1 -1
  32. data/lib/nilac.rb +46 -13
  33. data/shark/features/blocks.feature +11 -0
  34. data/shark/features/monkey_patch.feature +11 -0
  35. data/shark/test_files/blocks.nila +18 -0
  36. data/shark/test_files/correct_blocks.js +25 -0
  37. data/shark/test_files/correct_case.js +1 -1
  38. data/shark/test_files/correct_monkey_patch.js +24 -0
  39. data/shark/test_files/correct_multiple_return.js +2 -2
  40. data/shark/test_files/correct_splats.js +3 -3
  41. data/shark/test_files/lambda.nila +9 -1
  42. data/shark/test_files/monkey_patch.nila +18 -0
  43. data/shark/test_files/multiple_return.nila +8 -8
  44. data/shark/test_files/sample_class.nila +1 -1
  45. metadata +13 -7
  46. data/LICENSE +0 -20
  47. data/examples/countdown.nila +0 -31
  48. data/lib/nilac/compile_classes.rb +0 -19
  49. data/shark/test_files/array_sugar.nila +0 -3
  50. 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 extract_blocks(file_contents)
47
+ def block_compactor(input_block)
48
48
 
49
- javascript_regexp = /(if |for |while |case |default:|switch\(|\(function\(|= function\(|,\s*function\(|((=|:)\s+\{))/
49
+ modified_block = input_block.reject {|element| element.strip.eql?("")}
50
50
 
51
- block_starting_lines = file_contents.dup.reject { |element| element.index(javascript_regexp).nil? }[1..-1]
51
+ modified_block = modified_block.collect {|element| element.rstrip + "\n"}
52
52
 
53
- block_starting_lines = block_starting_lines.reject { |element| element.include?(" ") }
53
+ return modified_block
54
54
 
55
- initial_starting_lines = block_starting_lines.dup
55
+ end
56
56
 
57
- starting_line_indices = []
57
+ main_block_numbers = [ ] if main_block_numbers.nil?
58
58
 
59
- block_starting_lines.each do |line|
59
+ unless main_block_numbers.empty?
60
60
 
61
- starting_line_indices << file_contents.index(line)
61
+ javascript_regexp = /(if |for |while |case |default:|switch\(|,function\(|\(function\(|= function\(|((=|:)\s+\{))/
62
62
 
63
- end
63
+ starting_locations = []
64
64
 
65
- block_ending_lines = file_contents.dup.each_index.select { |index| (file_contents[index].eql? " }\n" or file_contents[index].eql? " };\n" or file_contents[index].lstrip.eql?("});\n"))}
65
+ file_contents.each_with_index do |line, index|
66
66
 
67
- block_ending_lines = block_ending_lines.reject {|index| file_contents[index].include?(" ")}
67
+ if line.index(javascript_regexp) != nil
68
68
 
69
- modified_file_contents = file_contents.dup
69
+ starting_locations << index
70
70
 
71
- code_blocks = []
72
-
73
- starting_index = starting_line_indices[0]
71
+ end
74
72
 
75
- begin
73
+ end
76
74
 
77
- for x in 0...initial_starting_lines.length
75
+ remaining_contents, blocks = roll_blocks(file_contents,starting_locations)
78
76
 
79
- code_blocks << modified_file_contents[starting_index..block_ending_lines[0]]
77
+ modified_block = []
80
78
 
81
- modified_file_contents[starting_index..block_ending_lines[0]] = []
79
+ blocks.each do |block|
82
80
 
83
- modified_file_contents.insert(starting_index, " *****")
81
+ while block.join.include?("--block")
84
82
 
85
- block_starting_lines = modified_file_contents.dup.reject { |element| element.index(javascript_regexp).nil? }[1..-1]
83
+ nested_blocks = block.reject {|element| !replace_strings(element).include?("--block")}
86
84
 
87
- block_starting_lines = block_starting_lines.reject { |element| element.include?(" ") }
85
+ block_numbers = nested_blocks.collect {|element| element.strip.split("--block")[1].to_i}
88
86
 
89
- starting_line_indices = []
87
+ block_numbers.each_with_index do |number,index|
90
88
 
91
- block_starting_lines.each do |line|
89
+ location = block.index(nested_blocks[index])
92
90
 
93
- starting_line_indices << modified_file_contents.index(line)
91
+ block[location] = blocks[number]
94
92
 
95
93
  end
96
94
 
97
- block_ending_lines = modified_file_contents.dup.each_index.select { |index| (modified_file_contents[index].eql? " }\n" or modified_file_contents[index].eql? " };\n" or modified_file_contents[index].lstrip.eql?("});\n")) }
98
-
99
- starting_index = starting_line_indices[0]
95
+ block = block.flatten
100
96
 
101
97
  end
102
98
 
103
- #rescue TypeError
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
- return modified_file_contents, code_blocks
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
- compact_contents, code_blocks = extract_blocks(compact_contents)
105
+ remaining_contents = remaining_contents.reject {|element| element.strip.eql?("")}
120
106
 
121
- processed_contents = compact_contents[1...-1].collect { |line| line+"\n" }
107
+ remaining_contents = [remaining_contents[0]] + remaining_contents[1...-1].collect {|element| element + "\n"} + [remaining_contents[-1]]
122
108
 
123
- compact_contents = [compact_contents[0]] + processed_contents + [compact_contents[-1]]
109
+ main_block_numbers.each do |number|
124
110
 
125
- code_block_locations = compact_contents.each_index.select { |index| compact_contents[index].eql? " *****\n" }
111
+ correct_block = block_compactor(modified_block[number])
126
112
 
127
- initial_locations = code_block_locations.dup
113
+ correct_block << "\n"
128
114
 
129
- starting_index = code_block_locations[0]
115
+ remaining_contents[remaining_contents.index("--block#{number}\n\n")] = correct_block
130
116
 
131
- for x in 0...initial_locations.length
117
+ end
132
118
 
133
- code_blocks[x][-1] = code_blocks[x][-1] + "\n"
119
+ remaining_contents = remaining_contents.flatten
134
120
 
135
- compact_contents = compact_contents[0...starting_index] + code_blocks[x] + compact_contents[starting_index+1..-1]
121
+ else
136
122
 
137
- code_block_locations = compact_contents.each_index.select { |index| compact_contents[index].eql? " *****\n" }
123
+ remaining_contents = block_compactor(file_contents)
138
124
 
139
- starting_index = code_block_locations[0]
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
- return compact_contents
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.each_with_index do |block|
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.lstrip.eql? "}\n" or line.lstrip.eql?("};\n") or line.lstrip.include?("_!;\n") or line.lstrip.include?("});\n")
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.lstrip.eql? "}\n" or line.lstrip.eql?("};\n") or line.lstrip.include?("_!;\n") or line.lstrip.include?("});\n")
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
- joined_file_contents = joined_file_contents.sub(block_id, modified_blocks[index])
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
- def extract_array(input_array, start_index, end_index)
6
-
7
- return input_array[start_index..end_index]
8
-
9
- end
8
+ final_modified_file_contents = nila_file_contents.clone
10
9
 
11
- end_locations = []
10
+ joined_file_contents = final_modified_file_contents.join
12
11
 
13
- key_word_locations = []
12
+ modified_file_contents = []
14
13
 
15
- start_blocks = []
14
+ rand_number = []
16
15
 
17
- end_blocks = []
16
+ nila_file_contents.each do |content|
18
17
 
19
- nila_regexp = /(def )/
18
+ if replace_strings(content).include?("def ")
20
19
 
21
- named_code_blocks = []
20
+ rand_num = rand(1..25)
22
21
 
23
- for x in 0...nila_file_contents.length
22
+ while rand_number.include?(rand_num)
24
23
 
25
- current_row = nila_file_contents[x]
24
+ rand_num = rand(1..10)
26
25
 
27
- if current_row.index(nila_regexp) != nil
26
+ end
28
27
 
29
- key_word_locations << x
28
+ modified_file_contents << content.sub("def ","#{" "*rand_num}def ")
30
29
 
31
- elsif current_row.lstrip.eql?("end\n") || current_row.strip.eql?("end")
30
+ rand_number << rand_num
32
31
 
33
- end_locations << x
32
+ else
34
33
 
34
+ modified_file_contents << content
35
35
 
36
36
  end
37
37
 
38
-
39
38
  end
40
39
 
41
- unless key_word_locations.empty?
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
- current_string = modified_file_contents[finder_location]
42
+ possible_function_blocks = nila_file_contents.reject {|element| !replace_strings(element).include?("def ")}
60
43
 
61
- end
44
+ function_block_locations = []
62
45
 
63
- code_block_begin = finder_location
46
+ possible_function_blocks.each do |block_start|
64
47
 
65
- code_block_end = current_location
48
+ function_block_locations << nila_file_contents.clone.each_index.select {|index| nila_file_contents[index] == block_start }
66
49
 
67
- start_blocks << code_block_begin
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
- modified_file_contents[code_block_begin] = code_block_begin_string
52
+ function_block_locations = function_block_locations.flatten
78
53
 
79
- rescue NoMethodError
80
-
81
- puts "Function compilation failed!"
54
+ function_block_locations = [0,function_block_locations,-1].flatten.uniq
82
55
 
83
- end
56
+ file_remains, code_blocks = extract_blocks(function_block_locations,final_modified_file_contents)
84
57
 
85
- end
58
+ modified_code_blocks = []
86
59
 
87
- final_modified_file_contents = nila_file_contents.dup
60
+ code_blocks.each do |block|
88
61
 
89
- joined_file_contents = final_modified_file_contents.join
62
+ modified_code_blocks << block.collect {|element| element.gsub("\n\t\nend\n\t\n","}#@$")}
90
63
 
91
- while start_blocks.length != 0
64
+ end
92
65
 
93
- top_most_level = start_blocks.min
66
+ code_blocks = modified_code_blocks.clone
94
67
 
95
- top_most_level_index = start_blocks.index(top_most_level)
68
+ named_code_blocks = code_blocks.clone.reject {|element| !replace_strings(element[0]).include?("def ")}
96
69
 
97
- matching_level = end_blocks[top_most_level_index]
70
+ modified_code_blocks = []
98
71
 
99
- named_code_blocks << extract_array(final_modified_file_contents, top_most_level, matching_level)
72
+ code_blocks.each do |block|
100
73
 
101
- start_blocks.delete_at(top_most_level_index)
74
+ modified_code_blocks << block.collect {|element| element.gsub("")}
102
75
 
103
- end_blocks.delete(matching_level)
76
+ end
104
77
 
105
- end
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
- return line_by_line_contents, named_functions, nested_functions
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
- def replace_strings(input_string)
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
- string_counter = 0
4
+ def replace_strings(input_string)
4
5
 
5
- if input_string.count("\"") % 2 == 0
6
+ element = input_string.gsub("==", "equalequal")
6
7
 
7
- while input_string.include?("\"")
8
+ element = element.gsub("!=", "notequal")
8
9
 
9
- string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
10
+ element = element.gsub("+=", "plusequal")
10
11
 
11
- input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
12
+ element = element.gsub("-=", "minusequal")
12
13
 
13
- string_counter += 1
14
+ element = element.gsub("*=", "multiequal")
14
15
 
15
- end
16
+ element = element.gsub("/=", "divequal")
16
17
 
17
- end
18
+ element = element.gsub("%=", "modequal")
18
19
 
19
- if input_string.count("'") % 2 == 0
20
+ element = element.gsub("=~", "matchequal")
20
21
 
21
- while input_string.include?("'")
22
+ element = element.gsub(">=", "greatequal")
22
23
 
23
- string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
24
+ input_string = element.gsub("<=", "lessyequal")
24
25
 
25
- input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
26
+ string_counter = 0
26
27
 
27
- string_counter += 1
28
+ if input_string.count("\"") % 2 == 0
28
29
 
29
- end
30
+ while input_string.include?("\"")
30
31
 
31
- end
32
+ string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
32
33
 
33
- return input_string
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
@@ -1,16 +1,36 @@
1
- def extract_blocks(statement_indexes, input_file_contents)
1
+ require_relative 'replace_strings'
2
2
 
3
- possible_if_blocks = []
3
+ def extract_blocks(statement_indexes, input_file_contents,options = [])
4
4
 
5
- if_block_counter = 0
5
+ possible_blocks = []
6
+
7
+ block_counter = 0
6
8
 
7
9
  extracted_blocks = []
8
10
 
9
- controlregexp = /(if |while |def | do )/
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
- for x in 0...if_statement_indexes.length-1
23
+ endexpr = "end" if options.empty?
12
24
 
13
- possible_if_blocks << input_file_contents[if_statement_indexes[x]..if_statement_indexes[x+1]]
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
- possible_if_blocks.each_with_index do |block|
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? "end"
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 and line.lstrip.index(rejectionregexp).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] = "--ifblock#{if_block_counter}"
91
+ current_block[block_start..block_end] = "--block#{block_counter}"
73
92
 
74
- if_block_counter += 1
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? "end"
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
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.3.9.6"
2
+ VERSION = "0.0.4.3.9.7"
3
3
  end