lib/nilac/compile_operators.rb in nilac-0.0.4.3.9.4 vs lib/nilac/compile_operators.rb in nilac-0.0.4.3.9.5
- old
+ new
@@ -1,83 +1,89 @@
- def compile_operators(input_file_contents)
+require_relative 'compile_existential_operator'
- def compile_power_operator(input_string)
+def compile_operators(input_file_contents)
- matches = input_string.scan(/(\w{1,}\*\*\w{1,})/).to_a.flatten
+ def compile_power_operator(input_string)
- unless matches.empty?
+ matches = input_string.scan(/(\w{1,}\*\*\w{1,})/).to_a.flatten
- matches.each do |match|
+ unless matches.empty?
- left, right = match.split("**")
+ matches.each do |match|
- input_string = input_string.sub(match, "Math.pow(#{left},#{right})")
+ left, right = match.split("**")
- end
+ input_string = input_string.sub(match, "Math.pow(#{left},#{right})")
end
- return input_string
-
end
- def compile_match_operator(input_string)
+ return input_string
- rejection_exp = /( aannddy | orriioo |nnoottyy )/
+ end
- if input_string.include?("=~")
+ def compile_match_operator(input_string)
- input_string = input_string.gsub(" && "," aannddy ").gsub(" || "," orriioo ").gsub("!","nnoottyy")
+ rejection_exp = /( aannddy | orriioo |nnoottyy )/
- left, right = input_string.split("=~")
+ if input_string.include?("=~")
- if left.index(rejection_exp) != nil
+ input_string = input_string.gsub(" && ", " aannddy ").gsub(" || ", " orriioo ").gsub("!", "nnoottyy")
- left = left[left.index(rejection_exp)..-1]
+ left, right = input_string.split("=~")
- elsif left.index(/\(/)
+ if left.index(rejection_exp) != nil
- left = left[left.index(/\(/)+1..-1]
+ left = left[left.index(rejection_exp)..-1]
- end
+ elsif left.index(/\(/)
- if right.index(rejection_exp) != nil
+ left = left[left.index(/\(/)+1..-1]
- right = right[0...right.index(rejection_exp)]
+ end
- elsif right.index(/\)/)
+ if right.index(rejection_exp) != nil
- right = right[0...right.index(/\)/)]
+ right = right[0...right.index(rejection_exp)]
- end
+ elsif right.index(/\)/)
- original_string = "#{left}=~#{right}"
+ right = right[0...right.index(/\)/)]
- replacement_string = "#{left.rstrip} = #{left.rstrip}.match(#{right.lstrip.rstrip})"
+ end
- input_string = input_string.sub(original_string,replacement_string)
+ original_string = "#{left}=~#{right}"
- input_string = input_string.gsub(" aannddy "," && ").gsub(" orriioo "," || ").gsub("nnoottyy","!")
+ replacement_string = "#{left.rstrip} = #{left.rstrip}.match(#{right.lstrip.rstrip})"
- end
+ input_string = input_string.sub(original_string, replacement_string)
- return input_string
+ input_string = input_string.gsub(" aannddy ", " && ").gsub(" orriioo ", " || ").gsub("nnoottyy", "!")
end
- input_file_contents = input_file_contents.collect { |element| element.sub("==", "===") }
+ return input_string
- input_file_contents = input_file_contents.collect { |element| element.sub("!=", "!==") }
+ end
- input_file_contents = input_file_contents.collect { |element| element.sub("equequ", "==") }
+ input_file_contents = input_file_contents.collect { |element| element.sub("==", "===") }
- input_file_contents = input_file_contents.collect { |element| element.sub("elsuf", "else if") }
+ input_file_contents = input_file_contents.collect { |element| element.sub("!=", "!==") }
- input_file_contents = input_file_contents.collect { |element| compile_power_operator(element) }
+ input_file_contents = input_file_contents.collect { |element| element.sub("equequ", "==") }
- input_file_contents = input_file_contents.collect {|element| compile_match_operator(element)}
+ input_file_contents = input_file_contents.collect { |element| element.sub("elsuf", "else if") }
- input_file_contents = input_file_contents.collect {|element| element.gsub("_!;",";")}
+ input_file_contents = compile_existential_operators(input_file_contents)
- return input_file_contents
+ input_file_contents = compile_undefined_operator(input_file_contents)
- end
+ input_file_contents = input_file_contents.collect { |element| compile_power_operator(element) }
+
+ input_file_contents = input_file_contents.collect { |element| compile_match_operator(element) }
+
+ input_file_contents = input_file_contents.collect { |element| element.gsub("_!;", ";") }
+
+ return input_file_contents
+
+end
\ No newline at end of file