bin/nilac in nilac-0.0.3 vs bin/nilac in nilac-0.0.3.1
- old
+ new
@@ -20,10 +20,11 @@
return file_line_by_line
end
+
def extract_parsable_array(input_file_contents)
#This method finds and removes the __END__ keyword and the following lines in a Nila file.
modified_file_contents = input_file_contents.dup
@@ -153,16 +154,12 @@
file_id2 = open(output_js_file, 'w')
file_id.write(modified_file_contents)
- file_id2.write("//Written in Nila and compiled to Javascript. Have fun!\n\n")
-
file_id.close()
- file_id2.close()
-
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
comments = multiline_comments.dup
return line_by_line_contents,comments,temporary_nila_file,output_js_file
@@ -207,10 +204,87 @@
return modified_file_contents
end
+ def compile_heredoc_strings(input_file_contents,temporary_nila_file)
+
+ #This method will compile all the Heredoc strings in Nila into pure
+ #Javascript strings. Ruby has two types of Heredocs. Currently, Nila doesn't support both of them.
+ #Here is an example of what Nila supports
+
+ #long_passage = <<-ipsumtext
+ #
+ #Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
+ #incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
+ #exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
+ #irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+ #pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
+ #deserunt mollit anim id est laborum.
+ #
+ #ipsumtext
+
+ def find_all_matching_indices(input_string,pattern)
+
+ locations = []
+
+ index = input_string.index(pattern)
+
+ while index != nil
+
+ locations << index
+
+ index = input_string.index(pattern,index+1)
+
+
+ end
+
+ return locations
+
+
+ end
+
+ preserve_formatting = %w{ \n \t }
+
+ joined_file_contents = input_file_contents.join
+
+ modified_file_contents = joined_file_contents.dup
+
+ heredoc_start_locations = find_all_matching_indices(joined_file_contents,"<<-")
+
+ heredoc_start_locations.each do |location|
+
+ string_extract = joined_file_contents[location..-1]
+
+ end_of_first_line = string_extract.index("\n")
+
+ name_of_heredoc = string_extract[3...end_of_first_line].rstrip
+
+ heredoc_start,heredoc_end = find_all_matching_indices(string_extract,name_of_heredoc)
+
+ heredoc = string_extract[heredoc_start..heredoc_end+name_of_heredoc.length-1]
+
+ heredoc_content = heredoc.split(name_of_heredoc)
+
+ heredoc_content = heredoc_content[1].lstrip.rstrip.gsub("\n","\\n").gsub("\t","\\t")
+
+ modified_file_contents = modified_file_contents.sub(string_extract[heredoc_start-3..heredoc_end+name_of_heredoc.length-1],"\""+heredoc_content+"\"")
+
+ end
+
+ file_id = open(temporary_nila_file, 'w')
+
+ file_id.write(modified_file_contents)
+
+ file_id.close()
+
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
+
+ return line_by_line_contents
+
+ end
+
def compile_interpolated_strings(input_file_contents)
modified_file_contents = input_file_contents.dup
input_file_contents.each_with_index do |line,index|
@@ -468,14 +542,18 @@
file_id.close()
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
- variable_declaration_string = "var " + variables.uniq.join(", ") + "\n\n"
+ if variables.length > 0
- line_by_line_contents = [variable_declaration_string,line_by_line_contents].flatten
+ variable_declaration_string = "var " + variables.uniq.join(", ") + "\n\n"
+ line_by_line_contents = [variable_declaration_string,line_by_line_contents].flatten
+
+ end
+
return variables.uniq,line_by_line_contents
end
def remove_question_marks(input_file_contents,variable_list,temporary_nila_file)
@@ -1332,11 +1410,11 @@
file_contents,multiline_comments,temp_file,output_js_file = replace_multiline_comments(file_contents,input_file_path)
file_contents = split_semicolon_seperated_expressions(file_contents)
- #file_contents = compile_heredoc_strings(file_contents,temp_file)
+ file_contents = compile_heredoc_strings(file_contents,temp_file)
file_contents = compile_interpolated_strings(file_contents)
file_contents,singleline_comments = replace_singleline_comments(file_contents)
@@ -1475,14 +1553,7 @@
puts "Build Successful!"
end
- opts.on("-v", "--version", "Version of Nilac") do
-
- version_number = "0.0.1"
-
- puts "Current Nilac Version: #{version_number}"
-
- end
end.parse!