nilac 0.0.4.2.9 → 0.0.4.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/nilac CHANGED
@@ -3077,24 +3077,124 @@ def compile(input_file_path, *output_file_name)
3077
3077
 
3078
3078
  block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2)
3079
3079
 
3080
- compiled_block = "(function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents} \n\n}(_i))_!;\n"
3080
+ compiled_block = "(function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents.strip} \n\n}(_i))_!;\n"
3081
3081
 
3082
3082
  return compiled_block
3083
3083
 
3084
3084
  end
3085
3085
 
3086
- modified_file_contents = input_file_contents.clone
3086
+ def extract_variable_names(input_file_contents, temporary_nila_file)
3087
+
3088
+ variables = []
3089
+
3090
+ input_file_contents = input_file_contents.collect { |element| element.gsub("==", "equalequal") }
3091
+
3092
+ input_file_contents = input_file_contents.collect { |element| element.gsub("!=", "notequal") }
3093
+
3094
+ input_file_contents = input_file_contents.collect { |element| element.gsub("+=", "plusequal") }
3095
+
3096
+ input_file_contents = input_file_contents.collect { |element| element.gsub("-=", "minusequal") }
3097
+
3098
+ input_file_contents = input_file_contents.collect { |element| element.gsub("*=", "multiequal") }
3099
+
3100
+ input_file_contents = input_file_contents.collect { |element| element.gsub("/=", "divequal") }
3101
+
3102
+ input_file_contents = input_file_contents.collect { |element| element.gsub("%=", "modequal") }
3103
+
3104
+ input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
3105
+
3106
+ javascript_regexp = /(if |while |for )/
3107
+
3108
+ for x in 0...input_file_contents.length
3109
+
3110
+ current_row = input_file_contents[x]
3111
+
3112
+ if current_row.include?("=") and current_row.index(javascript_regexp) == nil
3113
+
3114
+ current_row = current_row.rstrip + "\n"
3115
+
3116
+ current_row_split = current_row.split("=")
3117
+
3118
+ for y in 0...current_row_split.length
3119
+
3120
+ current_row_split[y] = current_row_split[y].strip
3121
+
3122
+
3123
+ end
3124
+
3125
+ if current_row_split[0].include?("[") or current_row_split[0].include?("(")
3126
+
3127
+ current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
3128
+
3129
+ end
3130
+
3131
+ variables << current_row_split[0]
3132
+
3133
+
3134
+ end
3135
+
3136
+ input_file_contents[x] = current_row
3137
+
3138
+ end
3139
+
3140
+ variables += ["_i","_j"]
3141
+
3142
+ variables = variables.flatten
3143
+
3144
+ return variables.uniq
3145
+
3146
+ end
3087
3147
 
3088
3148
  possible_times_loop = input_file_contents.reject{ |element| !element.include?(".times")}
3089
3149
 
3090
- oneliner_times_loop = possible_times_loop.reject {|element| !element.include?("{") and !element.include?("}")}
3150
+ multiline_times_loop = possible_times_loop.reject {|element| !element.include?(" do ")}
3151
+
3152
+ unless multiline_times_loop.empty?
3153
+
3154
+ multiline_times_loop.each do |starting_line|
3155
+
3156
+ index_counter = starting_counter = input_file_contents.index(starting_line)
3157
+
3158
+ line = starting_line
3159
+
3160
+ until line.strip.eql?("end")
3161
+
3162
+ index_counter += 1
3163
+
3164
+ line = input_file_contents[index_counter]
3165
+
3166
+ end
3167
+
3168
+ loop_extract = input_file_contents[starting_counter..index_counter]
3091
3169
 
3092
- #multiline_times_loop = possible_times_loop-oneliner_times_loop
3170
+ file_extract = input_file_contents[0..index_counter]
3093
3171
 
3094
- #multiline_times_loop = multiline_times_loop.reject {|element| !element.include?(" do ")}
3172
+ file_variables = extract_variable_names(file_extract,temporary_nila_file)
3173
+
3174
+ block_variables = extract_variable_names(loop_extract,temporary_nila_file)
3175
+
3176
+ var_need_of_declaration = file_variables-block_variables-["_i","_j"]
3177
+
3178
+ loop_condition, block = loop_extract.join.split(" do ")
3179
+
3180
+ block = block.split("end")[0]
3181
+
3182
+ replacement_string = "#{loop_condition.rstrip} {#{block.strip}}"
3183
+
3184
+ input_file_contents[starting_counter..index_counter] = replacement_string
3185
+
3186
+ end
3187
+
3188
+ end
3189
+
3190
+ possible_times_loop = input_file_contents.reject{ |element| !element.include?(".times")}
3191
+
3192
+ oneliner_times_loop = possible_times_loop.reject {|element| !element.include?("{") and !element.include?("}")}
3095
3193
 
3096
3194
  loop_variables = []
3097
3195
 
3196
+ modified_file_contents = input_file_contents.clone
3197
+
3098
3198
  unless oneliner_times_loop.empty?
3099
3199
 
3100
3200
  oneliner_times_loop.each do |loop|
@@ -3989,7 +4089,7 @@ def find_file_path(input_path, file_extension)
3989
4089
 
3990
4090
  end
3991
4091
 
3992
- nilac_version = "0.0.4.2.9"
4092
+ nilac_version = "0.0.4.3.0"
3993
4093
 
3994
4094
  opts = Slop.parse do
3995
4095
  on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
data/lib/nilac/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.2.9"
2
+ VERSION = "0.0.4.3.0"
3
3
  end
@@ -14,4 +14,11 @@
14
14
  console.log("Hello");
15
15
  }
16
16
 
17
+ for (_i = 0, _j = 10; _i < _j; _i += 1) {
18
+ (function(n) {
19
+ console.log("The number is " + (n));
20
+ console.log("Twice the number is " + (2*n) + "");
21
+ }(_i));
22
+ }
23
+
17
24
  }).call(this);
@@ -3,3 +3,11 @@ a = 5
3
3
  10.times { |n| puts "The number is #{a+n}" }
4
4
 
5
5
  10.times {puts "Hello"}
6
+
7
+ 10.times do |n|
8
+
9
+ puts "The number is #{n}"
10
+
11
+ puts "Twice the number is #{2*n}"
12
+
13
+ end
data/src/nilac.rb CHANGED
@@ -3075,24 +3075,124 @@ def compile(input_file_path, *output_file_name)
3075
3075
 
3076
3076
  block_parameters, block_contents = input_block[1...-1].split("|",2)[1].split("|",2)
3077
3077
 
3078
- compiled_block = "(function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents} \n\n}(_i))_!;\n"
3078
+ compiled_block = "(function(#{block_parameters.lstrip.rstrip}) {\n\n #{block_contents.strip} \n\n}(_i))_!;\n"
3079
3079
 
3080
3080
  return compiled_block
3081
3081
 
3082
3082
  end
3083
3083
 
3084
- modified_file_contents = input_file_contents.clone
3084
+ def extract_variable_names(input_file_contents, temporary_nila_file)
3085
+
3086
+ variables = []
3087
+
3088
+ input_file_contents = input_file_contents.collect { |element| element.gsub("==", "equalequal") }
3089
+
3090
+ input_file_contents = input_file_contents.collect { |element| element.gsub("!=", "notequal") }
3091
+
3092
+ input_file_contents = input_file_contents.collect { |element| element.gsub("+=", "plusequal") }
3093
+
3094
+ input_file_contents = input_file_contents.collect { |element| element.gsub("-=", "minusequal") }
3095
+
3096
+ input_file_contents = input_file_contents.collect { |element| element.gsub("*=", "multiequal") }
3097
+
3098
+ input_file_contents = input_file_contents.collect { |element| element.gsub("/=", "divequal") }
3099
+
3100
+ input_file_contents = input_file_contents.collect { |element| element.gsub("%=", "modequal") }
3101
+
3102
+ input_file_contents = input_file_contents.collect { |element| element.gsub("=~", "matchequal") }
3103
+
3104
+ javascript_regexp = /(if |while |for )/
3105
+
3106
+ for x in 0...input_file_contents.length
3107
+
3108
+ current_row = input_file_contents[x]
3109
+
3110
+ if current_row.include?("=") and current_row.index(javascript_regexp) == nil
3111
+
3112
+ current_row = current_row.rstrip + "\n"
3113
+
3114
+ current_row_split = current_row.split("=")
3115
+
3116
+ for y in 0...current_row_split.length
3117
+
3118
+ current_row_split[y] = current_row_split[y].strip
3119
+
3120
+
3121
+ end
3122
+
3123
+ if current_row_split[0].include?("[") or current_row_split[0].include?("(")
3124
+
3125
+ current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
3126
+
3127
+ end
3128
+
3129
+ variables << current_row_split[0]
3130
+
3131
+
3132
+ end
3133
+
3134
+ input_file_contents[x] = current_row
3135
+
3136
+ end
3137
+
3138
+ variables += ["_i","_j"]
3139
+
3140
+ variables = variables.flatten
3141
+
3142
+ return variables.uniq
3143
+
3144
+ end
3085
3145
 
3086
3146
  possible_times_loop = input_file_contents.reject{ |element| !element.include?(".times")}
3087
3147
 
3088
- oneliner_times_loop = possible_times_loop.reject {|element| !element.include?("{") and !element.include?("}")}
3148
+ multiline_times_loop = possible_times_loop.reject {|element| !element.include?(" do ")}
3149
+
3150
+ unless multiline_times_loop.empty?
3151
+
3152
+ multiline_times_loop.each do |starting_line|
3153
+
3154
+ index_counter = starting_counter = input_file_contents.index(starting_line)
3155
+
3156
+ line = starting_line
3157
+
3158
+ until line.strip.eql?("end")
3159
+
3160
+ index_counter += 1
3161
+
3162
+ line = input_file_contents[index_counter]
3163
+
3164
+ end
3165
+
3166
+ loop_extract = input_file_contents[starting_counter..index_counter]
3089
3167
 
3090
- #multiline_times_loop = possible_times_loop-oneliner_times_loop
3168
+ file_extract = input_file_contents[0..index_counter]
3091
3169
 
3092
- #multiline_times_loop = multiline_times_loop.reject {|element| !element.include?(" do ")}
3170
+ file_variables = extract_variable_names(file_extract,temporary_nila_file)
3171
+
3172
+ block_variables = extract_variable_names(loop_extract,temporary_nila_file)
3173
+
3174
+ var_need_of_declaration = file_variables-block_variables-["_i","_j"]
3175
+
3176
+ loop_condition, block = loop_extract.join.split(" do ")
3177
+
3178
+ block = block.split("end")[0]
3179
+
3180
+ replacement_string = "#{loop_condition.rstrip} {#{block.strip}}"
3181
+
3182
+ input_file_contents[starting_counter..index_counter] = replacement_string
3183
+
3184
+ end
3185
+
3186
+ end
3187
+
3188
+ possible_times_loop = input_file_contents.reject{ |element| !element.include?(".times")}
3189
+
3190
+ oneliner_times_loop = possible_times_loop.reject {|element| !element.include?("{") and !element.include?("}")}
3093
3191
 
3094
3192
  loop_variables = []
3095
3193
 
3194
+ modified_file_contents = input_file_contents.clone
3195
+
3096
3196
  unless oneliner_times_loop.empty?
3097
3197
 
3098
3198
  oneliner_times_loop.each do |loop|
@@ -3987,7 +4087,7 @@ def find_file_path(input_path, file_extension)
3987
4087
 
3988
4088
  end
3989
4089
 
3990
- nilac_version = "0.0.4.2.9"
4090
+ nilac_version = "0.0.4.3.0"
3991
4091
 
3992
4092
  opts = Slop.parse do
3993
4093
  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.9
4
+ version: 0.0.4.3.0
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-08-13 00:00:00.000000000 Z
12
+ date: 2013-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shark