nilac 0.0.4.3.4 → 0.0.4.3.6
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.
- checksums.yaml +4 -4
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/libraries/Generated_files.xml +13 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/nila.iml +21 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/watcherTasks.xml +26 -0
- data/.idea/workspace.xml +495 -0
- data/bin/nilac +422 -64
- data/examples/decBin.js +48 -0
- data/examples/decBin.nila +65 -0
- data/lib/nilac/version.rb +1 -1
- data/shark/features/ruby_methods.feature +11 -0
- data/shark/test_files/array_string_indexing.nila +2 -2
- data/shark/test_files/correct_default_parameters.js +1 -1
- data/shark/test_files/correct_initialization.js +1 -7
- data/shark/test_files/correct_multiple_return.js +1 -1
- data/shark/test_files/correct_regular_if.js +0 -1
- data/shark/test_files/correct_regular_while.js +0 -2
- data/shark/test_files/correct_ruby_methods.js +45 -0
- data/shark/test_files/multiple_initialization.nila +0 -2
- data/shark/test_files/regular_if.nila +0 -2
- data/shark/test_files/regular_while.nila +0 -2
- data/shark/test_files/ruby_methods.nila +23 -1
- data/src/nilac.rb +540 -64
- metadata +17 -2
data/bin/nilac
CHANGED
@@ -333,8 +333,6 @@ def compile(input_file_path, *output_file_name)
|
|
333
333
|
|
334
334
|
test_string = string_extract[0..closed_curly_brace_index[0]]
|
335
335
|
|
336
|
-
puts test_string
|
337
|
-
|
338
336
|
original_string = test_string.dup
|
339
337
|
|
340
338
|
if test_string.include?("{")
|
@@ -419,16 +417,48 @@ def compile(input_file_path, *output_file_name)
|
|
419
417
|
|
420
418
|
def replace_singleline_comments(input_file_contents)
|
421
419
|
|
420
|
+
def replace_strings(input_string)
|
421
|
+
|
422
|
+
string_counter = 0
|
423
|
+
|
424
|
+
while input_string.include?("\"")
|
425
|
+
|
426
|
+
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
427
|
+
|
428
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
429
|
+
|
430
|
+
string_counter += 1
|
431
|
+
|
432
|
+
end
|
433
|
+
|
434
|
+
while input_string.include?("'")
|
435
|
+
|
436
|
+
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
437
|
+
|
438
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
439
|
+
|
440
|
+
string_counter += 1
|
441
|
+
|
442
|
+
end
|
443
|
+
|
444
|
+
return input_string
|
445
|
+
|
446
|
+
end
|
447
|
+
|
422
448
|
single_line_comments = []
|
423
449
|
|
424
450
|
singleline_comment_counter = 1
|
425
451
|
|
452
|
+
modified_file_contents = input_file_contents.clone
|
453
|
+
|
426
454
|
for x in 0...input_file_contents.length
|
427
455
|
|
428
|
-
current_row = input_file_contents[x]
|
456
|
+
current_row = replace_strings(input_file_contents[x])
|
429
457
|
|
430
458
|
if current_row.include?("#")
|
431
459
|
|
460
|
+
current_row = modified_file_contents[x]
|
461
|
+
|
432
462
|
comment_start = current_row.index("#")
|
433
463
|
|
434
464
|
if current_row[comment_start+1] != "{"
|
@@ -443,13 +473,17 @@ def compile(input_file_path, *output_file_name)
|
|
443
473
|
|
444
474
|
end
|
445
475
|
|
476
|
+
else
|
477
|
+
|
478
|
+
current_row = modified_file_contents[x]
|
479
|
+
|
446
480
|
end
|
447
481
|
|
448
|
-
|
482
|
+
modified_file_contents[x] = current_row
|
449
483
|
|
450
484
|
end
|
451
485
|
|
452
|
-
return
|
486
|
+
return modified_file_contents, single_line_comments
|
453
487
|
|
454
488
|
end
|
455
489
|
|
@@ -481,7 +515,7 @@ def compile(input_file_path, *output_file_name)
|
|
481
515
|
|
482
516
|
key_word_locations << x
|
483
517
|
|
484
|
-
elsif current_row.lstrip.
|
518
|
+
elsif current_row.lstrip.eql?("end\n") || current_row.strip.eql?("end")
|
485
519
|
|
486
520
|
end_locations << x
|
487
521
|
|
@@ -529,9 +563,9 @@ def compile(input_file_path, *output_file_name)
|
|
529
563
|
|
530
564
|
modified_file_contents[code_block_begin] = code_block_begin_string
|
531
565
|
|
532
|
-
rescue NoMethodError
|
533
|
-
|
534
|
-
|
566
|
+
#rescue NoMethodError
|
567
|
+
#
|
568
|
+
# puts "Function compilation failed!"
|
535
569
|
|
536
570
|
end
|
537
571
|
|
@@ -610,12 +644,42 @@ def compile(input_file_path, *output_file_name)
|
|
610
644
|
|
611
645
|
def arrayify_right_side(input_string)
|
612
646
|
|
647
|
+
def replace_strings(input_string)
|
648
|
+
|
649
|
+
string_counter = 0
|
650
|
+
|
651
|
+
while input_string.include?("\"")
|
652
|
+
|
653
|
+
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
654
|
+
|
655
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
656
|
+
|
657
|
+
string_counter += 1
|
658
|
+
|
659
|
+
end
|
660
|
+
|
661
|
+
while input_string.include?("'")
|
662
|
+
|
663
|
+
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
664
|
+
|
665
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
666
|
+
|
667
|
+
string_counter += 1
|
668
|
+
|
669
|
+
end
|
670
|
+
|
671
|
+
return input_string
|
672
|
+
|
673
|
+
end
|
674
|
+
|
675
|
+
modified_input_string = input_string.dup
|
676
|
+
|
677
|
+
input_string = replace_strings(input_string)
|
678
|
+
|
613
679
|
javascript_regexp = /(if |while |for |function |function\()/
|
614
680
|
|
615
681
|
if input_string.include?("=") and input_string.index(javascript_regexp) == nil and input_string.strip[0..3] != "_ref" and !input_string.split("=")[1].include?("[")
|
616
682
|
|
617
|
-
modified_input_string = input_string.dup
|
618
|
-
|
619
683
|
right_side = input_string.split("=")[1]
|
620
684
|
|
621
685
|
if right_side.include?(",")
|
@@ -640,19 +704,19 @@ def compile(input_file_path, *output_file_name)
|
|
640
704
|
|
641
705
|
replacement_string = " [#{replacement_string.join(",").strip}]\n"
|
642
706
|
|
643
|
-
|
707
|
+
modified_input_string = modified_input_string.sub(right_side,replacement_string)
|
644
708
|
|
645
709
|
end
|
646
710
|
|
647
711
|
end
|
648
712
|
|
649
|
-
return
|
713
|
+
return modified_input_string
|
650
714
|
|
651
715
|
end
|
652
716
|
|
653
717
|
input_file_contents = input_file_contents.collect {|element| arrayify_right_side(element)}
|
654
718
|
|
655
|
-
possible_variable_lines = input_file_contents.reject { |element| !element.include? "=" }
|
719
|
+
possible_variable_lines = input_file_contents.clone.reject { |element| !element.include? "=" }
|
656
720
|
|
657
721
|
possible_parallel_assignment = possible_variable_lines.reject { |element| !element.split("=")[0].include? "," }
|
658
722
|
|
@@ -740,10 +804,30 @@ def compile(input_file_path, *output_file_name)
|
|
740
804
|
|
741
805
|
end
|
742
806
|
|
743
|
-
|
807
|
+
reject_regexp = /(function |Euuf |if |else|elsuf|switch |case|while |whaaleskey |for )/
|
808
|
+
|
809
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("==", "equalequal") }
|
810
|
+
|
811
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("!=", "notequal") }
|
812
|
+
|
813
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("+=", "plusequal") }
|
814
|
+
|
815
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("-=", "minusequal") }
|
816
|
+
|
817
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("*=", "multiequal") }
|
818
|
+
|
819
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("/=", "divequal") }
|
820
|
+
|
821
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("%=", "modequal") }
|
822
|
+
|
823
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
|
824
|
+
|
825
|
+
possible_default_values = input_file_contents.dup.reject { |element| (!element.include?("def")) }
|
744
826
|
|
745
827
|
possible_default_values = possible_default_values.reject { |element| !element.include?("=") }
|
746
828
|
|
829
|
+
possible_default_values = possible_default_values.reject {|element| !element.index(reject_regexp) == nil}
|
830
|
+
|
747
831
|
if !possible_default_values.empty?
|
748
832
|
|
749
833
|
possible_default_values.each do |line|
|
@@ -776,12 +860,56 @@ def compile(input_file_path, *output_file_name)
|
|
776
860
|
|
777
861
|
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
778
862
|
|
863
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("plusequal", "+=") }
|
864
|
+
|
865
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("minusequal", "-=") }
|
866
|
+
|
867
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("multiequal", "*=") }
|
868
|
+
|
869
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("divequal", "/=") }
|
870
|
+
|
871
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("modequal", "%=") }
|
872
|
+
|
873
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("equalequal", "==") }
|
874
|
+
|
875
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("notequal", "!=") }
|
876
|
+
|
877
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("matchequal", "=~") }
|
878
|
+
|
779
879
|
return line_by_line_contents
|
780
880
|
|
781
881
|
end
|
782
882
|
|
783
883
|
def get_variables(input_file_contents, temporary_nila_file, *loop_variables)
|
784
884
|
|
885
|
+
def replace_strings(input_string)
|
886
|
+
|
887
|
+
string_counter = 0
|
888
|
+
|
889
|
+
while input_string.include?("\"")
|
890
|
+
|
891
|
+
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
892
|
+
|
893
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
894
|
+
|
895
|
+
string_counter += 1
|
896
|
+
|
897
|
+
end
|
898
|
+
|
899
|
+
while input_string.include?("'")
|
900
|
+
|
901
|
+
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
902
|
+
|
903
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
904
|
+
|
905
|
+
string_counter += 1
|
906
|
+
|
907
|
+
end
|
908
|
+
|
909
|
+
return input_string
|
910
|
+
|
911
|
+
end
|
912
|
+
|
785
913
|
variables = []
|
786
914
|
|
787
915
|
input_file_contents = input_file_contents.collect { |element| element.gsub("==", "equalequal") }
|
@@ -800,6 +928,10 @@ def compile(input_file_path, *output_file_name)
|
|
800
928
|
|
801
929
|
input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
|
802
930
|
|
931
|
+
modified_file_contents = input_file_contents.clone
|
932
|
+
|
933
|
+
input_file_contents = input_file_contents.collect {|element| replace_strings(element)}
|
934
|
+
|
803
935
|
javascript_regexp = /(if |while |for )/
|
804
936
|
|
805
937
|
for x in 0...input_file_contents.length
|
@@ -825,8 +957,9 @@ def compile(input_file_path, *output_file_name)
|
|
825
957
|
|
826
958
|
end
|
827
959
|
|
828
|
-
|
960
|
+
current_row_split[0] = current_row_split[0].split(".",2)[0].strip if current_row_split[0].include?(".")
|
829
961
|
|
962
|
+
variables << current_row_split[0]
|
830
963
|
|
831
964
|
end
|
832
965
|
|
@@ -834,7 +967,7 @@ def compile(input_file_path, *output_file_name)
|
|
834
967
|
|
835
968
|
end
|
836
969
|
|
837
|
-
file_contents_as_string =
|
970
|
+
file_contents_as_string = modified_file_contents.join
|
838
971
|
|
839
972
|
file_id = open(temporary_nila_file, 'w')
|
840
973
|
|
@@ -937,7 +1070,7 @@ def compile(input_file_path, *output_file_name)
|
|
937
1070
|
|
938
1071
|
end
|
939
1072
|
|
940
|
-
def compile_arrays(input_file_contents, temporary_nila_file)
|
1073
|
+
def compile_arrays(input_file_contents, named_functions, temporary_nila_file)
|
941
1074
|
|
942
1075
|
def compile_w_arrays(input_file_contents)
|
943
1076
|
|
@@ -1189,7 +1322,7 @@ def compile(input_file_path, *output_file_name)
|
|
1189
1322
|
|
1190
1323
|
left, right = usage.split("<<")
|
1191
1324
|
|
1192
|
-
input_file_contents[input_file_contents.index(usage)] = left.rstrip + ".push(#{right.
|
1325
|
+
input_file_contents[input_file_contents.index(usage)] = left.rstrip + ".push(#{right.strip})\n\n"
|
1193
1326
|
|
1194
1327
|
end
|
1195
1328
|
|
@@ -1205,7 +1338,15 @@ def compile(input_file_path, *output_file_name)
|
|
1205
1338
|
|
1206
1339
|
input_file_contents = compile_array_operators(input_file_contents)
|
1207
1340
|
|
1208
|
-
|
1341
|
+
named_functions = named_functions.collect {|func| compile_w_arrays(func)}
|
1342
|
+
|
1343
|
+
named_functions = named_functions.collect { |func| compile_array_indexing(func)}
|
1344
|
+
|
1345
|
+
named_functions = named_functions.collect {|func| compile_multiline(func, temporary_nila_file)}
|
1346
|
+
|
1347
|
+
named_functions = named_functions.collect {|func| compile_array_operators(func)}
|
1348
|
+
|
1349
|
+
return input_file_contents, named_functions
|
1209
1350
|
|
1210
1351
|
|
1211
1352
|
end
|
@@ -1214,8 +1355,40 @@ def compile(input_file_path, *output_file_name)
|
|
1214
1355
|
|
1215
1356
|
def compile_multiline_hashes(input_file_contents,temporary_nila_file)
|
1216
1357
|
|
1358
|
+
def replace_strings(input_string)
|
1359
|
+
|
1360
|
+
string_counter = 0
|
1361
|
+
|
1362
|
+
while input_string.include?("\"")
|
1363
|
+
|
1364
|
+
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
1365
|
+
|
1366
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
1367
|
+
|
1368
|
+
string_counter += 1
|
1369
|
+
|
1370
|
+
end
|
1371
|
+
|
1372
|
+
while input_string.include?("'")
|
1373
|
+
|
1374
|
+
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
1375
|
+
|
1376
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
1377
|
+
|
1378
|
+
string_counter += 1
|
1379
|
+
|
1380
|
+
end
|
1381
|
+
|
1382
|
+
return input_string
|
1383
|
+
|
1384
|
+
end
|
1385
|
+
|
1217
1386
|
javascript_regexp = /(if |while |for |function |function\()/
|
1218
1387
|
|
1388
|
+
modified_file_contents = input_file_contents.clone
|
1389
|
+
|
1390
|
+
input_file_contents = input_file_contents.collect {|line| replace_strings(line)}
|
1391
|
+
|
1219
1392
|
possible_hashes = input_file_contents.reject { |element| !element.include?("{") }
|
1220
1393
|
|
1221
1394
|
possible_multiline_hashes = possible_hashes.reject { |element| element.include?("}") }
|
@@ -1228,21 +1401,21 @@ def compile(input_file_path, *output_file_name)
|
|
1228
1401
|
|
1229
1402
|
index = input_file_contents.index(starting_line)
|
1230
1403
|
|
1231
|
-
line =
|
1404
|
+
line = modified_file_contents[index]
|
1232
1405
|
|
1233
1406
|
until line.include?("}\n")
|
1234
1407
|
|
1235
1408
|
index += 1
|
1236
1409
|
|
1237
|
-
line =
|
1410
|
+
line = modified_file_contents[index]
|
1238
1411
|
|
1239
1412
|
end
|
1240
1413
|
|
1241
|
-
multiline_hashes <<
|
1414
|
+
multiline_hashes << modified_file_contents[input_file_contents.index(starting_line)..index]
|
1242
1415
|
|
1243
1416
|
end
|
1244
1417
|
|
1245
|
-
joined_file_contents =
|
1418
|
+
joined_file_contents = modified_file_contents.join
|
1246
1419
|
|
1247
1420
|
multiline_hashes.each do |hash|
|
1248
1421
|
|
@@ -1310,6 +1483,8 @@ def compile(input_file_path, *output_file_name)
|
|
1310
1483
|
|
1311
1484
|
possible_inline_hashes = possible_inline_hashes.reject {|element| element.index(javascript_regexp) != nil}
|
1312
1485
|
|
1486
|
+
possible_inline_hashes = possible_inline_hashes.reject {|element| element.include?("{}")}
|
1487
|
+
|
1313
1488
|
possible_inline_hashes.each do |hash|
|
1314
1489
|
|
1315
1490
|
hash = input_file_contents[modified_file_contents.index(hash)]
|
@@ -1560,7 +1735,37 @@ def compile(input_file_path, *output_file_name)
|
|
1560
1735
|
#This method will pickup and declare all the variables inside a function block. In future, this method will be
|
1561
1736
|
#merged with the get variables method
|
1562
1737
|
|
1563
|
-
|
1738
|
+
def replace_strings(input_string)
|
1739
|
+
|
1740
|
+
string_counter = 0
|
1741
|
+
|
1742
|
+
while input_string.include?("\"")
|
1743
|
+
|
1744
|
+
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
1745
|
+
|
1746
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
1747
|
+
|
1748
|
+
string_counter += 1
|
1749
|
+
|
1750
|
+
end
|
1751
|
+
|
1752
|
+
while input_string.include?("'")
|
1753
|
+
|
1754
|
+
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
1755
|
+
|
1756
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
1757
|
+
|
1758
|
+
string_counter += 1
|
1759
|
+
|
1760
|
+
end
|
1761
|
+
|
1762
|
+
return input_string
|
1763
|
+
|
1764
|
+
end
|
1765
|
+
|
1766
|
+
input_function_block = input_function_block.collect {|element| replace_strings(element)}
|
1767
|
+
|
1768
|
+
controlregexp = /(if |Euuf |while |def |function |function\()/
|
1564
1769
|
|
1565
1770
|
variables = []
|
1566
1771
|
|
@@ -1644,7 +1849,7 @@ def compile(input_file_path, *output_file_name)
|
|
1644
1849
|
|
1645
1850
|
if !rejected_array[0].strip.eql?("}")
|
1646
1851
|
|
1647
|
-
if !rejected_array[0].strip.eql?("end")
|
1852
|
+
if !rejected_array[0].strip.eql?("end") and !rejected_array[0].strip.include?("--single_line_comment")
|
1648
1853
|
|
1649
1854
|
last_statement = rejected_array[0]
|
1650
1855
|
|
@@ -1970,13 +2175,25 @@ def compile(input_file_path, *output_file_name)
|
|
1970
2175
|
|
1971
2176
|
modified_file_contents = input_file_contents.dup
|
1972
2177
|
|
2178
|
+
javascript_regexp = /(if |for |while |\(function\(|= function\(|((=|:)\s+\{))/
|
2179
|
+
|
1973
2180
|
input_file_contents.each_with_index do |line, index|
|
1974
2181
|
|
1975
2182
|
function_map.each do |function|
|
1976
2183
|
|
1977
|
-
if line.include?(function+"(") or line.include?(function+" ")
|
2184
|
+
if line.include?(function+"(") or line.include?(function+" ") and line.index(javascript_regexp) == nil
|
2185
|
+
|
2186
|
+
testsplit = line.split(function)
|
2187
|
+
|
2188
|
+
testsplit = testsplit.collect {|element| element.strip}
|
2189
|
+
|
2190
|
+
testsplit[0] = " " if testsplit[0].eql?("")
|
1978
2191
|
|
1979
|
-
|
2192
|
+
if testsplit[0][-1].eql?(" ") or testsplit[0].eql?("return")
|
2193
|
+
|
2194
|
+
modified_file_contents[index] = line.sub(function, function_map_replacements[function])
|
2195
|
+
|
2196
|
+
end
|
1980
2197
|
|
1981
2198
|
end
|
1982
2199
|
|
@@ -1997,11 +2214,14 @@ def compile(input_file_path, *output_file_name)
|
|
1997
2214
|
|
1998
2215
|
".split" => ".split(\" \")",
|
1999
2216
|
|
2000
|
-
".
|
2217
|
+
".join" => ".join()",
|
2218
|
+
|
2219
|
+
".strip" => ".replace(/^\\s+|\\s+$/g,'')",
|
2220
|
+
|
2221
|
+
".lstrip" => ".replace(/^\\s+/g,\"\")",
|
2001
2222
|
|
2002
|
-
".
|
2223
|
+
".rstrip" => ".replace(/\\s+$/g,\"\")"
|
2003
2224
|
|
2004
|
-
".rstrip" => ".replace(/\s+$/g,\"\")"
|
2005
2225
|
}
|
2006
2226
|
|
2007
2227
|
method_map = method_map_replacement.keys
|
@@ -2016,16 +2236,22 @@ def compile(input_file_path, *output_file_name)
|
|
2016
2236
|
|
2017
2237
|
if line.match(method_map_regex)
|
2018
2238
|
|
2019
|
-
|
2239
|
+
method_match = line.match(method_map_regex).to_a[0]
|
2020
2240
|
|
2021
|
-
|
2241
|
+
unless line.include?(method_match + "(")
|
2242
|
+
|
2243
|
+
line = line.sub(method_match,method_map_replacement[method_match])
|
2022
2244
|
|
2023
2245
|
end
|
2024
2246
|
|
2025
2247
|
end
|
2026
2248
|
|
2249
|
+
modified_file_contents[index] = line
|
2250
|
+
|
2027
2251
|
end
|
2028
2252
|
|
2253
|
+
return modified_file_contents
|
2254
|
+
|
2029
2255
|
end
|
2030
2256
|
|
2031
2257
|
def compile_whitespace_delimited_functions(input_file_contents, function_names, temporary_nila_file)
|
@@ -2272,7 +2498,7 @@ def compile(input_file_path, *output_file_name)
|
|
2272
2498
|
|
2273
2499
|
extracted_blocks = []
|
2274
2500
|
|
2275
|
-
controlregexp = /(if |while |def )/
|
2501
|
+
controlregexp = /(if |while |def | do )/
|
2276
2502
|
|
2277
2503
|
rejectionregexp = /( if | while )/
|
2278
2504
|
|
@@ -2290,7 +2516,16 @@ def compile(input_file_path, *output_file_name)
|
|
2290
2516
|
|
2291
2517
|
possible_if_blocks.each_with_index do |block|
|
2292
2518
|
|
2293
|
-
current_block
|
2519
|
+
unless current_block[-1] == block[0]
|
2520
|
+
|
2521
|
+
current_block += block
|
2522
|
+
|
2523
|
+
else
|
2524
|
+
|
2525
|
+
current_block += block[1..-1]
|
2526
|
+
|
2527
|
+
end
|
2528
|
+
|
2294
2529
|
|
2295
2530
|
current_block.each_with_index do |line, index|
|
2296
2531
|
|
@@ -2458,7 +2693,7 @@ def compile(input_file_path, *output_file_name)
|
|
2458
2693
|
|
2459
2694
|
if_statement_indexes = [0] + if_statement_indexes.flatten + [-1]
|
2460
2695
|
|
2461
|
-
controlregexp = /(while |def )/
|
2696
|
+
controlregexp = /(while |def | do )/
|
2462
2697
|
|
2463
2698
|
modified_input_contents, extracted_statements = extract_if_blocks(if_statement_indexes, input_file_contents.clone)
|
2464
2699
|
|
@@ -2570,7 +2805,7 @@ def compile(input_file_path, *output_file_name)
|
|
2570
2805
|
|
2571
2806
|
extracted_blocks = []
|
2572
2807
|
|
2573
|
-
controlregexp = /(if |while |def )/
|
2808
|
+
controlregexp = /(if |while |def | do )/
|
2574
2809
|
|
2575
2810
|
rejectionregexp = /( if | while )/
|
2576
2811
|
|
@@ -2728,7 +2963,7 @@ def compile(input_file_path, *output_file_name)
|
|
2728
2963
|
|
2729
2964
|
while_statement_indexes = [0] + while_statement_indexes.flatten + [-1]
|
2730
2965
|
|
2731
|
-
controlregexp = /(if |def )/
|
2966
|
+
controlregexp = /(if |def | do )/
|
2732
2967
|
|
2733
2968
|
modified_input_contents, extracted_statements = extract_while_blocks(while_statement_indexes, input_file_contents.clone)
|
2734
2969
|
|
@@ -2778,7 +3013,7 @@ def compile(input_file_path, *output_file_name)
|
|
2778
3013
|
|
2779
3014
|
else
|
2780
3015
|
|
2781
|
-
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0]
|
3016
|
+
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0])
|
2782
3017
|
|
2783
3018
|
rejected_elements_index.delete_at(0)
|
2784
3019
|
|
@@ -2788,7 +3023,7 @@ def compile(input_file_path, *output_file_name)
|
|
2788
3023
|
|
2789
3024
|
else
|
2790
3025
|
|
2791
|
-
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0]
|
3026
|
+
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0])
|
2792
3027
|
|
2793
3028
|
rejected_elements_index.delete_at(0)
|
2794
3029
|
|
@@ -2840,7 +3075,7 @@ def compile(input_file_path, *output_file_name)
|
|
2840
3075
|
|
2841
3076
|
extracted_blocks = []
|
2842
3077
|
|
2843
|
-
controlregexp = /(if |while |def |for )/
|
3078
|
+
controlregexp = /(if |while |def |for | do )/
|
2844
3079
|
|
2845
3080
|
rejectionregexp = /( if | while )/
|
2846
3081
|
|
@@ -3044,7 +3279,7 @@ def compile(input_file_path, *output_file_name)
|
|
3044
3279
|
|
3045
3280
|
for_statement_indexes = [0] + for_statement_indexes.flatten + [-1]
|
3046
3281
|
|
3047
|
-
controlregexp = /(if |def |while )/
|
3282
|
+
controlregexp = /(if |def |while | do )/
|
3048
3283
|
|
3049
3284
|
modified_input_contents, extracted_statements = extract_for_blocks(for_statement_indexes, input_file_contents.clone)
|
3050
3285
|
|
@@ -3104,7 +3339,7 @@ def compile(input_file_path, *output_file_name)
|
|
3104
3339
|
|
3105
3340
|
else
|
3106
3341
|
|
3107
|
-
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0]
|
3342
|
+
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0])
|
3108
3343
|
|
3109
3344
|
rejected_elements_index.delete_at(0)
|
3110
3345
|
|
@@ -3470,8 +3705,6 @@ def compile(input_file_path, *output_file_name)
|
|
3470
3705
|
|
3471
3706
|
file_contents = compile_ternary_if(input_file_contents)
|
3472
3707
|
|
3473
|
-
puts file_contents
|
3474
|
-
|
3475
3708
|
file_contents, rejected_lines = ignore_statement_modifiers(file_contents)
|
3476
3709
|
|
3477
3710
|
file_contents = replace_unless_until(file_contents)
|
@@ -3696,6 +3929,130 @@ def compile(input_file_path, *output_file_name)
|
|
3696
3929
|
|
3697
3930
|
end
|
3698
3931
|
|
3932
|
+
def compile_blocks(input_file_contents,temporary_nila_file)
|
3933
|
+
|
3934
|
+
def compile_one_line_blocks(input_block)
|
3935
|
+
|
3936
|
+
block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2)
|
3937
|
+
|
3938
|
+
compiled_block = "function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents.strip} \n\n}"
|
3939
|
+
|
3940
|
+
return compiled_block
|
3941
|
+
|
3942
|
+
end
|
3943
|
+
|
3944
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("append","appand")}
|
3945
|
+
|
3946
|
+
possible_blocks = input_file_contents.reject {|line| !line.include?(" do ")}
|
3947
|
+
|
3948
|
+
unless possible_blocks.empty?
|
3949
|
+
|
3950
|
+
possible_blocks.each do |starting_line|
|
3951
|
+
|
3952
|
+
index_counter = starting_counter = input_file_contents.index(starting_line)
|
3953
|
+
|
3954
|
+
line = starting_line
|
3955
|
+
|
3956
|
+
until line.strip.eql?("end")
|
3957
|
+
|
3958
|
+
index_counter += 1
|
3959
|
+
|
3960
|
+
line = input_file_contents[index_counter]
|
3961
|
+
|
3962
|
+
end
|
3963
|
+
|
3964
|
+
loop_extract = input_file_contents[starting_counter..index_counter]
|
3965
|
+
|
3966
|
+
loop_condition, block = loop_extract.join.split(" do ")
|
3967
|
+
|
3968
|
+
block = block.split("end")[0]
|
3969
|
+
|
3970
|
+
replacement_string = "#{loop_condition.rstrip} blockky {#{block.strip}}_!"
|
3971
|
+
|
3972
|
+
input_file_contents[starting_counter..index_counter] = replacement_string
|
3973
|
+
|
3974
|
+
end
|
3975
|
+
|
3976
|
+
end
|
3977
|
+
|
3978
|
+
possible_blocks = input_file_contents.reject{ |element| !element.include?(" blockky ")}
|
3979
|
+
|
3980
|
+
possible_blocks = possible_blocks.reject {|element| !element.include?("{") and !element.include?("}")}
|
3981
|
+
|
3982
|
+
modified_file_contents = input_file_contents.clone
|
3983
|
+
|
3984
|
+
unless possible_blocks.empty?
|
3985
|
+
|
3986
|
+
possible_blocks.each do |loop|
|
3987
|
+
|
3988
|
+
original_loop = loop.clone
|
3989
|
+
|
3990
|
+
string_counter = 1
|
3991
|
+
|
3992
|
+
extracted_string = []
|
3993
|
+
|
3994
|
+
while loop.include?("\"")
|
3995
|
+
|
3996
|
+
string_extract = loop[loop.index("\"")..loop.index("\"",loop.index("\"")+1)]
|
3997
|
+
|
3998
|
+
extracted_string << string_extract
|
3999
|
+
|
4000
|
+
loop = loop.sub(string_extract,"--repstring#{string_counter}")
|
4001
|
+
|
4002
|
+
string_counter += 1
|
4003
|
+
|
4004
|
+
end
|
4005
|
+
|
4006
|
+
block_extract = loop[loop.index("{")..loop.index("}_!")]
|
4007
|
+
|
4008
|
+
compiled_block = ""
|
4009
|
+
|
4010
|
+
if block_extract.count("|") == 2
|
4011
|
+
|
4012
|
+
compiled_block = compile_one_line_blocks(block_extract)
|
4013
|
+
|
4014
|
+
extracted_string.each_with_index do |string,index|
|
4015
|
+
|
4016
|
+
compiled_block = compiled_block.sub("--repstring#{index+1}",string)
|
4017
|
+
|
4018
|
+
end
|
4019
|
+
|
4020
|
+
else
|
4021
|
+
|
4022
|
+
compiled_block = block_extract[1...-1].lstrip.rstrip
|
4023
|
+
|
4024
|
+
extracted_string.each_with_index do |string,index|
|
4025
|
+
|
4026
|
+
compiled_block = compiled_block.sub("--repstring#{index+1}",string)
|
4027
|
+
|
4028
|
+
end
|
4029
|
+
|
4030
|
+
end
|
4031
|
+
|
4032
|
+
caller_func = loop.split(" blockky ")[0]
|
4033
|
+
|
4034
|
+
replacement_string = "#{caller_func.rstrip}(#{compiled_block.lstrip})"
|
4035
|
+
|
4036
|
+
modified_file_contents[input_file_contents.index(original_loop)] = replacement_string
|
4037
|
+
|
4038
|
+
end
|
4039
|
+
|
4040
|
+
end
|
4041
|
+
|
4042
|
+
modified_file_contents = modified_file_contents.collect {|element| element.gsub("appand","append")}
|
4043
|
+
|
4044
|
+
file_id = open(temporary_nila_file, 'w')
|
4045
|
+
|
4046
|
+
file_id.write(modified_file_contents.join)
|
4047
|
+
|
4048
|
+
file_id.close()
|
4049
|
+
|
4050
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
4051
|
+
|
4052
|
+
return line_by_line_contents
|
4053
|
+
|
4054
|
+
end
|
4055
|
+
|
3699
4056
|
def add_semicolons(input_file_contents)
|
3700
4057
|
|
3701
4058
|
def comment(input_string)
|
@@ -3912,7 +4269,7 @@ def compile(input_file_path, *output_file_name)
|
|
3912
4269
|
|
3913
4270
|
end
|
3914
4271
|
|
3915
|
-
block_ending_lines = file_contents.dup.each_index.select { |index| (file_contents[index].eql? " }\n" or file_contents[index].eql? " };\n")}
|
4272
|
+
block_ending_lines = file_contents.dup.each_index.select { |index| (file_contents[index].eql? " }\n" or file_contents[index].eql? " };\n" or file_contents[index].lstrip.eql?("});\n"))}
|
3916
4273
|
|
3917
4274
|
modified_file_contents = file_contents.dup
|
3918
4275
|
|
@@ -3942,19 +4299,19 @@ def compile(input_file_path, *output_file_name)
|
|
3942
4299
|
|
3943
4300
|
end
|
3944
4301
|
|
3945
|
-
block_ending_lines = modified_file_contents.dup.each_index.select { |index| (modified_file_contents[index].eql? " }\n" or modified_file_contents[index].eql? " };\n") }
|
4302
|
+
block_ending_lines = modified_file_contents.dup.each_index.select { |index| (modified_file_contents[index].eql? " }\n" or modified_file_contents[index].eql? " };\n" or modified_file_contents[index].lstrip.eql?("});\n")) }
|
3946
4303
|
|
3947
4304
|
starting_index = starting_line_indices[0]
|
3948
4305
|
|
3949
4306
|
end
|
3950
4307
|
|
3951
|
-
rescue TypeError
|
3952
|
-
|
3953
|
-
|
3954
|
-
|
3955
|
-
rescue ArgumentError
|
3956
|
-
|
3957
|
-
|
4308
|
+
#rescue TypeError
|
4309
|
+
#
|
4310
|
+
# puts "Whitespace was left unfixed!"
|
4311
|
+
#
|
4312
|
+
#rescue ArgumentError
|
4313
|
+
#
|
4314
|
+
# puts "Whitespace was left unfixed!"
|
3958
4315
|
|
3959
4316
|
end
|
3960
4317
|
|
@@ -3986,7 +4343,6 @@ def compile(input_file_path, *output_file_name)
|
|
3986
4343
|
|
3987
4344
|
starting_index = code_block_locations[0]
|
3988
4345
|
|
3989
|
-
|
3990
4346
|
end
|
3991
4347
|
|
3992
4348
|
return compact_contents
|
@@ -4039,7 +4395,7 @@ def compile(input_file_path, *output_file_name)
|
|
4039
4395
|
|
4040
4396
|
current_block.each_with_index do |line, index|
|
4041
4397
|
|
4042
|
-
if line.lstrip.eql? "}\n" or line.lstrip.eql?("};\n") or line.lstrip.include?("_!;\n")
|
4398
|
+
if line.lstrip.eql? "}\n" or line.lstrip.eql?("};\n") or line.lstrip.include?("_!;\n") or line.lstrip.include?("});\n")
|
4043
4399
|
|
4044
4400
|
end_counter += 1
|
4045
4401
|
|
@@ -4073,7 +4429,7 @@ def compile(input_file_path, *output_file_name)
|
|
4073
4429
|
|
4074
4430
|
block_end = current_block.index(block_extract[-1])
|
4075
4431
|
|
4076
|
-
current_block[block_start..block_end] = "--block#{block_counter}"
|
4432
|
+
current_block[block_start..block_end] = "--block#{block_counter}\n"
|
4077
4433
|
|
4078
4434
|
block_counter += 1
|
4079
4435
|
|
@@ -4083,7 +4439,7 @@ def compile(input_file_path, *output_file_name)
|
|
4083
4439
|
|
4084
4440
|
current_block.each_with_index do |line, index|
|
4085
4441
|
|
4086
|
-
if line.lstrip.eql? "}\n" or line.lstrip.eql?("};\n") or line.lstrip.include?("_!;\n")
|
4442
|
+
if line.lstrip.eql? "}\n" or line.lstrip.eql?("};\n") or line.lstrip.include?("_!;\n") or line.lstrip.include?("});\n")
|
4087
4443
|
|
4088
4444
|
end_counter += 1
|
4089
4445
|
|
@@ -4189,7 +4545,7 @@ def compile(input_file_path, *output_file_name)
|
|
4189
4545
|
|
4190
4546
|
current_block = [current_block[0]] + current_block[1...-1].collect { |element| soft_tabs*(soft_tabs_counter)+element } + [current_block[-1]]
|
4191
4547
|
|
4192
|
-
nested_block = current_block.reject { |row| !row.include?("--block") }
|
4548
|
+
nested_block = current_block.clone.reject { |row| !row.include?("--block") }
|
4193
4549
|
|
4194
4550
|
nested_block = nested_block.collect { |element| element.split("--block")[1] }
|
4195
4551
|
|
@@ -4197,7 +4553,7 @@ def compile(input_file_path, *output_file_name)
|
|
4197
4553
|
|
4198
4554
|
modified_nested_block = nested_block.clone
|
4199
4555
|
|
4200
|
-
current_block = current_block.join
|
4556
|
+
current_block = current_block.join("\n")
|
4201
4557
|
|
4202
4558
|
until modified_nested_block.empty?
|
4203
4559
|
|
@@ -4410,6 +4766,8 @@ def compile(input_file_path, *output_file_name)
|
|
4410
4766
|
|
4411
4767
|
file_contents = compile_conditional_structures(file_contents, temp_file)
|
4412
4768
|
|
4769
|
+
file_contents = compile_blocks(file_contents,temp_file)
|
4770
|
+
|
4413
4771
|
file_contents = compile_integers(file_contents)
|
4414
4772
|
|
4415
4773
|
file_contents = compile_default_values(file_contents, temp_file)
|
@@ -4420,17 +4778,17 @@ def compile(input_file_path, *output_file_name)
|
|
4420
4778
|
|
4421
4779
|
file_contents = compile_parallel_assignment(file_contents, temp_file)
|
4422
4780
|
|
4423
|
-
file_contents = compile_arrays(file_contents, temp_file)
|
4781
|
+
file_contents,named_functions = compile_arrays(file_contents, named_functions, temp_file)
|
4424
4782
|
|
4425
4783
|
file_contents = compile_strings(file_contents)
|
4426
4784
|
|
4427
4785
|
file_contents, function_names = compile_named_functions(file_contents, named_functions, nested_functions, temp_file)
|
4428
4786
|
|
4429
|
-
list_of_variables, file_contents = get_variables(file_contents, temp_file,loop_vars)
|
4787
|
+
list_of_variables, file_contents = get_variables(file_contents, temp_file,loop_vars+function_names)
|
4430
4788
|
|
4431
4789
|
file_contents, ruby_functions = compile_custom_function_map(file_contents)
|
4432
4790
|
|
4433
|
-
|
4791
|
+
file_contents = compile_ruby_methods(file_contents)
|
4434
4792
|
|
4435
4793
|
function_names << ruby_functions
|
4436
4794
|
|
@@ -4514,7 +4872,7 @@ def find_file_path(input_path, file_extension)
|
|
4514
4872
|
|
4515
4873
|
end
|
4516
4874
|
|
4517
|
-
nilac_version = "0.0.4.3.
|
4875
|
+
nilac_version = "0.0.4.3.4"
|
4518
4876
|
|
4519
4877
|
opts = Slop.parse do
|
4520
4878
|
on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
|