nilac 0.0.3.8 → 0.0.3.9

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.
data/bin/nilac CHANGED
@@ -309,7 +309,7 @@ def compile(input_file_path,*output_file_name)
309
309
 
310
310
  key_word_locations << x
311
311
 
312
- elsif current_row.include?("end\n") || current_row.include?("end")
312
+ elsif current_row.lstrip.include?("end\n") || current_row.include?("end")
313
313
 
314
314
  end_locations << x
315
315
 
@@ -414,6 +414,60 @@ def compile(input_file_path,*output_file_name)
414
414
 
415
415
  end
416
416
 
417
+ def compile_multiple_variable_initialization(input_file_contents,temporary_nila_file)
418
+
419
+ possible_variable_lines = input_file_contents.reject {|element| !element.include?"="}
420
+
421
+ possible_multiple_initialization = possible_variable_lines.reject {|element| !element.split("=")[0].include?","}
422
+
423
+ multiple_initialization_index = []
424
+
425
+ possible_multiple_initialization.each do |statement|
426
+
427
+ location_array = input_file_contents.each_index.select { |index| input_file_contents[index] == statement}
428
+
429
+ multiple_initialization_index << location_array[0]
430
+
431
+ end
432
+
433
+ modified_file_contents = input_file_contents.dup
434
+
435
+ multiple_init_counter = 1
436
+
437
+ possible_multiple_initialization.each_with_index do |line,index|
438
+
439
+ line_split = line.split(" = ")
440
+
441
+ right_side_variables = line_split[0].split(",")
442
+
443
+ replacement_string = "multipleinit#{multiple_init_counter} = #{line_split[1]}\n\n"
444
+
445
+ variable_string = ""
446
+
447
+ right_side_variables.each_with_index do |variable,var_index|
448
+
449
+ variable_string = variable_string + variable.rstrip + " = multipleinit#{multiple_init_counter}[#{var_index}]\n\n"
450
+
451
+ end
452
+
453
+ replacement_string = replacement_string + variable_string
454
+
455
+ modified_file_contents[multiple_initialization_index[index]] = replacement_string
456
+
457
+ end
458
+
459
+ file_id = open(temporary_nila_file, 'w')
460
+
461
+ file_id.write(modified_file_contents.join)
462
+
463
+ file_id.close()
464
+
465
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
466
+
467
+ return line_by_line_contents
468
+
469
+ end
470
+
417
471
  def get_variables(input_file_contents,temporary_nila_file)
418
472
 
419
473
  #This method is solely focused on getting a list of variables to be declared.
@@ -464,7 +518,7 @@ def compile(input_file_path,*output_file_name)
464
518
 
465
519
  if variables.length > 0
466
520
 
467
- variable_declaration_string = "var " + variables.uniq.join(", ") + "\n\n"
521
+ variable_declaration_string = "var " + variables.uniq.sort.join(", ") + "\n\n"
468
522
 
469
523
  line_by_line_contents = [variable_declaration_string,line_by_line_contents].flatten
470
524
 
@@ -526,73 +580,203 @@ def compile(input_file_path,*output_file_name)
526
580
  # 1. %w{} syntax
527
581
  # 2. Range - Coming soon!
528
582
 
529
- def extract(input_string,pattern_start,pattern_end)
583
+ def compile_w_arrays(input_file_contents)
530
584
 
531
- def find_all_matching_indices(input_string,pattern)
585
+ def extract(input_string,pattern_start,pattern_end)
532
586
 
533
- locations = []
587
+ def find_all_matching_indices(input_string,pattern)
534
588
 
535
- index = input_string.index(pattern)
589
+ locations = []
536
590
 
537
- while index != nil
591
+ index = input_string.index(pattern)
538
592
 
539
- locations << index
593
+ while index != nil
540
594
 
541
- index = input_string.index(pattern,index+1)
595
+ locations << index
596
+
597
+ index = input_string.index(pattern,index+1)
598
+
599
+
600
+ end
601
+
602
+ return locations
542
603
 
543
604
 
544
605
  end
545
606
 
546
- return locations
607
+ all_start_locations = find_all_matching_indices(input_string,pattern_start)
608
+
609
+ all_end_locations = find_all_matching_indices(input_string,pattern_end)
610
+
611
+ pattern = []
612
+
613
+ all_start_locations.each_with_index do |location,index|
547
614
 
615
+ pattern << input_string[location..all_end_locations[index]]
616
+
617
+ end
618
+
619
+ return pattern
548
620
 
549
621
  end
550
622
 
551
- all_start_locations = find_all_matching_indices(input_string,pattern_start)
623
+ def compile_w_syntax(input_string)
552
624
 
553
- all_end_locations = find_all_matching_indices(input_string,pattern_end)
625
+ modified_input_string = input_string[3...-1]
554
626
 
555
- pattern = []
627
+ string_split = modified_input_string.split(" ")
628
+
629
+ return string_split.to_s
630
+
631
+ end
632
+
633
+ modified_file_contents = input_file_contents.dup
634
+
635
+ input_file_contents.each_with_index do |line,index|
636
+
637
+ if line.include?("%w{")
556
638
 
557
- all_start_locations.each_with_index do |location,index|
639
+ string_arrays = extract(line,"%w{","}")
558
640
 
559
- pattern << input_string[location..all_end_locations[index]]
641
+ string_arrays.each do |array|
642
+
643
+ modified_file_contents[index] = modified_file_contents[index].sub(array,compile_w_syntax(array))
644
+
645
+ end
646
+
647
+ end
560
648
 
561
649
  end
562
650
 
563
- return pattern
651
+ return modified_file_contents
564
652
 
565
653
  end
566
654
 
567
- def compile_w_syntax(input_string)
655
+ def compile_array_indexing(input_file_contents)
568
656
 
569
- modified_input_string = input_string[3...-1]
657
+ #Nila allows two different kinds of indexing operations on arrays and strings. They are
570
658
 
571
- string_split = modified_input_string.split(" ")
659
+ #1. Using Ranges => numbers[0...5]
660
+ #2. Using Start and End Indexes => numbers[0,5]
572
661
 
573
- return string_split.to_s
662
+ #This method implements this Nila feature
574
663
 
575
- end
664
+ possible_indexing_operation = input_file_contents.dup.reject {|element| !element.include?"[" and !element.include?"]"}
576
665
 
577
- modified_file_contents = input_file_contents.dup
666
+ possible_range_indexing = possible_indexing_operation.reject {|element| !element.include?".."}
578
667
 
579
- input_file_contents.each_with_index do |line,index|
668
+ triple_range_indexing = possible_range_indexing.reject {|element| !element.include?"..."}
669
+
670
+ triple_range_indexes = []
671
+
672
+ triple_range_indexing.each do |line|
673
+
674
+ triple_range_indexes << input_file_contents.dup.each_index.select {|index| input_file_contents[index] == line}
675
+
676
+ end
677
+
678
+ triple_range_indexes = triple_range_indexes.flatten
679
+
680
+ triple_range_indexing.each_with_index do |line,index|
580
681
 
581
- if line.include?("%w{")
682
+ split1,split2 = line.split("[")
582
683
 
583
- string_arrays = extract(line,"%w{","}")
684
+ range_index,split3 = split2.split("]")
584
685
 
585
- string_arrays.each do |array|
686
+ index_start,index_end = range_index.split "..."
586
687
 
587
- modified_file_contents[index] = modified_file_contents[index].sub(array,compile_w_syntax(array))
688
+ replacement_string = nil
689
+
690
+ if index_end.strip == "end"
691
+
692
+ replacement_string = split1 + ".slice(#{index_start},#{split}.length)\n"
693
+
694
+ else
695
+
696
+ replacement_string = split1 + ".slice(#{index_start},#{index_end})\n"
588
697
 
589
698
  end
590
699
 
700
+ possible_range_indexing.delete(input_file_contents[triple_range_indexes[index]])
701
+
702
+ possible_indexing_operation.delete(input_file_contents[triple_range_indexes[index]])
703
+
704
+ input_file_contents[triple_range_indexes[index]] = replacement_string
705
+
591
706
  end
592
707
 
708
+ double_range_indexing = possible_range_indexing.reject {|element| !element.include?("..")}
709
+
710
+ double_range_indexes = []
711
+
712
+ double_range_indexing.each do |line|
713
+
714
+ double_range_indexes << input_file_contents.dup.each_index.select {|index| input_file_contents[index] == line}
715
+
716
+ end
717
+
718
+ double_range_indexes = double_range_indexes.flatten
719
+
720
+ double_range_indexing.each_with_index do |line,index|
721
+
722
+ split1,split2 = line.split("[")
723
+
724
+ range_index,split3 = split2.split("]")
725
+
726
+ index_start,index_end = range_index.split ".."
727
+
728
+ replacement_string = nil
729
+
730
+ if index_end.strip == "end"
731
+
732
+ replacement_string = split1 + ".slice(#{index_start})\n"
733
+
734
+ elsif index_end.strip == "" and index_start.strip == ""
735
+
736
+ replacement_string = split1 + ".slice(0)\n"
737
+
738
+ else
739
+
740
+ replacement_string = split1 + ".slice(#{index_start},#{index_end}+1)\n"
741
+
742
+ end
743
+
744
+ possible_range_indexing.delete(input_file_contents[double_range_indexes[index]])
745
+
746
+ possible_indexing_operation.delete(input_file_contents[double_range_indexes[index]])
747
+
748
+ input_file_contents[double_range_indexes[index]] = replacement_string
749
+
750
+ end
751
+
752
+ duplicating_operations = input_file_contents.dup.reject{|element| !element.include?(".dup")}
753
+
754
+ duplicating_operation_indexes = []
755
+
756
+ duplicating_operations.each do |line|
757
+
758
+ duplicating_operation_indexes << input_file_contents.dup.each_index.select {|index| input_file_contents[index] == line}
759
+
760
+ end
761
+
762
+ duplicating_operation_indexes = duplicating_operation_indexes.flatten
763
+
764
+ duplicating_operation_indexes.each do |index|
765
+
766
+ input_file_contents[index] = input_file_contents[index].sub(".dup",".slice(0)")
767
+
768
+ end
769
+
770
+ return input_file_contents
771
+
593
772
  end
594
773
 
595
- return modified_file_contents
774
+ input_file_contents = compile_w_arrays(input_file_contents)
775
+
776
+ input_file_contents = compile_array_indexing(input_file_contents)
777
+
778
+ return input_file_contents
779
+
596
780
 
597
781
  end
598
782
 
@@ -702,6 +886,134 @@ def compile(input_file_path,*output_file_name)
702
886
 
703
887
  end
704
888
 
889
+ def compile_multiple_return(input_array)
890
+
891
+ def find_all_matching_indices(input_string,pattern)
892
+
893
+ locations = []
894
+
895
+ index = input_string.index(pattern)
896
+
897
+ while index != nil
898
+
899
+ locations << index
900
+
901
+ index = input_string.index(pattern,index+1)
902
+
903
+
904
+ end
905
+
906
+ return locations
907
+
908
+
909
+ end
910
+
911
+ modified_input_array = input_array.dup
912
+
913
+ return_statements = input_array.dup.reject {|element| !element.include?"return"}
914
+
915
+ multiple_return_statements = return_statements.dup.reject {|element| !element.include?","}
916
+
917
+ modified_multiple_return_statements = multiple_return_statements.dup
918
+
919
+ return_statement_index = []
920
+
921
+ multiple_return_statements.each do |statement|
922
+
923
+ location_array = modified_input_array.each_index.select { |index| modified_input_array[index] == statement}
924
+
925
+ return_statement_index << location_array[0]
926
+
927
+ end
928
+
929
+ multiple_return_statements.each_with_index do |return_statement,index|
930
+
931
+ replacement_counter = 0
932
+
933
+ if return_statement.include? "\""
934
+
935
+ starting_quotes = find_all_matching_indices(return_statement,"\"")
936
+
937
+ for x in 0...(starting_quotes.length)/2
938
+
939
+ quotes = return_statement[starting_quotes[x]..starting_quotes[x+1]]
940
+
941
+ replacement_counter += 1
942
+
943
+ modified_multiple_return_statements[index] = modified_multiple_return_statements[index].sub(quotes,"repstring#{1}")
944
+
945
+ modified_input_array[return_statement_index[index]] = modified_multiple_return_statements[index].sub(quotes,"repstring#{1}")
946
+
947
+ end
948
+
949
+ end
950
+
951
+ end
952
+
953
+ modified_multiple_return_statements = modified_multiple_return_statements.reject {|element| !element.include?","}
954
+
955
+ return_statement_index = []
956
+
957
+ modified_multiple_return_statements.each do |statement|
958
+
959
+ location_array = modified_input_array.each_index.select { |index| modified_input_array[index] == statement}
960
+
961
+ return_statement_index << location_array[0]
962
+
963
+ end
964
+
965
+ modified_multiple_return_statements.each_with_index do |return_statement,index|
966
+
967
+ method_call_counter = 0
968
+
969
+ if return_statement.include?"("
970
+
971
+ open_paran_location = find_all_matching_indices(return_statement,"(")
972
+
973
+ open_paran_location.each do |paran_index|
974
+
975
+ method_call = return_statement[paran_index..return_statement.index(")",paran_index+1)]
976
+
977
+ method_call_counter += 1
978
+
979
+ modified_multiple_return_statements[index] = modified_multiple_return_statements[index].sub(method_call,"methodcall#{method_call_counter}")
980
+
981
+ modified_input_array[return_statement_index[index]] = modified_multiple_return_statements[index].sub(method_call,"methodcall#{method_call_counter}")
982
+
983
+ end
984
+
985
+ end
986
+
987
+ end
988
+
989
+ modified_multiple_return_statements = modified_multiple_return_statements.reject {|element| !element.include?(",")}
990
+
991
+ return_statement_index = []
992
+
993
+ modified_multiple_return_statements.each do |statement|
994
+
995
+ location_array = modified_input_array.each_index.select { |index| modified_input_array[index] == statement}
996
+
997
+ return_statement_index << location_array[0]
998
+
999
+ end
1000
+
1001
+ return_statement_index.each do |index|
1002
+
1003
+ original_statement = input_array[index]
1004
+
1005
+ statement_split = original_statement.split("return ")
1006
+
1007
+ replacement_split = "return [" + statement_split[1].rstrip + "]\n\n"
1008
+
1009
+ input_array[index] = replacement_split
1010
+
1011
+ end
1012
+
1013
+ return input_array
1014
+
1015
+ end
1016
+
705
1017
  def compile_function(input_array,temporary_nila_file)
706
1018
 
707
1019
  modified_input_array = input_array.dup
@@ -778,6 +1090,8 @@ def compile(input_file_path,*output_file_name)
778
1090
 
779
1091
  modified_input_array = add_auto_return_statement(modified_input_array)
780
1092
 
1093
+ modified_input_array = compile_multiple_return(modified_input_array)
1094
+
781
1095
  return modified_input_array
782
1096
 
783
1097
  end
@@ -1240,6 +1554,8 @@ def compile(input_file_path,*output_file_name)
1240
1554
 
1241
1555
  starting_index = starting_line_indices[0]
1242
1556
 
1557
+ begin
1558
+
1243
1559
  for x in 0...initial_starting_lines.length
1244
1560
 
1245
1561
  code_blocks << modified_file_contents[starting_index..block_ending_lines[0]]
@@ -1266,6 +1582,12 @@ def compile(input_file_path,*output_file_name)
1266
1582
 
1267
1583
  end
1268
1584
 
1585
+ rescue TypeError
1586
+
1587
+ puts "Whitespace was left unfixed!"
1588
+
1589
+ end
1590
+
1269
1591
  return modified_file_contents,code_blocks
1270
1592
 
1271
1593
  end
@@ -1476,7 +1798,7 @@ def compile(input_file_path,*output_file_name)
1476
1798
 
1477
1799
  File.delete(temporary_nila_file)
1478
1800
 
1479
- file_id.write("//Written in Nila 0.0.3.3. Visit http://adhithyan15.github.io/nila\n")
1801
+ file_id.write("//Written using Nila. Visit http://adhithyan15.github.io/nila\n")
1480
1802
 
1481
1803
  file_id.write(file_contents.join)
1482
1804
 
@@ -1492,19 +1814,21 @@ def compile(input_file_path,*output_file_name)
1492
1814
 
1493
1815
  file_contents,multiline_comments,temp_file,output_js_file = replace_multiline_comments(file_contents,input_file_path,*output_file_name)
1494
1816
 
1817
+ file_contents,singleline_comments = replace_singleline_comments(file_contents)
1818
+
1495
1819
  file_contents = split_semicolon_seperated_expressions(file_contents)
1496
1820
 
1497
1821
  file_contents = compile_interpolated_strings(file_contents)
1498
1822
 
1499
- file_contents,singleline_comments = replace_singleline_comments(file_contents)
1823
+ file_contents = compile_arrays(file_contents)
1500
1824
 
1501
1825
  file_contents,named_functions,nested_functions = replace_named_functions(file_contents,temp_file)
1502
1826
 
1503
1827
  comments = [singleline_comments,multiline_comments]
1504
1828
 
1505
- list_of_variables,file_contents = get_variables(file_contents,temp_file)
1829
+ file_contents = compile_multiple_variable_initialization(file_contents,temp_file)
1506
1830
 
1507
- file_contents = compile_arrays(file_contents)
1831
+ list_of_variables,file_contents = get_variables(file_contents,temp_file)
1508
1832
 
1509
1833
  file_contents = compile_conditional_structures(file_contents,temp_file)
1510
1834
 
@@ -1578,7 +1902,21 @@ def find_file_name(input_path,file_extension)
1578
1902
 
1579
1903
  end
1580
1904
 
1581
- nilac_version = "0.0.3.7"
1905
+ def find_file_path(input_path,file_extension)
1906
+
1907
+ extension_remover = input_path.split(file_extension)
1908
+
1909
+ remaining_string = extension_remover[0].reverse
1910
+
1911
+ path_finder = remaining_string.index("/")
1912
+
1913
+ remaining_string = remaining_string.reverse
1914
+
1915
+ return remaining_string[0...remaining_string.length-path_finder]
1916
+
1917
+ end
1918
+
1919
+ nilac_version = "0.0.3.9"
1582
1920
 
1583
1921
  opts = Slop.parse do
1584
1922
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
@@ -1617,7 +1955,16 @@ opts = Slop.parse do
1617
1955
 
1618
1956
  end
1619
1957
  on :r, :run=, 'Run Nila File', as:Array
1620
- on :m, :buildmac=, 'Build Nilac for Linux/Mac/Rubygems',as:Array
1958
+
1959
+ on :m, :buildmac, 'Build Nilac for Linux/Mac/Rubygems' do
1960
+
1961
+ file_path = Dir.pwd + "/src/nilac.rb"
1962
+
1963
+ create_mac_executable(file_path)
1964
+
1965
+ puts "Build Successful!"
1966
+
1967
+ end
1621
1968
  end
1622
1969
 
1623
1970
  opts = opts.to_hash
@@ -1714,18 +2061,10 @@ elsif opts[:run] != nil
1714
2061
 
1715
2062
  compile(file_path)
1716
2063
 
1717
- js_file_name = find_file_name(file_path,".nila") + ".js"
2064
+ js_file_name = find_file_path(file_path,".nila") + find_file_name(file_path,".nila") + ".js"
1718
2065
 
1719
2066
  node_output = `node #{js_file_name}`
1720
2067
 
1721
2068
  puts node_output
1722
2069
 
1723
- elsif opts[:buildmac] != nil
1724
-
1725
- file_path = Dir.pwd + "/bin/nilac.rb"
1726
-
1727
- create_mac_executable(file_path)
1728
-
1729
- puts "Build Successful!"
1730
-
1731
2070
  end
data/lib/nilac/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.3.8"
2
+ VERSION = "0.0.3.9"
3
3
  end
@@ -14,5 +14,5 @@ in a function. It is a rubyesque feature imported into Nila.
14
14
 
15
15
  Configurations:
16
16
 
17
- ~compiler => bin/nilac.rb
17
+ ~compiler => src/nilac.rb
18
18
  :v $cliusage => ruby :v --compile $file
@@ -0,0 +1,11 @@
1
+ Feature: This feature bring Ruby's indexing capabililty to Javascript.
2
+ Scenario: Input file with Ruby style Array and String indexing
3
+ Given the input file "array_string_indexing.nila"
4
+ When the ~compiler is run
5
+ The output file must be "array_string_indexing.js"
6
+ The output file must equal "correct_indexing.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => src/nilac.rb
11
+ :v $cliusage => ruby :v --compile $file
@@ -7,5 +7,5 @@ Feature: Compiling a single line nila program
7
7
 
8
8
  Configurations:
9
9
 
10
- ~compiler => bin/nilac.rb
10
+ ~compiler => src/nilac.rb
11
11
  :v $cliusage => ruby :v --compile $file
@@ -9,5 +9,5 @@ which will make it fail in a JSLint test.
9
9
 
10
10
  Configurations:
11
11
 
12
- ~compiler => bin/nilac.rb
12
+ ~compiler => src/nilac.rb
13
13
  :v $cliusage => ruby :v --compile $file
@@ -13,5 +13,5 @@ Feature: Javascript, by default, doesn't allow for the return of multiple values
13
13
 
14
14
  Configurations:
15
15
 
16
- ~compiler => bin/nilac.rb
16
+ ~compiler => src/nilac.rb
17
17
  :v $cliusage => ruby :v --compile $file
@@ -8,5 +8,5 @@ Feature: Javascript doesn't allow multiple variable initializations from a metho
8
8
 
9
9
  Configurations:
10
10
 
11
- ~compiler => bin/nilac.rb
11
+ ~compiler => src/nilac.rb
12
12
  :v $cliusage => ruby :v --compile $file
@@ -0,0 +1,21 @@
1
+ numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
2
+
3
+ start = numbers[0..2]
4
+
5
+ middle = numbers[3...6]
6
+
7
+ last = numbers[6..end]
8
+
9
+ copy = numbers.dup
10
+
11
+ copy = numbers[..]
12
+
13
+ name = "Adhithya Rajasekaran"
14
+
15
+ first_name = name[0..7]
16
+
17
+ second_name = name[9..end]
18
+
19
+ name_copy = name.dup
20
+
21
+ name_copy = name[..]
@@ -0,0 +1,27 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function() {
3
+ var copy, first_name, last, middle, name, name_copy, numbers, second_name, start;
4
+
5
+ numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
6
+
7
+ start = numbers.slice(0,2+1);
8
+
9
+ middle = numbers.slice(3,6);
10
+
11
+ last = numbers.slice(6);
12
+
13
+ copy = numbers.slice(0);
14
+
15
+ copy = numbers.slice(0);
16
+
17
+ name = "Adhithya Rajasekaran";
18
+
19
+ first_name = name.slice(0,7+1);
20
+
21
+ second_name = name.slice(9);
22
+
23
+ name_copy = name.slice(0);
24
+
25
+ name_copy = name.slice(0);
26
+
27
+ }).call(this);
@@ -1,6 +1,6 @@
1
1
  //Written using Nila. Visit http://adhithyan15.github.io/nila
2
2
  (function() {
3
- var multipleinit1, first_name, last_name;
3
+ var first_name, last_name, multipleinit1;
4
4
 
5
5
  // This file demonstrates multiple variable initialization
6
6
 
@@ -1,6 +1,6 @@
1
1
  //Written using Nila. Visit http://adhithyan15.github.io/nila
2
2
  (function() {
3
- var hello, msg, message, goal_reached;
3
+ var goal_reached, hello, message, msg;
4
4
 
5
5
  hello = "world";
6
6
 
@@ -0,0 +1,8 @@
1
+ #This is a simple if statement
2
+
3
+ if happy and knowsIt
4
+ clapsHands()
5
+ chaChaCha()
6
+ else
7
+ showIt()
8
+ end
@@ -307,7 +307,7 @@ def compile(input_file_path,*output_file_name)
307
307
 
308
308
  key_word_locations << x
309
309
 
310
- elsif current_row.include?("end\n") || current_row.include?("end")
310
+ elsif current_row.lstrip.include?("end\n") || current_row.include?("end")
311
311
 
312
312
  end_locations << x
313
313
 
@@ -516,7 +516,7 @@ def compile(input_file_path,*output_file_name)
516
516
 
517
517
  if variables.length > 0
518
518
 
519
- variable_declaration_string = "var " + variables.uniq.join(", ") + "\n\n"
519
+ variable_declaration_string = "var " + variables.uniq.sort.join(", ") + "\n\n"
520
520
 
521
521
  line_by_line_contents = [variable_declaration_string,line_by_line_contents].flatten
522
522
 
@@ -578,73 +578,207 @@ def compile(input_file_path,*output_file_name)
578
578
  # 1. %w{} syntax
579
579
  # 2. Range - Coming soon!
580
580
 
581
- def extract(input_string,pattern_start,pattern_end)
581
+ def compile_w_arrays(input_file_contents)
582
582
 
583
- def find_all_matching_indices(input_string,pattern)
583
+ def extract(input_string,pattern_start,pattern_end)
584
584
 
585
- locations = []
585
+ def find_all_matching_indices(input_string,pattern)
586
586
 
587
- index = input_string.index(pattern)
587
+ locations = []
588
588
 
589
- while index != nil
589
+ index = input_string.index(pattern)
590
590
 
591
- locations << index
591
+ while index != nil
592
592
 
593
- index = input_string.index(pattern,index+1)
593
+ locations << index
594
+
595
+ index = input_string.index(pattern,index+1)
596
+
597
+
598
+ end
599
+
600
+ return locations
594
601
 
595
602
 
596
603
  end
597
604
 
598
- return locations
605
+ all_start_locations = find_all_matching_indices(input_string,pattern_start)
606
+
607
+ all_end_locations = find_all_matching_indices(input_string,pattern_end)
599
608
 
609
+ pattern = []
610
+
611
+ all_start_locations.each_with_index do |location,index|
612
+
613
+ pattern << input_string[location..all_end_locations[index]]
614
+
615
+ end
616
+
617
+ return pattern
600
618
 
601
619
  end
602
620
 
603
- all_start_locations = find_all_matching_indices(input_string,pattern_start)
621
+ def compile_w_syntax(input_string)
604
622
 
605
- all_end_locations = find_all_matching_indices(input_string,pattern_end)
623
+ modified_input_string = input_string[3...-1]
606
624
 
607
- pattern = []
625
+ string_split = modified_input_string.split(" ")
626
+
627
+ return string_split.to_s
628
+
629
+ end
630
+
631
+ modified_file_contents = input_file_contents.dup
632
+
633
+ input_file_contents.each_with_index do |line,index|
634
+
635
+ if line.include?("%w{")
636
+
637
+ string_arrays = extract(line,"%w{","}")
608
638
 
609
- all_start_locations.each_with_index do |location,index|
639
+ string_arrays.each do |array|
610
640
 
611
- pattern << input_string[location..all_end_locations[index]]
641
+ modified_file_contents[index] = modified_file_contents[index].sub(array,compile_w_syntax(array))
642
+
643
+ end
644
+
645
+ end
612
646
 
613
647
  end
614
648
 
615
- return pattern
649
+ return modified_file_contents
616
650
 
617
651
  end
618
652
 
619
- def compile_w_syntax(input_string)
653
+ def compile_array_indexing(input_file_contents)
620
654
 
621
- modified_input_string = input_string[3...-1]
655
+ #Nila allows two different kinds of indexing operations on arrays and strings. They are
622
656
 
623
- string_split = modified_input_string.split(" ")
657
+ #1. Using Ranges => numbers[0...5]
658
+ #2. Using Start and End Indexes => numbers[0,5]
624
659
 
625
- return string_split.to_s
660
+ #This method implements this Nila feature
626
661
 
627
- end
662
+ possible_indexing_operation = input_file_contents.dup.reject {|element| !element.include?"[" and !element.include?"]"}
628
663
 
629
- modified_file_contents = input_file_contents.dup
664
+ possible_range_indexing = possible_indexing_operation.reject {|element| !element.include?".."}
630
665
 
631
- input_file_contents.each_with_index do |line,index|
666
+ triple_range_indexing = possible_range_indexing.reject {|element| !element.include?"..."}
667
+
668
+ triple_range_indexes = []
669
+
670
+ triple_range_indexing.each do |line|
671
+
672
+ triple_range_indexes << input_file_contents.dup.each_index.select {|index| input_file_contents[index] == line}
673
+
674
+ end
675
+
676
+ triple_range_indexes = triple_range_indexes.flatten
677
+
678
+ triple_range_indexing.each_with_index do |line,index|
679
+
680
+ split1,split2 = line.split("[")
681
+
682
+ range_index,split3 = split2.split("]")
683
+
684
+ index_start,index_end = range_index.split "..."
685
+
686
+ replacement_string = nil
687
+
688
+ if index_end.strip == "end"
689
+
690
+ replacement_string = split1 + ".slice(#{index_start},#{split}.length)\n"
691
+
692
+ else
693
+
694
+ replacement_string = split1 + ".slice(#{index_start},#{index_end})\n"
695
+
696
+ end
697
+
698
+ possible_range_indexing.delete(input_file_contents[triple_range_indexes[index]])
699
+
700
+ possible_indexing_operation.delete(input_file_contents[triple_range_indexes[index]])
632
701
 
633
- if line.include?("%w{")
702
+ input_file_contents[triple_range_indexes[index]] = replacement_string
634
703
 
635
- string_arrays = extract(line,"%w{","}")
704
+ end
705
+
706
+ double_range_indexing = possible_range_indexing.reject {|element| !element.include?("..")}
707
+
708
+ double_range_indexes = []
709
+
710
+ double_range_indexing.each do |line|
711
+
712
+ double_range_indexes << input_file_contents.dup.each_index.select {|index| input_file_contents[index] == line}
713
+
714
+ end
715
+
716
+ double_range_indexes = double_range_indexes.flatten
717
+
718
+ double_range_indexing.each_with_index do |line,index|
719
+
720
+ split1,split2 = line.split("[")
721
+
722
+ range_index,split3 = split2.split("]")
723
+
724
+ index_start,index_end = range_index.split ".."
725
+
726
+ index_start = "" if index_start.nil?
727
+
728
+ index_end = "" if index_end.nil?
636
729
 
637
- string_arrays.each do |array|
730
+ replacement_string = nil
638
731
 
639
- modified_file_contents[index] = modified_file_contents[index].sub(array,compile_w_syntax(array))
732
+ if index_end.strip == "end"
733
+
734
+ replacement_string = split1 + ".slice(#{index_start})\n"
735
+
736
+ elsif index_end.strip == "" and index_start.strip == ""
737
+
738
+ replacement_string = split1 + ".slice(0)\n"
739
+
740
+ else
741
+
742
+ replacement_string = split1 + ".slice(#{index_start},#{index_end}+1)\n"
640
743
 
641
744
  end
642
745
 
746
+ possible_range_indexing.delete(input_file_contents[double_range_indexes[index]])
747
+
748
+ possible_indexing_operation.delete(input_file_contents[double_range_indexes[index]])
749
+
750
+ input_file_contents[double_range_indexes[index]] = replacement_string
751
+
752
+ end
753
+
754
+ duplicating_operations = input_file_contents.dup.reject{|element| !element.include?(".dup")}
755
+
756
+ duplicating_operation_indexes = []
757
+
758
+ duplicating_operations.each do |line|
759
+
760
+ duplicating_operation_indexes << input_file_contents.dup.each_index.select {|index| input_file_contents[index] == line}
761
+
643
762
  end
644
763
 
764
+ duplicating_operation_indexes = duplicating_operation_indexes.flatten
765
+
766
+ duplicating_operation_indexes.each do |index|
767
+
768
+ input_file_contents[index] = input_file_contents[index].sub(".dup",".slice(0)")
769
+
770
+ end
771
+
772
+ return input_file_contents
773
+
645
774
  end
646
775
 
647
- return modified_file_contents
776
+ input_file_contents = compile_w_arrays(input_file_contents)
777
+
778
+ input_file_contents = compile_array_indexing(input_file_contents)
779
+
780
+ return input_file_contents
781
+
648
782
 
649
783
  end
650
784
 
@@ -1682,11 +1816,13 @@ def compile(input_file_path,*output_file_name)
1682
1816
 
1683
1817
  file_contents,multiline_comments,temp_file,output_js_file = replace_multiline_comments(file_contents,input_file_path,*output_file_name)
1684
1818
 
1819
+ file_contents,singleline_comments = replace_singleline_comments(file_contents)
1820
+
1685
1821
  file_contents = split_semicolon_seperated_expressions(file_contents)
1686
1822
 
1687
1823
  file_contents = compile_interpolated_strings(file_contents)
1688
1824
 
1689
- file_contents,singleline_comments = replace_singleline_comments(file_contents)
1825
+ file_contents = compile_arrays(file_contents)
1690
1826
 
1691
1827
  file_contents,named_functions,nested_functions = replace_named_functions(file_contents,temp_file)
1692
1828
 
@@ -1696,8 +1832,6 @@ def compile(input_file_path,*output_file_name)
1696
1832
 
1697
1833
  list_of_variables,file_contents = get_variables(file_contents,temp_file)
1698
1834
 
1699
- file_contents = compile_arrays(file_contents)
1700
-
1701
1835
  file_contents = compile_conditional_structures(file_contents,temp_file)
1702
1836
 
1703
1837
  file_contents, function_names = compile_named_functions(file_contents,named_functions,nested_functions,temp_file)
@@ -1784,7 +1918,7 @@ def find_file_path(input_path,file_extension)
1784
1918
 
1785
1919
  end
1786
1920
 
1787
- nilac_version = "0.0.3.8"
1921
+ nilac_version = "0.0.3.9"
1788
1922
 
1789
1923
  opts = Slop.parse do
1790
1924
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
@@ -1823,7 +1957,16 @@ opts = Slop.parse do
1823
1957
 
1824
1958
  end
1825
1959
  on :r, :run=, 'Run Nila File', as:Array
1826
- on :m, :buildmac=, 'Build Nilac for Linux/Mac/Rubygems',as:Array
1960
+
1961
+ on :m, :buildmac, 'Build Nilac for Linux/Mac/Rubygems' do
1962
+
1963
+ file_path = Dir.pwd + "/src/nilac.rb"
1964
+
1965
+ create_mac_executable(file_path)
1966
+
1967
+ puts "Build Successful!"
1968
+
1969
+ end
1827
1970
  end
1828
1971
 
1829
1972
  opts = opts.to_hash
@@ -1926,12 +2069,4 @@ elsif opts[:run] != nil
1926
2069
 
1927
2070
  puts node_output
1928
2071
 
1929
- elsif opts[:buildmac] != nil
1930
-
1931
- file_path = Dir.pwd + "/bin/nilac.rb"
1932
-
1933
- create_mac_executable(file_path)
1934
-
1935
- puts "Build Successful!"
1936
-
1937
2072
  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.3.8
4
+ version: 0.0.3.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-26 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shark
@@ -49,7 +49,6 @@ email:
49
49
  executables:
50
50
  - .gitignore
51
51
  - nilac
52
- - nilac.rb
53
52
  extensions: []
54
53
  extra_rdoc_files: []
55
54
  files:
@@ -60,31 +59,31 @@ files:
60
59
  - Rakefile
61
60
  - bin/.gitignore
62
61
  - bin/nilac
63
- - bin/nilac.rb
64
- - examples/sample.js
65
- - examples/sample.nila
66
62
  - lib/nilac.rb
67
63
  - lib/nilac/version.rb
68
64
  - nilac.gemspec
69
65
  - shark/features/add_auto_return_statement.feature
66
+ - shark/features/array_and_string_indexing.feature
70
67
  - shark/features/barebones_compilation.feature
71
68
  - shark/features/fix_newlines.feature
72
69
  - shark/features/method_multiple_return.feature
73
70
  - shark/features/multiple_variable_initialization.feature
71
+ - shark/test_files/array_string_indexing.nila
74
72
  - shark/test_files/correct.js
73
+ - shark/test_files/correct_indexing.js
75
74
  - shark/test_files/correct_initialization.js
76
75
  - shark/test_files/correct_multiple_return.js
77
76
  - shark/test_files/correct_return.js
78
77
  - shark/test_files/correct_single_return.js
79
78
  - shark/test_files/erratic.nila
80
- - shark/test_files/multiple_initialization.js
81
79
  - shark/test_files/multiple_initialization.nila
82
- - shark/test_files/multiple_return.js
83
80
  - shark/test_files/multiple_return.nila
84
81
  - shark/test_files/no_return.nila
85
82
  - shark/test_files/perfect.js
83
+ - shark/test_files/regular_if.nila
86
84
  - shark/test_files/simple.nila
87
85
  - shark/test_files/single_return.nila
86
+ - src/nilac.rb
88
87
  homepage: http://adhithyan15.github.com/nila
89
88
  licenses: []
90
89
  post_install_message:
data/examples/sample.js DELETED
@@ -1,46 +0,0 @@
1
- //Written in Nila 0.0.3.2. Visit http://adhithyan15.github.io/nila
2
- (function() {
3
- var hello, msg, message, goal_reached, isprime, visitor_present, names;
4
-
5
- hello = "world";
6
-
7
- msg = "Nila";
8
-
9
- message = "Welcome to " + msg;
10
-
11
- goal_reached = 72;
12
-
13
- isprime = false;
14
-
15
- visitor_present = true;
16
-
17
- if (visitor_present) {
18
- console.log("Hello Visitor!");
19
- }
20
-
21
- names = ["adhi", "alex", "john", "bill", "kelly"];
22
-
23
- function printsquare(input_number) {
24
- //This is a very simple Nila function
25
- var add_number, isvalid;
26
- add_number = input_number + 10;
27
- isvalid = true;
28
- function square(number) {
29
- return number*number;
30
- }
31
- return console.log("Square of " + add_number + " is " + square(add_number));
32
- }
33
-
34
- console.log(printsquare(5));
35
-
36
- function test_message() {
37
- return console.log("Welcome to Nila!");
38
- }
39
-
40
- function welcome_message() {
41
- return console.log("Welcome to Nila!");
42
- }
43
-
44
- console.log(welcome_message);
45
-
46
- }).call(this);
data/examples/sample.nila DELETED
@@ -1,45 +0,0 @@
1
- hello = "world";msg = "Nila"
2
-
3
- message = "Welcome to #{msg}"
4
-
5
- goal_reached = 72
6
-
7
- isprime? = false
8
-
9
- visitor_present? = true
10
-
11
- puts("Hello Visitor!") if visitor_present?
12
-
13
- names = %w{adhi alex john bill kelly}
14
-
15
- def printsquare(input_number) #This is a very simple Nila function
16
-
17
- add_number = input_number + 10
18
-
19
- isvalid? = true
20
-
21
- def square(number)
22
-
23
- number*number
24
-
25
- end
26
-
27
- puts "Square of #{add_number} is #{square(add_number)}"
28
-
29
- end
30
-
31
- puts(printsquare(5))
32
-
33
- def test_message
34
-
35
- puts "Welcome to Nila!"
36
-
37
- end
38
-
39
- def welcome_message
40
-
41
- puts "Welcome to Nila!"
42
-
43
- end
44
-
45
- puts welcome_message
@@ -1,21 +0,0 @@
1
- //Written using Nila. Visit http://adhithyan15.github.io/nila
2
- (function() {
3
- var multipleinit1, first_name, last_name;
4
-
5
- // This file demonstrates multiple variable initialization
6
-
7
- function parse_name(input_name) {
8
- var name_split;
9
- name_split = input_name.split(" ");
10
- return [name_split[0],name_split[1]];
11
- }
12
-
13
- multipleinit1 = parse_name("Adhithya Rajasekaran");
14
-
15
- first_name = multipleinit1[0];
16
-
17
- last_name = multipleinit1[1];
18
-
19
- console.log(first_name + " " + last_name);
20
-
21
- }).call(this);
@@ -1,19 +0,0 @@
1
- //Written using Nila. Visit http://adhithyan15.github.io/nila
2
- (function() {
3
- var parsed_name;
4
-
5
- // This method demonstrates multiple return values
6
-
7
- function parse_name(input_name) {
8
- var name_split;
9
- name_split = input_name.split(" ");
10
- return [name_split[0],name_split[1]];
11
- }
12
-
13
- function test_method() {
14
- return console.log("Hello, Adhithya");
15
- }
16
-
17
- parsed_name = parse_name("Adhithya Rajasekaran");
18
-
19
- }).call(this);