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,168 @@
|
|
1
|
+
require_relative 'replace_strings'
|
2
|
+
|
3
|
+
require_relative 'read_file_line_by_line'
|
4
|
+
|
5
|
+
def compile_case_statement(input_file_contents,temporary_nila_file)
|
6
|
+
|
7
|
+
# This method compiles simple Ruby style case statements to Javascript
|
8
|
+
# equivalent switch case statements
|
9
|
+
|
10
|
+
# For an example, look at shark/test_files/case.nila
|
11
|
+
|
12
|
+
def compile_when_statement(input_block)
|
13
|
+
|
14
|
+
condition,body = input_block[0],input_block[1..-1]
|
15
|
+
|
16
|
+
if replace_strings(condition.split("when ")[1]).include?(",")
|
17
|
+
|
18
|
+
condition_cases = condition.split("when ")[1].split(",").collect {|element| element.strip}
|
19
|
+
|
20
|
+
case_replacement = []
|
21
|
+
|
22
|
+
condition_cases.each do |ccase|
|
23
|
+
|
24
|
+
case_replacement << "case #{ccase}:%$%$ {\n\n"
|
25
|
+
|
26
|
+
case_replacement << body.collect {|element| " " + element.strip + "\n\n"}
|
27
|
+
|
28
|
+
case_replacement << " break\n%$%$\n}\n"
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
else
|
33
|
+
|
34
|
+
case_replacement = []
|
35
|
+
|
36
|
+
condition_case = condition.split("when ")[1].strip
|
37
|
+
|
38
|
+
case_replacement << "case #{condition_case}:%$%$ {\n\n"
|
39
|
+
|
40
|
+
case_replacement << body.collect {|element| " " + element.strip + "\n\n"}
|
41
|
+
|
42
|
+
case_replacement << " break\n%$%$\n}\n"
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
return case_replacement.join
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
modified_file_contents = input_file_contents.clone
|
51
|
+
|
52
|
+
possible_case_statements = input_file_contents.reject {|element| !element.include?("case ")}
|
53
|
+
|
54
|
+
case_statements = []
|
55
|
+
|
56
|
+
possible_case_statements.each do |statement|
|
57
|
+
|
58
|
+
starting_index = input_file_contents.index(statement)
|
59
|
+
|
60
|
+
index = starting_index
|
61
|
+
|
62
|
+
until input_file_contents[index].strip.eql?("end")
|
63
|
+
|
64
|
+
index += 1
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
case_statements << input_file_contents[starting_index..index].collect {|element| element.clone}.clone
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
legacy = case_statements.collect {|element| element.clone}
|
73
|
+
|
74
|
+
replacement_strings = []
|
75
|
+
|
76
|
+
case_statements.each do |statement_block|
|
77
|
+
|
78
|
+
condition = statement_block[0].split("case")[1].strip
|
79
|
+
|
80
|
+
statement_block[0] = "switch(#{condition}) {\n\n"
|
81
|
+
|
82
|
+
when_statements = statement_block.reject {|element| !replace_strings(element).include?("when")}
|
83
|
+
|
84
|
+
when_statements_index = []
|
85
|
+
|
86
|
+
when_statements.each do |statement|
|
87
|
+
|
88
|
+
when_statements_index << statement_block.each_index.select{|index| statement_block[index] == statement}
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
when_statements_index = when_statements_index.flatten
|
93
|
+
|
94
|
+
if replace_strings(statement_block.join).include?("else\n")
|
95
|
+
|
96
|
+
else_statement = statement_block.reject {|element| !replace_strings(element).strip.eql?("else")}
|
97
|
+
|
98
|
+
else_block = statement_block[statement_block.index(else_statement[0])+1...-1]
|
99
|
+
|
100
|
+
when_statements_index = when_statements_index + statement_block.each_index.select {|index| statement_block[index] == else_statement[0] }.to_a
|
101
|
+
|
102
|
+
when_statements_index = when_statements_index.flatten
|
103
|
+
|
104
|
+
statement_block[statement_block.index(else_statement[0])..-1] = ["default: %$%$ {\n\n",else_block.collect{|element| " " + element.strip + "\n\n"},"%$%$\n}\n\n}\n\n"].flatten
|
105
|
+
|
106
|
+
when_statement_blocks = []
|
107
|
+
|
108
|
+
when_statements.each_with_index do |statement,ind|
|
109
|
+
|
110
|
+
when_block = statement_block[when_statements_index[ind]...when_statements_index[ind+1]]
|
111
|
+
|
112
|
+
when_statement_blocks << when_block
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
replacement_blocks = when_statement_blocks.collect {|element| compile_when_statement(element)}
|
117
|
+
|
118
|
+
else
|
119
|
+
|
120
|
+
statement_block[-1] = "}\n\n" if statement_block[-1].strip.eql?("end")
|
121
|
+
|
122
|
+
when_statement_blocks = []
|
123
|
+
|
124
|
+
when_statements_index << -1
|
125
|
+
|
126
|
+
when_statements.each_with_index do |statement,ind|
|
127
|
+
|
128
|
+
when_block = statement_block[when_statements_index[ind]...when_statements_index[ind+1]]
|
129
|
+
|
130
|
+
when_statement_blocks << when_block
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
replacement_blocks = when_statement_blocks.collect {|element| compile_when_statement(element)}
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
statement_block = statement_block.join
|
139
|
+
|
140
|
+
when_statement_blocks.each_with_index do |blck,index|
|
141
|
+
|
142
|
+
statement_block = statement_block.sub(blck.join,replacement_blocks[index])
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
replacement_strings << statement_block
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
joined_file_contents = modified_file_contents.join
|
151
|
+
|
152
|
+
legacy.each_with_index do |statement,index|
|
153
|
+
|
154
|
+
joined_file_contents = joined_file_contents.sub(statement.join,replacement_strings[index])
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
file_id = open(temporary_nila_file, 'w')
|
159
|
+
|
160
|
+
file_id.write(joined_file_contents)
|
161
|
+
|
162
|
+
file_id.close()
|
163
|
+
|
164
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
165
|
+
|
166
|
+
return line_by_line_contents
|
167
|
+
|
168
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
def compile_classes(input_file_contents)
|
2
|
+
|
3
|
+
# Nila will have support for classes. But the current implementation is not ready for prime time
|
4
|
+
# yet. So it won't be documented.
|
5
|
+
|
6
|
+
def extract_classes
|
7
|
+
|
8
|
+
builtin_classes = [
|
9
|
+
|
10
|
+
"String",
|
11
|
+
|
12
|
+
]
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative 'read_file_line_by_line'
|
2
|
+
|
3
|
+
def compile_comments(input_file_contents, comments, temporary_nila_file)
|
4
|
+
|
5
|
+
#This method converts Nila comments into pure Javascript comments. This method
|
6
|
+
#handles both single line and multiline comments.
|
7
|
+
|
8
|
+
file_contents_as_string = input_file_contents.join
|
9
|
+
|
10
|
+
single_line_comments = comments[0]
|
11
|
+
|
12
|
+
multiline_comments = comments[1]
|
13
|
+
|
14
|
+
single_line_comment_counter = 1
|
15
|
+
|
16
|
+
multi_line_comment_counter = 1
|
17
|
+
|
18
|
+
ignorable_keywords = [/if/, /while/, /function/]
|
19
|
+
|
20
|
+
dummy_replacement_words = ["eeuuff", "whaalesskkey", "conffoolotion"]
|
21
|
+
|
22
|
+
for x in 0...single_line_comments.length
|
23
|
+
|
24
|
+
current_singleline_comment = "--single_line_comment[#{single_line_comment_counter}]"
|
25
|
+
|
26
|
+
replacement_singleline_string = single_line_comments[x].sub("#", "//")
|
27
|
+
|
28
|
+
ignorable_keywords.each_with_index do |keyword, index|
|
29
|
+
|
30
|
+
if replacement_singleline_string.index(keyword) != nil
|
31
|
+
|
32
|
+
replacement_singleline_string = replacement_singleline_string.sub(keyword.inspect[1...-1], dummy_replacement_words[index])
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
file_contents_as_string = file_contents_as_string.sub(current_singleline_comment, replacement_singleline_string)
|
39
|
+
|
40
|
+
single_line_comment_counter += 1
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
for y in 0...multiline_comments.length
|
46
|
+
|
47
|
+
current_multiline_comment = "--multiline_comment[#{multi_line_comment_counter}]"
|
48
|
+
|
49
|
+
replacement_multiline_string = multiline_comments[y].sub("=begin", "/*\n")
|
50
|
+
|
51
|
+
replacement_multiline_string = replacement_multiline_string.sub("=end", "\n*/")
|
52
|
+
|
53
|
+
ignorable_keywords.each_with_index do |keyword, index|
|
54
|
+
|
55
|
+
if replacement_multiline_string.index(keyword) != nil
|
56
|
+
|
57
|
+
replacement_multiline_string = replacement_multiline_string.sub(keyword.inspect[1...-1], dummy_replacement_words[index])
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
file_contents_as_string = file_contents_as_string.sub(current_multiline_comment, replacement_multiline_string)
|
64
|
+
|
65
|
+
multi_line_comment_counter += 1
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
file_id = open(temporary_nila_file, 'w')
|
70
|
+
|
71
|
+
file_id.write(file_contents_as_string)
|
72
|
+
|
73
|
+
file_id.close()
|
74
|
+
|
75
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
76
|
+
|
77
|
+
line_by_line_contents
|
78
|
+
|
79
|
+
end
|