nilac 0.0.4.3.9.2 → 0.0.4.3.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/bin/nilac +9 -5748
  4. data/examples/StringMagic.nila +23 -0
  5. data/examples/countdown.nila +31 -0
  6. data/examples/decBin.nila +3 -3
  7. data/examples/marky.js +30 -0
  8. data/examples/marky.nila +23 -0
  9. data/lib/nilac/ErrorDeclarations.rb +11 -0
  10. data/lib/nilac/add_semicolons.rb +57 -0
  11. data/lib/nilac/compile_arrays.rb +266 -0
  12. data/lib/nilac/compile_blocks.rb +137 -0
  13. data/lib/nilac/compile_case_statement.rb +168 -0
  14. data/lib/nilac/compile_classes.rb +18 -0
  15. data/lib/nilac/compile_comments.rb +79 -0
  16. data/lib/nilac/compile_conditional_structures.rb +1378 -0
  17. data/lib/nilac/compile_custom_function_map.rb +45 -0
  18. data/lib/nilac/compile_default_values.rb +160 -0
  19. data/lib/nilac/compile_hashes.rb +123 -0
  20. data/lib/nilac/compile_heredocs.rb +62 -0
  21. data/lib/nilac/compile_integers.rb +23 -0
  22. data/lib/nilac/compile_interpolated_strings.rb +133 -0
  23. data/lib/nilac/compile_loops.rb +211 -0
  24. data/lib/nilac/compile_named_functions.rb +690 -0
  25. data/lib/nilac/compile_operators.rb +83 -0
  26. data/lib/nilac/compile_parallel_assignment.rb +103 -0
  27. data/lib/nilac/compile_ruby_methods.rb +58 -0
  28. data/lib/nilac/compile_special_keywords.rb +44 -0
  29. data/lib/nilac/compile_strings.rb +145 -0
  30. data/lib/nilac/compile_whitespace_delimited_functions.rb +97 -0
  31. data/lib/nilac/create_mac_executable.rb +25 -0
  32. data/lib/nilac/extract_parsable_file.rb +23 -0
  33. data/lib/nilac/find_all_matching_indices.rb +18 -0
  34. data/lib/nilac/find_file_name.rb +13 -0
  35. data/lib/nilac/find_file_path.rb +13 -0
  36. data/lib/nilac/get_variables.rb +123 -0
  37. data/lib/nilac/output_javascript.rb +13 -0
  38. data/lib/nilac/parse_arguments.rb +41 -0
  39. data/lib/nilac/pretty_print_javascript.rb +457 -0
  40. data/lib/nilac/read_file_line_by_line.rb +11 -0
  41. data/lib/nilac/remove_question_marks.rb +46 -0
  42. data/lib/nilac/replace_multiline_comments.rb +92 -0
  43. data/lib/nilac/replace_named_functions.rb +154 -0
  44. data/lib/nilac/replace_singleline_comments.rb +45 -0
  45. data/lib/nilac/replace_strings.rb +35 -0
  46. data/lib/nilac/split_semicolon_seperated_expressions.rb +39 -0
  47. data/lib/nilac/strToArray.rb +15 -0
  48. data/lib/nilac/version.rb +1 -1
  49. data/lib/nilac.rb +324 -1
  50. data/nilac.gemspec +0 -1
  51. data/shark/features/add_auto_return_statement.feature +1 -1
  52. data/shark/features/array_and_string_indexing.feature +1 -1
  53. data/shark/features/barebones_compilation.feature +1 -1
  54. data/shark/features/case_when.feature +1 -1
  55. data/shark/features/default_method_parameters.feature +1 -1
  56. data/shark/features/fix_newlines.feature +1 -1
  57. data/shark/features/hashes.feature +1 -1
  58. data/shark/features/heredoc.feature +1 -1
  59. data/shark/features/if_then_else.feature +1 -1
  60. data/shark/features/loop.feature +1 -1
  61. data/shark/features/method_multiple_return.feature +1 -1
  62. data/shark/features/multiline_array.feature +1 -1
  63. data/shark/features/multiple_variable_initialization.feature +1 -1
  64. data/shark/features/numbers.feature +1 -1
  65. data/shark/features/regular_for.feature +1 -1
  66. data/shark/features/regular_if.feature +1 -1
  67. data/shark/features/regular_while.feature +1 -1
  68. data/shark/features/ruby_methods.feature +1 -1
  69. data/shark/features/ruby_operators.feature +1 -1
  70. data/shark/features/splats.feature +1 -1
  71. data/shark/features/string_interpolation.feature +1 -1
  72. data/shark/features/strings.feature +1 -1
  73. data/shark/features/times.feature +1 -1
  74. data/shark/features/unless_until.feature +1 -1
  75. data/shark/features/whitespace_delimitation.feature +1 -1
  76. metadata +46 -18
  77. 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