lib/nilac/compile_arrays.rb in nilac-0.0.4.3.9.7.1 vs lib/nilac/compile_arrays.rb in nilac-0.0.4.3.9.8
- old
+ new
@@ -1,10 +1,9 @@
require_relative 'find_all_matching_indices'
-
require_relative 'read_file_line_by_line'
-
require_relative 'compile_interpolated_strings'
+require_relative 'replace_strings'
def compile_arrays(input_file_contents, named_functions, temporary_nila_file)
def compile_w_arrays(input_file_contents)
@@ -38,14 +37,24 @@
modified_file_contents = input_file_contents.dup
input_file_contents.each_with_index do |line, index|
- if line.include?("%w{")
+ if line.include?("%w")
- string_arrays = extract(line, "%w{", "}")
+ start_delimiter = close_delimiter = line[line.index("%w")+2]
+ close_delimiter = "}" if start_delimiter.eql?("{")
+
+ close_delimiter = ")" if start_delimiter.eql?("(")
+
+ close_delimiter = ">" if start_delimiter.eql?("<")
+
+ close_delimiter = "]" if start_delimiter.eql?("[")
+
+ string_arrays = extract(line, "%w#{start_delimiter}", "#{close_delimiter}")
+
string_arrays.each do |array|
modified_file_contents[index] = modified_file_contents[index].sub(array, compile_w_syntax(array))
end
@@ -146,10 +155,12 @@
end
triple_range_indexes = triple_range_indexes.flatten
+ triple_range_indexes = triple_range_indexes.uniq
+
triple_range_indexing.each_with_index do |line, index|
split1, split2 = line.split("[")
range_index, split3 = split2.split("]")
@@ -185,10 +196,12 @@
double_range_indexes << input_file_contents.dup.each_index.select { |index| input_file_contents[index] == line }
end
double_range_indexes = double_range_indexes.flatten
+
+ double_range_indexes = double_range_indexes.uniq
double_range_indexing.each_with_index do |line, index|
split1, split2 = line.split("[")
@@ -212,11 +225,11 @@
replacement_string = split1 + ".slice(0)\n"
else
- replacement_string = split1 + ".slice(#{index_start},#{index_end}+1)\n"
+ replacement_string = split1 + ".slice(#{index_start},#{(index_end.to_i+1).to_s})\n"
end
possible_range_indexing.delete(input_file_contents[double_range_indexes[index]])
@@ -246,10 +259,28 @@
return input_file_contents
end
+ def compile_array_slicing(input_file_contents)
+
+ possible_slicing_operation = input_file_contents.reject {|element| !replace_strings(element).include?(".slice")}
+
+ possible_slicing_operation.each do |element|
+
+ if replace_strings(element).include?(",last")
+
+ input_file_contents[input_file_contents.index(element)] = input_file_contents[input_file_contents.index(element)].gsub(",last","")
+
+ end
+
+ end
+
+ return input_file_contents
+
+ end
+
def compile_multiline(input_file_contents, temporary_nila_file)
possible_arrays = input_file_contents.reject { |element| !element.include?("[") }
possible_multiline_arrays = possible_arrays.reject { |element| element.include?("]") }
@@ -321,9 +352,11 @@
input_file_contents = compile_w_arrays(input_file_contents)
input_file_contents = compile_capital_w_arrays(input_file_contents)
input_file_contents = compile_array_indexing(input_file_contents)
+
+ input_file_contents = compile_array_slicing(input_file_contents)
input_file_contents = compile_multiline(input_file_contents, temporary_nila_file)
input_file_contents = compile_array_operators(input_file_contents)
\ No newline at end of file