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,23 @@
1
+ # StringMagic is an implementation of Ruby's string methods in Javascript using Nila.
2
+ # It extends the String prototype by adding more methods to it.
3
+
4
+ # It is being written by Adhithya Rajasekaran and Sri Madhavi Rajasekaran.
5
+
6
+ # It is released under the MIT License
7
+
8
+ # Nila allows you to open native Classes/Prototypes and extend them with custom
9
+ # methods/functions. So we will be opening the String class and adding more methods
10
+ # to it.
11
+
12
+ class String
13
+
14
+ def endswith(suffix)
15
+
16
+ # suffix can be any string
17
+
18
+ self.include?(suffix,self.length-suffix.length)
19
+
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,31 @@
1
+ def countdown(minutes)
2
+
3
+ seconds = 60
4
+
5
+ mins = minutes
6
+
7
+ def tick
8
+
9
+ counter = document.getElementById("counter")
10
+
11
+ current_minutes = mins-1
12
+
13
+ seconds--
14
+
15
+ counter.innerHTML = "#{current_minutes.to_s}:#{if seconds < 10 then "0" else ""}#{String(seconds)}"
16
+
17
+ if seconds > 0
18
+
19
+ setTimeout(tick,1000)
20
+
21
+ else
22
+
23
+ countdown(mins - 1) if mins > 1
24
+
25
+ end
26
+
27
+ end
28
+
29
+ tick()
30
+
31
+ end
data/examples/decBin.nila CHANGED
@@ -45,7 +45,7 @@ def decimalToBinary(input_num)
45
45
 
46
46
  calc = decimalplaces * 2
47
47
 
48
- decans = calc.to_s[0];
48
+ decans = calc.to_s[0]
49
49
 
50
50
  decimalplaces = parseFloat("0.#{calc.to_s[2..last]}")
51
51
 
@@ -57,8 +57,8 @@ def decimalToBinary(input_num)
57
57
 
58
58
  end
59
59
 
60
- process.stdin.resume();
61
- process.stdin.setEncoding('utf8');
60
+ process.stdin.resume()
61
+ process.stdin.setEncoding('utf8')
62
62
  process.stdin.on 'data', do |chunk|
63
63
  print "Answer: #{decimalToBinary(chunk).join("")} \n\n"
64
64
  end
data/examples/marky.js ADDED
@@ -0,0 +1,30 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function() {
3
+ var commandline_args, parse_markdown;
4
+
5
+ // Marky is a simple markdown parser written in Nila and runs on Nodejs.
6
+
7
+ // This will demonstrate the power and expressiveness of Nila. We will also
8
+
9
+ // provide the Ruby version of the parser so that you can see how easy it
10
+
11
+ // is to port code from Ruby to Javascript using Nila
12
+
13
+ // This parser was written by Sri Madhavi Rajasekaran and is released under
14
+
15
+ // the MIT License.
16
+
17
+ // If you want to learn more about Nila, please visit http://adhithyan15.github.io/nila
18
+
19
+ parse_markdown = function() {
20
+ };
21
+
22
+ commandline_args = [];
23
+
24
+ process.argv.forEach(function(val,index,array) {
25
+ commandline_args.push(val);
26
+ });
27
+
28
+ console.log(commandline_args.slice(2));
29
+
30
+ }).call(this);
@@ -0,0 +1,23 @@
1
+ # Marky is a simple markdown parser written in Nila and runs on Nodejs.
2
+ # This will demonstrate the power and expressiveness of Nila. We will also
3
+ # provide the Ruby version of the parser so that you can see how easy it
4
+ # is to port code from Ruby to Javascript using Nila
5
+
6
+ # This parser was written by Sri Madhavi Rajasekaran and is released under
7
+ # the MIT License.
8
+
9
+ # If you want to learn more about Nila, please visit http://adhithyan15.github.io/nila
10
+
11
+ def parse_markdown
12
+
13
+ end
14
+
15
+ commandline_args = []
16
+
17
+ process.argv.forEach do |val,index,array|
18
+
19
+ commandline_args << val
20
+
21
+ end
22
+
23
+ puts commandline_args[2..last]
@@ -0,0 +1,11 @@
1
+ class NilaSyntaxError < RuntimeError
2
+
3
+ def initialize(message)
4
+
5
+ puts "SyntaxError: " + message
6
+
7
+ abort
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,57 @@
1
+ def add_semicolons(input_file_contents)
2
+
3
+ def comment(input_string)
4
+
5
+ if input_string.include?("--single_line_comment")
6
+
7
+ true
8
+
9
+ elsif input_string.include?("--multiline_comment")
10
+
11
+ true
12
+
13
+ else
14
+
15
+ false
16
+
17
+ end
18
+
19
+ end
20
+
21
+ reject_regexp = /(function |Euuf |if |else|elsuf|switch |case|while |whaaleskey |for )/
22
+
23
+ modified_file_contents = input_file_contents.dup
24
+
25
+ input_file_contents.each_with_index do |line,index|
26
+
27
+ if line.index(reject_regexp) == nil
28
+
29
+ if !comment(line)
30
+
31
+ if !line.lstrip.eql?("")
32
+
33
+ if !line.lstrip.eql?("}\n")
34
+
35
+ if !line.lstrip.eql?("}\n\n")
36
+
37
+ if line.rstrip[-1] != "[" and line.rstrip[-1] != "{" and line.rstrip[-1] != "," and line.rstrip[-1] != ";"
38
+
39
+ modified_file_contents[index] = line.rstrip + ";\n\n"
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ modified_file_contents
56
+
57
+ end
@@ -0,0 +1,266 @@
1
+ require_relative 'find_all_matching_indices'
2
+
3
+ require_relative 'read_file_line_by_line'
4
+
5
+ def compile_arrays(input_file_contents, named_functions, temporary_nila_file)
6
+
7
+ def compile_w_arrays(input_file_contents)
8
+
9
+ def extract(input_string, pattern_start, pattern_end)
10
+
11
+ all_start_locations = find_all_matching_indices(input_string, pattern_start)
12
+
13
+ all_end_locations = find_all_matching_indices(input_string, pattern_end)
14
+
15
+ pattern = []
16
+
17
+ all_start_locations.each_with_index do |location, index|
18
+
19
+ pattern << input_string[location..all_end_locations[index]]
20
+
21
+ end
22
+
23
+ return pattern
24
+
25
+ end
26
+
27
+ def compile_w_syntax(input_string)
28
+
29
+ modified_input_string = input_string[3...-1]
30
+
31
+ string_split = modified_input_string.split(" ")
32
+
33
+ return string_split.to_s
34
+
35
+ end
36
+
37
+ modified_file_contents = input_file_contents.dup
38
+
39
+ input_file_contents.each_with_index do |line, index|
40
+
41
+ if line.include?("%w{")
42
+
43
+ string_arrays = extract(line, "%w{", "}")
44
+
45
+ string_arrays.each do |array|
46
+
47
+ modified_file_contents[index] = modified_file_contents[index].sub(array, compile_w_syntax(array))
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ return modified_file_contents
56
+
57
+ end
58
+
59
+ def compile_array_indexing(input_file_contents)
60
+
61
+ possible_indexing_operation = input_file_contents.dup.reject { |element| !element.include? "[" and !element.include? "]" }
62
+
63
+ possible_range_indexing = possible_indexing_operation.reject { |element| !element.include? ".." }
64
+
65
+ triple_range_indexing = possible_range_indexing.reject { |element| !element.include? "..." }
66
+
67
+ triple_range_indexes = []
68
+
69
+ triple_range_indexing.each do |line|
70
+
71
+ triple_range_indexes << input_file_contents.dup.each_index.select { |index| input_file_contents[index] == line }
72
+
73
+ end
74
+
75
+ triple_range_indexes = triple_range_indexes.flatten
76
+
77
+ triple_range_indexing.each_with_index do |line, index|
78
+
79
+ split1, split2 = line.split("[")
80
+
81
+ range_index, split3 = split2.split("]")
82
+
83
+ index_start, index_end = range_index.split "..."
84
+
85
+ replacement_string = nil
86
+
87
+ if index_end.strip == "last"
88
+
89
+ replacement_string = split1 + ".slice(#{index_start},#{split}.length)\n"
90
+
91
+ else
92
+
93
+ replacement_string = split1 + ".slice(#{index_start},#{index_end})\n"
94
+
95
+ end
96
+
97
+ possible_range_indexing.delete(input_file_contents[triple_range_indexes[index]])
98
+
99
+ possible_indexing_operation.delete(input_file_contents[triple_range_indexes[index]])
100
+
101
+ input_file_contents[triple_range_indexes[index]] = replacement_string
102
+
103
+ end
104
+
105
+ double_range_indexing = possible_range_indexing.reject { |element| !element.include?("..") }
106
+
107
+ double_range_indexes = []
108
+
109
+ double_range_indexing.each do |line|
110
+
111
+ double_range_indexes << input_file_contents.dup.each_index.select { |index| input_file_contents[index] == line }
112
+
113
+ end
114
+
115
+ double_range_indexes = double_range_indexes.flatten
116
+
117
+ double_range_indexing.each_with_index do |line, index|
118
+
119
+ split1, split2 = line.split("[")
120
+
121
+ range_index, split3 = split2.split("]")
122
+
123
+ index_start, index_end = range_index.split ".."
124
+
125
+ index_start = "" if index_start.nil?
126
+
127
+ index_end = "" if index_end.nil?
128
+
129
+ split3 = "" if split3.nil?
130
+
131
+ replacement_string = nil
132
+
133
+ if index_end.strip == "last"
134
+
135
+ replacement_string = split1 + ".slice(#{index_start})" + split3.strip + "\n\n"
136
+
137
+ elsif index_end.strip == "" and index_start.strip == ""
138
+
139
+ replacement_string = split1 + ".slice(0)\n"
140
+
141
+ else
142
+
143
+ replacement_string = split1 + ".slice(#{index_start},#{index_end}+1)\n"
144
+
145
+ end
146
+
147
+ possible_range_indexing.delete(input_file_contents[double_range_indexes[index]])
148
+
149
+ possible_indexing_operation.delete(input_file_contents[double_range_indexes[index]])
150
+
151
+ input_file_contents[double_range_indexes[index]] = replacement_string
152
+
153
+ end
154
+
155
+ duplicating_operations = input_file_contents.dup.reject { |element| !element.include?(".dup") }
156
+
157
+ duplicating_operation_indexes = []
158
+
159
+ duplicating_operations.each do |line|
160
+
161
+ duplicating_operation_indexes << input_file_contents.dup.each_index.select { |index| input_file_contents[index] == line }
162
+
163
+ end
164
+
165
+ duplicating_operation_indexes = duplicating_operation_indexes.flatten
166
+
167
+ duplicating_operation_indexes.each do |index|
168
+
169
+ input_file_contents[index] = input_file_contents[index].sub(".dup", ".slice(0)")
170
+
171
+ end
172
+
173
+ return input_file_contents
174
+
175
+ end
176
+
177
+ def compile_multiline(input_file_contents, temporary_nila_file)
178
+
179
+ possible_arrays = input_file_contents.reject { |element| !element.include?("[") }
180
+
181
+ possible_multiline_arrays = possible_arrays.reject { |element| element.include?("]") }
182
+
183
+ multiline_arrays = []
184
+
185
+ possible_multiline_arrays.each do |starting_line|
186
+
187
+ index = input_file_contents.index(starting_line)
188
+
189
+ line = starting_line
190
+
191
+ until line.include?("]")
192
+
193
+ index += 1
194
+
195
+ line = input_file_contents[index]
196
+
197
+ end
198
+
199
+ multiline_arrays << input_file_contents[input_file_contents.index(starting_line)..index]
200
+
201
+ end
202
+
203
+ joined_file_contents = input_file_contents.join
204
+
205
+ multiline_arrays.each do |array|
206
+
207
+ modified_array = array.join
208
+
209
+ array_extract = modified_array[modified_array.index("[")..modified_array.index("]")]
210
+
211
+ array_contents = array_extract.split("[")[1].split("]")[0].lstrip.rstrip.split(",").collect { |element| element.lstrip.rstrip }
212
+
213
+ array_contents = "[" + array_contents.join(",") + "]"
214
+
215
+ joined_file_contents = joined_file_contents.sub(array_extract, array_contents)
216
+
217
+ end
218
+
219
+ file_id = open(temporary_nila_file, 'w')
220
+
221
+ file_id.write(joined_file_contents)
222
+
223
+ file_id.close()
224
+
225
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
226
+
227
+ return line_by_line_contents
228
+
229
+ end
230
+
231
+ def compile_array_operators(input_file_contents)
232
+
233
+ possible_operator_usage = input_file_contents.reject { |element| !element.include?("<<") }
234
+
235
+ possible_operator_usage.each do |usage|
236
+
237
+ left, right = usage.split("<<")
238
+
239
+ input_file_contents[input_file_contents.index(usage)] = left.rstrip + ".push(#{right.strip})\n\n"
240
+
241
+ end
242
+
243
+ return input_file_contents
244
+
245
+ end
246
+
247
+ input_file_contents = compile_w_arrays(input_file_contents)
248
+
249
+ input_file_contents = compile_array_indexing(input_file_contents)
250
+
251
+ input_file_contents = compile_multiline(input_file_contents, temporary_nila_file)
252
+
253
+ input_file_contents = compile_array_operators(input_file_contents)
254
+
255
+ named_functions = named_functions.collect {|func| compile_w_arrays(func)}
256
+
257
+ named_functions = named_functions.collect { |func| compile_array_indexing(func)}
258
+
259
+ named_functions = named_functions.collect {|func| compile_multiline(func, temporary_nila_file)}
260
+
261
+ named_functions = named_functions.collect {|func| compile_array_operators(func)}
262
+
263
+ return input_file_contents, named_functions
264
+
265
+
266
+ end
@@ -0,0 +1,137 @@
1
+ require_relative 'read_file_line_by_line'
2
+
3
+ def compile_blocks(input_file_contents,temporary_nila_file)
4
+
5
+ def compile_one_line_blocks(input_block)
6
+
7
+ block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2)
8
+
9
+ compiled_block = "function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents.strip} \n\n}"
10
+
11
+ return compiled_block
12
+
13
+ end
14
+
15
+ input_file_contents = input_file_contents.collect {|element| element.gsub("append","appand")}
16
+
17
+ possible_blocks = input_file_contents.reject {|line| !line.include?(" do ")}
18
+
19
+ unless possible_blocks.empty?
20
+
21
+ possible_blocks.each do |starting_line|
22
+
23
+ index_counter = starting_counter = input_file_contents.index(starting_line)
24
+
25
+ line = starting_line
26
+
27
+ until line.strip.eql?("end") or line.strip.eql?("end)")
28
+
29
+ index_counter += 1
30
+
31
+ line = input_file_contents[index_counter]
32
+
33
+ end
34
+
35
+ loop_extract = input_file_contents[starting_counter..index_counter]
36
+
37
+ loop_condition, block = loop_extract.join.split(" do ")
38
+
39
+ block = block.split("end")[0]
40
+
41
+ replacement_string = "#{loop_condition.rstrip} blockky {#{block.strip}}_!"
42
+
43
+ input_file_contents[starting_counter..index_counter] = replacement_string
44
+
45
+ end
46
+
47
+ end
48
+
49
+ possible_blocks = input_file_contents.reject{ |element| !element.include?(" blockky ")}
50
+
51
+ possible_blocks = possible_blocks.reject {|element| !element.include?("{") and !element.include?("}")}
52
+
53
+ modified_file_contents = input_file_contents.clone
54
+
55
+ unless possible_blocks.empty?
56
+
57
+ possible_blocks.each do |loop|
58
+
59
+ original_loop = loop.clone
60
+
61
+ string_counter = 1
62
+
63
+ extracted_string = []
64
+
65
+ while loop.include?("\"")
66
+
67
+ string_extract = loop[loop.index("\"")..loop.index("\"",loop.index("\"")+1)]
68
+
69
+ extracted_string << string_extract
70
+
71
+ loop = loop.sub(string_extract,"--repstring#{string_counter}")
72
+
73
+ string_counter += 1
74
+
75
+ end
76
+
77
+ block_extract = loop[loop.index("{")..loop.index("}_!")]
78
+
79
+ compiled_block = ""
80
+
81
+ if block_extract.count("|") == 2
82
+
83
+ compiled_block = compile_one_line_blocks(block_extract)
84
+
85
+ extracted_string.each_with_index do |string,index|
86
+
87
+ compiled_block = compiled_block.sub("--repstring#{index+1}",string)
88
+
89
+ end
90
+
91
+ else
92
+
93
+ compiled_block = block_extract[1...-1].lstrip.rstrip
94
+
95
+ extracted_string.each_with_index do |string,index|
96
+
97
+ compiled_block = compiled_block.sub("--repstring#{index+1}",string)
98
+
99
+ end
100
+
101
+ end
102
+
103
+ caller_func = loop.split(" blockky ")[0]
104
+
105
+ unless caller_func.rstrip[-1] == ","
106
+
107
+ replacement_string = "#{caller_func.rstrip}(#{compiled_block.lstrip})"
108
+
109
+ else
110
+
111
+ caller_func_split = caller_func.split("(") if caller_func.include?("(")
112
+
113
+ caller_func_split = caller_func.split(" ",2) if caller_func.include?(" ")
114
+
115
+ replacement_string = "#{caller_func_split[0]}(#{caller_func_split[1].strip + compiled_block.lstrip})"
116
+
117
+ end
118
+
119
+ modified_file_contents[input_file_contents.index(original_loop)] = replacement_string
120
+
121
+ end
122
+
123
+ end
124
+
125
+ modified_file_contents = modified_file_contents.collect {|element| element.gsub("appand","append")}
126
+
127
+ file_id = open(temporary_nila_file, 'w')
128
+
129
+ file_id.write(modified_file_contents.join)
130
+
131
+ file_id.close()
132
+
133
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
134
+
135
+ return line_by_line_contents
136
+
137
+ end