nilac 0.0.4.1.8 → 0.0.4.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/nilac CHANGED
@@ -202,6 +202,67 @@ def compile(input_file_path,*output_file_name)
202
202
 
203
203
  end
204
204
 
205
+ def compile_heredocs(input_file_contents,temporary_nila_file)
206
+
207
+ joined_file_contents = input_file_contents.join
208
+
209
+ possible_heredocs = input_file_contents.reject{|element| !element.include?("<<-")}
210
+
211
+ possible_heredocs = possible_heredocs.collect {|element| element.match(/<<-(.*|\w*)/).to_a[0]}
212
+
213
+ possible_heredocs.each do |heredoc|
214
+
215
+ delimiter = heredoc[3..-1]
216
+
217
+ quote = 2
218
+
219
+ if delimiter.include?("'")
220
+
221
+ quote = 1
222
+
223
+ end
224
+
225
+ delimiter = delimiter.gsub("\"","") if quote == 2
226
+
227
+ delimiter = delimiter.gsub("'","") if quote == 1
228
+
229
+ string_split = joined_file_contents.split(heredoc,2)
230
+
231
+ string_extract = string_split[1]
232
+
233
+ heredoc_extract = string_extract[0...string_extract.index(delimiter)]
234
+
235
+ replacement_string = ""
236
+
237
+ if quote == 1
238
+
239
+ replacement_string = "'#{heredoc_extract.delete("\"")}'".lstrip.inspect
240
+
241
+ replacement_string = replacement_string[1..-2]
242
+
243
+ elsif quote == 2
244
+
245
+ replacement_string = heredoc_extract.lstrip.inspect
246
+
247
+ end
248
+
249
+ joined_file_contents = joined_file_contents.sub(heredoc + heredoc_extract + delimiter,replacement_string)
250
+
251
+ end
252
+
253
+ file_id = open(temporary_nila_file, 'w')
254
+
255
+ file_id.write(joined_file_contents)
256
+
257
+ file_id.close()
258
+
259
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
260
+
261
+ return line_by_line_contents
262
+
263
+
264
+ end
265
+
205
266
  def compile_interpolated_strings(input_file_contents)
206
267
 
207
268
  def find_all_matching_indices(input_string,pattern)
@@ -226,6 +287,26 @@ def compile(input_file_path,*output_file_name)
226
287
 
227
288
  modified_file_contents = input_file_contents.dup
228
289
 
290
+ single_quoted_strings = input_file_contents.reject {|element| !element.include?("'")}
291
+
292
+ single_quoted_strings.each do |str|
293
+
294
+ modified_string = str.dup
295
+
296
+ while modified_string.include?("'")
297
+
298
+ first_index = modified_string.index("'")
299
+
300
+ string_extract = modified_string[first_index..modified_string.index("'",first_index+1)]
301
+
302
+ modified_string = modified_string.sub(string_extract,"--single_quoted")
303
+
304
+ end
305
+
306
+ input_file_contents[input_file_contents.index(str)] = modified_string
307
+
308
+ end
309
+
229
310
  input_file_contents.each_with_index do |line,index|
230
311
 
231
312
  if line.include?("\#{")
@@ -786,10 +867,6 @@ def compile(input_file_path,*output_file_name)
786
867
 
787
868
  def compile_arrays(input_file_contents,temporary_nila_file)
788
869
 
789
- #Currently the following kinds of array constructs are compilable
790
-
791
- # 1. %w{} syntax
792
-
793
870
  def compile_w_arrays(input_file_contents)
794
871
 
795
872
  def extract(input_string,pattern_start,pattern_end)
@@ -1032,12 +1109,30 @@ def compile(input_file_path,*output_file_name)
1032
1109
 
1033
1110
  end
1034
1111
 
1112
+ def compile_operators(input_file_contents)
1113
+
1114
+ possible_operator_usage = input_file_contents.reject {|element| !element.include?("<<")}
1115
+
1116
+ possible_operator_usage.each do |usage|
1117
+
1118
+ left,right = usage.split("<<")
1119
+
1120
+ input_file_contents[input_file_contents.index(usage)] = left.rstrip + ".push(#{right.lstrip})"
1121
+
1122
+ end
1123
+
1124
+ return input_file_contents
1125
+
1126
+ end
1127
+
1035
1128
  input_file_contents = compile_w_arrays(input_file_contents)
1036
1129
 
1037
1130
  input_file_contents = compile_array_indexing(input_file_contents)
1038
1131
 
1039
1132
  input_file_contents = compile_multiline(input_file_contents,temporary_nila_file)
1040
1133
 
1134
+ input_file_contents = compile_operators(input_file_contents)
1135
+
1041
1136
  return input_file_contents
1042
1137
 
1043
1138
 
@@ -3133,6 +3228,8 @@ def compile(input_file_path,*output_file_name)
3133
3228
 
3134
3229
  file_contents = split_semicolon_seperated_expressions(file_contents)
3135
3230
 
3231
+ file_contents = compile_heredocs(file_contents,temp_file)
3232
+
3136
3233
  file_contents = compile_interpolated_strings(file_contents)
3137
3234
 
3138
3235
  file_contents = compile_conditional_structures(file_contents,temp_file)
@@ -3235,7 +3332,7 @@ def find_file_path(input_path,file_extension)
3235
3332
 
3236
3333
  end
3237
3334
 
3238
- nilac_version = "0.0.4.1.8"
3335
+ nilac_version = "0.0.4.1.9"
3239
3336
 
3240
3337
  opts = Slop.parse do
3241
3338
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
@@ -3249,6 +3346,8 @@ opts = Slop.parse do
3249
3346
 
3250
3347
  puts " nilac -v/--version\n"
3251
3348
 
3349
+ puts " nilac -u/--update => Update Checker\n"
3350
+
3252
3351
  puts " nilac [command] [file_options]\n\n"
3253
3352
 
3254
3353
  puts " Available Commands:\n\n"
@@ -3265,7 +3364,7 @@ opts = Slop.parse do
3265
3364
 
3266
3365
  puts " Further Information:\n\n"
3267
3366
 
3268
- puts " Visit http://adhithyan15.github.io/nila to know more about the project."
3367
+ puts " Visit http://adhithyan15.github.io/nila to know more about the project.\n\n"
3269
3368
 
3270
3369
  end
3271
3370
  on :v, :version, 'Output Nilac Version No' do
data/lib/nilac/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.1.8"
2
+ VERSION = "0.0.4.1.9"
3
3
  end
@@ -0,0 +1,11 @@
1
+ Feature: This feature brings heredocs to Nila
2
+ Scenario: Input file with heredocs.
3
+ Given the input file "heredoc.nila"
4
+ When the ~compiler is run
5
+ The output file must be "heredoc.js"
6
+ The output file must equal "correct_heredoc.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => src/nilac.rb
11
+ :v $cliusage => ruby :v --compile $file
@@ -0,0 +1,11 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function() {
3
+ var numbers;
4
+
5
+ console.log("Grocery list\n----\n1. Salad mix.\n2. Strawberries.*\n3. Cereal.\n4. Milk.*\n \n* Organic\n");
6
+
7
+ numbers = [1,2,3,4,5,6,7];
8
+
9
+ numbers.push(7);
10
+
11
+ }).call(this);
@@ -10,4 +10,8 @@
10
10
 
11
11
  console.log("Hello " + "world");
12
12
 
13
+ console.log('Hello #{world}');
14
+
15
+ console.log('Hello');
16
+
13
17
  }).call(this);
@@ -16,4 +16,10 @@
16
16
 
17
17
  str = "this is a wonderful string" + "this is another wonderful string";
18
18
 
19
+ str = "this is a wonderful string";
20
+
21
+ str = "this is a wonderful string";
22
+
23
+ str = "this is a wonderful string" + "this is another wonderful string";
24
+
19
25
  }).call(this);
@@ -0,0 +1,21 @@
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 (container === null) {
7
+ container = "cup";
8
+ }
9
+ if (liquid === null) {
10
+ liquid = "coffee";
11
+ }
12
+ return console.log("Filling " + container + " with " + liquid);
13
+ }
14
+
15
+ fill();
16
+
17
+ fill("cup");
18
+
19
+ fill("bowl","soup");
20
+
21
+ }).call(this);
@@ -0,0 +1,14 @@
1
+ puts <<-Hello
2
+ Grocery list
3
+ ----
4
+ 1. Salad mix.
5
+ 2. Strawberries.*
6
+ 3. Cereal.
7
+ 4. Milk.*
8
+
9
+ * Organic
10
+ Hello
11
+
12
+ numbers = [1,2,3,4,5,6,7]
13
+
14
+ numbers << 7
@@ -2,7 +2,7 @@ numbers = [1,2,3,4,5,6,7,8,9,10]
2
2
 
3
3
  myarray = [
4
4
 
5
- "string 1",
5
+ "string 1",
6
6
  "string 2",
7
7
  "string 3"
8
8
 
@@ -0,0 +1,17 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function() {
3
+ var msg;
4
+
5
+ //This file tests the limits of the string interpolation feature present in Nila
6
+
7
+ msg = "Hello " + "world. A lovely place." + "" + "Another " + "Lovely quote";
8
+
9
+ console.log(msg);
10
+
11
+ console.log("Hello " + "world");
12
+
13
+ console.log('Hello #{world}');
14
+
15
+ console.log('Hello');
16
+
17
+ }).call(this);
@@ -5,3 +5,7 @@ msg = "Hello #{"world. A lovely place."}" + "Another #{"Lovely quote"}"
5
5
  puts msg
6
6
 
7
7
  puts "Hello #{"world"}"
8
+
9
+ puts 'Hello #{world}'
10
+
11
+ puts 'Hello'
data/src/nilac.rb CHANGED
@@ -200,6 +200,67 @@ def compile(input_file_path,*output_file_name)
200
200
 
201
201
  end
202
202
 
203
+ def compile_heredocs(input_file_contents,temporary_nila_file)
204
+
205
+ joined_file_contents = input_file_contents.join
206
+
207
+ possible_heredocs = input_file_contents.reject{|element| !element.include?("<<-")}
208
+
209
+ possible_heredocs = possible_heredocs.collect {|element| element.match(/<<-(.*|\w*)/).to_a[0]}
210
+
211
+ possible_heredocs.each do |heredoc|
212
+
213
+ delimiter = heredoc[3..-1]
214
+
215
+ quote = 2
216
+
217
+ if delimiter.include?("'")
218
+
219
+ quote = 1
220
+
221
+ end
222
+
223
+ delimiter = delimiter.gsub("\"","") if quote == 2
224
+
225
+ delimiter = delimiter.gsub("'","") if quote == 1
226
+
227
+ string_split = joined_file_contents.split(heredoc,2)
228
+
229
+ string_extract = string_split[1]
230
+
231
+ heredoc_extract = string_extract[0...string_extract.index(delimiter)]
232
+
233
+ replacement_string = ""
234
+
235
+ if quote == 1
236
+
237
+ replacement_string = "'#{heredoc_extract.delete("\"")}'".lstrip.inspect
238
+
239
+ replacement_string = replacement_string[1..-2]
240
+
241
+ elsif quote == 2
242
+
243
+ replacement_string = heredoc_extract.lstrip.inspect
244
+
245
+ end
246
+
247
+ joined_file_contents = joined_file_contents.sub(heredoc + heredoc_extract + delimiter,replacement_string)
248
+
249
+ end
250
+
251
+ file_id = open(temporary_nila_file, 'w')
252
+
253
+ file_id.write(joined_file_contents)
254
+
255
+ file_id.close()
256
+
257
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
258
+
259
+ return line_by_line_contents
260
+
261
+
262
+ end
263
+
203
264
  def compile_interpolated_strings(input_file_contents)
204
265
 
205
266
  def find_all_matching_indices(input_string,pattern)
@@ -224,6 +285,26 @@ def compile(input_file_path,*output_file_name)
224
285
 
225
286
  modified_file_contents = input_file_contents.dup
226
287
 
288
+ single_quoted_strings = input_file_contents.reject {|element| !(element.count("'") >= 2)}
289
+
290
+ single_quoted_strings.each do |str|
291
+
292
+ modified_string = str.dup
293
+
294
+ while modified_string.include?("'")
295
+
296
+ first_index = modified_string.index("'")
297
+
298
+ string_extract = modified_string[first_index..modified_string.index("'",first_index+1)]
299
+
300
+ modified_string = modified_string.sub(string_extract,"--single_quoted")
301
+
302
+ end
303
+
304
+ input_file_contents[input_file_contents.index(str)] = modified_string
305
+
306
+ end
307
+
227
308
  input_file_contents.each_with_index do |line,index|
228
309
 
229
310
  if line.include?("\#{")
@@ -784,10 +865,6 @@ def compile(input_file_path,*output_file_name)
784
865
 
785
866
  def compile_arrays(input_file_contents,temporary_nila_file)
786
867
 
787
- #Currently the following kinds of array constructs are compilable
788
-
789
- # 1. %w{} syntax
790
-
791
868
  def compile_w_arrays(input_file_contents)
792
869
 
793
870
  def extract(input_string,pattern_start,pattern_end)
@@ -1030,12 +1107,30 @@ def compile(input_file_path,*output_file_name)
1030
1107
 
1031
1108
  end
1032
1109
 
1110
+ def compile_array_operators(input_file_contents)
1111
+
1112
+ possible_operator_usage = input_file_contents.reject {|element| !element.include?("<<")}
1113
+
1114
+ possible_operator_usage.each do |usage|
1115
+
1116
+ left,right = usage.split("<<")
1117
+
1118
+ input_file_contents[input_file_contents.index(usage)] = left.rstrip + ".push(#{right.lstrip})"
1119
+
1120
+ end
1121
+
1122
+ return input_file_contents
1123
+
1124
+ end
1125
+
1033
1126
  input_file_contents = compile_w_arrays(input_file_contents)
1034
1127
 
1035
1128
  input_file_contents = compile_array_indexing(input_file_contents)
1036
1129
 
1037
1130
  input_file_contents = compile_multiline(input_file_contents,temporary_nila_file)
1038
1131
 
1132
+ input_file_contents = compile_array_operators(input_file_contents)
1133
+
1039
1134
  return input_file_contents
1040
1135
 
1041
1136
 
@@ -3131,6 +3226,8 @@ def compile(input_file_path,*output_file_name)
3131
3226
 
3132
3227
  file_contents = split_semicolon_seperated_expressions(file_contents)
3133
3228
 
3229
+ file_contents = compile_heredocs(file_contents,temp_file)
3230
+
3134
3231
  file_contents = compile_interpolated_strings(file_contents)
3135
3232
 
3136
3233
  file_contents = compile_conditional_structures(file_contents,temp_file)
@@ -3233,7 +3330,7 @@ def find_file_path(input_path,file_extension)
3233
3330
 
3234
3331
  end
3235
3332
 
3236
- nilac_version = "0.0.4.1.8"
3333
+ nilac_version = "0.0.4.1.9"
3237
3334
 
3238
3335
  opts = Slop.parse do
3239
3336
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
@@ -3247,6 +3344,8 @@ opts = Slop.parse do
3247
3344
 
3248
3345
  puts " nilac -v/--version\n"
3249
3346
 
3347
+ puts " nilac -u/--update => Update Checker\n"
3348
+
3250
3349
  puts " nilac [command] [file_options]\n\n"
3251
3350
 
3252
3351
  puts " Available Commands:\n\n"
@@ -3263,7 +3362,7 @@ opts = Slop.parse do
3263
3362
 
3264
3363
  puts " Further Information:\n\n"
3265
3364
 
3266
- puts " Visit http://adhithyan15.github.io/nila to know more about the project."
3365
+ puts " Visit http://adhithyan15.github.io/nila to know more about the project.\n\n"
3267
3366
 
3268
3367
  end
3269
3368
  on :v, :version, 'Output Nilac Version No' do
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.8
4
+ version: 0.0.4.1.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-07-25 00:00:00.000000000 Z
12
+ date: 2013-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shark
@@ -65,6 +65,7 @@ files:
65
65
  - shark/features/barebones_compilation.feature
66
66
  - shark/features/default_method_parameters.feature
67
67
  - shark/features/fix_newlines.feature
68
+ - shark/features/heredoc.feature
68
69
  - shark/features/method_multiple_return.feature
69
70
  - shark/features/multiline_array.feature
70
71
  - shark/features/multiple_variable_initialization.feature
@@ -78,9 +79,9 @@ files:
78
79
  - shark/test_files/array_string_indexing.nila
79
80
  - shark/test_files/correct.js
80
81
  - shark/test_files/correct_default_parameters.js
82
+ - shark/test_files/correct_heredoc.js
81
83
  - shark/test_files/correct_indexing.js
82
84
  - shark/test_files/correct_initialization.js
83
- - shark/test_files/correct_interpolation.js
84
85
  - shark/test_files/correct_multiline_array.js
85
86
  - shark/test_files/correct_multiple_return.js
86
87
  - shark/test_files/correct_operators.js
@@ -88,11 +89,14 @@ files:
88
89
  - shark/test_files/correct_regular_while.js
89
90
  - shark/test_files/correct_return.js
90
91
  - shark/test_files/correct_single_return.js
92
+ - shark/test_files/correct_string_interpolation.js
91
93
  - shark/test_files/correct_string_operators.js
92
94
  - shark/test_files/correct_unless_until.js
93
95
  - shark/test_files/correct_whitespace_delimiter.js
96
+ - shark/test_files/default_parameters.js
94
97
  - shark/test_files/default_parameters.nila
95
98
  - shark/test_files/erratic.nila
99
+ - shark/test_files/heredoc.nila
96
100
  - shark/test_files/multiline_array.nila
97
101
  - shark/test_files/multiple_initialization.nila
98
102
  - shark/test_files/multiple_return.nila
@@ -103,6 +107,7 @@ files:
103
107
  - shark/test_files/regular_while.nila
104
108
  - shark/test_files/simple.nila
105
109
  - shark/test_files/single_return.nila
110
+ - shark/test_files/string_interpolation.js
106
111
  - shark/test_files/string_interpolation.nila
107
112
  - shark/test_files/string_operators.nila
108
113
  - shark/test_files/unless_until.nila