nilac 0.0.4.3.9.7.1 → 0.0.4.3.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/Rakefile +1 -1
  4. data/cookbook/case_insensitive_compare.js +13 -0
  5. data/cookbook/case_insensitive_compare.nila +7 -0
  6. data/cookbook/compare_strings.js +13 -0
  7. data/cookbook/compare_strings.nila +7 -0
  8. data/cookbook/concat11.js +13 -0
  9. data/cookbook/concat11.nila +4 -0
  10. data/cookbook/concat12.js +23 -0
  11. data/cookbook/concat12.nila +15 -0
  12. data/cookbook/find_substring.js +15 -0
  13. data/cookbook/find_substring.nila +5 -0
  14. data/cookbook/string_interpolation.js +7 -0
  15. data/cookbook/string_interpolation.nila +1 -0
  16. data/cookbook/substring_extract.js +21 -0
  17. data/cookbook/substring_extract.nila +8 -0
  18. data/examples/my_file.js +5 -0
  19. data/examples/repl.js +0 -33
  20. data/examples/repl.nila +36 -8
  21. data/examples/temp_nila.nila +63 -0
  22. data/lib/nilac.rb +83 -68
  23. data/lib/nilac/add_line_numbers.rb +17 -0
  24. data/lib/nilac/add_semicolons.rb +13 -3
  25. data/lib/nilac/compile_arrays.rb +38 -5
  26. data/lib/nilac/compile_blocks.rb +87 -25
  27. data/lib/nilac/compile_case_statement.rb +4 -0
  28. data/lib/nilac/compile_chained_comparison.rb +35 -0
  29. data/lib/nilac/compile_comments.rb +9 -0
  30. data/lib/nilac/compile_conditional_structures.rb +26 -3
  31. data/lib/nilac/compile_custom_function_map.rb +24 -2
  32. data/lib/nilac/compile_hashes.rb +3 -1
  33. data/lib/nilac/compile_heredocs.rb +2 -0
  34. data/lib/nilac/compile_inline_for.rb +13 -0
  35. data/lib/nilac/compile_interpolated_strings.rb +184 -5
  36. data/lib/nilac/compile_lambdas.rb +24 -8
  37. data/lib/nilac/compile_new_keyword.rb +37 -0
  38. data/lib/nilac/compile_nilac_options.rb +79 -0
  39. data/lib/nilac/compile_parallel_assignment.rb +3 -1
  40. data/lib/nilac/compile_ranges.rb +60 -0
  41. data/lib/nilac/compile_require_statements.rb +4 -2
  42. data/lib/nilac/compile_ruby_math.rb +20 -0
  43. data/lib/nilac/compile_ruby_methods.rb +49 -0
  44. data/lib/nilac/compile_whitespace_delimited_functions.rb +15 -1
  45. data/lib/nilac/extract_paranthesis_contents.rb +37 -0
  46. data/lib/nilac/extract_strings.rb +63 -0
  47. data/lib/nilac/fix_javascript_traps.rb +89 -0
  48. data/lib/nilac/friendly_errors.rb +128 -0
  49. data/lib/nilac/get_variables.rb +48 -14
  50. data/lib/nilac/lexical_scoped_function_variables.rb +1 -3
  51. data/lib/nilac/optimizer.rb +13 -0
  52. data/lib/nilac/paranthesis_compactor.rb +3 -1
  53. data/lib/nilac/parse_arguments.rb +21 -7
  54. data/lib/nilac/pretty_print_javascript.rb +152 -18
  55. data/lib/nilac/pretty_print_nila.rb +17 -0
  56. data/lib/nilac/replace_comparison_operators.rb +25 -0
  57. data/lib/nilac/replace_multiline_comments.rb +4 -0
  58. data/lib/nilac/replace_singleline_comments.rb +23 -0
  59. data/lib/nilac/replace_strings.rb +3 -3
  60. data/lib/nilac/rollblocks.rb +7 -3
  61. data/lib/nilac/split_semicolon_seperated_expressions.rb +3 -17
  62. data/lib/nilac/square_brackets_compactor.rb +37 -0
  63. data/lib/nilac/version.rb +1 -1
  64. data/shark/features/arrays.feature +11 -0
  65. data/shark/features/builtin_new.feature +11 -0
  66. data/shark/features/comments.feature +11 -0
  67. data/shark/features/fix_newlines.feature +1 -1
  68. data/shark/features/variables.feature +11 -0
  69. data/shark/test_files/array_string_indexing.nila +5 -1
  70. data/shark/test_files/arrays.nila +3 -0
  71. data/shark/test_files/blocks.nila +10 -0
  72. data/shark/test_files/builtin_new.nila +3 -0
  73. data/shark/test_files/case.nila +8 -0
  74. data/shark/test_files/chained_comparison.nila +19 -0
  75. data/shark/test_files/comments.nila +15 -0
  76. data/shark/test_files/correct.js +1 -1
  77. data/shark/test_files/correct_arrays.js +7 -0
  78. data/shark/test_files/correct_blocks.js +14 -1
  79. data/shark/test_files/correct_builtin_new.js +9 -0
  80. data/shark/test_files/correct_case.js +10 -2
  81. data/shark/test_files/correct_comments.js +19 -0
  82. data/shark/test_files/correct_conditional_assignment.js +1 -1
  83. data/shark/test_files/correct_default_parameters.js +1 -1
  84. data/shark/test_files/correct_for.js +1 -1
  85. data/shark/test_files/correct_hashes.js +1 -1
  86. data/shark/test_files/correct_heredoc.js +6 -2
  87. data/shark/test_files/correct_if_then_else.js +5 -1
  88. data/shark/test_files/correct_indexing.js +7 -3
  89. data/shark/test_files/correct_initialization.js +1 -1
  90. data/shark/test_files/correct_javascript_methods.js +1 -1
  91. data/shark/test_files/correct_loop.js +1 -1
  92. data/shark/test_files/correct_monkey_patch.js +1 -1
  93. data/shark/test_files/correct_multiline_array.js +1 -1
  94. data/shark/test_files/correct_multiple_return.js +1 -1
  95. data/shark/test_files/correct_numbers.js +1 -1
  96. data/shark/test_files/correct_operators.js +1 -1
  97. data/shark/test_files/correct_regular_if.js +1 -1
  98. data/shark/test_files/correct_regular_while.js +1 -1
  99. data/shark/test_files/correct_required_module.js +1 -1
  100. data/shark/test_files/correct_return.js +1 -1
  101. data/shark/test_files/correct_ruby_methods.js +1 -1
  102. data/shark/test_files/correct_single_return.js +1 -1
  103. data/shark/test_files/{perfect.js → correct_spacing.js} +1 -1
  104. data/shark/test_files/correct_splats.js +1 -2
  105. data/shark/test_files/correct_string_interpolation.js +8 -2
  106. data/shark/test_files/correct_string_operators.js +1 -1
  107. data/shark/test_files/correct_times.js +1 -1
  108. data/shark/test_files/correct_unless_until.js +2 -4
  109. data/shark/test_files/correct_variables.js +13 -0
  110. data/shark/test_files/correct_whitespace_delimiter.js +1 -1
  111. data/shark/test_files/existential_operators.nila +7 -0
  112. data/shark/test_files/expression.nila +6 -0
  113. data/shark/test_files/global_variables_client.nila +5 -0
  114. data/shark/test_files/heredoc.nila +11 -1
  115. data/shark/test_files/if_then_else.nila +3 -1
  116. data/shark/test_files/inline_for.nila +5 -0
  117. data/shark/test_files/no_return.js +11 -0
  118. data/shark/test_files/parseInt_trap.nila +3 -0
  119. data/shark/test_files/single_return.js +11 -0
  120. data/shark/test_files/string_interpolation.nila +7 -1
  121. data/shark/test_files/variables.nila +7 -0
  122. metadata +54 -3
@@ -0,0 +1,17 @@
1
+ # This method will be used to pretty print the input nila source code.
2
+
3
+ # Why is pretty printing important?
4
+
5
+ # 1. The source code can be easily checked for errors if it correctly formatted
6
+ # 2. It will be make the code more readable.
7
+
8
+ # The work began on this module on June 1, 2014 and it might take a really long time
9
+ # for the work to be completed.
10
+
11
+ # All the formatting done this method is based on the Ruby Style Guide for all the Ruby derived features
12
+ # Python Style Guide for Python derived features and Scala Style Guide for Scala derived features.
13
+
14
+ def pretty_print_nila(input_file_contents)
15
+
16
+
17
+ end
@@ -0,0 +1,25 @@
1
+ def replace_comparison_operators(input_string)
2
+
3
+ element = input_string.gsub("equalequal","==")
4
+
5
+ element = element.gsub("notequal", "!=")
6
+
7
+ element = element.gsub("plusequal","+=")
8
+
9
+ element = element.gsub("minusequal","-=")
10
+
11
+ element = element.gsub("multiequal","*=")
12
+
13
+ element = element.gsub("divequal","/=")
14
+
15
+ element = element.gsub("modequal","%=")
16
+
17
+ element = element.gsub("matchequal","=~")
18
+
19
+ element = element.gsub("greatequal",">=")
20
+
21
+ input_string = element.gsub("lessyequal","<=")
22
+
23
+ return input_string
24
+
25
+ end
@@ -32,6 +32,10 @@
32
32
 
33
33
  multiline_comments = []
34
34
 
35
+ input_file_contents = input_file_contents.collect {|element| element.gsub(/=\s+begin\n/,"=begin")}
36
+
37
+ input_file_contents = input_file_contents.collect {|element| element.gsub(/=\s+end\n/,"=end")}
38
+
35
39
  file_contents_as_string = input_file_contents.join
36
40
 
37
41
  modified_file_contents = file_contents_as_string.dup
@@ -1,4 +1,5 @@
1
1
  require_relative 'replace_strings'
2
+ require_relative 'extract_strings'
2
3
 
3
4
  def replace_singleline_comments(input_file_contents)
4
5
 
@@ -16,14 +17,36 @@
16
17
 
17
18
  current_row = modified_file_contents[x]
18
19
 
20
+ current_row_strings = extract_strings(current_row)
21
+
22
+ current_row = replace_strings(current_row)
23
+
19
24
  comment_start = current_row.index("#")
20
25
 
21
26
  if current_row[comment_start+1] != "{"
22
27
 
23
28
  comment = current_row[comment_start..-1]
24
29
 
30
+ if comment.include?("--repstring")
31
+
32
+ comment,string_id = comment.split("--repstring")
33
+
34
+ comment = comment + current_row_strings[string_id.to_i]
35
+
36
+ end
37
+
25
38
  single_line_comments << comment
26
39
 
40
+ current_row_matches = current_row.scan(/--repstring\d+/).to_a
41
+
42
+ current_row_matches.each_with_index do |element,index|
43
+
44
+ junk,string_id = element.split("--repstring")
45
+
46
+ current_row = current_row.gsub("--repstring#{string_id}",current_row_strings[index])
47
+
48
+ end
49
+
27
50
  current_row = current_row.gsub(comment, "--single_line_comment[#{singleline_comment_counter}]\n\n")
28
51
 
29
52
  singleline_comment_counter += 1
@@ -29,11 +29,11 @@ def replace_strings(input_string)
29
29
 
30
30
  while input_string.include?("\"")
31
31
 
32
- string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
32
+ string_extract = input_string[input_string.index("\"")..input_string.index("\"",input_string.index("\"")+1)]
33
33
 
34
- input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
34
+ input_string = input_string.sub(string_extract,"--repstring#{string_counter}")
35
35
 
36
- string_counter += 1
36
+ string_counter += 1
37
37
 
38
38
  end
39
39
 
@@ -18,6 +18,8 @@ def extract_blocks(statement_indexes, input_file_contents,options = [])
18
18
 
19
19
  controlregexp = /(if |while |def | do |class )/ if options.length.eql?(2)
20
20
 
21
+ controlregexp = /(if |Euuf |while |for |def | do )/ if options.length.eql?(4)
22
+
21
23
  controlregexp = /(Euuf |while |for | do |function )/ if options.length.eql?(5)
22
24
 
23
25
  endexpr = "end" if options.empty?
@@ -26,6 +28,8 @@ def extract_blocks(statement_indexes, input_file_contents,options = [])
26
28
 
27
29
  endexpr = "end" if options.length.eql?(2)
28
30
 
31
+ endexpr = "end" if options.length.eql?(4)
32
+
29
33
  endexpr = "}" if options.length.eql?(5)
30
34
 
31
35
  for x in 0...statement_indexes.length-1
@@ -54,7 +58,7 @@ def extract_blocks(statement_indexes, input_file_contents,options = [])
54
58
 
55
59
  current_block.each_with_index do |line, index|
56
60
 
57
- if line.strip.eql? endexpr
61
+ if replace_strings(line).strip.eql? endexpr
58
62
 
59
63
  end_counter += 1
60
64
 
@@ -74,7 +78,7 @@ def extract_blocks(statement_indexes, input_file_contents,options = [])
74
78
 
75
79
  array_extract.each_with_index do |line|
76
80
 
77
- break if (line.lstrip.index(controlregexp) != nil)
81
+ break if (replace_strings(line).lstrip.index(controlregexp) != nil)
78
82
 
79
83
  index_counter += 1
80
84
 
@@ -98,7 +102,7 @@ def extract_blocks(statement_indexes, input_file_contents,options = [])
98
102
 
99
103
  current_block.each_with_index do |line, index|
100
104
 
101
- if line.strip.eql? endexpr
105
+ if replace_strings(line).strip.eql? endexpr
102
106
 
103
107
  end_counter += 1
104
108
 
@@ -1,26 +1,12 @@
1
+ require_relative 'replace_strings'
2
+
1
3
  def split_semicolon_seperated_expressions(input_file_contents)
2
4
 
3
5
  modified_file_contents = input_file_contents.dup
4
6
 
5
7
  input_file_contents.each_with_index do |line, index|
6
8
 
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
9
+ modified_line = replace_strings(line)
24
10
 
25
11
  if modified_line.include?(";")
26
12
 
@@ -0,0 +1,37 @@
1
+ def compact_square_brackets(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
@@ -1,3 +1,3 @@
1
1
  module Nilac
2
- VERSION = "0.0.4.3.9.7.1"
2
+ VERSION = "0.0.4.3.9.8"
3
3
  end
@@ -0,0 +1,11 @@
1
+ Feature: This feature bring Ruby's Different Array features to Nila
2
+ Scenario: Input file with multiple Ruby style arrays
3
+ Given the input file "arrays.nila"
4
+ When the ~compiler is run
5
+ The output file must be "arrays.js"
6
+ The output file must equal "correct_arrays.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => lib/nilac.rb
11
+ :v $cliusage => ruby :v --test --compile $file
@@ -0,0 +1,11 @@
1
+ Feature: This feature bring Ruby's builtin class's new method to Javascript
2
+ Scenario: Input file with multiple built class intialization by calling new method
3
+ Given the input file "builtin_new.nila"
4
+ When the ~compiler is run
5
+ The output file must be "builtin_new.js"
6
+ The output file must equal "correct_builtin_new.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => lib/nilac.rb
11
+ :v $cliusage => ruby :v --test --compile $file
@@ -0,0 +1,11 @@
1
+ Feature: This feature bring Ruby's style comments to Nila
2
+ Scenario: Input file with multiple versions of comments
3
+ Given the input file "comments.nila"
4
+ When the ~compiler is run
5
+ The output file must be "comments.js"
6
+ The output file must equal "correct_comments.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => lib/nilac.rb
11
+ :v $cliusage => ruby :v --test --compile $file
@@ -5,7 +5,7 @@ which will make it fail in a JSLint test.
5
5
  Given the input file "erratic.nila"
6
6
  When the ~compiler is run
7
7
  The output file must be "erratic.js"
8
- The output file must equal "perfect.js"
8
+ The output file must equal "correct_spacing.js"
9
9
 
10
10
  Configurations:
11
11
 
@@ -0,0 +1,11 @@
1
+ Feature: This feature brings various Ruby variable declaration features to Nila
2
+ Scenario: Input file with different variable declarations
3
+ Given the input file "variables.nila"
4
+ When the ~compiler is run
5
+ The output file must be "variables.js"
6
+ The output file must equal "correct_variables.js"
7
+
8
+ Configurations:
9
+
10
+ ~compiler => lib/nilac.rb
11
+ :v $cliusage => ruby :v --test --compile $file
@@ -2,8 +2,12 @@ numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
2
2
 
3
3
  start = numbers[0..2]
4
4
 
5
+ start = numbers[0 to 2]
6
+
5
7
  middle = numbers[3...6]
6
8
 
9
+ middle = numbers[3 until 6]
10
+
7
11
  last = numbers[6..last]
8
12
 
9
13
  copy = numbers.dup
@@ -18,4 +22,4 @@ second_name = name[9..last]
18
22
 
19
23
  name_copy = name.dup
20
24
 
21
- name_copy = name[..]
25
+ name_copy = name[..]
@@ -0,0 +1,3 @@
1
+ puts %w{foo bar baz}
2
+
3
+ puts %w(foo bar baz)
@@ -15,4 +15,14 @@ end
15
15
 
16
16
  process.argv.forEach do |val,index,array|
17
17
  commandline_args << val
18
+ end
19
+
20
+ read.on 'close', do
21
+ stream.end()
22
+ fs.unlink file_name, do |err|
23
+ puts "REPL Session Successfully concluded!"
24
+ end
25
+ puts "\n\nThanks for trying out Nila!\n"
26
+ puts "You can learn more about Nila at http://adhithyan15.github.io/nila\n"
27
+ process.exit(0)
18
28
  end
@@ -0,0 +1,3 @@
1
+ a = String.new("Hello World")
2
+
3
+ a.upcase
@@ -20,4 +20,12 @@ when 2
20
20
  puts 'Your input was 2'
21
21
  else
22
22
  puts "Your input was greater than 2"
23
+ end
24
+
25
+ input_name = prompt "What is your name?"
26
+
27
+ if input_name.downcase == "Jim".downcase
28
+ alert "Hey Jim!"
29
+ else
30
+ alert "Hey #{input_name}"
23
31
  end
@@ -0,0 +1,19 @@
1
+ x = 8
2
+
3
+ if x < 5
4
+
5
+ puts "X is less than 5"
6
+
7
+ end
8
+
9
+ if 5 < x < 10
10
+
11
+ puts "X is between 5 and 10"
12
+
13
+ end
14
+
15
+ if x > 10
16
+
17
+ puts "X is greater than 10"
18
+
19
+ end
@@ -0,0 +1,15 @@
1
+ = begin
2
+ This code was written by Adhithya Rajasekaran
3
+ This is licensed under the MIT License
4
+ =end
5
+
6
+ # square method takes a number and
7
+ # returns the square of the number
8
+
9
+ def square(num)
10
+
11
+ num*num
12
+
13
+ end
14
+
15
+ square(5)
@@ -1,5 +1,5 @@
1
1
  //Written using Nila. Visit http://adhithyan15.github.io/nila
2
- (function() {
2
+ (function () {
3
3
  console.log("Hello World!");
4
4
 
5
5
  }).call(this);
@@ -0,0 +1,7 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function () {
3
+ console.log(["foo", "bar", "baz"]);
4
+
5
+ console.log(["foo", "bar", "baz"]);
6
+
7
+ }).call(this);
@@ -1,5 +1,5 @@
1
1
  //Written using Nila. Visit http://adhithyan15.github.io/nila
2
- (function() {
2
+ (function () {
3
3
  var read;
4
4
 
5
5
  read = rl.on('line',function(line) {
@@ -22,4 +22,17 @@
22
22
  commandline_args.push(val);
23
23
  });
24
24
 
25
+ read.on('close',function() {
26
+ stream.end();
27
+ fs.unlink(file_name,function(err) {
28
+ if (err) {
29
+ console.log(err);
30
+ }
31
+ console.log("REPL Session Successfully concluded!");
32
+ });
33
+ console.log("\n\nThanks for trying out Nila!\n")
34
+ console.log("You can learn more about Nila at http://adhithyan15.github.io/nila\n");
35
+ process.exit(0);
36
+ });
37
+
25
38
  }).call(this);
@@ -0,0 +1,9 @@
1
+ //Written using Nila. Visit http://adhithyan15.github.io/nila
2
+ (function () {
3
+ var a;
4
+
5
+ a = new String("Hello World");
6
+
7
+ a.toUpperCase();
8
+
9
+ }).call(this);
@@ -1,6 +1,6 @@
1
1
  //Written using Nila. Visit http://adhithyan15.github.io/nila
2
- (function() {
3
- var _i, _j, grade, grades, num;
2
+ (function () {
3
+ var _i, _j, grade, grades, input_name, num;
4
4
 
5
5
  grades = ["A", "B", "A", "C", "D", "F"];
6
6
 
@@ -32,4 +32,12 @@
32
32
  console.log("Your input was greater than 2");
33
33
  }
34
34
 
35
+ input_name = prompt("What is your name?");
36
+
37
+ if (input_name.toLowerCase() === "Jim".toLowerCase()) {
38
+ alert("Hey Jim!");
39
+ } else {
40
+ alert("Hey " + (input_name));
41
+ }
42
+
35
43
  }).call(this);