nilac 0.0.4.1.7 → 0.0.4.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nilac +102 -2
- data/lib/nilac/version.rb +1 -1
- data/shark/features/string_interpolation.feature +11 -0
- data/shark/test_files/correct_interpolation.js +13 -0
- data/shark/test_files/correct_multiline_array.js +13 -0
- data/shark/test_files/string_interpolation.nila +7 -0
- data/src/nilac.rb +102 -2
- metadata +5 -2
- data/shark/test_files/correct_multiline_array.nila +0 -0
data/bin/nilac
CHANGED
@@ -204,13 +204,101 @@ def compile(input_file_path,*output_file_name)
|
|
204
204
|
|
205
205
|
def compile_interpolated_strings(input_file_contents)
|
206
206
|
|
207
|
+
def find_all_matching_indices(input_string,pattern)
|
208
|
+
|
209
|
+
locations = []
|
210
|
+
|
211
|
+
index = input_string.index(pattern)
|
212
|
+
|
213
|
+
while index != nil
|
214
|
+
|
215
|
+
locations << index
|
216
|
+
|
217
|
+
index = input_string.index(pattern,index+1)
|
218
|
+
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
return locations
|
223
|
+
|
224
|
+
|
225
|
+
end
|
226
|
+
|
207
227
|
modified_file_contents = input_file_contents.dup
|
208
228
|
|
209
229
|
input_file_contents.each_with_index do |line,index|
|
210
230
|
|
211
231
|
if line.include?("\#{")
|
212
232
|
|
213
|
-
|
233
|
+
modified_line = line.dup
|
234
|
+
|
235
|
+
interpol_starting_loc = find_all_matching_indices(modified_line,"\#{") + [-1]
|
236
|
+
|
237
|
+
interpolated_strings = []
|
238
|
+
|
239
|
+
until interpol_starting_loc.empty?
|
240
|
+
|
241
|
+
interpol_starting_loc[1] = -2 if interpol_starting_loc[1] == -1
|
242
|
+
|
243
|
+
string_extract = modified_line[interpol_starting_loc[0]+1..interpol_starting_loc[1]+1]
|
244
|
+
|
245
|
+
closed_curly_brace_index = find_all_matching_indices(string_extract,"}")
|
246
|
+
|
247
|
+
index_counter = 0
|
248
|
+
|
249
|
+
test_string = ""
|
250
|
+
|
251
|
+
until closed_curly_brace_index.empty?
|
252
|
+
|
253
|
+
test_string = string_extract[0..closed_curly_brace_index[0]]
|
254
|
+
|
255
|
+
original_string = test_string.dup
|
256
|
+
|
257
|
+
if test_string.include?("{")
|
258
|
+
|
259
|
+
test_string = test_string.reverse.sub("{","$#{index_counter}$").reverse
|
260
|
+
|
261
|
+
test_string[-1] = "@#{index_counter}@"
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
string_extract = string_extract.sub(original_string,test_string)
|
266
|
+
|
267
|
+
closed_curly_brace_index = find_all_matching_indices(string_extract,"}")
|
268
|
+
|
269
|
+
index_counter += 1
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
string_extract = string_extract[0..string_extract.length-string_extract.reverse.index(/@\d@/)]
|
274
|
+
|
275
|
+
interpolated_string = "\#{" + string_extract.split("@#{index_counter-1}@")[0].split("$#{index_counter-1}$")[1] + "}"
|
276
|
+
|
277
|
+
to_be_replaced = interpolated_string.scan(/\$\d\$/)
|
278
|
+
|
279
|
+
closing_brace_rep = interpolated_string.scan(/@\d@/)
|
280
|
+
|
281
|
+
to_be_replaced.each_with_index do |rep,index|
|
282
|
+
|
283
|
+
interpolated_string = interpolated_string.sub(rep,"{").sub(closing_brace_rep[index],"}")
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
interpolated_strings << interpolated_string
|
288
|
+
|
289
|
+
modified_line = modified_line.sub(interpolated_string,"--interpolate")
|
290
|
+
|
291
|
+
if find_all_matching_indices(modified_line,"\#{").empty?
|
292
|
+
|
293
|
+
interpol_starting_loc = []
|
294
|
+
|
295
|
+
else
|
296
|
+
|
297
|
+
interpol_starting_loc = find_all_matching_indices(modified_line,"\#{") + [-1]
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
214
302
|
|
215
303
|
interpolated_strings.each do |interpol|
|
216
304
|
|
@@ -977,6 +1065,10 @@ def compile(input_file_path,*output_file_name)
|
|
977
1065
|
|
978
1066
|
delimiter = "}" if delimiter.eql?("{")
|
979
1067
|
|
1068
|
+
delimiter = ")" if delimiter.eql?("(")
|
1069
|
+
|
1070
|
+
delimiter = ">" if delimiter.eql?("<")
|
1071
|
+
|
980
1072
|
if string_extract[-1].eql?(delimiter)
|
981
1073
|
|
982
1074
|
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"'#{string_extract[3...-1]}'")
|
@@ -1017,6 +1109,10 @@ def compile(input_file_path,*output_file_name)
|
|
1017
1109
|
|
1018
1110
|
delimiter = "}" if delimiter.eql?("{")
|
1019
1111
|
|
1112
|
+
delimiter = ")" if delimiter.eql?("(")
|
1113
|
+
|
1114
|
+
delimiter = ">" if delimiter.eql?("<")
|
1115
|
+
|
1020
1116
|
if string_extract[-1].eql?(delimiter)
|
1021
1117
|
|
1022
1118
|
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"\"#{string_extract[3...-1]}\"")
|
@@ -1059,6 +1155,10 @@ def compile(input_file_path,*output_file_name)
|
|
1059
1155
|
|
1060
1156
|
delimiter = "}" if delimiter.eql?("{")
|
1061
1157
|
|
1158
|
+
delimiter = ")" if delimiter.eql?("(")
|
1159
|
+
|
1160
|
+
delimiter = ">" if delimiter.eql?("<")
|
1161
|
+
|
1062
1162
|
if string_extract[-1].eql?(delimiter)
|
1063
1163
|
|
1064
1164
|
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]}\"")
|
@@ -3135,7 +3235,7 @@ def find_file_path(input_path,file_extension)
|
|
3135
3235
|
|
3136
3236
|
end
|
3137
3237
|
|
3138
|
-
nilac_version = "0.0.4.1.
|
3238
|
+
nilac_version = "0.0.4.1.8"
|
3139
3239
|
|
3140
3240
|
opts = Slop.parse do
|
3141
3241
|
on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
|
data/lib/nilac/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: This feature bring Ruby style string interpolation to Nila
|
2
|
+
Scenario: Input file with string interpolation
|
3
|
+
Given the input file "string_interpolation.nila"
|
4
|
+
When the ~compiler is run
|
5
|
+
The output file must be "string_interpolation.js"
|
6
|
+
The output file must equal "correct_string_interpolation.js"
|
7
|
+
|
8
|
+
Configurations:
|
9
|
+
|
10
|
+
~compiler => src/nilac.rb
|
11
|
+
:v $cliusage => ruby :v --compile $file
|
@@ -0,0 +1,13 @@
|
|
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
|
+
}).call(this);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
|
+
(function() {
|
3
|
+
var myarray, name, numbers;
|
4
|
+
|
5
|
+
numbers = [1,2,3,4,5,6,7,8,9,10];
|
6
|
+
|
7
|
+
myarray = ["string 1","string 2","string 3"];
|
8
|
+
|
9
|
+
name = "Adhithya";
|
10
|
+
|
11
|
+
name[5] = "t";
|
12
|
+
|
13
|
+
}).call(this);
|
data/src/nilac.rb
CHANGED
@@ -202,13 +202,101 @@ def compile(input_file_path,*output_file_name)
|
|
202
202
|
|
203
203
|
def compile_interpolated_strings(input_file_contents)
|
204
204
|
|
205
|
+
def find_all_matching_indices(input_string,pattern)
|
206
|
+
|
207
|
+
locations = []
|
208
|
+
|
209
|
+
index = input_string.index(pattern)
|
210
|
+
|
211
|
+
while index != nil
|
212
|
+
|
213
|
+
locations << index
|
214
|
+
|
215
|
+
index = input_string.index(pattern,index+1)
|
216
|
+
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
return locations
|
221
|
+
|
222
|
+
|
223
|
+
end
|
224
|
+
|
205
225
|
modified_file_contents = input_file_contents.dup
|
206
226
|
|
207
227
|
input_file_contents.each_with_index do |line,index|
|
208
228
|
|
209
229
|
if line.include?("\#{")
|
210
230
|
|
211
|
-
|
231
|
+
modified_line = line.dup
|
232
|
+
|
233
|
+
interpol_starting_loc = find_all_matching_indices(modified_line,"\#{") + [-1]
|
234
|
+
|
235
|
+
interpolated_strings = []
|
236
|
+
|
237
|
+
until interpol_starting_loc.empty?
|
238
|
+
|
239
|
+
interpol_starting_loc[1] = -2 if interpol_starting_loc[1] == -1
|
240
|
+
|
241
|
+
string_extract = modified_line[interpol_starting_loc[0]+1..interpol_starting_loc[1]+1]
|
242
|
+
|
243
|
+
closed_curly_brace_index = find_all_matching_indices(string_extract,"}")
|
244
|
+
|
245
|
+
index_counter = 0
|
246
|
+
|
247
|
+
test_string = ""
|
248
|
+
|
249
|
+
until closed_curly_brace_index.empty?
|
250
|
+
|
251
|
+
test_string = string_extract[0..closed_curly_brace_index[0]]
|
252
|
+
|
253
|
+
original_string = test_string.dup
|
254
|
+
|
255
|
+
if test_string.include?("{")
|
256
|
+
|
257
|
+
test_string = test_string.reverse.sub("{","$#{index_counter}$").reverse
|
258
|
+
|
259
|
+
test_string[-1] = "@#{index_counter}@"
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
string_extract = string_extract.sub(original_string,test_string)
|
264
|
+
|
265
|
+
closed_curly_brace_index = find_all_matching_indices(string_extract,"}")
|
266
|
+
|
267
|
+
index_counter += 1
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
string_extract = string_extract[0..string_extract.length-string_extract.reverse.index(/@\d@/)]
|
272
|
+
|
273
|
+
interpolated_string = "\#{" + string_extract.split("@#{index_counter-1}@")[0].split("$#{index_counter-1}$")[1] + "}"
|
274
|
+
|
275
|
+
to_be_replaced = interpolated_string.scan(/\$\d\$/)
|
276
|
+
|
277
|
+
closing_brace_rep = interpolated_string.scan(/@\d@/)
|
278
|
+
|
279
|
+
to_be_replaced.each_with_index do |rep,index|
|
280
|
+
|
281
|
+
interpolated_string = interpolated_string.sub(rep,"{").sub(closing_brace_rep[index],"}")
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
interpolated_strings << interpolated_string
|
286
|
+
|
287
|
+
modified_line = modified_line.sub(interpolated_string,"--interpolate")
|
288
|
+
|
289
|
+
if find_all_matching_indices(modified_line,"\#{").empty?
|
290
|
+
|
291
|
+
interpol_starting_loc = []
|
292
|
+
|
293
|
+
else
|
294
|
+
|
295
|
+
interpol_starting_loc = find_all_matching_indices(modified_line,"\#{") + [-1]
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
212
300
|
|
213
301
|
interpolated_strings.each do |interpol|
|
214
302
|
|
@@ -975,6 +1063,10 @@ def compile(input_file_path,*output_file_name)
|
|
975
1063
|
|
976
1064
|
delimiter = "}" if delimiter.eql?("{")
|
977
1065
|
|
1066
|
+
delimiter = ")" if delimiter.eql?("(")
|
1067
|
+
|
1068
|
+
delimiter = ">" if delimiter.eql?("<")
|
1069
|
+
|
978
1070
|
if string_extract[-1].eql?(delimiter)
|
979
1071
|
|
980
1072
|
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"'#{string_extract[3...-1]}'")
|
@@ -1015,6 +1107,10 @@ def compile(input_file_path,*output_file_name)
|
|
1015
1107
|
|
1016
1108
|
delimiter = "}" if delimiter.eql?("{")
|
1017
1109
|
|
1110
|
+
delimiter = ")" if delimiter.eql?("(")
|
1111
|
+
|
1112
|
+
delimiter = ">" if delimiter.eql?("<")
|
1113
|
+
|
1018
1114
|
if string_extract[-1].eql?(delimiter)
|
1019
1115
|
|
1020
1116
|
input_file_contents[input_file_contents.index(modified_line)] = input_file_contents[input_file_contents.index(modified_line)].sub(string_extract,"\"#{string_extract[3...-1]}\"")
|
@@ -1057,6 +1153,10 @@ def compile(input_file_path,*output_file_name)
|
|
1057
1153
|
|
1058
1154
|
delimiter = "}" if delimiter.eql?("{")
|
1059
1155
|
|
1156
|
+
delimiter = ")" if delimiter.eql?("(")
|
1157
|
+
|
1158
|
+
delimiter = ">" if delimiter.eql?("<")
|
1159
|
+
|
1060
1160
|
if string_extract[-1].eql?(delimiter)
|
1061
1161
|
|
1062
1162
|
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]}\"")
|
@@ -3133,7 +3233,7 @@ def find_file_path(input_path,file_extension)
|
|
3133
3233
|
|
3134
3234
|
end
|
3135
3235
|
|
3136
|
-
nilac_version = "0.0.4.1.
|
3236
|
+
nilac_version = "0.0.4.1.8"
|
3137
3237
|
|
3138
3238
|
opts = Slop.parse do
|
3139
3239
|
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.1.
|
4
|
+
version: 0.0.4.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- shark/features/regular_if.feature
|
72
72
|
- shark/features/regular_while.feature
|
73
73
|
- shark/features/ruby_operators.feature
|
74
|
+
- shark/features/string_interpolation.feature
|
74
75
|
- shark/features/strings.feature
|
75
76
|
- shark/features/unless_until.feature
|
76
77
|
- shark/features/whitespace_delimitation.feature
|
@@ -79,7 +80,8 @@ files:
|
|
79
80
|
- shark/test_files/correct_default_parameters.js
|
80
81
|
- shark/test_files/correct_indexing.js
|
81
82
|
- shark/test_files/correct_initialization.js
|
82
|
-
- shark/test_files/
|
83
|
+
- shark/test_files/correct_interpolation.js
|
84
|
+
- shark/test_files/correct_multiline_array.js
|
83
85
|
- shark/test_files/correct_multiple_return.js
|
84
86
|
- shark/test_files/correct_operators.js
|
85
87
|
- shark/test_files/correct_regular_if.js
|
@@ -101,6 +103,7 @@ files:
|
|
101
103
|
- shark/test_files/regular_while.nila
|
102
104
|
- shark/test_files/simple.nila
|
103
105
|
- shark/test_files/single_return.nila
|
106
|
+
- shark/test_files/string_interpolation.nila
|
104
107
|
- shark/test_files/string_operators.nila
|
105
108
|
- shark/test_files/unless_until.nila
|
106
109
|
- shark/test_files/whitespace_delimiter.nila
|
File without changes
|