nilac 0.0.4.0 → 0.0.4.0.1

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 (3) hide show
  1. data/bin/nilac +115 -3
  2. data/lib/nilac/version.rb +1 -1
  3. metadata +1 -1
data/bin/nilac CHANGED
@@ -468,6 +468,84 @@ def compile(input_file_path,*output_file_name)
468
468
 
469
469
  end
470
470
 
471
+ def compile_default_values(input_file_contents,temporary_nila_file)
472
+
473
+ #This method compiles default values present in functions. An example is provided below
474
+
475
+ # def fill(container = "cup",liquid = "coffee")
476
+ # puts "Filling the #{container} with #{liquid}"
477
+ # end
478
+
479
+ def parse_default_values(input_function_definition)
480
+
481
+ puts input_function_definition
482
+
483
+ split1,split2 = input_function_definition.split("(")
484
+
485
+ split2,split3 = split2.split(")")
486
+
487
+ function_parameters = split2.split(",")
488
+
489
+ default_value_parameters = function_parameters.reject {|element| !element.include?"="}
490
+
491
+ replacement_parameters = []
492
+
493
+ replacement_string = ""
494
+
495
+ default_value_parameters.each do |paramvalue|
496
+
497
+ param, value = paramvalue.split("=")
498
+
499
+ replacement_parameters << param.lstrip.rstrip
500
+
501
+ replacement_string = replacement_string + "\n" + "if (#{param.lstrip.rstrip} == null) {\n #{paramvalue.lstrip.rstrip}\n}\n" +"\n"
502
+
503
+ end
504
+
505
+ return replacement_string,default_value_parameters,replacement_parameters
506
+
507
+ end
508
+
509
+ possible_default_values = input_file_contents.dup.reject {|element| !element.include?("def")}
510
+
511
+ possible_default_values = possible_default_values.reject {|element| !element.include?("=")}
512
+
513
+ if !possible_default_values.empty?
514
+
515
+ possible_default_values.each do |line|
516
+
517
+ current_line_index = input_file_contents.each_index.select {|index| input_file_contents[index] == line}.flatten[0]
518
+
519
+ replacement_string,value_parameters,replacement_parameters = parse_default_values(line)
520
+
521
+ modified_line = line.dup
522
+
523
+ value_parameters.each_with_index do |val,index|
524
+
525
+ modified_line = modified_line.sub(val,replacement_parameters[index])
526
+
527
+ end
528
+
529
+ input_file_contents[current_line_index] = modified_line
530
+
531
+ input_file_contents[current_line_index + 1] = replacement_string
532
+
533
+ end
534
+
535
+ end
536
+
537
+ file_id = open(temporary_nila_file, 'w')
538
+
539
+ file_id.write(input_file_contents.join)
540
+
541
+ file_id.close()
542
+
543
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
544
+
545
+ return line_by_line_contents
546
+
547
+ end
548
+
471
549
  def get_variables(input_file_contents,temporary_nila_file)
472
550
 
473
551
  #This method is solely focused on getting a list of variables to be declared.
@@ -725,6 +803,10 @@ def compile(input_file_path,*output_file_name)
725
803
 
726
804
  index_start,index_end = range_index.split ".."
727
805
 
806
+ index_start = "" if index_start.nil?
807
+
808
+ index_end = "" if index_end.nil?
809
+
728
810
  replacement_string = nil
729
811
 
730
812
  if index_end.strip == "end"
@@ -818,11 +900,19 @@ def compile(input_file_path,*output_file_name)
818
900
  #This method will pickup and declare all the variables inside a function block. In future, this method will be
819
901
  #merged with the get variables method
820
902
 
903
+ controlregexp = /(if |while |def |function |function\()/
904
+
821
905
  variables = []
822
906
 
907
+ function_name,parameters = input_function_block[0].split("(")
908
+
909
+ parameters = parameters.split(")")[0].split(",")
910
+
911
+ parameters = parameters.collect {|element| element.strip}
912
+
823
913
  input_function_block.each do |line|
824
914
 
825
- if line.include? "=" and !line.include?("def")
915
+ if line.include? "=" and line.index(controlregexp).nil?
826
916
 
827
917
  current_line_split = line.strip.split("=")
828
918
 
@@ -832,7 +922,25 @@ def compile(input_file_path,*output_file_name)
832
922
 
833
923
  end
834
924
 
835
- variables.uniq
925
+ parameters.each do |param|
926
+
927
+ if variables.include?(param)
928
+
929
+ variables.delete(param)
930
+
931
+ end
932
+
933
+ end
934
+
935
+ if variables.empty?
936
+
937
+ return []
938
+
939
+ else
940
+
941
+ return variables.uniq
942
+
943
+ end
836
944
 
837
945
  end
838
946
 
@@ -1076,6 +1184,8 @@ def compile(input_file_path,*output_file_name)
1076
1184
 
1077
1185
  modified_input_array[-1] = input_array[-1].sub "end","}\n"
1078
1186
 
1187
+ modified_input_array = compile_multiple_variable_initialization(modified_input_array,temporary_nila_file)
1188
+
1079
1189
  variables = lexical_scoped_variables(modified_input_array)
1080
1190
 
1081
1191
  if !variables.empty?
@@ -1822,6 +1932,8 @@ def compile(input_file_path,*output_file_name)
1822
1932
 
1823
1933
  file_contents = compile_arrays(file_contents)
1824
1934
 
1935
+ file_contents = compile_default_values(file_contents,temp_file)
1936
+
1825
1937
  file_contents,named_functions,nested_functions = replace_named_functions(file_contents,temp_file)
1826
1938
 
1827
1939
  comments = [singleline_comments,multiline_comments]
@@ -1916,7 +2028,7 @@ def find_file_path(input_path,file_extension)
1916
2028
 
1917
2029
  end
1918
2030
 
1919
- nilac_version = "0.0.3.9"
2031
+ nilac_version = "0.0.4.0"
1920
2032
 
1921
2033
  opts = Slop.parse do
1922
2034
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
data/lib/nilac/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.0"
2
+ VERSION = "0.0.4.0.1"
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.0
4
+ version: 0.0.4.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: