nilac 0.0.4.3.9.6 → 0.0.4.3.9.7
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +2 -0
- data/examples/decBin.js +2 -2
- data/examples/repl.js +31 -0
- data/examples/repl.nila +24 -0
- data/lib/nilac/add_semicolons.rb +1 -1
- data/lib/nilac/compile_blocks.rb +20 -2
- data/lib/nilac/compile_case_statement.rb +1 -1
- data/lib/nilac/compile_conditional_structures.rb +20 -8
- data/lib/nilac/compile_custom_function_map.rb +3 -1
- data/lib/nilac/compile_default_values.rb +15 -1
- data/lib/nilac/compile_integers.rb +147 -2
- data/lib/nilac/compile_lambdas.rb +22 -6
- data/lib/nilac/compile_loops.rb +1 -1
- data/lib/nilac/compile_monkey_patching.rb +189 -0
- data/lib/nilac/compile_named_functions.rb +44 -70
- data/lib/nilac/compile_parallel_assignment.rb +2 -2
- data/lib/nilac/compile_ruby_methods.rb +3 -1
- data/lib/nilac/compile_strings.rb +4 -4
- data/lib/nilac/friendly_errors.rb +95 -0
- data/lib/nilac/get_variables.rb +29 -18
- data/lib/nilac/lexical_scoped_function_variables.rb +6 -0
- data/lib/nilac/output_javascript.rb +9 -7
- data/lib/nilac/paranthesis_compactor.rb +37 -0
- data/lib/nilac/pretty_print_javascript.rb +53 -61
- data/lib/nilac/replace_multiline_comments.rb +6 -2
- data/lib/nilac/replace_named_functions.rb +41 -65
- data/lib/nilac/replace_strings.rb +40 -17
- data/lib/nilac/rollblocks.rb +86 -13
- data/lib/nilac/version.rb +1 -1
- data/lib/nilac.rb +46 -13
- data/shark/features/blocks.feature +11 -0
- data/shark/features/monkey_patch.feature +11 -0
- data/shark/test_files/blocks.nila +18 -0
- data/shark/test_files/correct_blocks.js +25 -0
- data/shark/test_files/correct_case.js +1 -1
- data/shark/test_files/correct_monkey_patch.js +24 -0
- data/shark/test_files/correct_multiple_return.js +2 -2
- data/shark/test_files/correct_splats.js +3 -3
- data/shark/test_files/lambda.nila +9 -1
- data/shark/test_files/monkey_patch.nila +18 -0
- data/shark/test_files/multiple_return.nila +8 -8
- data/shark/test_files/sample_class.nila +1 -1
- metadata +13 -7
- data/LICENSE +0 -20
- data/examples/countdown.nila +0 -31
- data/lib/nilac/compile_classes.rb +0 -19
- data/shark/test_files/array_sugar.nila +0 -3
- data/shark/test_files/class.nila +0 -7
@@ -0,0 +1,189 @@
|
|
1
|
+
# Monkey Patching is an interesting concept. But fair warning, it is not recommended in the Javascript community.
|
2
|
+
# We are just implementing it so that we can learn more about Ruby and its Javascript counterpart. This will also serve
|
3
|
+
# as a starting point to implement classes.
|
4
|
+
|
5
|
+
require_relative 'rollblocks'
|
6
|
+
require_relative 'replace_strings'
|
7
|
+
require_relative 'read_file_line_by_line'
|
8
|
+
|
9
|
+
def compile_monkey_patching(input_file_contents,temporary_nila_file)
|
10
|
+
|
11
|
+
def extract_class_name(input_class_start)
|
12
|
+
|
13
|
+
class_split = input_class_start.strip.split("class ")
|
14
|
+
|
15
|
+
return class_split[1]
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def monkey_patch_errors(input_classes)
|
20
|
+
|
21
|
+
def extract_function_name(input_block_start)
|
22
|
+
|
23
|
+
first_line = input_block_start
|
24
|
+
|
25
|
+
first_line_split = first_line.split("=")
|
26
|
+
|
27
|
+
return first_line_split[0]
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def multiple_same_name_methods(input_class)
|
32
|
+
|
33
|
+
message = ""
|
34
|
+
|
35
|
+
input_class = input_class.collect {|element| element.gsub("(function","&F(^u@#N(C%%")}
|
36
|
+
|
37
|
+
method_blocks = input_class.reject {|element| !replace_strings(element).include?("= function")}
|
38
|
+
|
39
|
+
function_names = []
|
40
|
+
|
41
|
+
proceed_to_next = true
|
42
|
+
|
43
|
+
method_blocks.each do |method_start|
|
44
|
+
|
45
|
+
extract_name = extract_function_name(method_start)
|
46
|
+
|
47
|
+
if function_names.include?(extract_name)
|
48
|
+
|
49
|
+
proceed_to_next = false
|
50
|
+
|
51
|
+
break
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
function_names << extract_name
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
if proceed_to_next == false
|
60
|
+
|
61
|
+
puts "Hey I discovered two methods by the same name under a potential monkey patched/duck punched Prototype.\n\n"
|
62
|
+
|
63
|
+
puts "Unfortunately that is not allowed because one of your patches is going to be overridden by the other patch.\n\n"
|
64
|
+
|
65
|
+
puts "Please consider changing the code to make sure that all of your patch methods are unique. "
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
return proceed_to_next
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
proceed_to_next = true
|
74
|
+
|
75
|
+
class_counter = 0
|
76
|
+
|
77
|
+
while proceed_to_next and input_classes.length > class_counter
|
78
|
+
|
79
|
+
proceed_to_next = multiple_same_name_methods(input_classes[class_counter])
|
80
|
+
|
81
|
+
class_counter += 1
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
return proceed_to_next
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("}#@$","}")}
|
90
|
+
|
91
|
+
joined_file_contents = input_file_contents.join
|
92
|
+
|
93
|
+
possible_class_statements = input_file_contents.reject {|element| !replace_strings(element).include?("class ")}
|
94
|
+
|
95
|
+
class_statement_indices = []
|
96
|
+
|
97
|
+
possible_class_statements.each do |statement|
|
98
|
+
|
99
|
+
class_statement_indices << input_file_contents.each_index.select {|index| input_file_contents[index] == statement}
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
class_statement_indices = [0,class_statement_indices,-1].flatten.uniq
|
104
|
+
|
105
|
+
file_remains, blocks = extract_blocks(class_statement_indices,input_file_contents,["class","function"])
|
106
|
+
|
107
|
+
class_blocks = blocks.reject {|element| !replace_strings(element[0]).include?("class ")}
|
108
|
+
|
109
|
+
class_blocks = class_blocks.reject {|element| replace_strings(element.join).include?("initialize =")}
|
110
|
+
|
111
|
+
proceed = monkey_patch_errors(class_blocks)
|
112
|
+
|
113
|
+
if proceed
|
114
|
+
|
115
|
+
class_blocks.each do |block|
|
116
|
+
|
117
|
+
class_name = extract_class_name(block[0])
|
118
|
+
|
119
|
+
block = block.collect {|element| element.gsub("(function","&F(^u@#N(C%%")}
|
120
|
+
|
121
|
+
method_starters = block.reject {|element| !replace_strings(element).include?("= function")}
|
122
|
+
|
123
|
+
method_locations = []
|
124
|
+
|
125
|
+
method_starters.each do |element|
|
126
|
+
|
127
|
+
method_locations << block.each_index.select {|index| block[index] == element}
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
method_locations = [0,method_locations,-1].flatten.uniq
|
132
|
+
|
133
|
+
|
134
|
+
block_remains, sub_blocks = extract_blocks(method_locations,block[1...-1],["function"])
|
135
|
+
|
136
|
+
sub_method_blocks = sub_blocks.reject {|element| !replace_strings(element[0]).include?("= function")}
|
137
|
+
|
138
|
+
modified_method_blocks = []
|
139
|
+
|
140
|
+
sub_method_blocks.each do |block|
|
141
|
+
|
142
|
+
block[0] = class_name.capitalize + ".prototype." + block[0]
|
143
|
+
|
144
|
+
block = block.collect {|element| element.gsub("&F(^u@#N(C%%","(function")}
|
145
|
+
|
146
|
+
modified_method_blocks << []
|
147
|
+
|
148
|
+
block.each do |statement|
|
149
|
+
|
150
|
+
if replace_strings(statement).include?("self")
|
151
|
+
|
152
|
+
modified_method_blocks[-1] << statement.gsub("self","this")
|
153
|
+
|
154
|
+
else
|
155
|
+
|
156
|
+
modified_method_blocks[-1] << statement
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
modified_method_blocks.each_with_index do |block,index|
|
166
|
+
|
167
|
+
sub_blocks[sub_blocks.index(sub_method_blocks[index])] = block
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
block = block.collect {|element| element.gsub("&F(^u@#N(C%%","(function")}
|
172
|
+
|
173
|
+
joined_file_contents = joined_file_contents.sub(block.join,sub_blocks.join)
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
file_id = open(temporary_nila_file, 'w')
|
178
|
+
|
179
|
+
file_id.write(joined_file_contents)
|
180
|
+
|
181
|
+
file_id.close()
|
182
|
+
|
183
|
+
file_contents = read_file_line_by_line(temporary_nila_file)
|
184
|
+
|
185
|
+
return file_contents
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require_relative 'strToArray'
|
2
|
-
|
3
2
|
require_relative 'read_file_line_by_line'
|
3
|
+
require_relative 'paranthesis_compactor'
|
4
|
+
require_relative 'replace_strings'
|
5
|
+
require_relative 'rollblocks'
|
4
6
|
|
5
7
|
def compile_named_functions(input_file_contents, named_code_blocks, nested_functions, temporary_nila_file)
|
6
8
|
|
@@ -40,54 +42,6 @@ def compile_named_functions(input_file_contents, named_code_blocks, nested_funct
|
|
40
42
|
#This method will pickup and declare all the variables inside a function block. In future, this method will be
|
41
43
|
#merged with the get variables method
|
42
44
|
|
43
|
-
def replace_strings(input_string)
|
44
|
-
|
45
|
-
element = input_string.gsub("==", "equalequal")
|
46
|
-
|
47
|
-
element = element.gsub("!=", "notequal")
|
48
|
-
|
49
|
-
element = element.gsub("+=", "plusequal")
|
50
|
-
|
51
|
-
element = element.gsub("-=", "minusequal")
|
52
|
-
|
53
|
-
element = element.gsub("*=", "multiequal")
|
54
|
-
|
55
|
-
element = element.gsub("/=", "divequal")
|
56
|
-
|
57
|
-
element = element.gsub("%=", "modequal")
|
58
|
-
|
59
|
-
element = element.gsub("=~", "matchequal")
|
60
|
-
|
61
|
-
element = element.gsub(">=", "greatequal")
|
62
|
-
|
63
|
-
input_string = element.gsub("<=", "lessyequal")
|
64
|
-
|
65
|
-
string_counter = 0
|
66
|
-
|
67
|
-
while input_string.include?("\"")
|
68
|
-
|
69
|
-
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
70
|
-
|
71
|
-
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
72
|
-
|
73
|
-
string_counter += 1
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
while input_string.include?("'")
|
78
|
-
|
79
|
-
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
80
|
-
|
81
|
-
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
82
|
-
|
83
|
-
string_counter += 1
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
return input_string
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
45
|
input_function_block = input_function_block.collect {|element| replace_strings(element)}
|
92
46
|
|
93
47
|
controlregexp = /(if |Euuf |for |while |def |function |function\()/
|
@@ -106,6 +60,12 @@ def compile_named_functions(input_file_contents, named_code_blocks, nested_funct
|
|
106
60
|
|
107
61
|
current_line_split = line.strip.split("=")
|
108
62
|
|
63
|
+
if current_line_split[0].include?("return")
|
64
|
+
|
65
|
+
current_line_split[0] = current_line_split[0].sub("return","").strip
|
66
|
+
|
67
|
+
end
|
68
|
+
|
109
69
|
variables << current_line_split[0].rstrip
|
110
70
|
|
111
71
|
end
|
@@ -324,10 +284,14 @@ def compile_named_functions(input_file_contents, named_code_blocks, nested_funct
|
|
324
284
|
|
325
285
|
def coffee_type_function(input_array)
|
326
286
|
|
287
|
+
input_array = input_array.collect {|element| element.gsub("(function","&F*^u$#N)(&C")}
|
288
|
+
|
327
289
|
function_name = input_array[0].split("function ")[1].split("(")[0].lstrip
|
328
290
|
|
329
291
|
input_array[0] = "#{function_name} = function(" + input_array[0].split("function ")[1].split("(")[1].lstrip
|
330
292
|
|
293
|
+
input_array = input_array.collect {|element| element.gsub("&F*^u$#N)(&C","(function")}
|
294
|
+
|
331
295
|
return input_array
|
332
296
|
|
333
297
|
end
|
@@ -545,7 +509,7 @@ def compile_named_functions(input_file_contents, named_code_blocks, nested_funct
|
|
545
509
|
|
546
510
|
def compile_multiple_ruby_func_calls(input_file_contents)
|
547
511
|
|
548
|
-
def
|
512
|
+
def replace_complex_strings(input_string)
|
549
513
|
|
550
514
|
string_counter = 0
|
551
515
|
|
@@ -591,39 +555,45 @@ def compile_named_functions(input_file_contents, named_code_blocks, nested_funct
|
|
591
555
|
|
592
556
|
javascript_regexp = /(if |for |while |\(function\(|= function\(|((=|:)\s+\{))/
|
593
557
|
|
594
|
-
stringified_input = input_file_contents.collect {|element|
|
558
|
+
stringified_input = input_file_contents.collect {|element| replace_complex_strings(element)}
|
595
559
|
|
596
560
|
function_map.each do |func|
|
597
561
|
|
598
562
|
func_calls = input_file_contents.reject {|line| !(line.include?(func+"(") or line.include?(func+" ") and line.index(javascript_regexp) == nil)}
|
599
563
|
|
600
|
-
|
564
|
+
unless func_calls.empty?
|
601
565
|
|
602
|
-
|
566
|
+
modified_func_calls = func_calls.collect {|element| replace_complex_strings(element)}
|
603
567
|
|
604
|
-
|
568
|
+
modified_func_calls = modified_func_calls.reject {|element| !element.include?(",")}
|
605
569
|
|
606
|
-
|
570
|
+
modified_func_calls = modified_func_calls.reject {|element| !compact_paranthesis(element).include?(",")}
|
607
571
|
|
608
|
-
call_collector
|
572
|
+
call_collector = []
|
609
573
|
|
610
|
-
|
574
|
+
modified_func_calls.each_with_index do |ele|
|
611
575
|
|
612
|
-
|
576
|
+
call_collector << input_file_contents[stringified_input.index(ele)]
|
613
577
|
|
614
|
-
|
578
|
+
end
|
615
579
|
|
616
|
-
|
580
|
+
function_calls << modified_func_calls
|
617
581
|
|
618
|
-
|
582
|
+
rep_calls = []
|
619
583
|
|
620
|
-
|
584
|
+
call_collector.each do |fcall|
|
621
585
|
|
622
|
-
|
586
|
+
multiple_call = fcall.split(func)[1].split(",")
|
623
587
|
|
624
|
-
|
588
|
+
multiple_call = multiple_call.collect {|element| "\n#{func} " + element.strip + "\n\n"}
|
589
|
+
|
590
|
+
rep_calls << multiple_call.join
|
591
|
+
|
592
|
+
end
|
593
|
+
|
594
|
+
replacement_calls << rep_calls
|
625
595
|
|
626
|
-
|
596
|
+
end
|
627
597
|
|
628
598
|
end
|
629
599
|
|
@@ -657,15 +627,19 @@ def compile_named_functions(input_file_contents, named_code_blocks, nested_funct
|
|
657
627
|
|
658
628
|
codeblock_counter += 1
|
659
629
|
|
660
|
-
current_nested_functions = nested_functions[codeblock_counter-2]
|
661
|
-
|
662
630
|
function_names[codeblock_counter-2] << extract_function_name(codeblock)
|
663
631
|
|
664
|
-
|
632
|
+
unless nested_functions.empty?
|
633
|
+
|
634
|
+
current_nested_functions = nested_functions[codeblock_counter-2]
|
665
635
|
|
666
|
-
|
636
|
+
current_nested_functions.each do |nested_function|
|
667
637
|
|
668
|
-
|
638
|
+
function_names[codeblock_counter-2] << extract_function_name(nested_function)
|
639
|
+
|
640
|
+
joined_file_contents = joined_file_contents.sub(nested_function.join, compile_function(nested_function, temporary_nila_file).join)
|
641
|
+
|
642
|
+
end
|
669
643
|
|
670
644
|
end
|
671
645
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'replace_strings'
|
2
|
-
|
3
2
|
require_relative 'read_file_line_by_line'
|
3
|
+
require_relative 'paranthesis_compactor'
|
4
4
|
|
5
5
|
def compile_parallel_assignment(input_file_contents, temporary_nila_file)
|
6
6
|
|
@@ -16,7 +16,7 @@ require_relative 'read_file_line_by_line'
|
|
16
16
|
|
17
17
|
right_side = input_string.split("=")[1]
|
18
18
|
|
19
|
-
if right_side.include?(",")
|
19
|
+
if compact_paranthesis(right_side).include?(",")
|
20
20
|
|
21
21
|
splits = right_side.split(",")
|
22
22
|
|
@@ -65,6 +65,8 @@
|
|
65
65
|
|
66
66
|
".downcase" => ".toLowerCase()",
|
67
67
|
|
68
|
+
".zero?" => " === 0",
|
69
|
+
|
68
70
|
}
|
69
71
|
|
70
72
|
method_map = method_map_replacement.keys
|
@@ -83,7 +85,7 @@
|
|
83
85
|
|
84
86
|
unless line.include?(method_match + "(")
|
85
87
|
|
86
|
-
line = line.
|
88
|
+
line = line.gsub(method_match,method_map_replacement[method_match])
|
87
89
|
|
88
90
|
end
|
89
91
|
|
@@ -2,7 +2,7 @@ def compile_strings(input_file_contents)
|
|
2
2
|
|
3
3
|
def compile_small_q_syntax(input_file_contents)
|
4
4
|
|
5
|
-
possible_syntax_usage = input_file_contents.reject { |element| !element.include?("%q") }
|
5
|
+
possible_syntax_usage = input_file_contents.reject { |element| !element.include?(" %q") }
|
6
6
|
|
7
7
|
possible_syntax_usage.each do |line|
|
8
8
|
|
@@ -46,7 +46,7 @@ def compile_strings(input_file_contents)
|
|
46
46
|
|
47
47
|
def compile_big_q_syntax(input_file_contents)
|
48
48
|
|
49
|
-
possible_syntax_usage = input_file_contents.reject { |element| !element.include?("%Q") }
|
49
|
+
possible_syntax_usage = input_file_contents.reject { |element| !element.include?(" %Q") }
|
50
50
|
|
51
51
|
possible_syntax_usage.each do |line|
|
52
52
|
|
@@ -90,9 +90,9 @@ def compile_strings(input_file_contents)
|
|
90
90
|
|
91
91
|
def compile_percentage_syntax(input_file_contents)
|
92
92
|
|
93
|
-
possible_syntax_usage = input_file_contents.reject { |element| !element.include?("%") }
|
93
|
+
possible_syntax_usage = input_file_contents.reject { |element| !element.include?(" %") }
|
94
94
|
|
95
|
-
possible_syntax_usage = possible_syntax_usage.reject { |element| element.index(/(
|
95
|
+
possible_syntax_usage = possible_syntax_usage.reject { |element| element.index(/(%(\W|\s)\w{1,})/).nil? }
|
96
96
|
|
97
97
|
possible_syntax_usage.each do |line|
|
98
98
|
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# Nila currently lacks good error messages. So this is an attempt to fix the problem. This module will define a standard
|
2
|
+
# set of errors and debugging features that will be utilized by the Nila compiler.
|
3
|
+
|
4
|
+
require_relative 'replace_strings'
|
5
|
+
require_relative 'rollblocks'
|
6
|
+
|
7
|
+
module FriendlyErrors
|
8
|
+
|
9
|
+
def combine_strings(input_list)
|
10
|
+
|
11
|
+
if input_list.length == 1
|
12
|
+
|
13
|
+
return input_list.join
|
14
|
+
|
15
|
+
elsif input_list.length > 1
|
16
|
+
|
17
|
+
last_element = input_list.pop
|
18
|
+
|
19
|
+
statement = input_list.join(", ") + " and #{last_element}"
|
20
|
+
|
21
|
+
return statement
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_exist?(file_name)
|
28
|
+
|
29
|
+
message = ""
|
30
|
+
|
31
|
+
proceed_to_next = true
|
32
|
+
|
33
|
+
if File.exist?(file_name)
|
34
|
+
|
35
|
+
unless file_name.include?(".nila")
|
36
|
+
|
37
|
+
message = "Hey! I currently don't have the capacity to compile files other than Nila files. I am sorry!\n\n"
|
38
|
+
|
39
|
+
proceed_to_next = false
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
else
|
44
|
+
|
45
|
+
message = "Hey! I cannot find the file specified\n\nCan you check to see if the file exists or accessible?\n\n"
|
46
|
+
|
47
|
+
proceed_to_next = false
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
return message, proceed_to_next
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def proper_parsable_statement(file_contents)
|
56
|
+
|
57
|
+
match_expr = [/_(\w{3})_/,/__(\w{3})/,/_(\w{3})_/]
|
58
|
+
|
59
|
+
almost_match = /__(\w{3})__/
|
60
|
+
|
61
|
+
correct_expr = /__END__/
|
62
|
+
|
63
|
+
message = ""
|
64
|
+
|
65
|
+
proceed_to_next = true
|
66
|
+
|
67
|
+
modified_file_contents = file_contents.clone
|
68
|
+
|
69
|
+
possible_parse_end_statements = file_contents.reject {|element| !replace_strings(element).index(almost_match)}
|
70
|
+
|
71
|
+
parse_end_statements = possible_parse_end_statements.reject {|element| !element.index(correct_expr)}
|
72
|
+
|
73
|
+
if possible_parse_end_statements.length > 1
|
74
|
+
|
75
|
+
line_numbers = []
|
76
|
+
|
77
|
+
possible_parse_end_statements.each do |statement|
|
78
|
+
|
79
|
+
line_numbers << modified_file_contents.index(statement) + 1
|
80
|
+
|
81
|
+
modified_file_contents[line_numbers[-1]-1] = "--enddd_statement"
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
message = "Hey! I noticed that you used __END__ statement #{line_numbers.length} times in your file on line numbers #{combine_strings(line_numbers)}.\n\n"
|
86
|
+
|
87
|
+
message += "Unfortunately, this is not allowed. You can only use it once in a file.\n\nPlease remove one of those statements\n\nIf you are confused about the usage of __END__,please refer to the \ndocumentation at http://adhithyan15.github.io/nilac\n\n"
|
88
|
+
|
89
|
+
proceed_to_next = false
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/lib/nilac/get_variables.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative 'replace_strings'
|
2
|
-
|
3
2
|
require_relative 'read_file_line_by_line'
|
3
|
+
require_relative 'paranthesis_compactor'
|
4
4
|
|
5
5
|
def get_variables(input_file_contents, temporary_nila_file, *loop_variables)
|
6
6
|
|
@@ -40,41 +40,52 @@ require_relative 'read_file_line_by_line'
|
|
40
40
|
|
41
41
|
if current_row.include?("=") and current_row.index(javascript_regexp) == nil and !current_row.include?("#iggggnnnore")
|
42
42
|
|
43
|
-
|
43
|
+
if current_row.index(/,function\(/)
|
44
44
|
|
45
|
-
|
45
|
+
current_row = current_row.strip + "$@#)\n\n"
|
46
46
|
|
47
|
-
|
47
|
+
end
|
48
48
|
|
49
|
-
|
49
|
+
if compact_paranthesis(current_row).include?("=")
|
50
50
|
|
51
|
+
current_row = current_row.gsub("$@#)\n\n","\n")
|
51
52
|
|
52
|
-
|
53
|
+
current_row = current_row.rstrip + "\n"
|
53
54
|
|
54
|
-
|
55
|
+
current_row_split = current_row.split("=")
|
55
56
|
|
56
|
-
|
57
|
+
for y in 0...current_row_split.length
|
57
58
|
|
58
|
-
|
59
|
+
current_row_split[y] = current_row_split[y].strip
|
59
60
|
|
60
|
-
current_row_split[0] = current_row_split[0].split(".",2)[0].strip if current_row_split[0].include?(".")
|
61
61
|
|
62
|
-
|
62
|
+
end
|
63
63
|
|
64
|
-
|
64
|
+
if current_row_split[0].include?("[") or current_row_split[0].include?("(")
|
65
65
|
|
66
|
-
|
66
|
+
current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
|
67
67
|
|
68
|
-
|
68
|
+
end
|
69
69
|
|
70
|
-
|
70
|
+
current_row_split[0] = current_row_split[0].split(".",2)[0].strip if current_row_split[0].include?(".")
|
71
71
|
|
72
|
-
|
72
|
+
if current_row_split[0].include?(" ")
|
73
73
|
|
74
|
-
|
74
|
+
variable_name = current_row_split[0].split
|
75
|
+
|
76
|
+
variable_name = variable_name.join("_")
|
75
77
|
|
76
|
-
|
78
|
+
modified_file_contents[modified_file_contents.index(original_row)] = modified_file_contents[modified_file_contents.index(original_row)].gsub(current_row_split[0],variable_name)
|
77
79
|
|
80
|
+
else
|
81
|
+
|
82
|
+
variable_name = current_row_split[0]
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
variables << variable_name
|
87
|
+
|
88
|
+
end
|
78
89
|
|
79
90
|
end
|
80
91
|
|
@@ -69,6 +69,12 @@ def lexical_scoped_variables(input_function_block)
|
|
69
69
|
|
70
70
|
current_line_split = line.strip.split("=")
|
71
71
|
|
72
|
+
if current_line_split[0].include?("return")
|
73
|
+
|
74
|
+
current_line_split[0] = current_line_split[0].sub("return","").strip
|
75
|
+
|
76
|
+
end
|
77
|
+
|
72
78
|
variables << current_line_split[0].rstrip
|
73
79
|
|
74
80
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
-
|
1
|
+
require_relative 'version'
|
2
2
|
|
3
|
-
|
3
|
+
def output_javascript(file_contents, output_file, temporary_nila_file)
|
4
4
|
|
5
|
-
|
5
|
+
file_id = open(output_file, 'w')
|
6
6
|
|
7
|
-
|
7
|
+
File.delete(temporary_nila_file)
|
8
8
|
|
9
|
-
|
9
|
+
file_id.write("//Written using Nila. Visit http://adhithyan15.github.io/nila\n")
|
10
10
|
|
11
|
-
|
11
|
+
file_id.write(file_contents.join)
|
12
12
|
|
13
|
-
|
13
|
+
file_id.close()
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
def compact_paranthesis(input_string)
|
2
|
+
|
3
|
+
string_extract = input_string.reverse
|
4
|
+
|
5
|
+
paranthesis_extract = [""]
|
6
|
+
|
7
|
+
two_paranthesis = ""
|
8
|
+
|
9
|
+
open_paran_index = nil
|
10
|
+
|
11
|
+
offset_value = nil
|
12
|
+
|
13
|
+
while string_extract.include?("(")
|
14
|
+
|
15
|
+
open_paran_index = string_extract.index("(")
|
16
|
+
|
17
|
+
test_extract = string_extract[0..open_paran_index].reverse
|
18
|
+
|
19
|
+
two_paranthesis = test_extract[0..test_extract.index(")")]
|
20
|
+
|
21
|
+
previous_value = paranthesis_extract[-1]
|
22
|
+
|
23
|
+
if previous_value.length > two_paranthesis.length-(two_paranthesis.count("$@"))/2
|
24
|
+
|
25
|
+
offset_value = previous_value
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
paranthesis_extract << two_paranthesis.sub("$@"*previous_value.length,previous_value)
|
30
|
+
|
31
|
+
string_extract = string_extract.sub(two_paranthesis.reverse,"@$"*paranthesis_extract[-1].length)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
return string_extract.reverse
|
36
|
+
|
37
|
+
end
|