nilac 0.0.3.9 → 0.0.4.0
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/lib/nilac/version.rb +1 -1
- data/shark/features/default_method_parameters.feature +12 -0
- data/shark/test_files/correct_default_parameters.js +16 -0
- data/shark/test_files/correct_multiple_return.js +5 -3
- data/shark/test_files/default_parameters.nila +11 -0
- data/shark/test_files/multiple_return.nila +2 -2
- data/src/nilac.rb +111 -3
- metadata +5 -3
- data/shark/test_files/regular_if.nila +0 -8
data/lib/nilac/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
Feature: Javascript,by default,doesn't allow for the usage of default parameters for functions. So this
|
2
|
+
feature addresses that issue.
|
3
|
+
Scenario: Input function with default parameters
|
4
|
+
Given the input file "default_parameters.nila"
|
5
|
+
When the ~compiler is run
|
6
|
+
The output file must be "default_parameters.js"
|
7
|
+
The output file must equal "correct_default_parameters.js"
|
8
|
+
|
9
|
+
Configurations:
|
10
|
+
|
11
|
+
~compiler => src/nilac.rb
|
12
|
+
:v $cliusage => ruby :v --compile $file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
|
+
(function() {
|
3
|
+
// This is a demo of default parameters
|
4
|
+
|
5
|
+
function fill(container,liquid) {
|
6
|
+
if (liquid == null) {
|
7
|
+
liquid = "coffee";
|
8
|
+
}
|
9
|
+
return console.log("Filling " + container + " with " + liquid);
|
10
|
+
}
|
11
|
+
|
12
|
+
fill("cup");
|
13
|
+
|
14
|
+
fill("bowl","soup");
|
15
|
+
|
16
|
+
}).call(this);
|
@@ -5,9 +5,11 @@
|
|
5
5
|
// This method demonstrates multiple return values
|
6
6
|
|
7
7
|
function parse_name(input_name) {
|
8
|
-
var
|
9
|
-
|
10
|
-
|
8
|
+
var multipleinit1, first_name, last_name;
|
9
|
+
multipleinit1 = input_name.split(" ");
|
10
|
+
first_name = multipleinit1[0];
|
11
|
+
last_name = multipleinit1[1];
|
12
|
+
return [first_name,last_name];
|
11
13
|
}
|
12
14
|
|
13
15
|
function test_method() {
|
data/src/nilac.rb
CHANGED
@@ -466,6 +466,84 @@ def compile(input_file_path,*output_file_name)
|
|
466
466
|
|
467
467
|
end
|
468
468
|
|
469
|
+
def compile_default_values(input_file_contents,temporary_nila_file)
|
470
|
+
|
471
|
+
#This method compiles default values present in functions. An example is provided below
|
472
|
+
|
473
|
+
# def fill(container = "cup",liquid = "coffee")
|
474
|
+
# puts "Filling the #{container} with #{liquid}"
|
475
|
+
# end
|
476
|
+
|
477
|
+
def parse_default_values(input_function_definition)
|
478
|
+
|
479
|
+
puts input_function_definition
|
480
|
+
|
481
|
+
split1,split2 = input_function_definition.split("(")
|
482
|
+
|
483
|
+
split2,split3 = split2.split(")")
|
484
|
+
|
485
|
+
function_parameters = split2.split(",")
|
486
|
+
|
487
|
+
default_value_parameters = function_parameters.reject {|element| !element.include?"="}
|
488
|
+
|
489
|
+
replacement_parameters = []
|
490
|
+
|
491
|
+
replacement_string = ""
|
492
|
+
|
493
|
+
default_value_parameters.each do |paramvalue|
|
494
|
+
|
495
|
+
param, value = paramvalue.split("=")
|
496
|
+
|
497
|
+
replacement_parameters << param.lstrip.rstrip
|
498
|
+
|
499
|
+
replacement_string = replacement_string + "\n" + "if (#{param.lstrip.rstrip} == null) {\n #{paramvalue.lstrip.rstrip}\n}\n" +"\n"
|
500
|
+
|
501
|
+
end
|
502
|
+
|
503
|
+
return replacement_string,default_value_parameters,replacement_parameters
|
504
|
+
|
505
|
+
end
|
506
|
+
|
507
|
+
possible_default_values = input_file_contents.dup.reject {|element| !element.include?("def")}
|
508
|
+
|
509
|
+
possible_default_values = possible_default_values.reject {|element| !element.include?("=")}
|
510
|
+
|
511
|
+
if !possible_default_values.empty?
|
512
|
+
|
513
|
+
possible_default_values.each do |line|
|
514
|
+
|
515
|
+
current_line_index = input_file_contents.each_index.select {|index| input_file_contents[index] == line}.flatten[0]
|
516
|
+
|
517
|
+
replacement_string,value_parameters,replacement_parameters = parse_default_values(line)
|
518
|
+
|
519
|
+
modified_line = line.dup
|
520
|
+
|
521
|
+
value_parameters.each_with_index do |val,index|
|
522
|
+
|
523
|
+
modified_line = modified_line.sub(val,replacement_parameters[index])
|
524
|
+
|
525
|
+
end
|
526
|
+
|
527
|
+
input_file_contents[current_line_index] = modified_line
|
528
|
+
|
529
|
+
input_file_contents[current_line_index + 1] = replacement_string
|
530
|
+
|
531
|
+
end
|
532
|
+
|
533
|
+
end
|
534
|
+
|
535
|
+
file_id = open(temporary_nila_file, 'w')
|
536
|
+
|
537
|
+
file_id.write(input_file_contents.join)
|
538
|
+
|
539
|
+
file_id.close()
|
540
|
+
|
541
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
542
|
+
|
543
|
+
return line_by_line_contents
|
544
|
+
|
545
|
+
end
|
546
|
+
|
469
547
|
def get_variables(input_file_contents,temporary_nila_file)
|
470
548
|
|
471
549
|
#This method is solely focused on getting a list of variables to be declared.
|
@@ -820,11 +898,19 @@ def compile(input_file_path,*output_file_name)
|
|
820
898
|
#This method will pickup and declare all the variables inside a function block. In future, this method will be
|
821
899
|
#merged with the get variables method
|
822
900
|
|
901
|
+
controlregexp = /(if |while |def |function |function\()/
|
902
|
+
|
823
903
|
variables = []
|
824
904
|
|
905
|
+
function_name,parameters = input_function_block[0].split("(")
|
906
|
+
|
907
|
+
parameters = parameters.split(")")[0].split(",")
|
908
|
+
|
909
|
+
parameters = parameters.collect {|element| element.strip}
|
910
|
+
|
825
911
|
input_function_block.each do |line|
|
826
912
|
|
827
|
-
if line.include? "=" and
|
913
|
+
if line.include? "=" and line.index(controlregexp).nil?
|
828
914
|
|
829
915
|
current_line_split = line.strip.split("=")
|
830
916
|
|
@@ -834,7 +920,25 @@ def compile(input_file_path,*output_file_name)
|
|
834
920
|
|
835
921
|
end
|
836
922
|
|
837
|
-
|
923
|
+
parameters.each do |param|
|
924
|
+
|
925
|
+
if variables.include?(param)
|
926
|
+
|
927
|
+
variables.delete(param)
|
928
|
+
|
929
|
+
end
|
930
|
+
|
931
|
+
end
|
932
|
+
|
933
|
+
if variables.empty?
|
934
|
+
|
935
|
+
return []
|
936
|
+
|
937
|
+
else
|
938
|
+
|
939
|
+
return variables.uniq
|
940
|
+
|
941
|
+
end
|
838
942
|
|
839
943
|
end
|
840
944
|
|
@@ -1078,6 +1182,8 @@ def compile(input_file_path,*output_file_name)
|
|
1078
1182
|
|
1079
1183
|
modified_input_array[-1] = input_array[-1].sub "end","}\n"
|
1080
1184
|
|
1185
|
+
modified_input_array = compile_multiple_variable_initialization(modified_input_array,temporary_nila_file)
|
1186
|
+
|
1081
1187
|
variables = lexical_scoped_variables(modified_input_array)
|
1082
1188
|
|
1083
1189
|
if !variables.empty?
|
@@ -1824,6 +1930,8 @@ def compile(input_file_path,*output_file_name)
|
|
1824
1930
|
|
1825
1931
|
file_contents = compile_arrays(file_contents)
|
1826
1932
|
|
1933
|
+
file_contents = compile_default_values(file_contents,temp_file)
|
1934
|
+
|
1827
1935
|
file_contents,named_functions,nested_functions = replace_named_functions(file_contents,temp_file)
|
1828
1936
|
|
1829
1937
|
comments = [singleline_comments,multiline_comments]
|
@@ -1918,7 +2026,7 @@ def find_file_path(input_path,file_extension)
|
|
1918
2026
|
|
1919
2027
|
end
|
1920
2028
|
|
1921
|
-
nilac_version = "0.0.
|
2029
|
+
nilac_version = "0.0.4.0"
|
1922
2030
|
|
1923
2031
|
opts = Slop.parse do
|
1924
2032
|
on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
|
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
|
+
version: 0.0.4.0
|
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-07-
|
12
|
+
date: 2013-07-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shark
|
@@ -65,22 +65,24 @@ files:
|
|
65
65
|
- shark/features/add_auto_return_statement.feature
|
66
66
|
- shark/features/array_and_string_indexing.feature
|
67
67
|
- shark/features/barebones_compilation.feature
|
68
|
+
- shark/features/default_method_parameters.feature
|
68
69
|
- shark/features/fix_newlines.feature
|
69
70
|
- shark/features/method_multiple_return.feature
|
70
71
|
- shark/features/multiple_variable_initialization.feature
|
71
72
|
- shark/test_files/array_string_indexing.nila
|
72
73
|
- shark/test_files/correct.js
|
74
|
+
- shark/test_files/correct_default_parameters.js
|
73
75
|
- shark/test_files/correct_indexing.js
|
74
76
|
- shark/test_files/correct_initialization.js
|
75
77
|
- shark/test_files/correct_multiple_return.js
|
76
78
|
- shark/test_files/correct_return.js
|
77
79
|
- shark/test_files/correct_single_return.js
|
80
|
+
- shark/test_files/default_parameters.nila
|
78
81
|
- shark/test_files/erratic.nila
|
79
82
|
- shark/test_files/multiple_initialization.nila
|
80
83
|
- shark/test_files/multiple_return.nila
|
81
84
|
- shark/test_files/no_return.nila
|
82
85
|
- shark/test_files/perfect.js
|
83
|
-
- shark/test_files/regular_if.nila
|
84
86
|
- shark/test_files/simple.nila
|
85
87
|
- shark/test_files/single_return.nila
|
86
88
|
- src/nilac.rb
|