lib/nilac/compile_lambdas.rb in nilac-0.0.4.3.9.7.1 vs lib/nilac/compile_lambdas.rb in nilac-0.0.4.3.9.8

- old
+ new

@@ -10,12 +10,20 @@ # This method compiles a single lambda into a Javascript function expression if parameterless - block_contents = input_block[3...-1] + if input_block[0] = "{" and input_block[-1] = "}" + block_contents = input_block[1...-1] + + else + + block_contents = input_block[3...-1] + + end + compiled_lambda = "function() {\n\n #{block_contents.strip} \n\n}" else block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2) @@ -46,12 +54,14 @@ end input_file_contents = input_file_contents.collect {|element| (replace_strings(element).include?(" -> ") ? element.gsub(" -> "," lambda ") : element)} - input_file_contents = input_file_contents.collect {|element| element.gsub("append","appand")} + input_file_contents = input_file_contents.collect {|element| element.gsub("document","decccccumennt")} + input_file_contents = input_file_contents.collect {|element| element.gsub("append","appand").gsub(" do"," do ").gsub("do "," do ")} + possible_lambdas = input_file_contents.reject {|line| !replace_strings(line).include?("lambda")} possible_lambdas = possible_lambdas.reject {|line| line.index(/\s*do\s*/) == nil} lambda_names = [] @@ -72,11 +82,11 @@ end loop_extract = input_file_contents[starting_counter..index_counter] - var_name,block = loop_extract.join.split(/\s*do/) + var_name,block = loop_extract.join.split(/\s*do\s+/) var_name = var_name.split(/\s*=\s*lambda/)[0].strip block = block.split("end")[0] @@ -90,20 +100,22 @@ possible_lambdas = input_file_contents.reject{ |element| element.index(/lambda\s*(blockky)?\s*/) == nil} possible_lambdas = possible_lambdas.reject {|element| !element.include?("{") and !element.include?("}")} - possible_lambdas = possible_lambdas.collect {|element| element.gsub(/lambda\s*\{/,"lambda !_{")} - modified_file_contents = input_file_contents.clone unless possible_lambdas.empty? - possible_lambdas.each do |loop| + original_loops = possible_lambdas.clone - original_loop = loop.clone + possible_lambdas = possible_lambdas.collect {|element| element.gsub(/lambda\s*\{/,"lambda !_{")} + possible_lambdas.each_with_index do |loop,index| + + original_loop = original_loops[index] + string_counter = 1 extracted_string = [] while loop.include?("\"") @@ -180,16 +192,20 @@ replacement_array[-1] = replacement_array[-1].sub("}","\n-%%-") replacement_string = replacement_array.join - modified_file_contents[input_file_contents.index(original_loop)] = replacement_string[-1].eql?(";") ? replacement_string : replacement_string + ";" + replacement_string = replacement_string[-1].eql?(";") ? replacement_string : (replacement_string + ";") + modified_file_contents[input_file_contents.index(original_loop)] = (replacement_string + "\n\n") + end end modified_file_contents = modified_file_contents.collect {|element| element.gsub("appand","append")} + + modified_file_contents = modified_file_contents.collect {|element| element.gsub("decccccumennt","document")} file_id = open(temporary_nila_file, 'w') file_id.write(modified_file_contents.join) \ No newline at end of file