nilac 0.0.4.2.0 → 0.0.4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/nilac/version.rb +1 -1
- data/shark/features/hashes.feature +11 -0
- data/shark/features/loop.feature +11 -0
- data/shark/test_files/correct_hashes.js +31 -0
- data/shark/test_files/correct_loop.js +15 -0
- data/shark/test_files/correct_operators.js +7 -1
- data/shark/test_files/correct_unless_until.js +2 -2
- data/shark/test_files/hashes.nila +21 -0
- data/shark/test_files/loop.nila +6 -0
- data/shark/test_files/operators.nila +7 -1
- data/src/nilac.rb +450 -34
- metadata +8 -2
data/lib/nilac/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: This feature brings Ruby style Hashes to Nila
|
2
|
+
Scenario: Input file with hashes.
|
3
|
+
Given the input file "hashes.nila"
|
4
|
+
When the ~compiler is run
|
5
|
+
The output file must be "hashes.js"
|
6
|
+
The output file must equal "correct_hashes.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 loop keyword to Nila
|
2
|
+
Scenario: Input file with loop keyword.
|
3
|
+
Given the input file "loop.nila"
|
4
|
+
When the ~compiler is run
|
5
|
+
The output file must be "loop.js"
|
6
|
+
The output file must equal "correct_loop.js"
|
7
|
+
|
8
|
+
Configurations:
|
9
|
+
|
10
|
+
~compiler => src/nilac.rb
|
11
|
+
:v $cliusage => ruby :v --compile $file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
|
+
(function() {
|
3
|
+
var inst_section, student_ages;
|
4
|
+
|
5
|
+
// This file demonstrates several Hash features in Nila
|
6
|
+
|
7
|
+
inst_section = {
|
8
|
+
cello: 'string',
|
9
|
+
clarinet: 'woodwind',
|
10
|
+
drum: 'percussion',
|
11
|
+
oboe: 'woodwind',
|
12
|
+
trumpet: 'brass',
|
13
|
+
violin: 'string',
|
14
|
+
guitar: 'string',
|
15
|
+
};
|
16
|
+
|
17
|
+
if (variable === 10) {
|
18
|
+
process.stdout.write("Variable is 10");
|
19
|
+
} else if (variable === 20) {
|
20
|
+
process.stdout.write("Variable is 20");
|
21
|
+
} else {
|
22
|
+
process.stdout.write("Variable is something else")
|
23
|
+
}
|
24
|
+
|
25
|
+
student_ages = {
|
26
|
+
Jack: 10,
|
27
|
+
Jill: 12,
|
28
|
+
Bob: 14,
|
29
|
+
};
|
30
|
+
|
31
|
+
}).call(this);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
//Written using Nila. Visit http://adhithyan15.github.io/nila
|
2
2
|
(function() {
|
3
|
-
var a;
|
3
|
+
var a, line;
|
4
4
|
|
5
5
|
a = Math.pow(2,3);
|
6
6
|
|
@@ -8,4 +8,10 @@
|
|
8
8
|
console.log("Correct Calculation!");
|
9
9
|
}
|
10
10
|
|
11
|
+
line = "My favorite language is Ruby!";
|
12
|
+
|
13
|
+
if (line = line.match(/Ruby|Python/)) {
|
14
|
+
console.log("Scripting language mentioned: " + line);
|
15
|
+
}
|
16
|
+
|
11
17
|
}).call(this);
|
@@ -2,9 +2,9 @@
|
|
2
2
|
(function() {
|
3
3
|
var i;
|
4
4
|
|
5
|
-
// This file demonstrates unless
|
5
|
+
// This file demonstrates unless and until statements.
|
6
6
|
|
7
|
-
// Examples are from http://www.skorks.com/2009/09/a-wealth-of-ruby-loops-and-iterators/
|
7
|
+
// Examples are from http://www.skorks.com/2009/09/a-wealth-of-ruby-loops-and-iterators/ and
|
8
8
|
|
9
9
|
// http://37signals.com/svn/posts/2699-making-sense-with-rubys-unless
|
10
10
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file demonstrates several Hash features in Nila
|
2
|
+
|
3
|
+
inst_section = {
|
4
|
+
'cello' => 'string',
|
5
|
+
'clarinet' => 'woodwind',
|
6
|
+
'drum': 'percussion',
|
7
|
+
'oboe' : 'woodwind',
|
8
|
+
'trumpet' => 'brass',
|
9
|
+
'violin' => 'string',
|
10
|
+
:guitar => 'string'
|
11
|
+
}
|
12
|
+
|
13
|
+
if variable == 10
|
14
|
+
print "Variable is 10"
|
15
|
+
elsif variable == 20
|
16
|
+
print "Variable is 20"
|
17
|
+
else
|
18
|
+
print "Variable is something else"
|
19
|
+
end
|
20
|
+
|
21
|
+
student_ages = {"Jack" => 10,"Jill" => 12,"Bob" => 14}
|
data/src/nilac.rb
CHANGED
@@ -750,6 +750,8 @@ def compile(input_file_path, *output_file_name)
|
|
750
750
|
|
751
751
|
input_file_contents = input_file_contents.collect { |element| element.gsub("%=", "modequal") }
|
752
752
|
|
753
|
+
input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
|
754
|
+
|
753
755
|
for x in 0...input_file_contents.length
|
754
756
|
|
755
757
|
current_row = input_file_contents[x]
|
@@ -814,6 +816,8 @@ def compile(input_file_path, *output_file_name)
|
|
814
816
|
|
815
817
|
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("notequal", "!=") }
|
816
818
|
|
819
|
+
line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("matchequal", "=~") }
|
820
|
+
|
817
821
|
return variables.uniq, line_by_line_contents
|
818
822
|
|
819
823
|
end
|
@@ -1136,6 +1140,108 @@ def compile(input_file_path, *output_file_name)
|
|
1136
1140
|
|
1137
1141
|
end
|
1138
1142
|
|
1143
|
+
def compile_hashes(input_file_contents,temporary_nila_file)
|
1144
|
+
|
1145
|
+
def compile_multiline_hashes(input_file_contents,temporary_nila_file)
|
1146
|
+
|
1147
|
+
possible_hashes = input_file_contents.reject { |element| !element.include?("{") }
|
1148
|
+
|
1149
|
+
possible_multiline_hashes = possible_hashes.reject { |element| element.include?("}") }
|
1150
|
+
|
1151
|
+
multiline_hashes = []
|
1152
|
+
|
1153
|
+
possible_multiline_hashes.each do |starting_line|
|
1154
|
+
|
1155
|
+
index = input_file_contents.index(starting_line)
|
1156
|
+
|
1157
|
+
line = starting_line
|
1158
|
+
|
1159
|
+
until line.include?("}")
|
1160
|
+
|
1161
|
+
index += 1
|
1162
|
+
|
1163
|
+
line = input_file_contents[index]
|
1164
|
+
|
1165
|
+
end
|
1166
|
+
|
1167
|
+
multiline_hashes << input_file_contents[input_file_contents.index(starting_line)..index]
|
1168
|
+
|
1169
|
+
end
|
1170
|
+
|
1171
|
+
joined_file_contents = input_file_contents.join
|
1172
|
+
|
1173
|
+
multiline_hashes.each do |hash|
|
1174
|
+
|
1175
|
+
modified_hash = hash.join
|
1176
|
+
|
1177
|
+
hash_extract = modified_hash[modified_hash.index("{")..modified_hash.index("}")]
|
1178
|
+
|
1179
|
+
hash_contents = hash_extract.split("{")[1].split("}")[0].lstrip.rstrip.split(",").collect { |element| element.lstrip.rstrip }
|
1180
|
+
|
1181
|
+
hash_contents = "{" + hash_contents.join(",") + "}"
|
1182
|
+
|
1183
|
+
joined_file_contents = joined_file_contents.sub(hash_extract, hash_contents)
|
1184
|
+
|
1185
|
+
end
|
1186
|
+
|
1187
|
+
file_id = open(temporary_nila_file, 'w')
|
1188
|
+
|
1189
|
+
file_id.write(joined_file_contents)
|
1190
|
+
|
1191
|
+
file_id.close()
|
1192
|
+
|
1193
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
1194
|
+
|
1195
|
+
return line_by_line_contents
|
1196
|
+
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
def compile_inline_hashes(input_file_contents)
|
1200
|
+
|
1201
|
+
modified_file_contents = input_file_contents.clone.collect {|element| element.gsub(/(#|%)\w?\{/,"innerrii0opol115")}
|
1202
|
+
|
1203
|
+
possible_inline_hashes = modified_file_contents.reject {|element| !element.include?("{")}
|
1204
|
+
|
1205
|
+
possible_inline_hashes.each do |hash|
|
1206
|
+
|
1207
|
+
hash_extract = hash[hash.index("{")..hash.index("}")]
|
1208
|
+
|
1209
|
+
contents = hash_extract[1...-1].split(",")
|
1210
|
+
|
1211
|
+
hash_contents = []
|
1212
|
+
|
1213
|
+
contents.each do |items|
|
1214
|
+
|
1215
|
+
items = items.lstrip.sub(":","") if items.lstrip[0] == ":"
|
1216
|
+
|
1217
|
+
key, value = items.split("=>").collect {|element| element.lstrip.rstrip} if items.include?("=>")
|
1218
|
+
|
1219
|
+
key, value = items.split(":").collect {|element| element.lstrip.rstrip} if items.include?(":")
|
1220
|
+
|
1221
|
+
key = key.gsub("'","").gsub("\"","")
|
1222
|
+
|
1223
|
+
hash_contents << " #{key}: #{value},"
|
1224
|
+
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
replacement_string = "{\n" + hash_contents.join("\n") + "\n};\n"
|
1228
|
+
|
1229
|
+
input_file_contents[input_file_contents.index(hash)] = input_file_contents[input_file_contents.index(hash)].sub(hash_extract,replacement_string)
|
1230
|
+
|
1231
|
+
end
|
1232
|
+
|
1233
|
+
return input_file_contents
|
1234
|
+
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
file_contents = compile_multiline_hashes(input_file_contents,temporary_nila_file)
|
1238
|
+
|
1239
|
+
file_contents = compile_inline_hashes(file_contents)
|
1240
|
+
|
1241
|
+
return file_contents
|
1242
|
+
|
1243
|
+
end
|
1244
|
+
|
1139
1245
|
def compile_strings(input_file_contents)
|
1140
1246
|
|
1141
1247
|
def compile_small_q_syntax(input_file_contents)
|
@@ -1837,6 +1943,8 @@ def compile(input_file_path, *output_file_name)
|
|
1837
1943
|
|
1838
1944
|
junk, condition = command.split("unless ")
|
1839
1945
|
|
1946
|
+
condition = condition.gsub(" and "," && ").gsub(" or "," || ").gsub(" not "," !")
|
1947
|
+
|
1840
1948
|
replacement_string = "if !(#{condition.lstrip.rstrip})\n"
|
1841
1949
|
|
1842
1950
|
modified_file_contents[modified_file_contents.index(command)] = replacement_string
|
@@ -1851,6 +1959,8 @@ def compile(input_file_path, *output_file_name)
|
|
1851
1959
|
|
1852
1960
|
junk, condition = command.split("until ")
|
1853
1961
|
|
1962
|
+
condition = condition.gsub(" and "," && ").gsub(" or "," || ").gsub(" not "," !")
|
1963
|
+
|
1854
1964
|
replacement_string = "while !(#{condition.lstrip.rstrip})\n"
|
1855
1965
|
|
1856
1966
|
modified_file_contents[modified_file_contents.index(command)] = replacement_string
|
@@ -1879,21 +1989,25 @@ def compile(input_file_path, *output_file_name)
|
|
1879
1989
|
|
1880
1990
|
line_split = line.split(plain_conditionals[index])
|
1881
1991
|
|
1992
|
+
condition = line_split[1]
|
1993
|
+
|
1994
|
+
condition = condition.gsub(" and "," && ").gsub(" or "," || ").gsub(" not "," !")
|
1995
|
+
|
1882
1996
|
if index == 0
|
1883
1997
|
|
1884
|
-
output_statement = "if (#{
|
1998
|
+
output_statement = "if (#{condition.lstrip.rstrip.gsub("?", "")}) {\n\n#{line_split[0]}\n}\n"
|
1885
1999
|
|
1886
2000
|
elsif index == 1
|
1887
2001
|
|
1888
|
-
output_statement = "while (#{
|
2002
|
+
output_statement = "while (#{condition.lstrip.rstrip.gsub("?", "")}) {\n\n#{line_split[0]}\n}\n"
|
1889
2003
|
|
1890
2004
|
elsif index == 2
|
1891
2005
|
|
1892
|
-
output_statement = "if (!(#{
|
2006
|
+
output_statement = "if (!(#{condition.lstrip.rstrip.gsub("?", "")})) {\n\n#{line_split[0]}\n}\n"
|
1893
2007
|
|
1894
2008
|
elsif index == 3
|
1895
2009
|
|
1896
|
-
output_statement = "while (!(#{
|
2010
|
+
output_statement = "while (!(#{condition.lstrip.rstrip.gsub("?", "")})) {\n\n#{line_split[0]}\n}\n"
|
1897
2011
|
|
1898
2012
|
end
|
1899
2013
|
|
@@ -2059,6 +2173,8 @@ def compile(input_file_path, *output_file_name)
|
|
2059
2173
|
|
2060
2174
|
junk, condition = starting_line.split("if")
|
2061
2175
|
|
2176
|
+
condition = condition.gsub(" and "," && ").gsub(" or "," || ").gsub(" not "," !")
|
2177
|
+
|
2062
2178
|
input_block[0] = "Euuf (#{condition.lstrip.rstrip.gsub("?", "")}) {\n"
|
2063
2179
|
|
2064
2180
|
input_block[-1] = input_block[-1].lstrip.sub("end", "}")
|
@@ -2069,6 +2185,8 @@ def compile(input_file_path, *output_file_name)
|
|
2069
2185
|
|
2070
2186
|
junk, condition = statement.split("elsuf")
|
2071
2187
|
|
2188
|
+
condition = condition.gsub(" and "," && ").gsub(" or "," || ").gsub(" not "," !")
|
2189
|
+
|
2072
2190
|
input_block[input_block.index(statement)] = "} elsuf (#{condition.lstrip.rstrip.gsub("?", "")}) {\n"
|
2073
2191
|
|
2074
2192
|
end
|
@@ -2479,6 +2597,274 @@ def compile(input_file_path, *output_file_name)
|
|
2479
2597
|
|
2480
2598
|
end
|
2481
2599
|
|
2600
|
+
def compile_loop_keyword(input_file_contents,temporary_nila_file)
|
2601
|
+
|
2602
|
+
def convert_string_to_array(input_string, temporary_nila_file)
|
2603
|
+
|
2604
|
+
file_id = open(temporary_nila_file, 'w')
|
2605
|
+
|
2606
|
+
file_id.write(input_string)
|
2607
|
+
|
2608
|
+
file_id.close()
|
2609
|
+
|
2610
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
2611
|
+
|
2612
|
+
return line_by_line_contents
|
2613
|
+
|
2614
|
+
end
|
2615
|
+
|
2616
|
+
def extract_loop_blocks(loop_statement_indexes, input_file_contents)
|
2617
|
+
|
2618
|
+
possible_loop_blocks = []
|
2619
|
+
|
2620
|
+
loop_block_counter = 0
|
2621
|
+
|
2622
|
+
extracted_blocks = []
|
2623
|
+
|
2624
|
+
controlregexp = /(if |while |def |loop )/
|
2625
|
+
|
2626
|
+
rejectionregexp = /( if | while )/
|
2627
|
+
|
2628
|
+
for x in 0...loop_statement_indexes.length-1
|
2629
|
+
|
2630
|
+
possible_loop_blocks << input_file_contents[loop_statement_indexes[x]..loop_statement_indexes[x+1]]
|
2631
|
+
|
2632
|
+
end
|
2633
|
+
|
2634
|
+
end_counter = 0
|
2635
|
+
|
2636
|
+
end_index = []
|
2637
|
+
|
2638
|
+
current_block = []
|
2639
|
+
|
2640
|
+
possible_loop_blocks.each_with_index do |block|
|
2641
|
+
|
2642
|
+
current_block += block
|
2643
|
+
|
2644
|
+
current_block.each_with_index do |line, index|
|
2645
|
+
|
2646
|
+
if line.strip.eql? "end"
|
2647
|
+
|
2648
|
+
end_counter += 1
|
2649
|
+
|
2650
|
+
end_index << index
|
2651
|
+
|
2652
|
+
end
|
2653
|
+
|
2654
|
+
end
|
2655
|
+
|
2656
|
+
if end_counter > 0
|
2657
|
+
|
2658
|
+
until end_index.empty?
|
2659
|
+
|
2660
|
+
array_extract = current_block[0..end_index[0]].reverse
|
2661
|
+
|
2662
|
+
index_counter = 0
|
2663
|
+
|
2664
|
+
array_extract.each_with_index do |line|
|
2665
|
+
|
2666
|
+
break if (line.lstrip.index(controlregexp) != nil and line.lstrip.index(rejectionregexp).nil?)
|
2667
|
+
|
2668
|
+
index_counter += 1
|
2669
|
+
|
2670
|
+
end
|
2671
|
+
|
2672
|
+
block_extract = array_extract[0..index_counter].reverse
|
2673
|
+
|
2674
|
+
extracted_blocks << block_extract
|
2675
|
+
|
2676
|
+
block_start = current_block.index(block_extract[0])
|
2677
|
+
|
2678
|
+
block_end = current_block.index(block_extract[-1])
|
2679
|
+
|
2680
|
+
current_block[block_start..block_end] = "--loopblock#{loop_block_counter}"
|
2681
|
+
|
2682
|
+
loop_block_counter += 1
|
2683
|
+
|
2684
|
+
end_counter = 0
|
2685
|
+
|
2686
|
+
end_index = []
|
2687
|
+
|
2688
|
+
current_block.each_with_index do |line, index|
|
2689
|
+
|
2690
|
+
if line.strip.eql? "end"
|
2691
|
+
|
2692
|
+
end_counter += 1
|
2693
|
+
|
2694
|
+
end_index << index
|
2695
|
+
|
2696
|
+
end
|
2697
|
+
|
2698
|
+
end
|
2699
|
+
|
2700
|
+
end
|
2701
|
+
|
2702
|
+
end
|
2703
|
+
|
2704
|
+
end
|
2705
|
+
|
2706
|
+
return current_block, extracted_blocks
|
2707
|
+
|
2708
|
+
end
|
2709
|
+
|
2710
|
+
def compile_loop_syntax(input_block)
|
2711
|
+
|
2712
|
+
modified_input_block = input_block.dup
|
2713
|
+
|
2714
|
+
strings = []
|
2715
|
+
|
2716
|
+
string_counter = 0
|
2717
|
+
|
2718
|
+
input_block.each_with_index do |line, index|
|
2719
|
+
|
2720
|
+
if line.include?("\"")
|
2721
|
+
|
2722
|
+
opening_quotes = line.index("\"")
|
2723
|
+
|
2724
|
+
string_extract = line[opening_quotes..line.index("\"", opening_quotes+1)]
|
2725
|
+
|
2726
|
+
strings << string_extract
|
2727
|
+
|
2728
|
+
modified_input_block[index] = modified_input_block[index].sub(string_extract, "--string{#{string_counter}}")
|
2729
|
+
|
2730
|
+
string_counter += 1
|
2731
|
+
|
2732
|
+
end
|
2733
|
+
|
2734
|
+
end
|
2735
|
+
|
2736
|
+
input_block = modified_input_block
|
2737
|
+
|
2738
|
+
starting_line = input_block[0]
|
2739
|
+
|
2740
|
+
starting_line = starting_line + "\n" if starting_line.lstrip == starting_line
|
2741
|
+
|
2742
|
+
input_block[0] = "whaaleskey (true) {\n"
|
2743
|
+
|
2744
|
+
input_block[-1] = input_block[-1].lstrip.sub("end", "}")
|
2745
|
+
|
2746
|
+
modified_input_block = input_block.dup
|
2747
|
+
|
2748
|
+
input_block.each_with_index do |line, index|
|
2749
|
+
|
2750
|
+
if line.include?("--string{")
|
2751
|
+
|
2752
|
+
junk, remains = line.split("--string{")
|
2753
|
+
|
2754
|
+
string_index, junk = remains.split("}")
|
2755
|
+
|
2756
|
+
modified_input_block[index] = modified_input_block[index].sub("--string{#{string_index.strip}}", strings[string_index.strip.to_i])
|
2757
|
+
|
2758
|
+
end
|
2759
|
+
|
2760
|
+
end
|
2761
|
+
|
2762
|
+
return modified_input_block
|
2763
|
+
|
2764
|
+
end
|
2765
|
+
|
2766
|
+
possible_loop_statements = input_file_contents.reject { |element| !element.include?("loop") }
|
2767
|
+
|
2768
|
+
if !possible_loop_statements.empty?
|
2769
|
+
|
2770
|
+
loop_statement_indexes = []
|
2771
|
+
|
2772
|
+
possible_loop_statements.each do |statement|
|
2773
|
+
|
2774
|
+
loop_statement_indexes << input_file_contents.dup.each_index.select { |index| input_file_contents[index] == statement }
|
2775
|
+
|
2776
|
+
end
|
2777
|
+
|
2778
|
+
loop_statement_indexes = [0] + loop_statement_indexes.flatten + [-1]
|
2779
|
+
|
2780
|
+
controlregexp = /(if |def )/
|
2781
|
+
|
2782
|
+
modified_input_contents, extracted_statements = extract_loop_blocks(loop_statement_indexes, input_file_contents.clone)
|
2783
|
+
|
2784
|
+
joined_blocks = extracted_statements.collect { |element| element.join }
|
2785
|
+
|
2786
|
+
loop_statements = joined_blocks.reject { |element| element.index(controlregexp) != nil }
|
2787
|
+
|
2788
|
+
rejected_elements = joined_blocks - loop_statements
|
2789
|
+
|
2790
|
+
rejected_elements_index = []
|
2791
|
+
|
2792
|
+
rejected_elements.each do |element|
|
2793
|
+
|
2794
|
+
rejected_elements_index << joined_blocks.each_index.select { |index| joined_blocks[index] == element }
|
2795
|
+
|
2796
|
+
end
|
2797
|
+
|
2798
|
+
loop_blocks_index = (0...extracted_statements.length).to_a
|
2799
|
+
|
2800
|
+
rejected_elements_index = rejected_elements_index.flatten
|
2801
|
+
|
2802
|
+
loop_blocks_index -= rejected_elements_index
|
2803
|
+
|
2804
|
+
modified_loop_statements = loop_statements.collect { |string| convert_string_to_array(string, temporary_nila_file) }
|
2805
|
+
|
2806
|
+
modified_loop_statements = modified_loop_statements.collect { |block| compile_loop_syntax(block) }.reverse
|
2807
|
+
|
2808
|
+
loop_blocks_index = loop_blocks_index.collect { |element| "--loopblock#{element}" }.reverse
|
2809
|
+
|
2810
|
+
rejected_elements_index = rejected_elements_index.collect { |element| "--loopblock#{element}" }.reverse
|
2811
|
+
|
2812
|
+
rejected_elements = rejected_elements.reverse
|
2813
|
+
|
2814
|
+
joined_file_contents = modified_input_contents.join
|
2815
|
+
|
2816
|
+
until loop_blocks_index.empty? and rejected_elements_index.empty?
|
2817
|
+
|
2818
|
+
if !loop_blocks_index.empty?
|
2819
|
+
|
2820
|
+
if joined_file_contents.include?(loop_blocks_index[0])
|
2821
|
+
|
2822
|
+
joined_file_contents = joined_file_contents.sub(loop_blocks_index[0], modified_loop_statements[0].join)
|
2823
|
+
|
2824
|
+
loop_blocks_index.delete_at(0)
|
2825
|
+
|
2826
|
+
modified_loop_statements.delete_at(0)
|
2827
|
+
|
2828
|
+
else
|
2829
|
+
|
2830
|
+
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0].join)
|
2831
|
+
|
2832
|
+
rejected_elements_index.delete_at(0)
|
2833
|
+
|
2834
|
+
rejected_elements.delete_at(0)
|
2835
|
+
|
2836
|
+
end
|
2837
|
+
|
2838
|
+
else
|
2839
|
+
|
2840
|
+
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0], rejected_elements[0].join)
|
2841
|
+
|
2842
|
+
rejected_elements_index.delete_at(0)
|
2843
|
+
|
2844
|
+
rejected_elements.delete_at(0)
|
2845
|
+
|
2846
|
+
end
|
2847
|
+
|
2848
|
+
end
|
2849
|
+
|
2850
|
+
else
|
2851
|
+
|
2852
|
+
joined_file_contents = input_file_contents.join
|
2853
|
+
|
2854
|
+
end
|
2855
|
+
|
2856
|
+
file_id = open(temporary_nila_file, 'w')
|
2857
|
+
|
2858
|
+
file_id.write(joined_file_contents)
|
2859
|
+
|
2860
|
+
file_id.close()
|
2861
|
+
|
2862
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
2863
|
+
|
2864
|
+
return line_by_line_contents
|
2865
|
+
|
2866
|
+
end
|
2867
|
+
|
2482
2868
|
def ignore_statement_modifiers(input_block)
|
2483
2869
|
|
2484
2870
|
modified_input_block = input_block.dup
|
@@ -2555,6 +2941,8 @@ def compile(input_file_path, *output_file_name)
|
|
2555
2941
|
|
2556
2942
|
file_contents = compile_regular_while(file_contents, temporary_nila_file)
|
2557
2943
|
|
2944
|
+
file_contents = compile_loop_keyword(file_contents,temporary_nila_file)
|
2945
|
+
|
2558
2946
|
file_contents = replace_statement_modifiers(file_contents, rejected_lines)
|
2559
2947
|
|
2560
2948
|
file_contents = compile_inline_conditionals(file_contents, temporary_nila_file)
|
@@ -2585,9 +2973,9 @@ def compile(input_file_path, *output_file_name)
|
|
2585
2973
|
|
2586
2974
|
reject_regexp = /(function |Euuf |if |else|elsuf|switch |case|while |whaaleskey |for )/
|
2587
2975
|
|
2588
|
-
modified_file_contents =
|
2976
|
+
modified_file_contents = input_file_contents.dup
|
2589
2977
|
|
2590
|
-
input_file_contents.
|
2978
|
+
input_file_contents.each_with_index do |line,index|
|
2591
2979
|
|
2592
2980
|
if line.index(reject_regexp) == nil
|
2593
2981
|
|
@@ -2599,36 +2987,20 @@ def compile(input_file_path, *output_file_name)
|
|
2599
2987
|
|
2600
2988
|
if !line.lstrip.eql?("}\n\n")
|
2601
2989
|
|
2602
|
-
|
2990
|
+
if line.rstrip[-1] != "[" and line.rstrip[-1] != "{" and line.rstrip[-1] != "," and line.rstrip[-1] != ";"
|
2603
2991
|
|
2604
|
-
|
2992
|
+
modified_file_contents[index] = line.rstrip + ";\n\n"
|
2605
2993
|
|
2606
|
-
|
2994
|
+
end
|
2607
2995
|
|
2608
2996
|
end
|
2609
2997
|
|
2610
|
-
else
|
2611
|
-
|
2612
|
-
modified_file_contents << line
|
2613
|
-
|
2614
2998
|
end
|
2615
2999
|
|
2616
|
-
else
|
2617
|
-
|
2618
|
-
modified_file_contents << line
|
2619
|
-
|
2620
3000
|
end
|
2621
3001
|
|
2622
|
-
else
|
2623
|
-
|
2624
|
-
modified_file_contents << line
|
2625
|
-
|
2626
3002
|
end
|
2627
3003
|
|
2628
|
-
else
|
2629
|
-
|
2630
|
-
modified_file_contents << line
|
2631
|
-
|
2632
3004
|
end
|
2633
3005
|
|
2634
3006
|
end
|
@@ -2779,7 +3151,7 @@ def compile(input_file_path, *output_file_name)
|
|
2779
3151
|
|
2780
3152
|
def extract_blocks(file_contents)
|
2781
3153
|
|
2782
|
-
javascript_regexp = /(if |while |function |function\()/
|
3154
|
+
javascript_regexp = /(if |while |function |function\(|((=|:)\s+\{))/
|
2783
3155
|
|
2784
3156
|
block_starting_lines = file_contents.dup.reject { |element| element.index(javascript_regexp).nil? }[1..-1]
|
2785
3157
|
|
@@ -2795,7 +3167,7 @@ def compile(input_file_path, *output_file_name)
|
|
2795
3167
|
|
2796
3168
|
end
|
2797
3169
|
|
2798
|
-
block_ending_lines = file_contents.dup.each_index.select { |index| file_contents[index].eql? " }\n" }
|
3170
|
+
block_ending_lines = file_contents.dup.each_index.select { |index| (file_contents[index].eql? " }\n" or file_contents[index].eql? " };\n")}
|
2799
3171
|
|
2800
3172
|
modified_file_contents = file_contents.dup
|
2801
3173
|
|
@@ -2825,7 +3197,7 @@ def compile(input_file_path, *output_file_name)
|
|
2825
3197
|
|
2826
3198
|
end
|
2827
3199
|
|
2828
|
-
block_ending_lines = modified_file_contents.dup.each_index.select { |index| modified_file_contents[index].eql? " }\n" }
|
3200
|
+
block_ending_lines = modified_file_contents.dup.each_index.select { |index| (modified_file_contents[index].eql? " }\n" or modified_file_contents[index].eql? " };\n") }
|
2829
3201
|
|
2830
3202
|
starting_index = starting_line_indices[0]
|
2831
3203
|
|
@@ -2880,7 +3252,7 @@ def compile(input_file_path, *output_file_name)
|
|
2880
3252
|
|
2881
3253
|
if !code_block_starting_locations.empty?
|
2882
3254
|
|
2883
|
-
controlregexp = /(if |while |function |function\()/
|
3255
|
+
controlregexp = /(if |while |function |function\(|((=|:)\s+\{))/
|
2884
3256
|
|
2885
3257
|
code_block_starting_locations = [0, code_block_starting_locations, -1].flatten
|
2886
3258
|
|
@@ -2908,7 +3280,7 @@ def compile(input_file_path, *output_file_name)
|
|
2908
3280
|
|
2909
3281
|
current_block.each_with_index do |line, index|
|
2910
3282
|
|
2911
|
-
if line.lstrip.eql? "}\n"
|
3283
|
+
if line.lstrip.eql? "}\n" or line.lstrip.eql?("};\n")
|
2912
3284
|
|
2913
3285
|
end_counter += 1
|
2914
3286
|
|
@@ -3010,7 +3382,7 @@ def compile(input_file_path, *output_file_name)
|
|
3010
3382
|
|
3011
3383
|
end
|
3012
3384
|
|
3013
|
-
javascript_regexp = /(if |while |function |function\()/
|
3385
|
+
javascript_regexp = /(if |while |function |function\(|((=|:)\s+\{))/
|
3014
3386
|
|
3015
3387
|
javascript_file_contents = javascript_file_contents.collect { |element| element.sub("Euuf", "if") }
|
3016
3388
|
|
@@ -3176,9 +3548,49 @@ def compile(input_file_path, *output_file_name)
|
|
3176
3548
|
|
3177
3549
|
end
|
3178
3550
|
|
3179
|
-
|
3551
|
+
def compile_match_operator(input_string)
|
3552
|
+
|
3553
|
+
rejection_exp = /( aannddy | orriioo |nnoottyy )/
|
3554
|
+
|
3555
|
+
if input_string.include?("=~")
|
3556
|
+
|
3557
|
+
input_string = input_string.gsub(" && "," aannddy ").gsub(" || "," orriioo ").gsub("!","nnoottyy")
|
3558
|
+
|
3559
|
+
left, right = input_string.split("=~")
|
3560
|
+
|
3561
|
+
if left.index(rejection_exp) != nil
|
3180
3562
|
|
3181
|
-
|
3563
|
+
left = left[left.index(rejection_exp)..-1]
|
3564
|
+
|
3565
|
+
elsif left.index(/\(/)
|
3566
|
+
|
3567
|
+
left = left[left.index(/\(/)+1..-1]
|
3568
|
+
|
3569
|
+
end
|
3570
|
+
|
3571
|
+
if right.index(rejection_exp) != nil
|
3572
|
+
|
3573
|
+
right = right[0...right.index(rejection_exp)]
|
3574
|
+
|
3575
|
+
elsif right.index(/\)/)
|
3576
|
+
|
3577
|
+
right = right[0...right.index(/\)/)]
|
3578
|
+
|
3579
|
+
end
|
3580
|
+
|
3581
|
+
original_string = "#{left}=~#{right}"
|
3582
|
+
|
3583
|
+
replacement_string = "#{left.rstrip} = #{left.rstrip}.match(#{right.lstrip.rstrip})"
|
3584
|
+
|
3585
|
+
input_string = input_string.sub(original_string,replacement_string)
|
3586
|
+
|
3587
|
+
input_string = input_string.gsub(" aannddy "," && ").gsub(" orriioo "," || ").gsub("nnoottyy","!")
|
3588
|
+
|
3589
|
+
end
|
3590
|
+
|
3591
|
+
return input_string
|
3592
|
+
|
3593
|
+
end
|
3182
3594
|
|
3183
3595
|
input_file_contents = input_file_contents.collect { |element| element.sub("==", "===") }
|
3184
3596
|
|
@@ -3188,6 +3600,8 @@ def compile(input_file_path, *output_file_name)
|
|
3188
3600
|
|
3189
3601
|
input_file_contents = input_file_contents.collect { |element| compile_power_operator(element) }
|
3190
3602
|
|
3603
|
+
input_file_contents = input_file_contents.collect {|element| compile_match_operator(element)}
|
3604
|
+
|
3191
3605
|
return input_file_contents
|
3192
3606
|
|
3193
3607
|
end
|
@@ -3227,6 +3641,8 @@ def compile(input_file_path, *output_file_name)
|
|
3227
3641
|
|
3228
3642
|
file_contents = compile_interpolated_strings(file_contents)
|
3229
3643
|
|
3644
|
+
file_contents = compile_hashes(file_contents,temp_file)
|
3645
|
+
|
3230
3646
|
file_contents = compile_conditional_structures(file_contents, temp_file)
|
3231
3647
|
|
3232
3648
|
file_contents = compile_arrays(file_contents, temp_file)
|
@@ -3327,7 +3743,7 @@ def find_file_path(input_path, file_extension)
|
|
3327
3743
|
|
3328
3744
|
end
|
3329
3745
|
|
3330
|
-
nilac_version = "0.0.4.2.
|
3746
|
+
nilac_version = "0.0.4.2.1"
|
3331
3747
|
|
3332
3748
|
opts = Slop.parse do
|
3333
3749
|
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.2.
|
4
|
+
version: 0.0.4.2.1
|
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-
|
12
|
+
date: 2013-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shark
|
@@ -65,7 +65,9 @@ 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/hashes.feature
|
68
69
|
- shark/features/heredoc.feature
|
70
|
+
- shark/features/loop.feature
|
69
71
|
- shark/features/method_multiple_return.feature
|
70
72
|
- shark/features/multiline_array.feature
|
71
73
|
- shark/features/multiple_variable_initialization.feature
|
@@ -79,9 +81,11 @@ files:
|
|
79
81
|
- shark/test_files/array_string_indexing.nila
|
80
82
|
- shark/test_files/correct.js
|
81
83
|
- shark/test_files/correct_default_parameters.js
|
84
|
+
- shark/test_files/correct_hashes.js
|
82
85
|
- shark/test_files/correct_heredoc.js
|
83
86
|
- shark/test_files/correct_indexing.js
|
84
87
|
- shark/test_files/correct_initialization.js
|
88
|
+
- shark/test_files/correct_loop.js
|
85
89
|
- shark/test_files/correct_multiline_array.js
|
86
90
|
- shark/test_files/correct_multiple_return.js
|
87
91
|
- shark/test_files/correct_operators.js
|
@@ -95,7 +99,9 @@ files:
|
|
95
99
|
- shark/test_files/correct_whitespace_delimiter.js
|
96
100
|
- shark/test_files/default_parameters.nila
|
97
101
|
- shark/test_files/erratic.nila
|
102
|
+
- shark/test_files/hashes.nila
|
98
103
|
- shark/test_files/heredoc.nila
|
104
|
+
- shark/test_files/loop.nila
|
99
105
|
- shark/test_files/multiline_array.nila
|
100
106
|
- shark/test_files/multiple_initialization.nila
|
101
107
|
- shark/test_files/multiple_return.nila
|