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,211 @@
|
|
1
|
+
require_relative 'read_file_line_by_line'
|
2
|
+
|
3
|
+
def compile_loops(input_file_contents,temporary_nila_file)
|
4
|
+
|
5
|
+
def compile_times_loop(input_file_contents,temporary_nila_file)
|
6
|
+
|
7
|
+
def compile_one_line_blocks(input_block)
|
8
|
+
|
9
|
+
block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2)
|
10
|
+
|
11
|
+
compiled_block = "(function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents.strip} \n\n}(_i))_!;\n"
|
12
|
+
|
13
|
+
return compiled_block
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def extract_variable_names(input_file_contents)
|
18
|
+
|
19
|
+
variables = []
|
20
|
+
|
21
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("==", "equalequal") }
|
22
|
+
|
23
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("!=", "notequal") }
|
24
|
+
|
25
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("+=", "plusequal") }
|
26
|
+
|
27
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("-=", "minusequal") }
|
28
|
+
|
29
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("*=", "multiequal") }
|
30
|
+
|
31
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("/=", "divequal") }
|
32
|
+
|
33
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("%=", "modequal") }
|
34
|
+
|
35
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
|
36
|
+
|
37
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub(">=", "greatequal") }
|
38
|
+
|
39
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("<=", "lessyequal") }
|
40
|
+
|
41
|
+
javascript_regexp = /(if |while |for )/
|
42
|
+
|
43
|
+
for x in 0...input_file_contents.length
|
44
|
+
|
45
|
+
current_row = input_file_contents[x]
|
46
|
+
|
47
|
+
if current_row.include?("=") and current_row.index(javascript_regexp) == nil
|
48
|
+
|
49
|
+
current_row = current_row.rstrip + "\n"
|
50
|
+
|
51
|
+
current_row_split = current_row.split("=")
|
52
|
+
|
53
|
+
for y in 0...current_row_split.length
|
54
|
+
|
55
|
+
current_row_split[y] = current_row_split[y].strip
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
if current_row_split[0].include?("[") or current_row_split[0].include?("(")
|
61
|
+
|
62
|
+
current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
variables << current_row_split[0]
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
input_file_contents[x] = current_row
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
variables += ["_i","_j"]
|
76
|
+
|
77
|
+
variables = variables.flatten
|
78
|
+
|
79
|
+
return variables.uniq
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
possible_times_loop = input_file_contents.reject{ |element| !element.include?(".times")}
|
84
|
+
|
85
|
+
multiline_times_loop = possible_times_loop.reject {|element| !element.include?(" do ")}
|
86
|
+
|
87
|
+
unless multiline_times_loop.empty?
|
88
|
+
|
89
|
+
multiline_times_loop.each do |starting_line|
|
90
|
+
|
91
|
+
index_counter = starting_counter = input_file_contents.index(starting_line)
|
92
|
+
|
93
|
+
line = starting_line
|
94
|
+
|
95
|
+
until line.strip.eql?("end")
|
96
|
+
|
97
|
+
index_counter += 1
|
98
|
+
|
99
|
+
line = input_file_contents[index_counter]
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
loop_extract = input_file_contents[starting_counter..index_counter]
|
104
|
+
|
105
|
+
file_extract = input_file_contents[0..index_counter]
|
106
|
+
|
107
|
+
file_variables = extract_variable_names(file_extract)
|
108
|
+
|
109
|
+
block_variables = extract_variable_names(loop_extract)
|
110
|
+
|
111
|
+
var_need_of_declaration = file_variables-block_variables-["_i","_j"]
|
112
|
+
|
113
|
+
loop_condition, block = loop_extract.join.split(" do ")
|
114
|
+
|
115
|
+
block = block.split("end")[0]
|
116
|
+
|
117
|
+
replacement_string = "#{loop_condition.rstrip} {#{block.strip}}"
|
118
|
+
|
119
|
+
input_file_contents[starting_counter..index_counter] = replacement_string
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
possible_times_loop = input_file_contents.reject{ |element| !element.include?(".times")}
|
126
|
+
|
127
|
+
oneliner_times_loop = possible_times_loop.reject {|element| !element.include?("{") and !element.include?("}")}
|
128
|
+
|
129
|
+
loop_variables = []
|
130
|
+
|
131
|
+
modified_file_contents = input_file_contents.clone
|
132
|
+
|
133
|
+
unless oneliner_times_loop.empty?
|
134
|
+
|
135
|
+
oneliner_times_loop.each do |loop|
|
136
|
+
|
137
|
+
original_loop = loop.clone
|
138
|
+
|
139
|
+
string_counter = 1
|
140
|
+
|
141
|
+
extracted_string = []
|
142
|
+
|
143
|
+
while loop.include?("\"")
|
144
|
+
|
145
|
+
string_extract = loop[loop.index("\"")..loop.index("\"",loop.index("\"")+1)]
|
146
|
+
|
147
|
+
extracted_string << string_extract
|
148
|
+
|
149
|
+
loop = loop.sub(string_extract,"--repstring#{string_counter}")
|
150
|
+
|
151
|
+
string_counter += 1
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
block_extract = loop[loop.index("{")..loop.index("}")]
|
156
|
+
|
157
|
+
compiled_block = ""
|
158
|
+
|
159
|
+
if block_extract.count("|") == 2
|
160
|
+
|
161
|
+
compiled_block = compile_one_line_blocks(block_extract)
|
162
|
+
|
163
|
+
extracted_string.each_with_index do |string,index|
|
164
|
+
|
165
|
+
compiled_block = compiled_block.sub("--repstring#{index+1}",string)
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
else
|
170
|
+
|
171
|
+
compiled_block = block_extract[1...-1].lstrip.rstrip
|
172
|
+
|
173
|
+
extracted_string.each_with_index do |string,index|
|
174
|
+
|
175
|
+
compiled_block = compiled_block.sub("--repstring#{index+1}",string)
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
times_counter = loop.split(".times")[0].lstrip
|
182
|
+
|
183
|
+
times_counter = times_counter[1...-1] if times_counter.include?("(") and times_counter.include?(")")
|
184
|
+
|
185
|
+
replacement_string = "for (_i = 0, _j = #{times_counter}; _i < _j; _i += 1) {\n\n#{compiled_block}\n\n}"
|
186
|
+
|
187
|
+
modified_file_contents[input_file_contents.index(original_loop)] = replacement_string
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
loop_variables = ["_i","_j"]
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
file_id = open(temporary_nila_file, 'w')
|
196
|
+
|
197
|
+
file_id.write(modified_file_contents.join)
|
198
|
+
|
199
|
+
file_id.close()
|
200
|
+
|
201
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
202
|
+
|
203
|
+
return line_by_line_contents,loop_variables
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
file_contents,loop_variables = compile_times_loop(input_file_contents,temporary_nila_file)
|
208
|
+
|
209
|
+
return file_contents,loop_variables
|
210
|
+
|
211
|
+
end
|