bin/nilac in nilac-0.0.4.1.1 vs bin/nilac in nilac-0.0.4.1.2

- old
+ new

@@ -317,101 +317,112 @@ end end - modified_file_contents = nila_file_contents.dup + unless key_word_locations.empty? - for y in 0...end_locations.length + modified_file_contents = nila_file_contents.dup - current_location = end_locations[y] + for y in 0...end_locations.length - current_string = modified_file_contents[current_location] + current_location = end_locations[y] - finder_location = current_location + current_string = modified_file_contents[current_location] - begin + finder_location = current_location - while current_string.index(nila_regexp) == nil + begin - finder_location -= 1 + while current_string.index(nila_regexp) == nil - current_string = modified_file_contents[finder_location] + finder_location -= 1 - end + current_string = modified_file_contents[finder_location] - code_block_begin = finder_location + end - code_block_end = current_location + code_block_begin = finder_location - start_blocks << code_block_begin + code_block_end = current_location - end_blocks << code_block_end + start_blocks << code_block_begin - code_block_begin_string_split = modified_file_contents[code_block_begin].split(" ") + end_blocks << code_block_end - code_block_begin_string_split[0] = code_block_begin_string_split[0].reverse + code_block_begin_string_split = modified_file_contents[code_block_begin].split(" ") - code_block_begin_string = code_block_begin_string_split.join(" ") + code_block_begin_string_split[0] = code_block_begin_string_split[0].reverse - modified_file_contents[code_block_begin] = code_block_begin_string + code_block_begin_string = code_block_begin_string_split.join(" ") - rescue NoMethodError + modified_file_contents[code_block_begin] = code_block_begin_string - puts "Function compilation failed!" + rescue NoMethodError + puts "Function compilation failed!" + + end + end - end + final_modified_file_contents = nila_file_contents.dup - final_modified_file_contents = nila_file_contents.dup + joined_file_contents = final_modified_file_contents.join - joined_file_contents = final_modified_file_contents.join + while start_blocks.length != 0 - while start_blocks.length != 0 + top_most_level = start_blocks.min - top_most_level = start_blocks.min + top_most_level_index = start_blocks.index(top_most_level) - top_most_level_index = start_blocks.index(top_most_level) + matching_level = end_blocks[top_most_level_index] - matching_level = end_blocks[top_most_level_index] + named_code_blocks << extract_array(final_modified_file_contents,top_most_level,matching_level) - named_code_blocks << extract_array(final_modified_file_contents,top_most_level,matching_level) + start_blocks.delete_at(top_most_level_index) - start_blocks.delete_at(top_most_level_index) + end_blocks.delete(matching_level) - end_blocks.delete(matching_level) + end - end + codeblock_counter = 1 - codeblock_counter = 1 + named_functions = named_code_blocks.dup - named_functions = named_code_blocks.dup + nested_functions = [] - nested_functions = [] + named_code_blocks.each do |codeblock| - named_code_blocks.each do |codeblock| + if joined_file_contents.include?(codeblock.join) - if joined_file_contents.include?(codeblock.join) + joined_file_contents = joined_file_contents.sub(codeblock.join,"--named_function[#{codeblock_counter}]\n") - joined_file_contents = joined_file_contents.sub(codeblock.join,"--named_function[#{codeblock_counter}]\n") + codeblock_counter += 1 - codeblock_counter += 1 + nested_functions = nested_functions + [[]] - nested_functions = nested_functions + [[]] + else - else + nested_functions[codeblock_counter-2] << codeblock - nested_functions[codeblock_counter-2] << codeblock + named_functions.delete(codeblock) - named_functions.delete(codeblock) + end end - end + else + joined_file_contents = nila_file_contents.join + named_functions = [] + + nested_functions = [] + + end + file_id = open(temporary_nila_file, 'w') file_id.write(joined_file_contents) file_id.close() @@ -555,10 +566,14 @@ def get_variables(input_file_contents,temporary_nila_file) variables = [] + input_file_contents = input_file_contents.collect {|element| element.gsub("==","equalequal")} + + input_file_contents = input_file_contents.collect {|element| element.gsub("!=","notequal")} + input_file_contents = input_file_contents.collect {|element| element.gsub("+=","plusequal")} input_file_contents = input_file_contents.collect {|element| element.gsub("-=","minusequal")} input_file_contents = input_file_contents.collect {|element| element.gsub("*=","multiequal")} @@ -621,10 +636,14 @@ line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("divequal","/=")} line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("modequal","%=")} + line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("equalequal","==")} + + line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("notequal","!=")} + return variables.uniq,line_by_line_contents end def remove_question_marks(input_file_contents,variable_list,temporary_nila_file) @@ -1248,34 +1267,42 @@ end joined_file_contents = input_file_contents.join - codeblock_counter = 1 + unless named_code_blocks.empty? - function_names = [] + codeblock_counter = 1 - named_code_blocks.each do |codeblock| + function_names = [] - function_names[codeblock_counter-1] = [] + named_code_blocks.each do |codeblock| - joined_file_contents = joined_file_contents.sub("--named_function[#{codeblock_counter}]\n",compile_function(codeblock,temporary_nila_file).join) + function_names[codeblock_counter-1] = [] - codeblock_counter += 1 + joined_file_contents = joined_file_contents.sub("--named_function[#{codeblock_counter}]\n",compile_function(codeblock,temporary_nila_file).join) - current_nested_functions = nested_functions[codeblock_counter-2] + codeblock_counter += 1 - function_names[codeblock_counter-2] << extract_function_name(codeblock) + current_nested_functions = nested_functions[codeblock_counter-2] - current_nested_functions.each do |nested_function| + function_names[codeblock_counter-2] << extract_function_name(codeblock) - function_names[codeblock_counter-2] << extract_function_name(nested_function) + current_nested_functions.each do |nested_function| - joined_file_contents = joined_file_contents.sub(nested_function.join,compile_function(nested_function,temporary_nila_file).join) + function_names[codeblock_counter-2] << extract_function_name(nested_function) + joined_file_contents = joined_file_contents.sub(nested_function.join,compile_function(nested_function,temporary_nila_file).join) + + end + end + else + + function_names = [] + end file_id = open(temporary_nila_file, 'w') file_id.write(joined_file_contents) @@ -1510,11 +1537,11 @@ current_block += block current_block.each_with_index do |line,index| - if line.lstrip.eql? "end\n" + if line.strip.eql? "end" end_counter += 1 end_index << index @@ -1554,11 +1581,11 @@ end_index = [] current_block.each_with_index do |line,index| - if line.lstrip.eql? "end\n" + if line.strip.eql? "end" end_counter += 1 end_index << index @@ -1576,10 +1603,36 @@ end def compile_if_syntax(input_block) + strings = [] + + string_counter = 0 + + modified_input_block = input_block.dup + + input_block.each_with_index do |line,index| + + if line.include?("\"") + + opening_quotes = line.index("\"") + + string_extract = line[opening_quotes..line.index("\"",opening_quotes+1)] + + strings << string_extract + + modified_input_block[index] = modified_input_block[index].sub(string_extract,"--string{#{string_counter}}") + + string_counter += 1 + + end + + end + + input_block = modified_input_block + starting_line = input_block[0] starting_line = starting_line + "\n" if starting_line.lstrip == starting_line junk,condition = starting_line.split("if") @@ -1604,12 +1657,28 @@ input_block[input_block.index(statement)] = "} else {\n" end - return input_block + modified_input_block = input_block.dup + input_block.each_with_index do |line,index| + + if line.include?("--string{") + + junk,remains = line.split("--string{") + + string_index,junk = remains.split("}") + + modified_input_block[index] = modified_input_block[index].sub("--string{#{string_index.strip}}",strings[string_index.strip.to_i]) + + end + + end + + return modified_input_block + end input_file_contents = input_file_contents.collect {|element| element.sub("elsif","elsuf")} possible_if_statements = input_file_contents.reject {|element| !element.include?("if")} @@ -2438,10 +2507,10 @@ return remaining_string[0...remaining_string.length-path_finder] end -nilac_version = "0.0.4.1" +nilac_version = "0.0.4.1.2" opts = Slop.parse do on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":" on :h, :help, 'Help With Nilac' do