nilac 0.0.4.3.9.5 → 0.0.4.3.9.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 193275e07ff9a381b98f8cba61b4178b4aa67746
4
- data.tar.gz: fdb154e462dccec62c8b6c92221303d86c47c50f
3
+ metadata.gz: 2aae60bb21de5dafc4e90454f1b4f6fb98b222ef
4
+ data.tar.gz: 5be7a1d1fa7e3ead44e3163463b3ac191ea60442
5
5
  SHA512:
6
- metadata.gz: e46d6cf55cd21f52feed937192522cc287a34e79979b2f8cbb199154d8cddb38b279b1ccab3bb6a69533df0bb93e557d21c408051ed903f47e7a1b78e8e81513
7
- data.tar.gz: 46eabf7a2ad1f5188e1398120971fcc0ecbcacf7befb88b0f067da15dbc02f79d4d0a99e88c57178612783c81c3e1ea93073c7e02f6a887d4710c5ecf551b971
6
+ metadata.gz: e049e7f5ade3d9c6f6652bce8a5cdb4489719954f3ba1dad8a5e356b48400a1d2be5a2389c6a93a92c2e7d0b541492cfea24c9cff66aa91061e511e81c0012d4
7
+ data.tar.gz: e47c6c6f6f95a0e06115257adf24d8a3e2fac841883a5365920a4c0aa86c3bb10d01b67df0ca1178198578a7f9d967c1279a047e14c010545e956f8cf8b35337
data/examples/marky.nila CHANGED
@@ -13,7 +13,7 @@ require 'fs'
13
13
  def parse_markdown(input_file)
14
14
 
15
15
  fs.readFile input_file, 'utf8', do |err,data|
16
- puts err if err
16
+
17
17
  puts data
18
18
  end
19
19
 
@@ -0,0 +1,33 @@
1
+ def add_auto_return_statement(input_array)
2
+
3
+ joined_array = input_array.join
4
+
5
+ reversed_input_array = input_array.reverse
6
+
7
+ if !joined_array.include?("return ")
8
+
9
+ rejected_array = reversed_input_array.reject { |content| content.lstrip.eql?("") }
10
+
11
+ rejected_array = rejected_array.reject {|content| content.strip.eql?("")}
12
+
13
+ rejected_array = rejected_array[1..-1]
14
+
15
+ unless rejected_array[0].strip.eql?("}") or rejected_array[0].strip.eql?("})")
16
+
17
+ if !rejected_array[0].strip.eql?("end") and !rejected_array[0].strip.include?("--single_line_comment")
18
+
19
+ last_statement = rejected_array[0]
20
+
21
+ replacement_string = "return #{last_statement.lstrip}"
22
+
23
+ input_array[input_array.index(last_statement)] = replacement_string
24
+
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ return input_array
32
+
33
+ end
@@ -18,6 +18,8 @@
18
18
 
19
19
  end
20
20
 
21
+ input_file_contents = input_file_contents.collect {|element| element.gsub("#iggggnnnore ","")}
22
+
21
23
  reject_regexp = /(function |Euuf |if |else|elsuf|switch |case|while |whaaleskey |for )/
22
24
 
23
25
  modified_file_contents = input_file_contents.dup
@@ -1,4 +1,6 @@
1
1
  require_relative 'read_file_line_by_line'
2
+ require_relative 'strToArray'
3
+ require_relative 'lexical_scoped_function_variables'
2
4
 
3
5
  def compile_blocks(input_file_contents,temporary_nila_file)
4
6
 
@@ -6,6 +8,12 @@ require_relative 'read_file_line_by_line'
6
8
 
7
9
  block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2)
8
10
 
11
+ if block_parameters.include?("err") and !block_contents.include?("err")
12
+
13
+ block_contents = "if (err) {\n puts err \n}\n" + block_contents
14
+
15
+ end
16
+
9
17
  compiled_block = "function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents.strip} \n\n}"
10
18
 
11
19
  return compiled_block
@@ -102,7 +110,7 @@ require_relative 'read_file_line_by_line'
102
110
 
103
111
  caller_func = loop.split(" blockky ")[0]
104
112
 
105
- unless caller_func.rstrip[-1] == ","
113
+ unless caller_func.strip[-1] == ","
106
114
 
107
115
  replacement_string = "#{caller_func.rstrip}(#{compiled_block.lstrip})"
108
116
 
@@ -116,7 +124,21 @@ require_relative 'read_file_line_by_line'
116
124
 
117
125
  end
118
126
 
119
- modified_file_contents[input_file_contents.index(original_loop)] = replacement_string
127
+ replacement_array = strToArray(replacement_string)
128
+
129
+ variables = lexical_scoped_variables(replacement_array)
130
+
131
+ if !variables.empty?
132
+
133
+ variable_string = "\nvar " + variables.join(", ") + "\n"
134
+
135
+ replacement_array.insert(1, variable_string)
136
+
137
+ end
138
+
139
+ replacement_array[1...-1] = replacement_array[1...-1].collect {|element| "#iggggnnnore #{element}"}
140
+
141
+ modified_file_contents[input_file_contents.index(original_loop)] = replacement_array.join
120
142
 
121
143
  end
122
144
 
@@ -12,6 +12,8 @@ def compile_custom_function_map(input_file_contents)
12
12
 
13
13
  "require" => "require",
14
14
 
15
+ "alert" => "alert"
16
+
15
17
  }
16
18
 
17
19
  function_map = function_map_replacements.keys
@@ -28,7 +30,7 @@ def compile_custom_function_map(input_file_contents)
28
30
 
29
31
  if test_line.include?(function+"(") or test_line.include?(function+" ") and test_line.index(javascript_regexp) == nil
30
32
 
31
- testsplit = line.split(function)
33
+ testsplit = line.gsub("#iggggnnnore","").split(function)
32
34
 
33
35
  testsplit = testsplit.collect {|element| element.strip}
34
36
 
@@ -36,7 +38,7 @@ def compile_custom_function_map(input_file_contents)
36
38
 
37
39
  if testsplit[0][-1].eql?(" ") or testsplit[0].eql?("return")
38
40
 
39
- modified_file_contents[index] = line.sub(function, function_map_replacements[function])
41
+ modified_file_contents[index] = line.gsub(function, function_map_replacements[function])
40
42
 
41
43
  end
42
44
 
@@ -2,6 +2,92 @@ require_relative 'replace_strings'
2
2
 
3
3
  def compile_existential_operators(input_file_contents)
4
4
 
5
+ # This method compiles Nila's existential operator.
6
+ #
7
+ # Example:
8
+ #
9
+ # input_args[0].exist?
10
+ #
11
+ # The above line should compile to
12
+ #
13
+ # typeof input_args[0] !== undefined && input_args[0] !== nil
14
+
15
+ modified_contents = input_file_contents.collect {|element| replace_strings(element)}
16
+
17
+ possible_existential_calls = modified_contents.reject {|element| !element.include?(".exist")}
18
+
19
+ split_regexp = /((if|while) \((!\()?)/
20
+
21
+ second_split_regexp = /(&&|\|\|)/
22
+
23
+ possible_existential_calls.each do |statement|
24
+
25
+ reconstructed_statement = input_file_contents[modified_contents.index(statement)]
26
+
27
+ counter = 0
28
+
29
+ while reconstructed_statement.include?(".exist")
30
+
31
+ before,after = reconstructed_statement.split(".exist",2)
32
+
33
+ if counter == 0
34
+
35
+ split_data = before.split(split_regexp)
36
+
37
+ before2 = split_data[1]
38
+
39
+ if before2.eql?("if (") or before2.eql?("while (")
40
+
41
+ usage = split_data[3]
42
+
43
+ elsif before2.eql?("if (!(") or before2.eql?("while (!(")
44
+
45
+ usage = split_data[4]
46
+
47
+ end
48
+
49
+ replacement_string = "(typeof #{usage} !== \"undefined\" &|&| #{usage} !== null)"
50
+
51
+ reconstructed_statement = before.split(before2)[0] + before2 + replacement_string + after
52
+
53
+ elsif counter > 0
54
+
55
+ split_data = before.split(second_split_regexp)
56
+
57
+ before2 = split_data[0]
58
+
59
+ operator = split_data[1]
60
+
61
+ operator = " &|&| " if operator.strip.eql?("&&")
62
+
63
+ operator = " |$|$ " if operator.strip.eql?("||")
64
+
65
+ usage = split_data[2]
66
+
67
+ replacement_string = "(typeof #{usage} !== \"undefined\" &|&| #{usage} !== null)"
68
+
69
+ reconstructed_statement = before2 + operator + replacement_string + after
70
+
71
+ end
72
+
73
+ counter += 1
74
+
75
+ end
76
+
77
+ reconstructed_statement = reconstructed_statement.gsub("&|&|","&&").gsub("|$|$","&&")
78
+
79
+ input_file_contents[modified_contents.index(statement)] = reconstructed_statement
80
+
81
+ modified_contents = input_file_contents
82
+
83
+ end
84
+
85
+ return input_file_contents
86
+
87
+ end
88
+
89
+ def compile_nil_operator(input_file_contents)
90
+
5
91
  # This method compiles Nila's existential operator.
6
92
  #
7
93
  # Example:
@@ -10,7 +96,7 @@ def compile_existential_operators(input_file_contents)
10
96
  #
11
97
  # The above line should compile to
12
98
  #
13
- # typeof input_args[0] === undefined && input_args[0] === nil
99
+ # input_args[0] === nil
14
100
 
15
101
  modified_contents = input_file_contents.collect {|element| replace_strings(element)}
16
102
 
@@ -46,7 +132,7 @@ def compile_existential_operators(input_file_contents)
46
132
 
47
133
  end
48
134
 
49
- replacement_string = "(typeof #{usage} === \"undefined\" &|&| #{usage} === null)"
135
+ replacement_string = "(#{usage} === null)"
50
136
 
51
137
  reconstructed_statement = before.split(before2)[0] + before2 + replacement_string + after
52
138
 
@@ -64,7 +150,7 @@ def compile_existential_operators(input_file_contents)
64
150
 
65
151
  usage = split_data[2]
66
152
 
67
- replacement_string = "(typeof #{usage} === \"undefined\" &|&| #{usage} === null)"
153
+ replacement_string = "(#{usage} === null)"
68
154
 
69
155
  reconstructed_statement = before2 + operator + replacement_string + after
70
156
 
@@ -78,6 +164,8 @@ def compile_existential_operators(input_file_contents)
78
164
 
79
165
  input_file_contents[modified_contents.index(statement)] = reconstructed_statement
80
166
 
167
+ modified_contents = input_file_contents
168
+
81
169
  end
82
170
 
83
171
  return input_file_contents
@@ -162,6 +250,8 @@ def compile_undefined_operator(input_file_contents)
162
250
 
163
251
  input_file_contents[modified_contents.index(statement)] = reconstructed_statement
164
252
 
253
+ modified_contents = input_file_contents
254
+
165
255
  end
166
256
 
167
257
  return input_file_contents
@@ -68,7 +68,7 @@ require_relative 'read_file_line_by_line'
68
68
 
69
69
  def compile_inline_hashes(input_file_contents)
70
70
 
71
- javascript_regexp = /(if |while |for |function |function\(|%[qQw]*\{)/
71
+ javascript_regexp = /(if |while |for |function |function\(|%[qQw]*\{|lambda\s*\{|\s*->\s*\{)/
72
72
 
73
73
  modified_file_contents = input_file_contents.clone.collect {|element| replace_strings(element)}
74
74
 
@@ -0,0 +1,187 @@
1
+ require_relative 'replace_strings'
2
+ require_relative 'compile_multiple_return'
3
+ require_relative 'strToArray'
4
+ require_relative 'lexical_scoped_function_variables'
5
+ require_relative 'add_auto_return_statement'
6
+
7
+ def compile_lambdas(input_file_contents,temporary_nila_file)
8
+
9
+ def compile_single_line_lambda(input_block)
10
+
11
+ # This method compiles a single lambda into a Javascript function expression
12
+
13
+ block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2)
14
+
15
+ compiled_lambda = "function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents.strip} \n\n}"
16
+
17
+ return compiled_lambda
18
+
19
+ end
20
+
21
+ def find_lambda_name(input_block)
22
+
23
+ first_line = input_block[0]
24
+
25
+ var_name = "varrrr"
26
+
27
+ if first_line.include?("=")
28
+
29
+ var_name,junk = first_line.split("=")
30
+
31
+ var_name = var_name.strip
32
+
33
+ end
34
+
35
+ return var_name
36
+
37
+ end
38
+
39
+ input_file_contents = input_file_contents.collect {|element| element.gsub(" -> "," lambda ")}
40
+
41
+ input_file_contents = input_file_contents.collect {|element| element.gsub("append","appand")}
42
+
43
+ possible_lambdas = input_file_contents.reject {|line| !replace_strings(line).include?("lambda")}
44
+
45
+ possible_lambdas = possible_lambdas.reject {|line| line.index(/\s*do\s*/) == nil}
46
+
47
+ lambda_names = []
48
+
49
+ unless possible_lambdas.empty?
50
+
51
+ possible_lambdas.each do |starting_line|
52
+
53
+ index_counter = starting_counter = input_file_contents.index(starting_line)
54
+
55
+ line = starting_line
56
+
57
+ until line.strip.eql?("end") or line.strip.eql?("end)")
58
+
59
+ index_counter += 1
60
+
61
+ line = input_file_contents[index_counter]
62
+
63
+ end
64
+
65
+ loop_extract = input_file_contents[starting_counter..index_counter]
66
+
67
+ var_name,block = loop_extract.join.split(/\s*do/)
68
+
69
+ var_name = var_name.split(/\s*=\s*lambda/)[0].strip
70
+
71
+ block = block.split("end")[0]
72
+
73
+ replacement_string = "#{var_name} = lambda blockky {#{block.strip}}_!"
74
+
75
+ input_file_contents[starting_counter..index_counter] = replacement_string
76
+
77
+ end
78
+
79
+ end
80
+
81
+ possible_lambdas = input_file_contents.reject{ |element| element.index(/lambda\s*(blockky)?\s*/) == nil}
82
+
83
+ possible_lambdas = possible_lambdas.reject {|element| !element.include?("{") and !element.include?("}")}
84
+
85
+ possible_lambdas = possible_lambdas.collect {|element| element.gsub(/lambda\s*\{/,"lambda !_{")}
86
+
87
+ modified_file_contents = input_file_contents.clone
88
+
89
+ unless possible_lambdas.empty?
90
+
91
+ possible_lambdas.each do |loop|
92
+
93
+ original_loop = loop.clone
94
+
95
+ string_counter = 1
96
+
97
+ extracted_string = []
98
+
99
+ while loop.include?("\"")
100
+
101
+ string_extract = loop[loop.index("\"")..loop.index("\"",loop.index("\"")+1)]
102
+
103
+ extracted_string << string_extract
104
+
105
+ loop = loop.sub(string_extract,"--repstring#{string_counter}")
106
+
107
+ string_counter += 1
108
+
109
+ end
110
+
111
+ lambda_extract = loop[loop.index("{")..loop.index("}_!")] if loop.include?("}_!")
112
+
113
+ lambda_extract = loop[loop.index("!_{")..loop.index("}")] if loop.include?("!_{")
114
+
115
+ compiled_lambda = ""
116
+
117
+ if lambda_extract.count("|") == 2
118
+
119
+ compiled_lambda = compile_single_line_lambda(lambda_extract)
120
+
121
+ extracted_string.each_with_index do |string,index|
122
+
123
+ compiled_lambda = compiled_lambda.sub("--repstring#{index+1}",string)
124
+
125
+ end
126
+
127
+ else
128
+
129
+ compiled_lambda = lambda_extract[1...-1].lstrip.rstrip
130
+
131
+ extracted_string.each_with_index do |string,index|
132
+
133
+ compiled_lambda = compiled_lambda.sub("--repstring#{index+1}",string)
134
+
135
+ end
136
+
137
+ end
138
+
139
+ original_loop = original_loop.gsub("!_{","{")
140
+
141
+ replacement_string = loop.split(lambda_extract)[0].split("lambda")[0] + compiled_lambda
142
+
143
+ replacement_array = strToArray(replacement_string)
144
+
145
+ replacement_array = compile_multiple_return(replacement_array)
146
+
147
+ replacement_array = add_auto_return_statement(replacement_array)
148
+
149
+ variables = lexical_scoped_variables(replacement_array)
150
+
151
+ if !variables.empty?
152
+
153
+ variable_string = "\nvar " + variables.join(", ") + "\n"
154
+
155
+ replacement_array.insert(1, variable_string)
156
+
157
+ end
158
+
159
+ lambda_name = find_lambda_name(replacement_array)
160
+
161
+ unless lambda_name.eql?("varrrr")
162
+
163
+ lambda_names << lambda_name
164
+
165
+ end
166
+
167
+ replacement_array[1...-1] = replacement_array[1...-1].collect {|element| "#iggggnnnore #{element}"}
168
+
169
+ modified_file_contents[input_file_contents.index(original_loop)] = replacement_array.join
170
+
171
+ end
172
+
173
+ end
174
+
175
+ modified_file_contents = modified_file_contents.collect {|element| element.gsub("appand","append")}
176
+
177
+ file_id = open(temporary_nila_file, 'w')
178
+
179
+ file_id.write(modified_file_contents.join)
180
+
181
+ file_id.close()
182
+
183
+ line_by_line_contents = read_file_line_by_line(temporary_nila_file)
184
+
185
+ return line_by_line_contents,lambda_names
186
+
187
+ end
@@ -0,0 +1,127 @@
1
+ def compile_multiple_return(input_array)
2
+
3
+ def find_all_matching_indices(input_string, pattern)
4
+
5
+ locations = []
6
+
7
+ index = input_string.index(pattern)
8
+
9
+ while index != nil
10
+
11
+ locations << index
12
+
13
+ index = input_string.index(pattern, index+1)
14
+
15
+
16
+ end
17
+
18
+ return locations
19
+
20
+
21
+ end
22
+
23
+ modified_input_array = input_array.dup
24
+
25
+ return_statements = input_array.dup.reject { |element| !element.include? "return" }
26
+
27
+ multiple_return_statements = return_statements.dup.reject { |element| !element.include? "," }
28
+
29
+ modified_multiple_return_statements = multiple_return_statements.dup
30
+
31
+ return_statement_index = []
32
+
33
+ multiple_return_statements.each do |statement|
34
+
35
+ location_array = modified_input_array.each_index.select { |index| modified_input_array[index] == statement }
36
+
37
+ return_statement_index << location_array[0]
38
+
39
+ end
40
+
41
+ multiple_return_statements.each_with_index do |return_statement, index|
42
+
43
+ replacement_counter = 0
44
+
45
+ if return_statement.include? "\""
46
+
47
+ starting_quotes = find_all_matching_indices(return_statement, "\"")
48
+
49
+ for x in 0...(starting_quotes.length)/2
50
+
51
+ quotes = return_statement[starting_quotes[x]..starting_quotes[x+1]]
52
+
53
+ replacement_counter += 1
54
+
55
+ modified_multiple_return_statements[index] = modified_multiple_return_statements[index].sub(quotes, "repstring#{1}")
56
+
57
+ modified_input_array[return_statement_index[index]] = modified_multiple_return_statements[index].sub(quotes, "repstring#{1}")
58
+
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+
65
+ modified_multiple_return_statements = modified_multiple_return_statements.reject { |element| !element.include? "," }
66
+
67
+ return_statement_index = []
68
+
69
+ modified_multiple_return_statements.each do |statement|
70
+
71
+ location_array = modified_input_array.each_index.select { |index| modified_input_array[index] == statement }
72
+
73
+ return_statement_index << location_array[0]
74
+
75
+ end
76
+
77
+ modified_multiple_return_statements.each_with_index do |return_statement, index|
78
+
79
+ method_call_counter = 0
80
+
81
+ if return_statement.include? "("
82
+
83
+ open_paran_location = find_all_matching_indices(return_statement, "(")
84
+
85
+ open_paran_location.each do |paran_index|
86
+
87
+ method_call = return_statement[paran_index..return_statement.index(")", paran_index+1)]
88
+
89
+ method_call_counter += 1
90
+
91
+ modified_multiple_return_statements[index] = modified_multiple_return_statements[index].sub(method_call, "methodcall#{method_call_counter}")
92
+
93
+ modified_input_array[return_statement_index[index]] = modified_multiple_return_statements[index].sub(method_call, "methodcall#{method_call_counter}")
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ modified_multiple_return_statements = modified_multiple_return_statements.reject { |element| !element.include?(",") }
102
+
103
+ return_statement_index = []
104
+
105
+ modified_multiple_return_statements.each do |statement|
106
+
107
+ location_array = modified_input_array.each_index.select { |index| modified_input_array[index] == statement }
108
+
109
+ return_statement_index << location_array[0]
110
+
111
+ end
112
+
113
+ return_statement_index.each do |index|
114
+
115
+ original_statement = input_array[index]
116
+
117
+ statement_split = original_statement.split("return ")
118
+
119
+ replacement_split = "return [" + statement_split[1].rstrip + "]\n\n"
120
+
121
+ input_array[index] = replacement_split
122
+
123
+ end
124
+
125
+ return input_array
126
+
127
+ end
@@ -66,6 +66,33 @@ def compile_operators(input_file_contents)
66
66
 
67
67
  end
68
68
 
69
+ def compile_conditional_assignment(input_string)
70
+
71
+ if input_string.include?("||=")
72
+
73
+ before,after = input_string.split("||=")
74
+
75
+ replacement_string = before + " = #{before.lstrip} || #{after}"
76
+
77
+ input_string = replacement_string
78
+
79
+ end
80
+
81
+ if input_string.include?("&&=")
82
+
83
+ before, after = input_string.split("&&=")
84
+
85
+ replacement_string = before + " = #{before.lstrip} && #{after}"
86
+
87
+ input_string = replacement_string
88
+
89
+ end
90
+
91
+ return input_string
92
+
93
+
94
+ end
95
+
69
96
  input_file_contents = input_file_contents.collect { |element| element.sub("==", "===") }
70
97
 
71
98
  input_file_contents = input_file_contents.collect { |element| element.sub("!=", "!==") }
@@ -74,10 +101,14 @@ def compile_operators(input_file_contents)
74
101
 
75
102
  input_file_contents = input_file_contents.collect { |element| element.sub("elsuf", "else if") }
76
103
 
104
+ input_file_contents = input_file_contents.collect {|element| compile_conditional_assignment(element)}
105
+
77
106
  input_file_contents = compile_existential_operators(input_file_contents)
78
107
 
79
108
  input_file_contents = compile_undefined_operator(input_file_contents)
80
109
 
110
+ input_file_contents = compile_nil_operator(input_file_contents)
111
+
81
112
  input_file_contents = input_file_contents.collect { |element| compile_power_operator(element) }
82
113
 
83
114
  input_file_contents = input_file_contents.collect { |element| compile_match_operator(element) }
@@ -1,5 +1,7 @@
1
1
  def extract_parsable_file(input_file_contents)
2
2
 
3
+ input_file_contents = input_file_contents.collect {|element| element.gsub(".?",".exist?")}
4
+
3
5
  reversed_file_contents = input_file_contents.reverse
4
6
 
5
7
  line_counter = 0
@@ -30,13 +30,15 @@ require_relative 'read_file_line_by_line'
30
30
 
31
31
  input_file_contents = input_file_contents.collect {|element| replace_strings(element)}
32
32
 
33
- javascript_regexp = /(if |while |for )/
33
+ javascript_regexp = /(if |while |for |\|\|=|&&=)/
34
34
 
35
35
  for x in 0...input_file_contents.length
36
36
 
37
37
  current_row = input_file_contents[x]
38
38
 
39
- if current_row.include?("=") and current_row.index(javascript_regexp) == nil
39
+ original_row = current_row.clone
40
+
41
+ if current_row.include?("=") and current_row.index(javascript_regexp) == nil and !current_row.include?("#iggggnnnore")
40
42
 
41
43
  current_row = current_row.rstrip + "\n"
42
44
 
@@ -57,12 +59,24 @@ require_relative 'read_file_line_by_line'
57
59
 
58
60
  current_row_split[0] = current_row_split[0].split(".",2)[0].strip if current_row_split[0].include?(".")
59
61
 
60
- variables << current_row_split[0]
62
+ if current_row_split[0].include?(" ")
61
63
 
64
+ variable_name = current_row_split[0].split
62
65
 
63
- end
66
+ variable_name = variable_name.join("_")
67
+
68
+ 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)
64
69
 
65
- input_file_contents[x] = current_row
70
+ else
71
+
72
+ variable_name = current_row_split[0]
73
+
74
+ end
75
+
76
+ variables << variable_name
77
+
78
+
79
+ end
66
80
 
67
81
  end
68
82
 
@@ -84,8 +98,6 @@ require_relative 'read_file_line_by_line'
84
98
 
85
99
  for_loop_statements = for_loop_statements.reject {|line| line.include?("forEach")}
86
100
 
87
- puts for_loop_statements
88
-
89
101
  for_loop_statements.each do |statement|
90
102
 
91
103
  varis = statement.split("for (")[1].split(";",2)[0].split(",")
@@ -0,0 +1,98 @@
1
+ def lexical_scoped_variables(input_function_block)
2
+
3
+ #This method will pickup and declare all the variables inside a function block. In future, this method will be
4
+ #merged with the get variables method
5
+
6
+ def replace_strings(input_string)
7
+
8
+ element = input_string.gsub("==", "equalequal")
9
+
10
+ element = element.gsub("!=", "notequal")
11
+
12
+ element = element.gsub("+=", "plusequal")
13
+
14
+ element = element.gsub("-=", "minusequal")
15
+
16
+ element = element.gsub("*=", "multiequal")
17
+
18
+ element = element.gsub("/=", "divequal")
19
+
20
+ element = element.gsub("%=", "modequal")
21
+
22
+ element = element.gsub("=~", "matchequal")
23
+
24
+ element = element.gsub(">=", "greatequal")
25
+
26
+ input_string = element.gsub("<=", "lessyequal")
27
+
28
+ string_counter = 0
29
+
30
+ while input_string.include?("\"")
31
+
32
+ string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
33
+
34
+ input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
35
+
36
+ string_counter += 1
37
+
38
+ end
39
+
40
+ while input_string.include?("'")
41
+
42
+ string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
43
+
44
+ input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
45
+
46
+ string_counter += 1
47
+
48
+ end
49
+
50
+ return input_string
51
+
52
+ end
53
+
54
+ input_function_block = input_function_block.collect {|element| replace_strings(element)}
55
+
56
+ controlregexp = /(if |Euuf |for |while |def |function |function\()/
57
+
58
+ variables = []
59
+
60
+ function_name, parameters = input_function_block[0].split("(")
61
+
62
+ parameters = parameters.split(")")[0].split(",")
63
+
64
+ parameters = parameters.collect { |element| element.strip }
65
+
66
+ input_function_block.each do |line|
67
+
68
+ if line.include? "=" and line.index(controlregexp).nil?
69
+
70
+ current_line_split = line.strip.split("=")
71
+
72
+ variables << current_line_split[0].rstrip
73
+
74
+ end
75
+
76
+ end
77
+
78
+ parameters.each do |param|
79
+
80
+ if variables.include?(param)
81
+
82
+ variables.delete(param)
83
+
84
+ end
85
+
86
+ end
87
+
88
+ if variables.empty?
89
+
90
+ return []
91
+
92
+ else
93
+
94
+ return variables.uniq.sort
95
+
96
+ end
97
+
98
+ end
@@ -46,7 +46,7 @@ require_relative 'read_file_line_by_line'
46
46
 
47
47
  def extract_blocks(file_contents)
48
48
 
49
- javascript_regexp = /(if |for |while |case |default:|switch\(|\(function\(|= function\(|function\(|((=|:)\s+\{))/
49
+ javascript_regexp = /(if |for |while |case |default:|switch\(|\(function\(|= function\(|,\s*function\(|((=|:)\s+\{))/
50
50
 
51
51
  block_starting_lines = file_contents.dup.reject { |element| element.index(javascript_regexp).nil? }[1..-1]
52
52
 
@@ -62,7 +62,9 @@ require_relative 'read_file_line_by_line'
62
62
 
63
63
  end
64
64
 
65
- block_ending_lines = file_contents.dup.each_index.select { |index| (file_contents[index].eql? " }\n" or file_contents[index].eql? " };\n" or file_contents[index].strip.eql?("});\n"))}
65
+ block_ending_lines = file_contents.dup.each_index.select { |index| (file_contents[index].eql? " }\n" or file_contents[index].eql? " };\n" or file_contents[index].lstrip.eql?("});\n"))}
66
+
67
+ block_ending_lines = block_ending_lines.reject {|index| file_contents[index].include?(" ")}
66
68
 
67
69
  modified_file_contents = file_contents.dup
68
70
 
@@ -98,13 +100,13 @@ require_relative 'read_file_line_by_line'
98
100
 
99
101
  end
100
102
 
101
- rescue TypeError
102
- #
103
- puts "Whitespace was left unfixed!"
104
- #
105
- rescue ArgumentError
106
- #
107
- puts "Whitespace was left unfixed!"
103
+ #rescue TypeError
104
+ ##
105
+ # puts "Whitespace was left unfixed!"
106
+ ##
107
+ #rescue ArgumentError
108
+ ##
109
+ # puts "Whitespace was left unfixed!"
108
110
 
109
111
  end
110
112
 
data/lib/nilac/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.3.9.5"
2
+ VERSION = "0.0.4.3.9.6"
3
3
  end
data/lib/nilac.rb CHANGED
@@ -8,81 +8,44 @@ $LOAD_PATH << File.dirname(__FILE__)
8
8
  module Nilac
9
9
 
10
10
  require 'nilac/version'
11
-
12
11
  require 'fileutils'
13
-
14
12
  require 'nilac/read_file_line_by_line'
15
-
16
13
  require 'nilac/find_file_name'
17
-
18
14
  require 'nilac/find_file_path'
19
-
20
15
  require 'nilac/extract_parsable_file'
21
-
22
16
  require 'nilac/compile_require_statements'
23
-
24
17
  require 'nilac/replace_multiline_comments'
25
-
26
18
  require 'nilac/split_semicolon_seperated_expressions'
27
-
28
19
  require 'nilac/compile_heredocs'
29
-
30
20
  require 'nilac/compile_interpolated_strings'
31
-
32
21
  require 'nilac/replace_singleline_comments'
33
-
34
22
  require 'nilac/replace_named_functions'
35
-
36
23
  require 'nilac/compile_parallel_assignment'
37
-
38
24
  require 'nilac/compile_default_values'
39
-
40
25
  require 'nilac/get_variables'
41
-
42
26
  require 'nilac/remove_question_marks'
43
-
44
27
  require 'nilac/compile_arrays'
45
-
46
28
  require 'nilac/compile_hashes'
47
-
48
29
  require 'nilac/compile_strings'
49
-
50
30
  require 'nilac/compile_integers'
51
-
52
31
  require 'nilac/compile_classes'
53
-
54
32
  require 'nilac/compile_named_functions'
55
-
56
33
  require 'nilac/compile_custom_function_map'
57
-
58
34
  require 'nilac/compile_ruby_methods'
59
-
60
35
  require 'nilac/compile_special_keywords'
61
-
62
36
  require 'nilac/compile_whitespace_delimited_functions'
63
-
64
37
  require 'nilac/compile_conditional_structures'
65
-
66
38
  require 'nilac/compile_case_statement'
67
-
68
39
  require 'nilac/compile_loops'
69
-
40
+ require 'nilac/compile_lambdas'
70
41
  require 'nilac/compile_blocks'
71
-
72
42
  require 'nilac/add_semicolons'
73
-
74
43
  require 'nilac/compile_comments'
75
-
76
44
  require 'nilac/pretty_print_javascript'
77
-
78
45
  require 'nilac/compile_operators'
79
-
80
46
  require 'nilac/output_javascript'
81
-
82
47
  require 'nilac/create_mac_executable'
83
-
84
48
  require 'nilac/parse_arguments'
85
-
86
49
  require 'nilac/compile_classes'
87
50
 
88
51
  class NilaCompiler
@@ -109,8 +72,6 @@ module Nilac
109
72
 
110
73
  file_contents = split_semicolon_seperated_expressions(file_contents)
111
74
 
112
- compile_classes(file_contents)
113
-
114
75
  file_contents = compile_heredocs(file_contents, temp_file)
115
76
 
116
77
  file_contents,loop_vars = compile_loops(file_contents,temp_file)
@@ -123,6 +84,8 @@ module Nilac
123
84
 
124
85
  file_contents = compile_conditional_structures(file_contents, temp_file)
125
86
 
87
+ file_contents,lambda_names = compile_lambdas(file_contents,temp_file)
88
+
126
89
  file_contents = compile_blocks(file_contents,temp_file)
127
90
 
128
91
  file_contents = compile_integers(file_contents)
@@ -153,6 +116,8 @@ module Nilac
153
116
 
154
117
  function_names << ruby_functions
155
118
 
119
+ function_names << lambda_names
120
+
156
121
  list_of_variables += loop_vars
157
122
 
158
123
  file_contents = compile_whitespace_delimited_functions(file_contents, function_names, temp_file)
@@ -324,9 +289,7 @@ end
324
289
  if ARGV.include?("--test")
325
290
 
326
291
  ARGV.delete("--test")
327
-
328
292
  compiler = Nilac::NilaCompiler.new(ARGV)
329
-
330
293
  compiler.start_compile()
331
294
 
332
295
  end
@@ -0,0 +1,11 @@
1
+ Feature: This feature introduces .undefined?, .nil? and .exist? operators to help Javascript development.
2
+ Scenario: Input file with different operators
3
+ Given the input file "javascript_methods.nila"
4
+ When the ~compiler is run
5
+ The output file must be "javascript_methods.js"
6
+ The output file must equal "correct_javascript_methods.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => lib/nilac.rb
11
+ :v $cliusage => ruby :v --test --compile $file
@@ -0,0 +1,9 @@
1
+ # This file demonstrates the conditional assignment operator in Nila
2
+
3
+ a = nil
4
+ b = 20
5
+ a ||= b
6
+
7
+ a = true
8
+ b = 20
9
+ a &&= b
@@ -0,0 +1,19 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function() {
3
+ var a, b;
4
+
5
+ // This file demonstrates the conditional assignment operator in Nila
6
+
7
+ a = null;
8
+
9
+ b = 20;
10
+
11
+ a = a || b;
12
+
13
+ a = true;
14
+
15
+ b = 20;
16
+
17
+ a = a && b;
18
+
19
+ }).call(this);
@@ -0,0 +1,25 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function() {
3
+ var commandline_args, overspeed;
4
+
5
+ if ((typeof console !== "undefined" && console !== null)) {
6
+ console.log("You can use console.log");
7
+ }
8
+
9
+ if ((typeof console !== "undefined" && console !== null)) {
10
+ console.log("You can use console.log");
11
+ }
12
+
13
+ commandline_args = ["-c"];
14
+
15
+ if ((typeof commandline_args[1] === "undefined")) {
16
+ console.log("Your second argument was empty!");
17
+ }
18
+
19
+ overspeed = null;
20
+
21
+ if ((overspeed === null)) {
22
+ console.log("No overspeeding vehicles found!");
23
+ }
24
+
25
+ }).call(this);
@@ -1,9 +1,11 @@
1
1
  //Written using Nila. Visit http://adhithyan15.github.io/nila
2
2
  (function() {
3
- var fs;
3
+ var fs, http;
4
4
 
5
5
  fs = require('fs');
6
6
 
7
+ http = require('http');
8
+
7
9
  fs.readFile('/etc/hosts','utf8',function(err,data) {
8
10
  if (err) {
9
11
  console.log(err);
@@ -0,0 +1,19 @@
1
+ puts "You can use console.log" if console.exist?
2
+
3
+ puts "You can use console.log" if console.?
4
+
5
+ commandline_args = %w{-c}
6
+
7
+ if commandline_args[1].undefined?
8
+
9
+ puts "Your second argument was empty!"
10
+
11
+ end
12
+
13
+ overspeed = nil
14
+
15
+ if overspeed.nil?
16
+
17
+ puts "No overspeeding vehicles found!"
18
+
19
+ end
@@ -0,0 +1,8 @@
1
+ square = -> {|num| num*num }
2
+
3
+ l = lambda do |a, b|
4
+ tmp = a * 7
5
+ tmp * b / 50
6
+ end
7
+
8
+ puts square 5
@@ -0,0 +1,7 @@
1
+ # This example was taken from http://alvinalexander.com/blog/post/ruby/examples-ruby-ternary-operator-true-false-syntax
2
+
3
+ # set the speed
4
+ speed = 90
5
+
6
+ # somewhere later in the program ...
7
+ speed > 55 ? (speed < 70 ? puts("Fine is $400") : puts("Fine is $800")) : puts("I'm a careful driver")
@@ -0,0 +1,6 @@
1
+ # An experiment to allow spaces in variable names. Inspired by Pogoscript (http://pogoscript.org)
2
+ # The Nilac implementation is not complete. Again, this is just an experiment
3
+
4
+ wind speed = 25
5
+
6
+ average temperature = 32
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nilac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.3.9.5
4
+ version: 0.0.4.3.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adhithya Rajasekaran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-10 00:00:00.000000000 Z
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shark
@@ -38,7 +38,6 @@ files:
38
38
  - README.md
39
39
  - Rakefile
40
40
  - bin/nilac
41
- - examples/StringMagic.nila
42
41
  - examples/countdown.nila
43
42
  - examples/decBin.js
44
43
  - examples/decBin.nila
@@ -46,6 +45,7 @@ files:
46
45
  - examples/marky.nila
47
46
  - lib/nilac.rb
48
47
  - lib/nilac/ErrorDeclarations.rb
48
+ - lib/nilac/add_auto_return_statement.rb
49
49
  - lib/nilac/add_semicolons.rb
50
50
  - lib/nilac/compile_arrays.rb
51
51
  - lib/nilac/compile_blocks.rb
@@ -60,7 +60,9 @@ files:
60
60
  - lib/nilac/compile_heredocs.rb
61
61
  - lib/nilac/compile_integers.rb
62
62
  - lib/nilac/compile_interpolated_strings.rb
63
+ - lib/nilac/compile_lambdas.rb
63
64
  - lib/nilac/compile_loops.rb
65
+ - lib/nilac/compile_multiple_return.rb
64
66
  - lib/nilac/compile_named_functions.rb
65
67
  - lib/nilac/compile_operators.rb
66
68
  - lib/nilac/compile_parallel_assignment.rb
@@ -68,7 +70,6 @@ files:
68
70
  - lib/nilac/compile_ruby_methods.rb
69
71
  - lib/nilac/compile_special_keywords.rb
70
72
  - lib/nilac/compile_strings.rb
71
- - lib/nilac/compile_ternary_operator.rb
72
73
  - lib/nilac/compile_whitespace_delimited_functions.rb
73
74
  - lib/nilac/create_mac_executable.rb
74
75
  - lib/nilac/extract_parsable_file.rb
@@ -76,6 +77,7 @@ files:
76
77
  - lib/nilac/find_file_name.rb
77
78
  - lib/nilac/find_file_path.rb
78
79
  - lib/nilac/get_variables.rb
80
+ - lib/nilac/lexical_scoped_function_variables.rb
79
81
  - lib/nilac/output_javascript.rb
80
82
  - lib/nilac/parse_arguments.rb
81
83
  - lib/nilac/pretty_print_javascript.rb
@@ -100,6 +102,7 @@ files:
100
102
  - shark/features/hashes.feature
101
103
  - shark/features/heredoc.feature
102
104
  - shark/features/if_then_else.feature
105
+ - shark/features/javascript_methods.feature
103
106
  - shark/features/loop.feature
104
107
  - shark/features/method_multiple_return.feature
105
108
  - shark/features/multiline_array.feature
@@ -120,8 +123,10 @@ files:
120
123
  - shark/test_files/array_sugar.nila
121
124
  - shark/test_files/case.nila
122
125
  - shark/test_files/class.nila
126
+ - shark/test_files/conditional_assignment.nila
123
127
  - shark/test_files/correct.js
124
128
  - shark/test_files/correct_case.js
129
+ - shark/test_files/correct_conditional_assignment.js
125
130
  - shark/test_files/correct_default_parameters.js
126
131
  - shark/test_files/correct_for.js
127
132
  - shark/test_files/correct_hashes.js
@@ -129,6 +134,7 @@ files:
129
134
  - shark/test_files/correct_if_then_else.js
130
135
  - shark/test_files/correct_indexing.js
131
136
  - shark/test_files/correct_initialization.js
137
+ - shark/test_files/correct_javascript_methods.js
132
138
  - shark/test_files/correct_loop.js
133
139
  - shark/test_files/correct_multiline_array.js
134
140
  - shark/test_files/correct_multiple_return.js
@@ -151,6 +157,8 @@ files:
151
157
  - shark/test_files/hashes.nila
152
158
  - shark/test_files/heredoc.nila
153
159
  - shark/test_files/if_then_else.nila
160
+ - shark/test_files/javascript_methods.nila
161
+ - shark/test_files/lambda.nila
154
162
  - shark/test_files/loop.nila
155
163
  - shark/test_files/multiline_array.nila
156
164
  - shark/test_files/multiple_initialization.nila
@@ -170,8 +178,10 @@ files:
170
178
  - shark/test_files/splats.nila
171
179
  - shark/test_files/string_interpolation.nila
172
180
  - shark/test_files/string_operators.nila
181
+ - shark/test_files/ternary.nila
173
182
  - shark/test_files/times.nila
174
183
  - shark/test_files/unless_until.nila
184
+ - shark/test_files/variable_spaces.nila
175
185
  - shark/test_files/whitespace_delimiter.nila
176
186
  homepage: http://adhithyan15.github.com/nila
177
187
  licenses: []
@@ -1,23 +0,0 @@
1
- # StringMagic is an implementation of Ruby's string methods in Javascript using Nila.
2
- # It extends the String prototype by adding more methods to it.
3
-
4
- # It is being written by Adhithya Rajasekaran and Sri Madhavi Rajasekaran.
5
-
6
- # It is released under the MIT License
7
-
8
- # Nila allows you to open native Classes/Prototypes and extend them with custom
9
- # methods/functions. So we will be opening the String class and adding more methods
10
- # to it.
11
-
12
- class String
13
-
14
- def endswith(suffix)
15
-
16
- # suffix can be any string
17
-
18
- self.include?(suffix,self.length-suffix.length)
19
-
20
- end
21
-
22
-
23
- end
@@ -1,6 +0,0 @@
1
- # This method compiles plain ternary operators into equivalent Javascript code
2
-
3
- def compile_ternary_operator(input_file_contents)
4
-
5
-
6
- end