nilac 0.0.4.3.9.2 → 0.0.4.3.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/nilac +9 -5748
- data/examples/StringMagic.nila +23 -0
- data/examples/countdown.nila +31 -0
- data/examples/decBin.nila +3 -3
- data/examples/marky.js +30 -0
- data/examples/marky.nila +23 -0
- data/lib/nilac/ErrorDeclarations.rb +11 -0
- data/lib/nilac/add_semicolons.rb +57 -0
- data/lib/nilac/compile_arrays.rb +266 -0
- data/lib/nilac/compile_blocks.rb +137 -0
- data/lib/nilac/compile_case_statement.rb +168 -0
- data/lib/nilac/compile_classes.rb +18 -0
- data/lib/nilac/compile_comments.rb +79 -0
- data/lib/nilac/compile_conditional_structures.rb +1378 -0
- data/lib/nilac/compile_custom_function_map.rb +45 -0
- data/lib/nilac/compile_default_values.rb +160 -0
- data/lib/nilac/compile_hashes.rb +123 -0
- data/lib/nilac/compile_heredocs.rb +62 -0
- data/lib/nilac/compile_integers.rb +23 -0
- data/lib/nilac/compile_interpolated_strings.rb +133 -0
- data/lib/nilac/compile_loops.rb +211 -0
- data/lib/nilac/compile_named_functions.rb +690 -0
- data/lib/nilac/compile_operators.rb +83 -0
- data/lib/nilac/compile_parallel_assignment.rb +103 -0
- data/lib/nilac/compile_ruby_methods.rb +58 -0
- data/lib/nilac/compile_special_keywords.rb +44 -0
- data/lib/nilac/compile_strings.rb +145 -0
- data/lib/nilac/compile_whitespace_delimited_functions.rb +97 -0
- data/lib/nilac/create_mac_executable.rb +25 -0
- data/lib/nilac/extract_parsable_file.rb +23 -0
- data/lib/nilac/find_all_matching_indices.rb +18 -0
- data/lib/nilac/find_file_name.rb +13 -0
- data/lib/nilac/find_file_path.rb +13 -0
- data/lib/nilac/get_variables.rb +123 -0
- data/lib/nilac/output_javascript.rb +13 -0
- data/lib/nilac/parse_arguments.rb +41 -0
- data/lib/nilac/pretty_print_javascript.rb +457 -0
- data/lib/nilac/read_file_line_by_line.rb +11 -0
- data/lib/nilac/remove_question_marks.rb +46 -0
- data/lib/nilac/replace_multiline_comments.rb +92 -0
- data/lib/nilac/replace_named_functions.rb +154 -0
- data/lib/nilac/replace_singleline_comments.rb +45 -0
- data/lib/nilac/replace_strings.rb +35 -0
- data/lib/nilac/split_semicolon_seperated_expressions.rb +39 -0
- data/lib/nilac/strToArray.rb +15 -0
- data/lib/nilac/version.rb +1 -1
- data/lib/nilac.rb +324 -1
- data/nilac.gemspec +0 -1
- data/shark/features/add_auto_return_statement.feature +1 -1
- data/shark/features/array_and_string_indexing.feature +1 -1
- data/shark/features/barebones_compilation.feature +1 -1
- data/shark/features/case_when.feature +1 -1
- data/shark/features/default_method_parameters.feature +1 -1
- data/shark/features/fix_newlines.feature +1 -1
- data/shark/features/hashes.feature +1 -1
- data/shark/features/heredoc.feature +1 -1
- data/shark/features/if_then_else.feature +1 -1
- data/shark/features/loop.feature +1 -1
- data/shark/features/method_multiple_return.feature +1 -1
- data/shark/features/multiline_array.feature +1 -1
- data/shark/features/multiple_variable_initialization.feature +1 -1
- data/shark/features/numbers.feature +1 -1
- data/shark/features/regular_for.feature +1 -1
- data/shark/features/regular_if.feature +1 -1
- data/shark/features/regular_while.feature +1 -1
- data/shark/features/ruby_methods.feature +1 -1
- data/shark/features/ruby_operators.feature +1 -1
- data/shark/features/splats.feature +1 -1
- data/shark/features/string_interpolation.feature +1 -1
- data/shark/features/strings.feature +1 -1
- data/shark/features/times.feature +1 -1
- data/shark/features/unless_until.feature +1 -1
- data/shark/features/whitespace_delimitation.feature +1 -1
- metadata +46 -18
- data/src/nilac.rb +0 -5753
@@ -0,0 +1,45 @@
|
|
1
|
+
def compile_custom_function_map(input_file_contents)
|
2
|
+
|
3
|
+
function_map_replacements = {
|
4
|
+
|
5
|
+
"puts" => "console.log",
|
6
|
+
|
7
|
+
"p" => "console.log",
|
8
|
+
|
9
|
+
"print" => "process.stdout.write",
|
10
|
+
|
11
|
+
}
|
12
|
+
|
13
|
+
function_map = function_map_replacements.keys
|
14
|
+
|
15
|
+
modified_file_contents = input_file_contents.dup
|
16
|
+
|
17
|
+
javascript_regexp = /(if |for |while |\(function\(|= function\(|((=|:)\s+\{))/
|
18
|
+
|
19
|
+
input_file_contents.each_with_index do |line, index|
|
20
|
+
|
21
|
+
function_map.each do |function|
|
22
|
+
|
23
|
+
if line.include?(function+"(") or line.include?(function+" ") and line.index(javascript_regexp) == nil
|
24
|
+
|
25
|
+
testsplit = line.split(function)
|
26
|
+
|
27
|
+
testsplit = testsplit.collect {|element| element.strip}
|
28
|
+
|
29
|
+
testsplit[0] = " " if testsplit[0].eql?("")
|
30
|
+
|
31
|
+
if testsplit[0][-1].eql?(" ") or testsplit[0].eql?("return")
|
32
|
+
|
33
|
+
modified_file_contents[index] = line.sub(function, function_map_replacements[function])
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
return modified_file_contents, function_map_replacements.values
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require_relative 'ErrorDeclarations'
|
2
|
+
|
3
|
+
require_relative 'read_file_line_by_line'
|
4
|
+
|
5
|
+
def compile_default_values(input_file_contents, temporary_nila_file)
|
6
|
+
|
7
|
+
#This method compiles default values present in functions. An example is provided below
|
8
|
+
|
9
|
+
# def fill(container = "cup",liquid = "coffee")
|
10
|
+
# puts "Filling the #{container} with #{liquid}"
|
11
|
+
# end
|
12
|
+
|
13
|
+
def errorFree(function_params)
|
14
|
+
|
15
|
+
# This method checks for use cases in complex arguments where a default argument is used
|
16
|
+
# after an optional argument. This will result in erroneous output. So this method will
|
17
|
+
# stop it from happening.
|
18
|
+
|
19
|
+
# Example:
|
20
|
+
# def method_name(a,b,*c,d = 1,c,e)
|
21
|
+
|
22
|
+
optional_param = function_params.reject {|element| !replace_strings(element).include?("*")}[0]
|
23
|
+
|
24
|
+
unless optional_param.nil?
|
25
|
+
|
26
|
+
after_splat = function_params[function_params.index(optional_param)+1..-1]
|
27
|
+
|
28
|
+
if after_splat.reject {|element| !element.include?("=")}.empty?
|
29
|
+
|
30
|
+
true
|
31
|
+
|
32
|
+
else
|
33
|
+
|
34
|
+
NilaSyntaxError.new("You cannot have default argument after an optional argument! Change the following usage!\n#{function_params.join(",")}")
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
else
|
39
|
+
|
40
|
+
true
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_default_values(input_function_definition)
|
47
|
+
|
48
|
+
split1, split2 = input_function_definition.split("(")
|
49
|
+
|
50
|
+
split2, split3 = split2.split(")")
|
51
|
+
|
52
|
+
function_parameters = split2.split(",")
|
53
|
+
|
54
|
+
if errorFree(function_parameters)
|
55
|
+
|
56
|
+
default_value_parameters = function_parameters.reject { |element| !element.include? "=" }
|
57
|
+
|
58
|
+
replacement_parameters = []
|
59
|
+
|
60
|
+
replacement_string = ""
|
61
|
+
|
62
|
+
default_value_parameters.each do |paramvalue|
|
63
|
+
|
64
|
+
param, value = paramvalue.split("=")
|
65
|
+
|
66
|
+
replacement_parameters << param.lstrip.rstrip
|
67
|
+
|
68
|
+
replacement_string = replacement_string + "\n" + "if (#{param.lstrip.rstrip} equequ null) {\n #{paramvalue.lstrip.rstrip}\n}\n" +"\n"
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
return replacement_string, default_value_parameters, replacement_parameters
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
reject_regexp = /(function |Euuf |if |else|elsuf|switch |case|while |whaaleskey |for )/
|
79
|
+
|
80
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("==", "equalequal") }
|
81
|
+
|
82
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("!=", "notequal") }
|
83
|
+
|
84
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("+=", "plusequal") }
|
85
|
+
|
86
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("-=", "minusequal") }
|
87
|
+
|
88
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("*=", "multiequal") }
|
89
|
+
|
90
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("/=", "divequal") }
|
91
|
+
|
92
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("%=", "modequal") }
|
93
|
+
|
94
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
|
95
|
+
|
96
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub(">=", "greatequal") }
|
97
|
+
|
98
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("<=", "lessyequal") }
|
99
|
+
|
100
|
+
possible_default_values = input_file_contents.dup.reject { |element| (!element.include?("def")) }
|
101
|
+
|
102
|
+
possible_default_values = possible_default_values.reject { |element| !element.include?("=") }
|
103
|
+
|
104
|
+
possible_default_values = possible_default_values.reject {|element| !element.index(reject_regexp) == nil}
|
105
|
+
|
106
|
+
if !possible_default_values.empty?
|
107
|
+
|
108
|
+
possible_default_values.each do |line|
|
109
|
+
|
110
|
+
current_line_index = input_file_contents.each_index.select { |index| input_file_contents[index] == line }.flatten[0]
|
111
|
+
|
112
|
+
replacement_string, value_parameters, replacement_parameters = parse_default_values(line)
|
113
|
+
|
114
|
+
modified_line = line.dup
|
115
|
+
|
116
|
+
value_parameters.each_with_index do |val, index|
|
117
|
+
|
118
|
+
modified_line = modified_line.sub(val, replacement_parameters[index])
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
input_file_contents[current_line_index] = modified_line
|
123
|
+
|
124
|
+
input_file_contents.insert(current_line_index+1,replacement_string)
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
file_id = open(temporary_nila_file, 'w')
|
131
|
+
|
132
|
+
file_id.write(input_file_contents.join)
|
133
|
+
|
134
|
+
file_id.close()
|
135
|
+
|
136
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
137
|
+
|
138
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("plusequal", "+=") }
|
139
|
+
|
140
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("minusequal", "-=") }
|
141
|
+
|
142
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("multiequal", "*=") }
|
143
|
+
|
144
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("divequal", "/=") }
|
145
|
+
|
146
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("modequal", "%=") }
|
147
|
+
|
148
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("equalequal", "==") }
|
149
|
+
|
150
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("notequal", "!=") }
|
151
|
+
|
152
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("matchequal", "=~") }
|
153
|
+
|
154
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("greatequal", ">=") }
|
155
|
+
|
156
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("lessyequal", "<=") }
|
157
|
+
|
158
|
+
return line_by_line_contents
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require_relative 'replace_strings'
|
2
|
+
|
3
|
+
require_relative 'read_file_line_by_line'
|
4
|
+
|
5
|
+
def compile_hashes(input_file_contents,temporary_nila_file)
|
6
|
+
|
7
|
+
def compile_multiline_hashes(input_file_contents,temporary_nila_file)
|
8
|
+
|
9
|
+
javascript_regexp = /(if |while |for |function |function\()/
|
10
|
+
|
11
|
+
modified_file_contents = input_file_contents.clone
|
12
|
+
|
13
|
+
input_file_contents = input_file_contents.collect {|line| replace_strings(line)}
|
14
|
+
|
15
|
+
possible_hashes = input_file_contents.reject { |element| !element.include?("{") }
|
16
|
+
|
17
|
+
possible_multiline_hashes = possible_hashes.reject { |element| element.include?("}") }
|
18
|
+
|
19
|
+
possible_multiline_hashes = possible_multiline_hashes.reject {|element| element.index(javascript_regexp) != nil}
|
20
|
+
|
21
|
+
multiline_hashes = []
|
22
|
+
|
23
|
+
possible_multiline_hashes.each do |starting_line|
|
24
|
+
|
25
|
+
index = input_file_contents.index(starting_line)
|
26
|
+
|
27
|
+
line = modified_file_contents[index]
|
28
|
+
|
29
|
+
until line.include?("}\n")
|
30
|
+
|
31
|
+
index += 1
|
32
|
+
|
33
|
+
line = modified_file_contents[index]
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
multiline_hashes << modified_file_contents[input_file_contents.index(starting_line)..index]
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
joined_file_contents = modified_file_contents.join
|
42
|
+
|
43
|
+
multiline_hashes.each do |hash|
|
44
|
+
|
45
|
+
modified_hash = hash.join
|
46
|
+
|
47
|
+
hash_extract = modified_hash[modified_hash.index("{")..modified_hash.index("}")]
|
48
|
+
|
49
|
+
hash_contents = hash_extract.split("{")[1].split("}")[0].lstrip.rstrip.split(",").collect { |element| element.lstrip.rstrip }
|
50
|
+
|
51
|
+
hash_contents = "{" + hash_contents.join(",") + "}"
|
52
|
+
|
53
|
+
joined_file_contents = joined_file_contents.sub(hash_extract, hash_contents)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
file_id = open(temporary_nila_file, 'w')
|
58
|
+
|
59
|
+
file_id.write(joined_file_contents)
|
60
|
+
|
61
|
+
file_id.close()
|
62
|
+
|
63
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
64
|
+
|
65
|
+
return line_by_line_contents
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def compile_inline_hashes(input_file_contents)
|
70
|
+
|
71
|
+
javascript_regexp = /(if |while |for |function |function\(|%[qQw]*\{)/
|
72
|
+
|
73
|
+
modified_file_contents = input_file_contents.clone.collect {|element| replace_strings(element)}
|
74
|
+
|
75
|
+
possible_inline_hashes = modified_file_contents.reject {|element| element.count("{") != 1}
|
76
|
+
|
77
|
+
possible_inline_hashes = possible_inline_hashes.reject {|element| element.count("}") != 1}
|
78
|
+
|
79
|
+
possible_inline_hashes = possible_inline_hashes.reject {|element| element.index(javascript_regexp) != nil}
|
80
|
+
|
81
|
+
possible_inline_hashes = possible_inline_hashes.reject {|element| element.include?("{}")}
|
82
|
+
|
83
|
+
possible_inline_hashes.each do |hash|
|
84
|
+
|
85
|
+
hash = input_file_contents[modified_file_contents.index(hash)]
|
86
|
+
|
87
|
+
hash_extract = hash[hash.index("{")..hash.index("}")]
|
88
|
+
|
89
|
+
contents = hash_extract[1...-1].split(",")
|
90
|
+
|
91
|
+
hash_contents = []
|
92
|
+
|
93
|
+
contents.each do |items|
|
94
|
+
|
95
|
+
items = items.lstrip.sub(":","") if items.lstrip[0] == ":"
|
96
|
+
|
97
|
+
key, value = items.split("=>").collect {|element| element.lstrip.rstrip} if items.include?("=>")
|
98
|
+
|
99
|
+
key, value = items.split(":").collect {|element| element.lstrip.rstrip} if items.include?(":")
|
100
|
+
|
101
|
+
key = key.gsub("'","").gsub("\"","")
|
102
|
+
|
103
|
+
hash_contents << " #{key}: #{value},"
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
replacement_string = "{\n" + hash_contents.join("\n") + "\n};\n"
|
108
|
+
|
109
|
+
input_file_contents[input_file_contents.index(hash)] = input_file_contents[input_file_contents.index(hash)].sub(hash_extract,replacement_string)
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
return input_file_contents
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
file_contents = compile_multiline_hashes(input_file_contents,temporary_nila_file)
|
118
|
+
|
119
|
+
file_contents = compile_inline_hashes(file_contents)
|
120
|
+
|
121
|
+
return file_contents
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative 'read_file_line_by_line'
|
2
|
+
|
3
|
+
def compile_heredocs(input_file_contents, temporary_nila_file)
|
4
|
+
|
5
|
+
joined_file_contents = input_file_contents.join
|
6
|
+
|
7
|
+
possible_heredocs = input_file_contents.reject { |element| !element.include?("<<-") }
|
8
|
+
|
9
|
+
possible_heredocs = possible_heredocs.collect { |element| element.match(/<<-(.*|\w*)/).to_a[0] }
|
10
|
+
|
11
|
+
possible_heredocs.each do |heredoc|
|
12
|
+
|
13
|
+
delimiter = heredoc[3..-1]
|
14
|
+
|
15
|
+
quote = 2
|
16
|
+
|
17
|
+
if delimiter.include?("'")
|
18
|
+
|
19
|
+
quote = 1
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
delimiter = delimiter.gsub("\"", "") if quote == 2
|
24
|
+
|
25
|
+
delimiter = delimiter.gsub("'", "") if quote == 1
|
26
|
+
|
27
|
+
string_split = joined_file_contents.split(heredoc, 2)
|
28
|
+
|
29
|
+
string_extract = string_split[1]
|
30
|
+
|
31
|
+
heredoc_extract = string_extract[0...string_extract.index(delimiter)]
|
32
|
+
|
33
|
+
replacement_string = ""
|
34
|
+
|
35
|
+
if quote == 1
|
36
|
+
|
37
|
+
replacement_string = "'#{heredoc_extract.delete("\"")}'".lstrip.inspect
|
38
|
+
|
39
|
+
replacement_string = replacement_string[1..-2]
|
40
|
+
|
41
|
+
elsif quote == 2
|
42
|
+
|
43
|
+
replacement_string = heredoc_extract.lstrip.inspect
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
joined_file_contents = joined_file_contents.sub(heredoc + heredoc_extract + delimiter, replacement_string)
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
file_id = open(temporary_nila_file, 'w')
|
52
|
+
|
53
|
+
file_id.write(joined_file_contents)
|
54
|
+
|
55
|
+
file_id.close()
|
56
|
+
|
57
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
58
|
+
|
59
|
+
return line_by_line_contents
|
60
|
+
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
def compile_integers(input_file_contents)
|
2
|
+
|
3
|
+
modified_file_contents = input_file_contents.clone
|
4
|
+
|
5
|
+
input_file_contents.each_with_index do |line,index|
|
6
|
+
|
7
|
+
matches = line.scan(/(([0-9]+_)+([0-9]+|$))/)
|
8
|
+
|
9
|
+
unless matches.empty?
|
10
|
+
|
11
|
+
matches.each do |match_arr|
|
12
|
+
|
13
|
+
modified_file_contents[index] = modified_file_contents[index].sub(match_arr[0],match_arr[0].gsub("_",""))
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
return modified_file_contents
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_relative 'find_all_matching_indices'
|
2
|
+
|
3
|
+
def compile_interpolated_strings(input_file_contents)
|
4
|
+
|
5
|
+
modified_file_contents = input_file_contents.dup
|
6
|
+
|
7
|
+
single_quoted_strings = input_file_contents.reject { |element| !(element.count("'") >= 2) }
|
8
|
+
|
9
|
+
single_quoted_strings.each do |str|
|
10
|
+
|
11
|
+
modified_string = str.dup
|
12
|
+
|
13
|
+
while modified_string.include?("'")
|
14
|
+
|
15
|
+
first_index = modified_string.index("'")
|
16
|
+
|
17
|
+
string_extract = modified_string[first_index..modified_string.index("'", first_index+1)]
|
18
|
+
|
19
|
+
modified_string = modified_string.sub(string_extract, "--single_quoted")
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
input_file_contents[input_file_contents.index(str)] = modified_string
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
input_file_contents.each_with_index do |line, index|
|
28
|
+
|
29
|
+
if line.include?("\#{")
|
30
|
+
|
31
|
+
modified_line = line.dup
|
32
|
+
|
33
|
+
interpol_starting_loc = find_all_matching_indices(modified_line, "\#{") + [-1]
|
34
|
+
|
35
|
+
interpolated_strings = []
|
36
|
+
|
37
|
+
until interpol_starting_loc.empty?
|
38
|
+
|
39
|
+
interpol_starting_loc[1] = -2 if interpol_starting_loc[1] == -1
|
40
|
+
|
41
|
+
string_extract = modified_line[interpol_starting_loc[0]+1..interpol_starting_loc[1]+1]
|
42
|
+
|
43
|
+
closed_curly_brace_index = find_all_matching_indices(string_extract, "}")
|
44
|
+
|
45
|
+
index_counter = 0
|
46
|
+
|
47
|
+
test_string = ""
|
48
|
+
|
49
|
+
until closed_curly_brace_index.empty?
|
50
|
+
|
51
|
+
test_string = string_extract[0..closed_curly_brace_index[0]]
|
52
|
+
|
53
|
+
original_string = test_string.dup
|
54
|
+
|
55
|
+
if test_string.include?("{")
|
56
|
+
|
57
|
+
test_string = test_string.reverse.sub("{", "$#{index_counter}$").reverse
|
58
|
+
|
59
|
+
test_string[-1] = "@#{index_counter}@"
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
string_extract = string_extract.sub(original_string, test_string)
|
64
|
+
|
65
|
+
closed_curly_brace_index = find_all_matching_indices(string_extract, "}")
|
66
|
+
|
67
|
+
index_counter += 1
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
string_extract = string_extract[0..string_extract.length-string_extract.reverse.index(/@\d@/)]
|
72
|
+
|
73
|
+
interpolated_string = "\#{" + string_extract.split("@#{index_counter-1}@")[0].split("$#{index_counter-1}$")[1] + "}"
|
74
|
+
|
75
|
+
to_be_replaced = interpolated_string.scan(/\$\d\$/)
|
76
|
+
|
77
|
+
closing_brace_rep = interpolated_string.scan(/@\d@/)
|
78
|
+
|
79
|
+
to_be_replaced.each_with_index do |rep, index|
|
80
|
+
|
81
|
+
interpolated_string = interpolated_string.sub(rep, "{").sub(closing_brace_rep[index], "}")
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
interpolated_strings << interpolated_string
|
86
|
+
|
87
|
+
modified_line = modified_line.sub(interpolated_string, "--interpolate")
|
88
|
+
|
89
|
+
if find_all_matching_indices(modified_line, "\#{").empty?
|
90
|
+
|
91
|
+
interpol_starting_loc = []
|
92
|
+
|
93
|
+
else
|
94
|
+
|
95
|
+
interpol_starting_loc = find_all_matching_indices(modified_line, "\#{") + [-1]
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
interpolated_strings.each do |interpol|
|
102
|
+
|
103
|
+
string_split = line.split(interpol)
|
104
|
+
|
105
|
+
if string_split[1].eql?("\"\n")
|
106
|
+
|
107
|
+
replacement_string = "\" + " + "(#{interpol[2...-1]})"
|
108
|
+
|
109
|
+
modified_file_contents[index] = modified_file_contents[index].sub(interpol+"\"", replacement_string)
|
110
|
+
|
111
|
+
elsif string_split[1].eql?("\")\n")
|
112
|
+
|
113
|
+
replacement_string = "\" + " + "(#{interpol[2...-1]})"
|
114
|
+
|
115
|
+
modified_file_contents[index] = modified_file_contents[index].sub(interpol + "\"", replacement_string)
|
116
|
+
|
117
|
+
else
|
118
|
+
|
119
|
+
replacement_string = "\"" + " + " + "(#{interpol[2...-1]})" + " + \""
|
120
|
+
|
121
|
+
modified_file_contents[index] = modified_file_contents[index].sub(interpol, replacement_string)
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
return modified_file_contents
|
132
|
+
|
133
|
+
end
|