nilac 0.0.4.3.6 → 0.0.4.3.7

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nilac +177 -25
  3. data/lib/nilac/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93e0394535005dd35537d7979c3aaa495b11e4d7
4
- data.tar.gz: 45b2a7bb891f2c389f5ae5e99d7f3f09a70e770e
3
+ metadata.gz: 1134f4be8a507aaab07700dfb882b0ef88ecb985
4
+ data.tar.gz: 53494da4adc0e265b169282703dafa702e3d26db
5
5
  SHA512:
6
- metadata.gz: b9df698a5afc8b23b6c6dc24663a9bae9acc8c9cbb54e04c16e7a9e51c633254e29c7d48306315ea489c7d22765b73d6d25edbdb4b13c4726f6dd487c81b1d4a
7
- data.tar.gz: 8fa6965d4e1db48122fb30b7ab0b46884ad4b9609b5ef8bb9de8fa7d91bdf76c34557cfb2fa5d873255533284b37158a5b9a162f17c86febbe6968f9e76fcd7c
6
+ metadata.gz: 36b990668a578a13bffbd8ce30be8f5943cab2e9345b3b8ad356f0418bdd7844dc66d1256ad2cdc4f73d757cb0979eaf8259442c267fac9c1bb45982a3740d3c
7
+ data.tar.gz: 62c848bf78ef3ef811b7affcde6dbf6c848901682b31df7ae0841d3e736bc06656cf1cb0c39d08ad79bc49323065acd075289e9161d90a4eb30b0c6d4240a097
data/bin/nilac CHANGED
@@ -421,7 +421,9 @@ def compile(input_file_path, *output_file_name)
421
421
 
422
422
  string_counter = 0
423
423
 
424
- while input_string.include?("\"")
424
+ if input_string.count("\"") % 2 == 0
425
+
426
+ while input_string.include?("\"")
425
427
 
426
428
  string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
427
429
 
@@ -429,15 +431,21 @@ def compile(input_file_path, *output_file_name)
429
431
 
430
432
  string_counter += 1
431
433
 
434
+ end
435
+
432
436
  end
433
437
 
434
- while input_string.include?("'")
438
+ if input_string.count("'") % 2 == 0
435
439
 
436
- string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
440
+ while input_string.include?("'")
437
441
 
438
- input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
442
+ string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
439
443
 
440
- string_counter += 1
444
+ input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
445
+
446
+ string_counter += 1
447
+
448
+ end
441
449
 
442
450
  end
443
451
 
@@ -822,6 +830,10 @@ def compile(input_file_path, *output_file_name)
822
830
 
823
831
  input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
824
832
 
833
+ input_file_contents = input_file_contents.collect { |element| element.gsub(">=", "greatequal") }
834
+
835
+ input_file_contents = input_file_contents.collect { |element| element.gsub("<=", "lessyequal") }
836
+
825
837
  possible_default_values = input_file_contents.dup.reject { |element| (!element.include?("def")) }
826
838
 
827
839
  possible_default_values = possible_default_values.reject { |element| !element.include?("=") }
@@ -876,6 +888,10 @@ def compile(input_file_path, *output_file_name)
876
888
 
877
889
  line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("matchequal", "=~") }
878
890
 
891
+ line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("greatequal", ">=") }
892
+
893
+ line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("lessyequal", "<=") }
894
+
879
895
  return line_by_line_contents
880
896
 
881
897
  end
@@ -928,6 +944,10 @@ def compile(input_file_path, *output_file_name)
928
944
 
929
945
  input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
930
946
 
947
+ input_file_contents = input_file_contents.collect { |element| element.gsub(">=", "greatequal") }
948
+
949
+ input_file_contents = input_file_contents.collect { |element| element.gsub("<=", "lessyequal") }
950
+
931
951
  modified_file_contents = input_file_contents.clone
932
952
 
933
953
  input_file_contents = input_file_contents.collect {|element| replace_strings(element)}
@@ -961,6 +981,7 @@ def compile(input_file_path, *output_file_name)
961
981
 
962
982
  variables << current_row_split[0]
963
983
 
984
+
964
985
  end
965
986
 
966
987
  input_file_contents[x] = current_row
@@ -997,14 +1018,6 @@ def compile(input_file_path, *output_file_name)
997
1018
 
998
1019
  variables = variables.flatten
999
1020
 
1000
- if variables.length > 0
1001
-
1002
- variable_declaration_string = "var " + variables.uniq.sort.join(", ") + "\n\n"
1003
-
1004
- line_by_line_contents = [variable_declaration_string, line_by_line_contents].flatten
1005
-
1006
- end
1007
-
1008
1021
  line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("plusequal", "+=") }
1009
1022
 
1010
1023
  line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("minusequal", "-=") }
@@ -1021,6 +1034,10 @@ def compile(input_file_path, *output_file_name)
1021
1034
 
1022
1035
  line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("matchequal", "=~") }
1023
1036
 
1037
+ line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("greatequal", ">=") }
1038
+
1039
+ line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("lessyequal", "<=") }
1040
+
1024
1041
  return variables.uniq, line_by_line_contents
1025
1042
 
1026
1043
  end
@@ -1172,7 +1189,7 @@ def compile(input_file_path, *output_file_name)
1172
1189
 
1173
1190
  replacement_string = nil
1174
1191
 
1175
- if index_end.strip == "end"
1192
+ if index_end.strip == "last"
1176
1193
 
1177
1194
  replacement_string = split1 + ".slice(#{index_start},#{split}.length)\n"
1178
1195
 
@@ -1216,9 +1233,9 @@ def compile(input_file_path, *output_file_name)
1216
1233
 
1217
1234
  replacement_string = nil
1218
1235
 
1219
- if index_end.strip == "end"
1236
+ if index_end.strip == "last"
1220
1237
 
1221
- replacement_string = split1 + ".slice(#{index_start})\n"
1238
+ replacement_string = split1 + ".slice(#{index_start})" + split3.strip + "\n\n"
1222
1239
 
1223
1240
  elsif index_end.strip == "" and index_start.strip == ""
1224
1241
 
@@ -1737,6 +1754,26 @@ def compile(input_file_path, *output_file_name)
1737
1754
 
1738
1755
  def replace_strings(input_string)
1739
1756
 
1757
+ element = input_string.gsub("==", "equalequal")
1758
+
1759
+ element = element.gsub("!=", "notequal")
1760
+
1761
+ element = element.gsub("+=", "plusequal")
1762
+
1763
+ element = element.gsub("-=", "minusequal")
1764
+
1765
+ element = element.gsub("*=", "multiequal")
1766
+
1767
+ element = element.gsub("/=", "divequal")
1768
+
1769
+ element = element.gsub("%=", "modequal")
1770
+
1771
+ element = element.gsub("=~", "matchequal")
1772
+
1773
+ element = element.gsub(">=", "greatequal")
1774
+
1775
+ input_string = element.gsub("<=", "lessyequal")
1776
+
1740
1777
  string_counter = 0
1741
1778
 
1742
1779
  while input_string.include?("\"")
@@ -1765,7 +1802,7 @@ def compile(input_file_path, *output_file_name)
1765
1802
 
1766
1803
  input_function_block = input_function_block.collect {|element| replace_strings(element)}
1767
1804
 
1768
- controlregexp = /(if |Euuf |while |def |function |function\()/
1805
+ controlregexp = /(if |Euuf |for |while |def |function |function\()/
1769
1806
 
1770
1807
  variables = []
1771
1808
 
@@ -2220,7 +2257,13 @@ def compile(input_file_path, *output_file_name)
2220
2257
 
2221
2258
  ".lstrip" => ".replace(/^\\s+/g,\"\")",
2222
2259
 
2223
- ".rstrip" => ".replace(/\\s+$/g,\"\")"
2260
+ ".rstrip" => ".replace(/\\s+$/g,\"\")",
2261
+
2262
+ ".to_s" => ".toString()",
2263
+
2264
+ ".reverse" => ".reverse()",
2265
+
2266
+ ".empty?" => ".length == 0",
2224
2267
 
2225
2268
  }
2226
2269
 
@@ -2254,6 +2297,85 @@ def compile(input_file_path, *output_file_name)
2254
2297
 
2255
2298
  end
2256
2299
 
2300
+ def compile_special_keywords(input_file_contents)
2301
+
2302
+ # This method compiles some Ruby specific keywords to Javascript to make it easy to port
2303
+ # Ruby code into Javascript
2304
+
2305
+ def replace_strings(input_string)
2306
+
2307
+ string_counter = 0
2308
+
2309
+ if input_string.count("\"") % 2 == 0
2310
+
2311
+ while input_string.include?("\"")
2312
+
2313
+ string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
2314
+
2315
+ input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
2316
+
2317
+ string_counter += 1
2318
+
2319
+ end
2320
+
2321
+ end
2322
+
2323
+ if input_string.count("'") % 2 == 0
2324
+
2325
+ while input_string.include?("'")
2326
+
2327
+ string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
2328
+
2329
+ input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
2330
+
2331
+ string_counter += 1
2332
+
2333
+ end
2334
+
2335
+ end
2336
+
2337
+ return input_string
2338
+
2339
+ end
2340
+
2341
+ keyword_replacement_map = {
2342
+
2343
+ "nil" => "null",
2344
+
2345
+ "Array.new" => "Array()"
2346
+
2347
+ }
2348
+
2349
+ special_keywords = keyword_replacement_map.keys
2350
+
2351
+ keyword_map_regex = special_keywords.collect {|name| name.gsub(".","\\.")}
2352
+
2353
+ keyword_map_regex = Regexp.new(keyword_map_regex.join("|"))
2354
+
2355
+ modified_file_contents = input_file_contents.clone
2356
+
2357
+ input_file_contents.each_with_index do |line, index|
2358
+
2359
+ if replace_strings(line).match(keyword_map_regex)
2360
+
2361
+ method_match = line.match(keyword_map_regex).to_a[0]
2362
+
2363
+ if line.split(keyword_map_regex)[0].include?("=")
2364
+
2365
+ line = line.sub(method_match,keyword_replacement_map[method_match])
2366
+
2367
+ end
2368
+
2369
+ end
2370
+
2371
+ modified_file_contents[index] = line
2372
+
2373
+ end
2374
+
2375
+ return modified_file_contents
2376
+
2377
+ end
2378
+
2257
2379
  def compile_whitespace_delimited_functions(input_file_contents, function_names, temporary_nila_file)
2258
2380
 
2259
2381
  def extract(input_string, pattern_start, pattern_end)
@@ -3759,6 +3881,10 @@ def compile(input_file_path, *output_file_name)
3759
3881
 
3760
3882
  input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
3761
3883
 
3884
+ input_file_contents = input_file_contents.collect { |element| element.gsub(">=", "greatequal") }
3885
+
3886
+ input_file_contents = input_file_contents.collect { |element| element.gsub("<=", "lessyequal") }
3887
+
3762
3888
  javascript_regexp = /(if |while |for )/
3763
3889
 
3764
3890
  for x in 0...input_file_contents.length
@@ -3901,6 +4027,8 @@ def compile(input_file_path, *output_file_name)
3901
4027
 
3902
4028
  times_counter = loop.split(".times")[0].lstrip
3903
4029
 
4030
+ times_counter = times_counter[1...-1] if times_counter.include?("(") and times_counter.include?(")")
4031
+
3904
4032
  replacement_string = "for (_i = 0, _j = #{times_counter}; _i < _j; _i += 1) {\n\n#{compiled_block}\n\n}"
3905
4033
 
3906
4034
  modified_file_contents[input_file_contents.index(original_loop)] = replacement_string
@@ -3953,7 +4081,7 @@ def compile(input_file_path, *output_file_name)
3953
4081
 
3954
4082
  line = starting_line
3955
4083
 
3956
- until line.strip.eql?("end")
4084
+ until line.strip.eql?("end") or line.strip.eql?("end)")
3957
4085
 
3958
4086
  index_counter += 1
3959
4087
 
@@ -4031,7 +4159,19 @@ def compile(input_file_path, *output_file_name)
4031
4159
 
4032
4160
  caller_func = loop.split(" blockky ")[0]
4033
4161
 
4034
- replacement_string = "#{caller_func.rstrip}(#{compiled_block.lstrip})"
4162
+ unless caller_func.rstrip[-1] == ","
4163
+
4164
+ replacement_string = "#{caller_func.rstrip}(#{compiled_block.lstrip})"
4165
+
4166
+ else
4167
+
4168
+ caller_func_split = caller_func.split("(") if caller_func.include?("(")
4169
+
4170
+ caller_func_split = caller_func.split(" ",2) if caller_func.include?(" ")
4171
+
4172
+ replacement_string = "#{caller_func_split[0]}(#{caller_func_split[1].strip + compiled_block.lstrip})"
4173
+
4174
+ end
4035
4175
 
4036
4176
  modified_file_contents[input_file_contents.index(original_loop)] = replacement_string
4037
4177
 
@@ -4189,7 +4329,7 @@ def compile(input_file_path, *output_file_name)
4189
4329
 
4190
4330
  end
4191
4331
 
4192
- def pretty_print_javascript(javascript_file_contents, temporary_nila_file)
4332
+ def pretty_print_javascript(javascript_file_contents, temporary_nila_file,declarable_variables)
4193
4333
 
4194
4334
  def reset_tabs(input_file_contents)
4195
4335
 
@@ -4353,7 +4493,7 @@ def compile(input_file_path, *output_file_name)
4353
4493
 
4354
4494
  if !code_block_starting_locations.empty?
4355
4495
 
4356
- controlregexp = /(if |for |while |\(function\(|= function\(|((=|:)\s+\{))/
4496
+ controlregexp = /(if |for |while |,function\(|\(function\(|= function\(|((=|:)\s+\{))/
4357
4497
 
4358
4498
  code_block_starting_locations = [0, code_block_starting_locations, -1].flatten
4359
4499
 
@@ -4483,7 +4623,7 @@ def compile(input_file_path, *output_file_name)
4483
4623
 
4484
4624
  def replace_ignored_words(input_string)
4485
4625
 
4486
- ignorable_keywords = [/if/, /while/, /function/]
4626
+ ignorable_keywords = [/if/, /while/, /function/,/function/]
4487
4627
 
4488
4628
  dummy_replacement_words = ["eeuuff", "whaalesskkey", "conffoolotion"]
4489
4629
 
@@ -4499,6 +4639,14 @@ def compile(input_file_path, *output_file_name)
4499
4639
 
4500
4640
  javascript_regexp = /(if |for |while |\(function\(|= function\(|((=|:)\s+\{))/
4501
4641
 
4642
+ if declarable_variables.length > 0
4643
+
4644
+ declaration_string = "var " + declarable_variables.flatten.uniq.sort.join(", ") + ";\n\n"
4645
+
4646
+ javascript_file_contents = [declaration_string,javascript_file_contents].flatten
4647
+
4648
+ end
4649
+
4502
4650
  javascript_file_contents = javascript_file_contents.collect { |element| element.sub("Euuf", "if") }
4503
4651
 
4504
4652
  javascript_file_contents = javascript_file_contents.collect { |element| element.sub("whaaleskey", "while") }
@@ -4782,14 +4930,18 @@ def compile(input_file_path, *output_file_name)
4782
4930
 
4783
4931
  file_contents = compile_strings(file_contents)
4784
4932
 
4933
+ list_of_variables, file_contents = get_variables(file_contents, temp_file,loop_vars)
4934
+
4785
4935
  file_contents, function_names = compile_named_functions(file_contents, named_functions, nested_functions, temp_file)
4786
4936
 
4787
- list_of_variables, file_contents = get_variables(file_contents, temp_file,loop_vars+function_names)
4937
+ func_names = function_names.dup
4788
4938
 
4789
4939
  file_contents, ruby_functions = compile_custom_function_map(file_contents)
4790
4940
 
4791
4941
  file_contents = compile_ruby_methods(file_contents)
4792
4942
 
4943
+ file_contents = compile_special_keywords(file_contents)
4944
+
4793
4945
  function_names << ruby_functions
4794
4946
 
4795
4947
  list_of_variables += loop_vars
@@ -4802,7 +4954,7 @@ def compile(input_file_path, *output_file_name)
4802
4954
 
4803
4955
  file_contents = compile_comments(file_contents, comments, temp_file)
4804
4956
 
4805
- file_contents = pretty_print_javascript(file_contents, temp_file)
4957
+ file_contents = pretty_print_javascript(file_contents, temp_file,list_of_variables+func_names)
4806
4958
 
4807
4959
  file_contents = compile_operators(file_contents)
4808
4960
 
data/lib/nilac/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.3.6"
2
+ VERSION = "0.0.4.3.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nilac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.3.6
4
+ version: 0.0.4.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adhithya Rajasekaran