nilac 0.0.4.1.5 → 0.0.4.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/bin/nilac CHANGED
@@ -586,8 +586,6 @@ def compile(input_file_path,*output_file_name)
586
586
 
587
587
  current_row = input_file_contents[x]
588
588
 
589
- #The condition below verifies if the rows contain any equation operators.
590
-
591
589
  if current_row.include?("=") and !current_row.include?("def")
592
590
 
593
591
  current_row = current_row.rstrip + "\n"
@@ -601,6 +599,12 @@ def compile(input_file_path,*output_file_name)
601
599
 
602
600
  end
603
601
 
602
+ if current_row_split[0].include?("[") or current_row_split[0].include?("(")
603
+
604
+ current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
605
+
606
+ end
607
+
604
608
  variables << current_row_split[0]
605
609
 
606
610
 
@@ -691,7 +695,7 @@ def compile(input_file_path,*output_file_name)
691
695
 
692
696
  end
693
697
 
694
- def compile_arrays(input_file_contents)
698
+ def compile_arrays(input_file_contents,temporary_nila_file)
695
699
 
696
700
  #Currently the following kinds of array constructs are compilable
697
701
 
@@ -885,10 +889,66 @@ def compile(input_file_path,*output_file_name)
885
889
 
886
890
  end
887
891
 
892
+ def compile_multiline(input_file_contents,temporary_nila_file)
893
+
894
+ possible_arrays = input_file_contents.reject {|element| !element.include?("[")}
895
+
896
+ possible_multiline_arrays = possible_arrays.reject {|element| element.include?("]")}
897
+
898
+ multiline_arrays = []
899
+
900
+ possible_multiline_arrays.each do |starting_line|
901
+
902
+ index = input_file_contents.index(starting_line)
903
+
904
+ line = starting_line
905
+
906
+ until line.include?("]")
907
+
908
+ index += 1
909
+
910
+ line = input_file_contents[index]
911
+
912
+ end
913
+
914
+ multiline_arrays << input_file_contents[input_file_contents.index(starting_line)..index]
915
+
916
+ end
917
+
918
+ joined_file_contents = input_file_contents.join
919
+
920
+ multiline_arrays.each do |array|
921
+
922
+ modified_array = array.join
923
+
924
+ array_extract = modified_array[modified_array.index("[")..modified_array.index("]")]
925
+
926
+ array_contents = array_extract.split("[")[1].split("]")[0].lstrip.rstrip.split(",").collect {|element| element.lstrip.rstrip}
927
+
928
+ array_contents = "[" + array_contents.join(",") + "]"
929
+
930
+ joined_file_contents = joined_file_contents.sub(array_extract,array_contents)
931
+
932
+ end
933
+
934
+ file_id = open(temporary_nila_file, 'w')
935
+
936
+ file_id.write(joined_file_contents)
937
+
938
+ file_id.close()
939
+
940
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
941
+
942
+ return line_by_line_contents
943
+
944
+ end
945
+
888
946
  input_file_contents = compile_w_arrays(input_file_contents)
889
947
 
890
948
  input_file_contents = compile_array_indexing(input_file_contents)
891
949
 
950
+ input_file_contents = compile_multiline(input_file_contents,temporary_nila_file)
951
+
892
952
  return input_file_contents
893
953
 
894
954
 
@@ -896,7 +956,7 @@ def compile(input_file_path,*output_file_name)
896
956
 
897
957
  def compile_strings(input_file_contents)
898
958
 
899
- # This method will compile %q, %Q and %{} syntax. Heredocs support will be added in the future
959
+ # This method will compile %q, %Q and % syntax. Heredocs support will be added in the future
900
960
 
901
961
  def compile_small_q_syntax(input_file_contents)
902
962
 
@@ -978,9 +1038,53 @@ def compile(input_file_path,*output_file_name)
978
1038
 
979
1039
  end
980
1040
 
1041
+ def compile_percentage_syntax(input_file_contents)
1042
+
1043
+ possible_syntax_usage = input_file_contents.reject {|element| !element.include?("%")}
1044
+
1045
+ possible_syntax_usage = possible_syntax_usage.reject {|element| element.index(/(\%(\W|\s)\w{1,})/).nil?}
1046
+
1047
+ possible_syntax_usage.each do |line|
1048
+
1049
+ modified_line = line.dup
1050
+
1051
+ line_split = line.split("+").collect {|element| element.lstrip.rstrip}
1052
+
1053
+ line_split.each do |str|
1054
+
1055
+ delimiter = str[str.index("%")+1]
1056
+
1057
+ string_extract = str[str.index("%")..-1]
1058
+
1059
+ delimiter = "}" if delimiter.eql?("{")
1060
+
1061
+ if string_extract[-1].eql?(delimiter)
1062
+
1063
+ input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"\"#{string_extract[2...-1]}\"")
1064
+
1065
+ modified_line = modified_line.sub(string_extract,"\"#{string_extract[2...-1]}\"")
1066
+
1067
+ elsif delimiter.eql?(" ")
1068
+
1069
+ input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"\"#{string_extract[2..-1]}\"")
1070
+
1071
+ modified_line = modified_line.sub(string_extract,"\"#{string_extract[2..-1]}\"")
1072
+
1073
+ end
1074
+
1075
+ end
1076
+
1077
+ end
1078
+
1079
+ return input_file_contents
1080
+
1081
+ end
1082
+
981
1083
  file_contents = compile_small_q_syntax(input_file_contents)
982
1084
 
983
- file_contents = compile_big_q_syntax(input_file_contents)
1085
+ file_contents = compile_big_q_syntax(file_contents)
1086
+
1087
+ file_contents = compile_percentage_syntax(file_contents)
984
1088
 
985
1089
  return file_contents
986
1090
 
@@ -1003,7 +1107,7 @@ def compile(input_file_path,*output_file_name)
1003
1107
  #
1004
1108
  # return input_number*input_number;
1005
1109
  #
1006
- # }
1110
+ #}
1007
1111
 
1008
1112
  def is_parameterless?(input_function_block)
1009
1113
 
@@ -2932,7 +3036,7 @@ def compile(input_file_path,*output_file_name)
2932
3036
 
2933
3037
  file_contents = compile_conditional_structures(file_contents,temp_file)
2934
3038
 
2935
- file_contents = compile_arrays(file_contents)
3039
+ file_contents = compile_arrays(file_contents,temp_file)
2936
3040
 
2937
3041
  file_contents = compile_strings(file_contents)
2938
3042
 
@@ -3030,7 +3134,7 @@ def find_file_path(input_path,file_extension)
3030
3134
 
3031
3135
  end
3032
3136
 
3033
- nilac_version = "0.0.4.1.3"
3137
+ nilac_version = "0.0.4.1.6"
3034
3138
 
3035
3139
  opts = Slop.parse do
3036
3140
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
@@ -3074,8 +3178,12 @@ opts = Slop.parse do
3074
3178
 
3075
3179
  file_path = Dir.pwd + "/src/nilac.rb"
3076
3180
 
3181
+ puts file_path
3182
+
3077
3183
  create_mac_executable(file_path)
3078
3184
 
3185
+ FileUtils.mv("#{file_path[0...-3]}","#{Dir.pwd}/bin/nilac")
3186
+
3079
3187
  puts "Build Successful!"
3080
3188
 
3081
3189
  end
data/lib/nilac/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.1.5"
2
+ VERSION = "0.0.4.1.6"
3
3
  end
@@ -0,0 +1,11 @@
1
+ Feature: This feature brings multiline arrays to Nila
2
+ Scenario: Input file with multiline array and regular arrays.
3
+ Given the input file "multiline_array.nila"
4
+ When the ~compiler is run
5
+ The output file must be "multiline_array.js"
6
+ The output file must equal "correct_multiline_array.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => src/nilac.rb
11
+ :v $cliusage => ruby :v --compile $file
@@ -0,0 +1,11 @@
1
+ Feature: This feature brings whitespace delimitation features to Nila
2
+ Scenario: Input file with whitespace delimitation features.
3
+ Given the input file "whitespace_delimiter.nila"
4
+ When the ~compiler is run
5
+ The output file must be "whitespace_delimiter.js"
6
+ The output file must equal "correct_whitespace_delimiter.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => src/nilac.rb
11
+ :v $cliusage => ruby :v --compile $file
@@ -18,4 +18,4 @@ second_name = name[9..end]
18
18
 
19
19
  name_copy = name.dup
20
20
 
21
- name_copy = name[..]
21
+ name_copy = name[..]
File without changes
@@ -0,0 +1,15 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function() {
3
+ function square(input_number) {
4
+ return input_number*input_number;
5
+ }
6
+
7
+ function return_number(input_number) {
8
+ return input_number;
9
+ }
10
+
11
+ console.log(message);
12
+
13
+ console.log(square(return_number(5)));
14
+
15
+ }).call(this);
@@ -0,0 +1,13 @@
1
+ numbers = [1,2,3,4,5,6,7,8,9,10]
2
+
3
+ myarray = [
4
+
5
+ "string 1",
6
+ "string 2",
7
+ "string 3"
8
+
9
+ ]
10
+
11
+ name = "Adhithya"
12
+
13
+ name[5] = "t"
@@ -10,4 +10,10 @@ str = %Q{this is a wonderful string}
10
10
 
11
11
  str = %Q!this is a wonderful string!
12
12
 
13
- str = %Q this is a wonderful string + %Q this is another wonderful string
13
+ str = %Q this is a wonderful string + %Q this is another wonderful string
14
+
15
+ str = %|this is a wonderful string|
16
+
17
+ str = %!this is a wonderful string!
18
+
19
+ str = % this is a wonderful string + % this is another wonderful string
@@ -0,0 +1,16 @@
1
+
2
+ def square(input_number)
3
+
4
+ input_number*input_number
5
+
6
+ end
7
+
8
+ def return_number(input_number)
9
+
10
+ input_number
11
+
12
+ end
13
+
14
+ puts message
15
+
16
+ puts square return_number 5
data/src/nilac.rb CHANGED
@@ -6,6 +6,7 @@
6
6
  require 'slop'
7
7
  require 'fileutils'
8
8
 
9
+
9
10
  def compile(input_file_path,*output_file_name)
10
11
 
11
12
  def read_file_line_by_line(input_path)
@@ -584,8 +585,6 @@ def compile(input_file_path,*output_file_name)
584
585
 
585
586
  current_row = input_file_contents[x]
586
587
 
587
- #The condition below verifies if the rows contain any equation operators.
588
-
589
588
  if current_row.include?("=") and !current_row.include?("def")
590
589
 
591
590
  current_row = current_row.rstrip + "\n"
@@ -599,6 +598,12 @@ def compile(input_file_path,*output_file_name)
599
598
 
600
599
  end
601
600
 
601
+ if current_row_split[0].include?("[") or current_row_split[0].include?("(")
602
+
603
+ current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
604
+
605
+ end
606
+
602
607
  variables << current_row_split[0]
603
608
 
604
609
 
@@ -689,7 +694,7 @@ def compile(input_file_path,*output_file_name)
689
694
 
690
695
  end
691
696
 
692
- def compile_arrays(input_file_contents)
697
+ def compile_arrays(input_file_contents,temporary_nila_file)
693
698
 
694
699
  #Currently the following kinds of array constructs are compilable
695
700
 
@@ -883,10 +888,66 @@ def compile(input_file_path,*output_file_name)
883
888
 
884
889
  end
885
890
 
891
+ def compile_multiline(input_file_contents,temporary_nila_file)
892
+
893
+ possible_arrays = input_file_contents.reject {|element| !element.include?("[")}
894
+
895
+ possible_multiline_arrays = possible_arrays.reject {|element| element.include?("]")}
896
+
897
+ multiline_arrays = []
898
+
899
+ possible_multiline_arrays.each do |starting_line|
900
+
901
+ index = input_file_contents.index(starting_line)
902
+
903
+ line = starting_line
904
+
905
+ until line.include?("]")
906
+
907
+ index += 1
908
+
909
+ line = input_file_contents[index]
910
+
911
+ end
912
+
913
+ multiline_arrays << input_file_contents[input_file_contents.index(starting_line)..index]
914
+
915
+ end
916
+
917
+ joined_file_contents = input_file_contents.join
918
+
919
+ multiline_arrays.each do |array|
920
+
921
+ modified_array = array.join
922
+
923
+ array_extract = modified_array[modified_array.index("[")..modified_array.index("]")]
924
+
925
+ array_contents = array_extract.split("[")[1].split("]")[0].lstrip.rstrip.split(",").collect {|element| element.lstrip.rstrip}
926
+
927
+ array_contents = "[" + array_contents.join(",") + "]"
928
+
929
+ joined_file_contents = joined_file_contents.sub(array_extract,array_contents)
930
+
931
+ end
932
+
933
+ file_id = open(temporary_nila_file, 'w')
934
+
935
+ file_id.write(joined_file_contents)
936
+
937
+ file_id.close()
938
+
939
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
940
+
941
+ return line_by_line_contents
942
+
943
+ end
944
+
886
945
  input_file_contents = compile_w_arrays(input_file_contents)
887
946
 
888
947
  input_file_contents = compile_array_indexing(input_file_contents)
889
948
 
949
+ input_file_contents = compile_multiline(input_file_contents,temporary_nila_file)
950
+
890
951
  return input_file_contents
891
952
 
892
953
 
@@ -894,7 +955,7 @@ def compile(input_file_path,*output_file_name)
894
955
 
895
956
  def compile_strings(input_file_contents)
896
957
 
897
- # This method will compile %q, %Q and %{} syntax. Heredocs support will be added in the future
958
+ # This method will compile %q, %Q and % syntax. Heredocs support will be added in the future
898
959
 
899
960
  def compile_small_q_syntax(input_file_contents)
900
961
 
@@ -976,9 +1037,53 @@ def compile(input_file_path,*output_file_name)
976
1037
 
977
1038
  end
978
1039
 
1040
+ def compile_percentage_syntax(input_file_contents)
1041
+
1042
+ possible_syntax_usage = input_file_contents.reject {|element| !element.include?("%")}
1043
+
1044
+ possible_syntax_usage = possible_syntax_usage.reject {|element| element.index(/(\%(\W|\s)\w{1,})/).nil?}
1045
+
1046
+ possible_syntax_usage.each do |line|
1047
+
1048
+ modified_line = line.dup
1049
+
1050
+ line_split = line.split("+").collect {|element| element.lstrip.rstrip}
1051
+
1052
+ line_split.each do |str|
1053
+
1054
+ delimiter = str[str.index("%")+1]
1055
+
1056
+ string_extract = str[str.index("%")..-1]
1057
+
1058
+ delimiter = "}" if delimiter.eql?("{")
1059
+
1060
+ if string_extract[-1].eql?(delimiter)
1061
+
1062
+ input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"\"#{string_extract[2...-1]}\"")
1063
+
1064
+ modified_line = modified_line.sub(string_extract,"\"#{string_extract[2...-1]}\"")
1065
+
1066
+ elsif delimiter.eql?(" ")
1067
+
1068
+ input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"\"#{string_extract[2..-1]}\"")
1069
+
1070
+ modified_line = modified_line.sub(string_extract,"\"#{string_extract[2..-1]}\"")
1071
+
1072
+ end
1073
+
1074
+ end
1075
+
1076
+ end
1077
+
1078
+ return input_file_contents
1079
+
1080
+ end
1081
+
979
1082
  file_contents = compile_small_q_syntax(input_file_contents)
980
1083
 
981
- file_contents = compile_big_q_syntax(input_file_contents)
1084
+ file_contents = compile_big_q_syntax(file_contents)
1085
+
1086
+ file_contents = compile_percentage_syntax(file_contents)
982
1087
 
983
1088
  return file_contents
984
1089
 
@@ -1001,7 +1106,7 @@ def compile(input_file_path,*output_file_name)
1001
1106
  #
1002
1107
  # return input_number*input_number;
1003
1108
  #
1004
- # }
1109
+ #}
1005
1110
 
1006
1111
  def is_parameterless?(input_function_block)
1007
1112
 
@@ -2930,7 +3035,7 @@ def compile(input_file_path,*output_file_name)
2930
3035
 
2931
3036
  file_contents = compile_conditional_structures(file_contents,temp_file)
2932
3037
 
2933
- file_contents = compile_arrays(file_contents)
3038
+ file_contents = compile_arrays(file_contents,temp_file)
2934
3039
 
2935
3040
  file_contents = compile_strings(file_contents)
2936
3041
 
@@ -3028,7 +3133,7 @@ def find_file_path(input_path,file_extension)
3028
3133
 
3029
3134
  end
3030
3135
 
3031
- nilac_version = "0.0.4.1.3"
3136
+ nilac_version = "0.0.4.1.6"
3032
3137
 
3033
3138
  opts = Slop.parse do
3034
3139
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
@@ -3074,6 +3179,8 @@ opts = Slop.parse do
3074
3179
 
3075
3180
  create_mac_executable(file_path)
3076
3181
 
3182
+ FileUtils.mv("#{file_path[0...-3]}","#{Dir.pwd}/bin/nilac")
3183
+
3077
3184
  puts "Build Successful!"
3078
3185
 
3079
3186
  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.1.5
4
+ version: 0.0.4.1.6
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-23 00:00:00.000000000 Z
12
+ date: 2013-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shark
@@ -66,17 +66,20 @@ files:
66
66
  - shark/features/default_method_parameters.feature
67
67
  - shark/features/fix_newlines.feature
68
68
  - shark/features/method_multiple_return.feature
69
+ - shark/features/multiline_array.feature
69
70
  - shark/features/multiple_variable_initialization.feature
70
71
  - shark/features/regular_if.feature
71
72
  - shark/features/regular_while.feature
72
73
  - shark/features/ruby_operators.feature
73
74
  - shark/features/strings.feature
74
75
  - shark/features/unless_until.feature
76
+ - shark/features/whitespace_delimitation.feature
75
77
  - shark/test_files/array_string_indexing.nila
76
78
  - shark/test_files/correct.js
77
79
  - shark/test_files/correct_default_parameters.js
78
80
  - shark/test_files/correct_indexing.js
79
81
  - shark/test_files/correct_initialization.js
82
+ - shark/test_files/correct_multiline_array.nila
80
83
  - shark/test_files/correct_multiple_return.js
81
84
  - shark/test_files/correct_operators.js
82
85
  - shark/test_files/correct_regular_if.js
@@ -85,8 +88,10 @@ files:
85
88
  - shark/test_files/correct_single_return.js
86
89
  - shark/test_files/correct_string_operators.js
87
90
  - shark/test_files/correct_unless_until.js
91
+ - shark/test_files/correct_whitespace_delimiter.js
88
92
  - shark/test_files/default_parameters.nila
89
93
  - shark/test_files/erratic.nila
94
+ - shark/test_files/multiline_array.nila
90
95
  - shark/test_files/multiple_initialization.nila
91
96
  - shark/test_files/multiple_return.nila
92
97
  - shark/test_files/no_return.nila
@@ -98,6 +103,7 @@ files:
98
103
  - shark/test_files/single_return.nila
99
104
  - shark/test_files/string_operators.nila
100
105
  - shark/test_files/unless_until.nila
106
+ - shark/test_files/whitespace_delimiter.nila
101
107
  - src/nilac.rb
102
108
  homepage: http://adhithyan15.github.com/nila
103
109
  licenses: []