nilac 0.0.4.3.9.2 → 0.0.4.3.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/nilac +9 -5748
- data/examples/StringMagic.nila +23 -0
- data/examples/countdown.nila +31 -0
- data/examples/decBin.nila +3 -3
- data/examples/marky.js +30 -0
- data/examples/marky.nila +23 -0
- data/lib/nilac/ErrorDeclarations.rb +11 -0
- data/lib/nilac/add_semicolons.rb +57 -0
- data/lib/nilac/compile_arrays.rb +266 -0
- data/lib/nilac/compile_blocks.rb +137 -0
- data/lib/nilac/compile_case_statement.rb +168 -0
- data/lib/nilac/compile_classes.rb +18 -0
- data/lib/nilac/compile_comments.rb +79 -0
- data/lib/nilac/compile_conditional_structures.rb +1378 -0
- data/lib/nilac/compile_custom_function_map.rb +45 -0
- data/lib/nilac/compile_default_values.rb +160 -0
- data/lib/nilac/compile_hashes.rb +123 -0
- data/lib/nilac/compile_heredocs.rb +62 -0
- data/lib/nilac/compile_integers.rb +23 -0
- data/lib/nilac/compile_interpolated_strings.rb +133 -0
- data/lib/nilac/compile_loops.rb +211 -0
- data/lib/nilac/compile_named_functions.rb +690 -0
- data/lib/nilac/compile_operators.rb +83 -0
- data/lib/nilac/compile_parallel_assignment.rb +103 -0
- data/lib/nilac/compile_ruby_methods.rb +58 -0
- data/lib/nilac/compile_special_keywords.rb +44 -0
- data/lib/nilac/compile_strings.rb +145 -0
- data/lib/nilac/compile_whitespace_delimited_functions.rb +97 -0
- data/lib/nilac/create_mac_executable.rb +25 -0
- data/lib/nilac/extract_parsable_file.rb +23 -0
- data/lib/nilac/find_all_matching_indices.rb +18 -0
- data/lib/nilac/find_file_name.rb +13 -0
- data/lib/nilac/find_file_path.rb +13 -0
- data/lib/nilac/get_variables.rb +123 -0
- data/lib/nilac/output_javascript.rb +13 -0
- data/lib/nilac/parse_arguments.rb +41 -0
- data/lib/nilac/pretty_print_javascript.rb +457 -0
- data/lib/nilac/read_file_line_by_line.rb +11 -0
- data/lib/nilac/remove_question_marks.rb +46 -0
- data/lib/nilac/replace_multiline_comments.rb +92 -0
- data/lib/nilac/replace_named_functions.rb +154 -0
- data/lib/nilac/replace_singleline_comments.rb +45 -0
- data/lib/nilac/replace_strings.rb +35 -0
- data/lib/nilac/split_semicolon_seperated_expressions.rb +39 -0
- data/lib/nilac/strToArray.rb +15 -0
- data/lib/nilac/version.rb +1 -1
- data/lib/nilac.rb +324 -1
- data/nilac.gemspec +0 -1
- data/shark/features/add_auto_return_statement.feature +1 -1
- data/shark/features/array_and_string_indexing.feature +1 -1
- data/shark/features/barebones_compilation.feature +1 -1
- data/shark/features/case_when.feature +1 -1
- data/shark/features/default_method_parameters.feature +1 -1
- data/shark/features/fix_newlines.feature +1 -1
- data/shark/features/hashes.feature +1 -1
- data/shark/features/heredoc.feature +1 -1
- data/shark/features/if_then_else.feature +1 -1
- data/shark/features/loop.feature +1 -1
- data/shark/features/method_multiple_return.feature +1 -1
- data/shark/features/multiline_array.feature +1 -1
- data/shark/features/multiple_variable_initialization.feature +1 -1
- data/shark/features/numbers.feature +1 -1
- data/shark/features/regular_for.feature +1 -1
- data/shark/features/regular_if.feature +1 -1
- data/shark/features/regular_while.feature +1 -1
- data/shark/features/ruby_methods.feature +1 -1
- data/shark/features/ruby_operators.feature +1 -1
- data/shark/features/splats.feature +1 -1
- data/shark/features/string_interpolation.feature +1 -1
- data/shark/features/strings.feature +1 -1
- data/shark/features/times.feature +1 -1
- data/shark/features/unless_until.feature +1 -1
- data/shark/features/whitespace_delimitation.feature +1 -1
- metadata +46 -18
- data/src/nilac.rb +0 -5753
@@ -0,0 +1,92 @@
|
|
1
|
+
require_relative "find_file_name"
|
2
|
+
|
3
|
+
require_relative "find_file_path"
|
4
|
+
|
5
|
+
require_relative "read_file_line_by_line"
|
6
|
+
|
7
|
+
def replace_multiline_comments(input_file_contents, nila_file_path, *output_js_file_path)
|
8
|
+
|
9
|
+
#This method will replace both the single and multiline comments
|
10
|
+
#
|
11
|
+
#Single line comment will be replaced by => --single_line_comment[n]
|
12
|
+
#
|
13
|
+
#Multiline comment will be replaced by => --multiline_comment[n]
|
14
|
+
|
15
|
+
def find_all_matching_indices(input_string, pattern)
|
16
|
+
|
17
|
+
locations = []
|
18
|
+
|
19
|
+
index = input_string.index(pattern)
|
20
|
+
|
21
|
+
while index != nil
|
22
|
+
|
23
|
+
locations << index
|
24
|
+
|
25
|
+
index = input_string.index(pattern, index+1)
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
return locations
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
multiline_comments = []
|
36
|
+
|
37
|
+
file_contents_as_string = input_file_contents.join
|
38
|
+
|
39
|
+
modified_file_contents = file_contents_as_string.dup
|
40
|
+
|
41
|
+
multiline_comment_counter = 1
|
42
|
+
|
43
|
+
multiline_comments_start = find_all_matching_indices(file_contents_as_string, "=begin")
|
44
|
+
|
45
|
+
multiline_comments_end = find_all_matching_indices(file_contents_as_string, "=end")
|
46
|
+
|
47
|
+
for y in 0...multiline_comments_start.length
|
48
|
+
|
49
|
+
start_of_multiline_comment = multiline_comments_start[y]
|
50
|
+
|
51
|
+
end_of_multiline_comment = multiline_comments_end[y]
|
52
|
+
|
53
|
+
multiline_comment = file_contents_as_string[start_of_multiline_comment..end_of_multiline_comment+3]
|
54
|
+
|
55
|
+
modified_file_contents = modified_file_contents.gsub(multiline_comment, "--multiline_comment[#{multiline_comment_counter}]\n\n")
|
56
|
+
|
57
|
+
multiline_comment_counter += 1
|
58
|
+
|
59
|
+
multiline_comments << multiline_comment
|
60
|
+
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
temporary_nila_file = find_file_path(nila_file_path, ".nila") + "temp_nila.nila"
|
65
|
+
|
66
|
+
if output_js_file_path.empty?
|
67
|
+
|
68
|
+
output_js_file = find_file_path(nila_file_path, ".nila") + find_file_name(nila_file_path, ".nila") + ".js"
|
69
|
+
|
70
|
+
else
|
71
|
+
|
72
|
+
output_js_file = output_js_file_path[0]
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
file_id = open(temporary_nila_file, 'w')
|
77
|
+
|
78
|
+
file_id2 = open(output_js_file, 'w')
|
79
|
+
|
80
|
+
file_id.write(modified_file_contents)
|
81
|
+
|
82
|
+
file_id.close()
|
83
|
+
|
84
|
+
file_id2.close()
|
85
|
+
|
86
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
87
|
+
|
88
|
+
comments = multiline_comments.dup
|
89
|
+
|
90
|
+
return line_by_line_contents, comments, temporary_nila_file, output_js_file
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require_relative 'read_file_line_by_line'
|
2
|
+
|
3
|
+
def replace_named_functions(nila_file_contents, temporary_nila_file)
|
4
|
+
|
5
|
+
def extract_array(input_array, start_index, end_index)
|
6
|
+
|
7
|
+
return input_array[start_index..end_index]
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
end_locations = []
|
12
|
+
|
13
|
+
key_word_locations = []
|
14
|
+
|
15
|
+
start_blocks = []
|
16
|
+
|
17
|
+
end_blocks = []
|
18
|
+
|
19
|
+
nila_regexp = /(def )/
|
20
|
+
|
21
|
+
named_code_blocks = []
|
22
|
+
|
23
|
+
for x in 0...nila_file_contents.length
|
24
|
+
|
25
|
+
current_row = nila_file_contents[x]
|
26
|
+
|
27
|
+
if current_row.index(nila_regexp) != nil
|
28
|
+
|
29
|
+
key_word_locations << x
|
30
|
+
|
31
|
+
elsif current_row.lstrip.eql?("end\n") || current_row.strip.eql?("end")
|
32
|
+
|
33
|
+
end_locations << x
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
unless key_word_locations.empty?
|
42
|
+
|
43
|
+
modified_file_contents = nila_file_contents.dup
|
44
|
+
|
45
|
+
for y in 0...end_locations.length
|
46
|
+
|
47
|
+
current_location = end_locations[y]
|
48
|
+
|
49
|
+
current_string = modified_file_contents[current_location]
|
50
|
+
|
51
|
+
finder_location = current_location
|
52
|
+
|
53
|
+
begin
|
54
|
+
|
55
|
+
while current_string.index(nila_regexp) == nil
|
56
|
+
|
57
|
+
finder_location -= 1
|
58
|
+
|
59
|
+
current_string = modified_file_contents[finder_location]
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
code_block_begin = finder_location
|
64
|
+
|
65
|
+
code_block_end = current_location
|
66
|
+
|
67
|
+
start_blocks << code_block_begin
|
68
|
+
|
69
|
+
end_blocks << code_block_end
|
70
|
+
|
71
|
+
code_block_begin_string_split = modified_file_contents[code_block_begin].split(" ")
|
72
|
+
|
73
|
+
code_block_begin_string_split[0] = code_block_begin_string_split[0].reverse
|
74
|
+
|
75
|
+
code_block_begin_string = code_block_begin_string_split.join(" ")
|
76
|
+
|
77
|
+
modified_file_contents[code_block_begin] = code_block_begin_string
|
78
|
+
|
79
|
+
rescue NoMethodError
|
80
|
+
|
81
|
+
puts "Function compilation failed!"
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
final_modified_file_contents = nila_file_contents.dup
|
88
|
+
|
89
|
+
joined_file_contents = final_modified_file_contents.join
|
90
|
+
|
91
|
+
while start_blocks.length != 0
|
92
|
+
|
93
|
+
top_most_level = start_blocks.min
|
94
|
+
|
95
|
+
top_most_level_index = start_blocks.index(top_most_level)
|
96
|
+
|
97
|
+
matching_level = end_blocks[top_most_level_index]
|
98
|
+
|
99
|
+
named_code_blocks << extract_array(final_modified_file_contents, top_most_level, matching_level)
|
100
|
+
|
101
|
+
start_blocks.delete_at(top_most_level_index)
|
102
|
+
|
103
|
+
end_blocks.delete(matching_level)
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
codeblock_counter = 1
|
108
|
+
|
109
|
+
named_functions = named_code_blocks.dup
|
110
|
+
|
111
|
+
nested_functions = []
|
112
|
+
|
113
|
+
named_code_blocks.each do |codeblock|
|
114
|
+
|
115
|
+
if joined_file_contents.include?(codeblock.join)
|
116
|
+
|
117
|
+
joined_file_contents = joined_file_contents.sub(codeblock.join, "--named_function[#{codeblock_counter}]\n")
|
118
|
+
|
119
|
+
codeblock_counter += 1
|
120
|
+
|
121
|
+
nested_functions = nested_functions + [[]]
|
122
|
+
|
123
|
+
else
|
124
|
+
|
125
|
+
nested_functions[codeblock_counter-2] << codeblock
|
126
|
+
|
127
|
+
named_functions.delete(codeblock)
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
else
|
134
|
+
|
135
|
+
joined_file_contents = nila_file_contents.join
|
136
|
+
|
137
|
+
named_functions = []
|
138
|
+
|
139
|
+
nested_functions = []
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
file_id = open(temporary_nila_file, 'w')
|
144
|
+
|
145
|
+
file_id.write(joined_file_contents)
|
146
|
+
|
147
|
+
file_id.close()
|
148
|
+
|
149
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
150
|
+
|
151
|
+
return line_by_line_contents, named_functions, nested_functions
|
152
|
+
|
153
|
+
|
154
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'replace_strings'
|
2
|
+
|
3
|
+
def replace_singleline_comments(input_file_contents)
|
4
|
+
|
5
|
+
single_line_comments = []
|
6
|
+
|
7
|
+
singleline_comment_counter = 1
|
8
|
+
|
9
|
+
modified_file_contents = input_file_contents.clone
|
10
|
+
|
11
|
+
for x in 0...input_file_contents.length
|
12
|
+
|
13
|
+
current_row = replace_strings(input_file_contents[x])
|
14
|
+
|
15
|
+
if current_row.include?("#")
|
16
|
+
|
17
|
+
current_row = modified_file_contents[x]
|
18
|
+
|
19
|
+
comment_start = current_row.index("#")
|
20
|
+
|
21
|
+
if current_row[comment_start+1] != "{"
|
22
|
+
|
23
|
+
comment = current_row[comment_start..-1]
|
24
|
+
|
25
|
+
single_line_comments << comment
|
26
|
+
|
27
|
+
current_row = current_row.gsub(comment, "--single_line_comment[#{singleline_comment_counter}]\n\n")
|
28
|
+
|
29
|
+
singleline_comment_counter += 1
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
else
|
34
|
+
|
35
|
+
current_row = modified_file_contents[x]
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
modified_file_contents[x] = current_row
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
return modified_file_contents, single_line_comments
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
def replace_strings(input_string)
|
2
|
+
|
3
|
+
string_counter = 0
|
4
|
+
|
5
|
+
if input_string.count("\"") % 2 == 0
|
6
|
+
|
7
|
+
while input_string.include?("\"")
|
8
|
+
|
9
|
+
string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
|
10
|
+
|
11
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
12
|
+
|
13
|
+
string_counter += 1
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
if input_string.count("'") % 2 == 0
|
20
|
+
|
21
|
+
while input_string.include?("'")
|
22
|
+
|
23
|
+
string_extract = input_string[input_string.index("'")..input_string.index("'",input_string.index("'")+1)]
|
24
|
+
|
25
|
+
input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
|
26
|
+
|
27
|
+
string_counter += 1
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
return input_string
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
def split_semicolon_seperated_expressions(input_file_contents)
|
2
|
+
|
3
|
+
modified_file_contents = input_file_contents.dup
|
4
|
+
|
5
|
+
input_file_contents.each_with_index do |line, index|
|
6
|
+
|
7
|
+
if line.include?("\"")
|
8
|
+
|
9
|
+
first_index = line.index("\"")
|
10
|
+
|
11
|
+
modified_line = line.sub(line[first_index..line.index("\"", first_index+1)], "--string")
|
12
|
+
|
13
|
+
elsif line.include?("'")
|
14
|
+
|
15
|
+
first_index = line.index("'")
|
16
|
+
|
17
|
+
modified_line = line.sub(line[first_index..line.index("'", first_index+1)], "--string")
|
18
|
+
|
19
|
+
else
|
20
|
+
|
21
|
+
modified_line = line
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
if modified_line.include?(";")
|
26
|
+
|
27
|
+
replacement_line = modified_file_contents[index]
|
28
|
+
|
29
|
+
replacement_line = replacement_line.split(";").join("\n\n") + "\n"
|
30
|
+
|
31
|
+
modified_file_contents[index] = replacement_line
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
return modified_file_contents
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
def strToArray(input_string)
|
2
|
+
|
3
|
+
file_id = File.new('hello.nila','w')
|
4
|
+
|
5
|
+
file_id.write(input_string)
|
6
|
+
|
7
|
+
file_id.close()
|
8
|
+
|
9
|
+
line_by_line_contents = read_file_line_by_line('hello.nila')
|
10
|
+
|
11
|
+
File.delete(file_id)
|
12
|
+
|
13
|
+
return line_by_line_contents
|
14
|
+
|
15
|
+
end
|
data/lib/nilac/version.rb
CHANGED