nilac 0.0.4.3.9.7.1 → 0.0.4.3.9.8
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 +4 -4
- data/.gitignore +1 -2
- data/Rakefile +1 -1
- data/cookbook/case_insensitive_compare.js +13 -0
- data/cookbook/case_insensitive_compare.nila +7 -0
- data/cookbook/compare_strings.js +13 -0
- data/cookbook/compare_strings.nila +7 -0
- data/cookbook/concat11.js +13 -0
- data/cookbook/concat11.nila +4 -0
- data/cookbook/concat12.js +23 -0
- data/cookbook/concat12.nila +15 -0
- data/cookbook/find_substring.js +15 -0
- data/cookbook/find_substring.nila +5 -0
- data/cookbook/string_interpolation.js +7 -0
- data/cookbook/string_interpolation.nila +1 -0
- data/cookbook/substring_extract.js +21 -0
- data/cookbook/substring_extract.nila +8 -0
- data/examples/my_file.js +5 -0
- data/examples/repl.js +0 -33
- data/examples/repl.nila +36 -8
- data/examples/temp_nila.nila +63 -0
- data/lib/nilac.rb +83 -68
- data/lib/nilac/add_line_numbers.rb +17 -0
- data/lib/nilac/add_semicolons.rb +13 -3
- data/lib/nilac/compile_arrays.rb +38 -5
- data/lib/nilac/compile_blocks.rb +87 -25
- data/lib/nilac/compile_case_statement.rb +4 -0
- data/lib/nilac/compile_chained_comparison.rb +35 -0
- data/lib/nilac/compile_comments.rb +9 -0
- data/lib/nilac/compile_conditional_structures.rb +26 -3
- data/lib/nilac/compile_custom_function_map.rb +24 -2
- data/lib/nilac/compile_hashes.rb +3 -1
- data/lib/nilac/compile_heredocs.rb +2 -0
- data/lib/nilac/compile_inline_for.rb +13 -0
- data/lib/nilac/compile_interpolated_strings.rb +184 -5
- data/lib/nilac/compile_lambdas.rb +24 -8
- data/lib/nilac/compile_new_keyword.rb +37 -0
- data/lib/nilac/compile_nilac_options.rb +79 -0
- data/lib/nilac/compile_parallel_assignment.rb +3 -1
- data/lib/nilac/compile_ranges.rb +60 -0
- data/lib/nilac/compile_require_statements.rb +4 -2
- data/lib/nilac/compile_ruby_math.rb +20 -0
- data/lib/nilac/compile_ruby_methods.rb +49 -0
- data/lib/nilac/compile_whitespace_delimited_functions.rb +15 -1
- data/lib/nilac/extract_paranthesis_contents.rb +37 -0
- data/lib/nilac/extract_strings.rb +63 -0
- data/lib/nilac/fix_javascript_traps.rb +89 -0
- data/lib/nilac/friendly_errors.rb +128 -0
- data/lib/nilac/get_variables.rb +48 -14
- data/lib/nilac/lexical_scoped_function_variables.rb +1 -3
- data/lib/nilac/optimizer.rb +13 -0
- data/lib/nilac/paranthesis_compactor.rb +3 -1
- data/lib/nilac/parse_arguments.rb +21 -7
- data/lib/nilac/pretty_print_javascript.rb +152 -18
- data/lib/nilac/pretty_print_nila.rb +17 -0
- data/lib/nilac/replace_comparison_operators.rb +25 -0
- data/lib/nilac/replace_multiline_comments.rb +4 -0
- data/lib/nilac/replace_singleline_comments.rb +23 -0
- data/lib/nilac/replace_strings.rb +3 -3
- data/lib/nilac/rollblocks.rb +7 -3
- data/lib/nilac/split_semicolon_seperated_expressions.rb +3 -17
- data/lib/nilac/square_brackets_compactor.rb +37 -0
- data/lib/nilac/version.rb +1 -1
- data/shark/features/arrays.feature +11 -0
- data/shark/features/builtin_new.feature +11 -0
- data/shark/features/comments.feature +11 -0
- data/shark/features/fix_newlines.feature +1 -1
- data/shark/features/variables.feature +11 -0
- data/shark/test_files/array_string_indexing.nila +5 -1
- data/shark/test_files/arrays.nila +3 -0
- data/shark/test_files/blocks.nila +10 -0
- data/shark/test_files/builtin_new.nila +3 -0
- data/shark/test_files/case.nila +8 -0
- data/shark/test_files/chained_comparison.nila +19 -0
- data/shark/test_files/comments.nila +15 -0
- data/shark/test_files/correct.js +1 -1
- data/shark/test_files/correct_arrays.js +7 -0
- data/shark/test_files/correct_blocks.js +14 -1
- data/shark/test_files/correct_builtin_new.js +9 -0
- data/shark/test_files/correct_case.js +10 -2
- data/shark/test_files/correct_comments.js +19 -0
- data/shark/test_files/correct_conditional_assignment.js +1 -1
- data/shark/test_files/correct_default_parameters.js +1 -1
- data/shark/test_files/correct_for.js +1 -1
- data/shark/test_files/correct_hashes.js +1 -1
- data/shark/test_files/correct_heredoc.js +6 -2
- data/shark/test_files/correct_if_then_else.js +5 -1
- data/shark/test_files/correct_indexing.js +7 -3
- data/shark/test_files/correct_initialization.js +1 -1
- data/shark/test_files/correct_javascript_methods.js +1 -1
- data/shark/test_files/correct_loop.js +1 -1
- data/shark/test_files/correct_monkey_patch.js +1 -1
- data/shark/test_files/correct_multiline_array.js +1 -1
- data/shark/test_files/correct_multiple_return.js +1 -1
- data/shark/test_files/correct_numbers.js +1 -1
- data/shark/test_files/correct_operators.js +1 -1
- data/shark/test_files/correct_regular_if.js +1 -1
- data/shark/test_files/correct_regular_while.js +1 -1
- data/shark/test_files/correct_required_module.js +1 -1
- data/shark/test_files/correct_return.js +1 -1
- data/shark/test_files/correct_ruby_methods.js +1 -1
- data/shark/test_files/correct_single_return.js +1 -1
- data/shark/test_files/{perfect.js → correct_spacing.js} +1 -1
- data/shark/test_files/correct_splats.js +1 -2
- data/shark/test_files/correct_string_interpolation.js +8 -2
- data/shark/test_files/correct_string_operators.js +1 -1
- data/shark/test_files/correct_times.js +1 -1
- data/shark/test_files/correct_unless_until.js +2 -4
- data/shark/test_files/correct_variables.js +13 -0
- data/shark/test_files/correct_whitespace_delimiter.js +1 -1
- data/shark/test_files/existential_operators.nila +7 -0
- data/shark/test_files/expression.nila +6 -0
- data/shark/test_files/global_variables_client.nila +5 -0
- data/shark/test_files/heredoc.nila +11 -1
- data/shark/test_files/if_then_else.nila +3 -1
- data/shark/test_files/inline_for.nila +5 -0
- data/shark/test_files/no_return.js +11 -0
- data/shark/test_files/parseInt_trap.nila +3 -0
- data/shark/test_files/single_return.js +11 -0
- data/shark/test_files/string_interpolation.nila +7 -1
- data/shark/test_files/variables.nila +7 -0
- metadata +54 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 44907f99e8bd2ae65cc6c5e10bfbfde0ffa8d828
         | 
| 4 | 
            +
              data.tar.gz: c7e9887180c1b8c37dea78842673d4c4ab1f6f62
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 29cd85597e4398193eb8dd6dcd926f7c39237224346b5d2536dbbec05969b451c205475311fd72e7920036bf6344795f5684ede626b96367d1641776040051bc
         | 
| 7 | 
            +
              data.tar.gz: 26b30c2f2123978596c05702514280717007b5c6f723030501a365c0e600a21e8f9eb1b877d89ffb8ced927d232444944d50970cd7b8c10ab4053ac6e5c5d351
         | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    | @@ -1,2 +1,2 @@ | |
| 1 1 | 
             
            #!/usr/bin/env rake
         | 
| 2 | 
            -
            require "bundler/gem_tasks"
         | 
| 2 | 
            +
            require "bundler/gem_tasks"
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            //Written using Nila. Visit http://adhithyan15.github.io/nila
         | 
| 2 | 
            +
            (function () {
         | 
| 3 | 
            +
              var input_name;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              input_name = prompt("What is your name?");
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              if (input_name.toLowerCase() === "Jim".toLowerCase()) {
         | 
| 8 | 
            +
                alert("Hey Jim!");
         | 
| 9 | 
            +
              } else {
         | 
| 10 | 
            +
                alert("Hey " + (input_name));
         | 
| 11 | 
            +
              }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            }).call(this);
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            //Written using Nila. Visit http://adhithyan15.github.io/nila
         | 
| 2 | 
            +
            (function() {
         | 
| 3 | 
            +
              var input_name;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              input_name = prompt("What is your name?");
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              if (input_name === "Jim") {
         | 
| 8 | 
            +
                alert("Hey Jim!");
         | 
| 9 | 
            +
              } else {
         | 
| 10 | 
            +
                alert("Hey " + (input_name));
         | 
| 11 | 
            +
              }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            }).call(this);
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            //Written using Nila. Visit http://adhithyan15.github.io/nila
         | 
| 2 | 
            +
            (function() {
         | 
| 3 | 
            +
              var string1, string2, string3;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              string1 = "This is a";
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              string2 = "test";
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              string3 = string1 + string2;
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              console.log(string3); //=> This is a test
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            }).call(this);
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            //Written using Nila. Visit http://adhithyan15.github.io/nila
         | 
| 2 | 
            +
            (function() {
         | 
| 3 | 
            +
              var bool1, string1, string2;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              // Javascript approach
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              string1 = "Trust Jim: ";
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              bool1 = true;
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              string2 = string1 + bool1;
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              console.log(string2);
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              // Ruby approach
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              bool1 = true;
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              string2 = "Trust Jim: " + (bool1);
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              console.log(string2);
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            }).call(this);
         | 
| @@ -0,0 +1,15 @@ | |
| 1 | 
            +
            //Written using Nila. Visit http://adhithyan15.github.io/nila
         | 
| 2 | 
            +
            (function () {
         | 
| 3 | 
            +
              var find_string, main_string;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              main_string = "This is a test string";
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              find_string = "test";
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              if (main_string.indexOf(find_string) !== -1){
         | 
| 10 | 
            +
                console.log("Substring found!");
         | 
| 11 | 
            +
              }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              //=> Substring found!
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            }).call(this);
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            puts "I've set x to #{x = 5; x += 1}." 
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            //Written using Nila. Visit http://adhithyan15.github.io/nila
         | 
| 2 | 
            +
            (function() {
         | 
| 3 | 
            +
              var fruits_i_like, fruits_list, start;
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              fruits_i_like = "List of fruits I like:apples, oranges, pineapple and mango";
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              start = fruits_i_like.indexOf(":");
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              // Indexing Range Method
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              fruits_list = fruits_i_like.slice(start+1);
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              console.log(fruits_list);
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              // Slicing Method
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              fruits_list = fruits_i_like.slice(start+1);
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              console.log(fruits_list);
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            }).call(this);
         | 
| @@ -0,0 +1,8 @@ | |
| 1 | 
            +
            fruits_i_like = "List of fruits I like:apples, oranges, pineapple and mango"
         | 
| 2 | 
            +
            start = fruits_i_like.index(":")
         | 
| 3 | 
            +
            # Indexing Range Method
         | 
| 4 | 
            +
            fruits_list = fruits_i_like[start+1..last]
         | 
| 5 | 
            +
            puts fruits_list
         | 
| 6 | 
            +
            # Slicing Method
         | 
| 7 | 
            +
            fruits_list = fruits_i_like.slice(start+1,last)
         | 
| 8 | 
            +
            puts fruits_list
         | 
    
        data/examples/my_file.js
    ADDED
    
    
    
        data/examples/repl.js
    CHANGED
    
    | @@ -1,33 +0,0 @@ | |
| 1 | 
            -
            //Written using Nila. Visit http://adhithyan15.github.io/nila
         | 
| 2 | 
            -
            (function() {
         | 
| 3 | 
            -
              var read, readline, rl, stream;
         | 
| 4 | 
            -
             | 
| 5 | 
            -
              // This is a small REPL for Nila to test out nila code and do bug fixes
         | 
| 6 | 
            -
             | 
| 7 | 
            -
              readline = require('readline');
         | 
| 8 | 
            -
             | 
| 9 | 
            -
              require('fs');
         | 
| 10 | 
            -
             | 
| 11 | 
            -
              stream = fs.createWriteStream("my_file.nila");
         | 
| 12 | 
            -
             | 
| 13 | 
            -
              stream.once('open',function(fd) {
         | 
| 14 | 
            -
                stream.write("Testing!\n");
         | 
| 15 | 
            -
                stream.;
         | 
| 16 | 
            -
              });
         | 
| 17 | 
            -
             | 
| 18 | 
            -
              rl = readline.createInterface(process.stdin, process.stdout);
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              rl.setPrompt('nila> ');
         | 
| 21 | 
            -
             | 
| 22 | 
            -
              rl.prompt();
         | 
| 23 | 
            -
             | 
| 24 | 
            -
              read = rl.on('line',function(line) {
         | 
| 25 | 
            -
                rl.prompt();
         | 
| 26 | 
            -
              });
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              read.on('close',function() {
         | 
| 29 | 
            -
                console.log("Have a great day!");
         | 
| 30 | 
            -
                process.exit(0);
         | 
| 31 | 
            -
              });
         | 
| 32 | 
            -
             | 
| 33 | 
            -
            }).call(this);
         | 
    
        data/examples/repl.nila
    CHANGED
    
    | @@ -4,14 +4,20 @@ require 'readline' | |
| 4 4 |  | 
| 5 5 | 
             
            require 'fs'
         | 
| 6 6 |  | 
| 7 | 
            -
             | 
| 7 | 
            +
            require 'sys'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            exec = require('child_process').exec
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            file_name = "#{__dirname}/my_file.nila"
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            output_file_name = "#{__dirname}/my_file.js"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            stream = fs.createWriteStream(file_name)
         | 
| 8 16 |  | 
| 9 17 | 
             
            stream.once 'open', do |fd|
         | 
| 10 18 |  | 
| 11 | 
            -
             stream.write(" | 
| 19 | 
            +
             stream.write("# REPL Session #{new Date().to_s}\n\n")
         | 
| 12 20 |  | 
| 13 | 
            -
             stream.end()
         | 
| 14 | 
            -
             | 
| 15 21 | 
             
            end
         | 
| 16 22 |  | 
| 17 23 | 
             
            rl = readline.createInterface(process.stdin, process.stdout)
         | 
| @@ -21,11 +27,33 @@ rl.setPrompt('nila> ') | |
| 21 27 | 
             
            rl.prompt()
         | 
| 22 28 |  | 
| 23 29 | 
             
            read = rl.on 'line', do |line|
         | 
| 24 | 
            -
              
         | 
| 30 | 
            +
              stream.write("puts (#{line})\n\n")
         | 
| 31 | 
            +
              exec 'nilac -c my_file.nila', do |error,stdout,stderr|
         | 
| 32 | 
            +
                if error != nil
         | 
| 33 | 
            +
                  sys.print("error: #{error}")
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
                if stdout.strip == "Compilation is successful!"
         | 
| 36 | 
            +
                  exec output_file_name, do |error,stdout,stderr|
         | 
| 37 | 
            +
                    if error != nil
         | 
| 38 | 
            +
                      sys.print(error + "\n")
         | 
| 39 | 
            +
                    else
         | 
| 40 | 
            +
                      sys.print(stdout + "\n")
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 25 45 | 
             
              rl.prompt()
         | 
| 26 46 | 
             
            end
         | 
| 27 47 |  | 
| 28 | 
            -
            read.on 'close', do
         | 
| 29 | 
            -
               | 
| 48 | 
            +
            read.on 'close', do 
         | 
| 49 | 
            +
              stream.end()
         | 
| 50 | 
            +
              fs.unlink file_name, do |err|
         | 
| 51 | 
            +
                puts "Nila file couldn't be deleted!"
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
              fs.unlink output_file_name, do |err|
         | 
| 54 | 
            +
                puts "Output js file couldn't be deleted!"
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
              puts "\n\nThanks for trying out Nila!\n"
         | 
| 57 | 
            +
              puts "You can learn more about Nila at http://adhithyan15.github.io/nila\n"
         | 
| 30 58 | 
             
              process.exit(0)
         | 
| 31 | 
            -
            end
         | 
| 59 | 
            +
            end
         | 
| @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            --single_line_comment[1]
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             | 
| 4 | 
            +
            readline = require 'readline'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            fs = require 'fs'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            sys = require 'sys'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            exec = require('child_process').exec
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            file_name = "" + (__dirname) + "/my_file.nila"
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            output_file_name = "" + (__dirname) + "/my_file.js"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            stream = fs.createWriteStream(file_name)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            stream.once 'open',  do  |fd|
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             stream.write("# REPL Session " + (new Date().to_s) + "\n\n")
         | 
| 21 | 
            +
             
         | 
| 22 | 
            +
            end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            rl = readline.createInterface(process.stdin, process.stdout)
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            rl.setPrompt('nila> ')
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            rl.prompt()
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            read = rl.on 'line',  do  |line|
         | 
| 31 | 
            +
              stream.write("puts (" + (line) + ")\n\n")
         | 
| 32 | 
            +
              exec 'nilac -c my_file.nila',  do  |error,stdout,stderr|
         | 
| 33 | 
            +
            Euuf (error != nil) {
         | 
| 34 | 
            +
                  sys.print("error: " + (error))
         | 
| 35 | 
            +
            }#@$
         | 
| 36 | 
            +
            		
         | 
| 37 | 
            +
            Euuf (stdout.strip == "Compilation is successful!") {
         | 
| 38 | 
            +
                  exec output_file_name,  do  |error,stdout,stderr|
         | 
| 39 | 
            +
            Euuf (error != nil) {
         | 
| 40 | 
            +
                      sys.print(error + "\n")
         | 
| 41 | 
            +
            } else {
         | 
| 42 | 
            +
                      sys.print(stdout + "\n")
         | 
| 43 | 
            +
            }#@$
         | 
| 44 | 
            +
            		
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                }#@$
         | 
| 47 | 
            +
            		
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
              rl.prompt()
         | 
| 50 | 
            +
            end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            read.on 'close',  do  
         | 
| 53 | 
            +
              stream.enttttttttttt()
         | 
| 54 | 
            +
              fs.unlink file_name,  do  |err|
         | 
| 55 | 
            +
                puts "Nila file couldn't be deleted!"
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
              fs.unlink output_file_name,  do  |err|
         | 
| 58 | 
            +
                puts "Output js file couldn't be deleted!"
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
              puts "\n\nThanks for trying out Nila!\n"
         | 
| 61 | 
            +
              puts "You can learn more about Nila at http://adhithyan15.github.io/nila\n"
         | 
| 62 | 
            +
              process.exit(0)
         | 
| 63 | 
            +
            end
         | 
    
        data/lib/nilac.rb
    CHANGED
    
    | @@ -3,6 +3,8 @@ | |
| 3 3 |  | 
| 4 4 | 
             
            #Nila and Nilac are being crafted by Adhithya Rajasekaran and Sri Madhavi Rajasekaran
         | 
| 5 5 |  | 
| 6 | 
            +
            #All the code in this project is licensed under the MIT License
         | 
| 7 | 
            +
             | 
| 6 8 | 
             
            $LOAD_PATH << File.dirname(__FILE__)
         | 
| 7 9 |  | 
| 8 10 | 
             
            module Nilac
         | 
| @@ -10,6 +12,7 @@ module Nilac | |
| 10 12 | 
             
              require 'nilac/version'
         | 
| 11 13 | 
             
              require 'fileutils'
         | 
| 12 14 | 
             
              require 'nilac/read_file_line_by_line'
         | 
| 15 | 
            +
              require 'nilac/add_line_numbers'
         | 
| 13 16 | 
             
              require 'nilac/find_file_name'
         | 
| 14 17 | 
             
              require 'nilac/find_file_path'
         | 
| 15 18 | 
             
              require 'nilac/extract_parsable_file'
         | 
| @@ -47,6 +50,13 @@ module Nilac | |
| 47 50 | 
             
              require 'nilac/parse_arguments'
         | 
| 48 51 | 
             
              require 'nilac/friendly_errors'
         | 
| 49 52 | 
             
              require 'nilac/compile_monkey_patching'
         | 
| 53 | 
            +
              require 'nilac/compile_ranges'
         | 
| 54 | 
            +
              require 'nilac/compile_chained_comparison'
         | 
| 55 | 
            +
              require 'nilac/compile_new_keyword'
         | 
| 56 | 
            +
              require 'nilac/compile_inline_for'
         | 
| 57 | 
            +
              require 'nilac/fix_javascript_traps'
         | 
| 58 | 
            +
              require 'nilac/compile_ruby_math'
         | 
| 59 | 
            +
              require 'nilac/compile_nilac_options'
         | 
| 50 60 |  | 
| 51 61 | 
             
              class NilaCompiler
         | 
| 52 62 |  | 
| @@ -58,7 +68,7 @@ module Nilac | |
| 58 68 |  | 
| 59 69 | 
             
                end
         | 
| 60 70 |  | 
| 61 | 
            -
                def compile(input_file_path, options =  | 
| 71 | 
            +
                def compile(input_file_path, options = {}, *output_file_name)
         | 
| 62 72 |  | 
| 63 73 | 
             
                  message,proceed = file_exist?(input_file_path)
         | 
| 64 74 |  | 
| @@ -66,135 +76,140 @@ module Nilac | |
| 66 76 |  | 
| 67 77 | 
             
                    file_contents = read_file_line_by_line(input_file_path)
         | 
| 68 78 |  | 
| 79 | 
            +
                    line_numbered_file_contents = add_line_numbers(file_contents)
         | 
| 80 | 
            +
             | 
| 69 81 | 
             
                    file_contents = file_contents.collect {|element| element.gsub("\r\n","\n")}
         | 
| 70 82 |  | 
| 83 | 
            +
                    file_contents = file_contents.collect {|element| element.gsub(".end",".enttttttttttt")}
         | 
| 84 | 
            +
             | 
| 71 85 | 
             
                    file_contents = extract_parsable_file(file_contents)
         | 
| 72 86 |  | 
| 73 87 | 
             
                    file_contents = compile_require_statements(file_contents)
         | 
| 74 88 |  | 
| 75 | 
            -
                     | 
| 89 | 
            +
                    proceed = check_comments(line_numbered_file_contents)
         | 
| 76 90 |  | 
| 77 | 
            -
                     | 
| 91 | 
            +
                    if proceed
         | 
| 78 92 |  | 
| 79 | 
            -
             | 
| 93 | 
            +
                      file_contents, multiline_comments, temp_file, output_js_file = replace_multiline_comments(file_contents, input_file_path, *output_file_name)
         | 
| 80 94 |  | 
| 81 | 
            -
             | 
| 95 | 
            +
                      file_contents, singleline_comments = replace_singleline_comments(file_contents)
         | 
| 82 96 |  | 
| 83 | 
            -
             | 
| 97 | 
            +
                      file_contents = split_semicolon_seperated_expressions(file_contents)
         | 
| 84 98 |  | 
| 85 | 
            -
             | 
| 99 | 
            +
                      file_contents = compile_ranges(file_contents)
         | 
| 86 100 |  | 
| 87 | 
            -
             | 
| 101 | 
            +
                      file_contents = compile_heredocs(file_contents, temp_file)
         | 
| 88 102 |  | 
| 89 | 
            -
             | 
| 103 | 
            +
                      file_contents,lambda_names = compile_lambdas(file_contents,temp_file)
         | 
| 90 104 |  | 
| 91 | 
            -
             | 
| 105 | 
            +
                      file_contents,loop_vars = compile_loops(file_contents,temp_file)
         | 
| 92 106 |  | 
| 93 | 
            -
             | 
| 107 | 
            +
                      file_contents, interpolation_vars  = compile_interpolated_strings(file_contents)
         | 
| 94 108 |  | 
| 95 | 
            -
             | 
| 109 | 
            +
                      file_contents = compile_hashes(file_contents,temp_file)
         | 
| 96 110 |  | 
| 97 | 
            -
             | 
| 111 | 
            +
                      file_contents = compile_case_statement(file_contents,temp_file)
         | 
| 98 112 |  | 
| 99 | 
            -
             | 
| 113 | 
            +
                      compile_inline_for(file_contents)
         | 
| 100 114 |  | 
| 101 | 
            -
             | 
| 115 | 
            +
                      file_contents = compile_conditional_structures(file_contents, temp_file)
         | 
| 102 116 |  | 
| 103 | 
            -
             | 
| 117 | 
            +
                      file_contents = compile_blocks(file_contents,temp_file)
         | 
| 104 118 |  | 
| 105 | 
            -
             | 
| 119 | 
            +
                      file_contents = compile_integers(file_contents)
         | 
| 106 120 |  | 
| 107 | 
            -
             | 
| 121 | 
            +
                      file_contents = compile_default_values(file_contents, temp_file)
         | 
| 108 122 |  | 
| 109 | 
            -
             | 
| 123 | 
            +
                      file_contents, named_functions, nested_functions = replace_named_functions(file_contents, temp_file)
         | 
| 110 124 |  | 
| 111 | 
            -
             | 
| 125 | 
            +
                      comments = [singleline_comments, multiline_comments]
         | 
| 112 126 |  | 
| 113 | 
            -
             | 
| 127 | 
            +
                      file_contents = compile_parallel_assignment(file_contents, temp_file)
         | 
| 114 128 |  | 
| 115 | 
            -
             | 
| 129 | 
            +
                      file_contents,named_functions = compile_arrays(file_contents, named_functions, temp_file)
         | 
| 116 130 |  | 
| 117 | 
            -
             | 
| 131 | 
            +
                      file_contents = compile_strings(file_contents)
         | 
| 118 132 |  | 
| 119 | 
            -
             | 
| 133 | 
            +
                      list_of_variables, file_contents = get_variables(file_contents, temp_file,loop_vars)
         | 
| 120 134 |  | 
| 121 | 
            -
             | 
| 135 | 
            +
                      file_contents, function_names = compile_named_functions(file_contents, named_functions, nested_functions, temp_file)
         | 
| 122 136 |  | 
| 123 | 
            -
             | 
| 137 | 
            +
                      file_contents = compile_monkey_patching(file_contents,temp_file)
         | 
| 124 138 |  | 
| 125 | 
            -
             | 
| 139 | 
            +
                      func_names = function_names.dup
         | 
| 126 140 |  | 
| 127 | 
            -
             | 
| 141 | 
            +
                      file_contents, ruby_functions = compile_custom_function_map(file_contents)
         | 
| 128 142 |  | 
| 129 | 
            -
             | 
| 143 | 
            +
                      file_contents = compile_ruby_methods(file_contents)
         | 
| 130 144 |  | 
| 131 | 
            -
             | 
| 145 | 
            +
                      file_contents = compile_special_keywords(file_contents)
         | 
| 132 146 |  | 
| 133 | 
            -
             | 
| 147 | 
            +
                      function_names << ruby_functions
         | 
| 134 148 |  | 
| 135 | 
            -
             | 
| 149 | 
            +
                      function_names << lambda_names
         | 
| 136 150 |  | 
| 137 | 
            -
             | 
| 151 | 
            +
                      list_of_variables += loop_vars
         | 
| 138 152 |  | 
| 139 | 
            -
             | 
| 153 | 
            +
                      list_of_variables += interpolation_vars
         | 
| 140 154 |  | 
| 141 | 
            -
             | 
| 155 | 
            +
                      file_contents = compile_whitespace_delimited_functions(file_contents, function_names, temp_file)
         | 
| 142 156 |  | 
| 143 | 
            -
             | 
| 157 | 
            +
                      file_contents = fix_javascript_traps(file_contents)
         | 
| 144 158 |  | 
| 145 | 
            -
             | 
| 159 | 
            +
                      file_contents = remove_question_marks(file_contents, list_of_variables, temp_file)
         | 
| 146 160 |  | 
| 147 | 
            -
             | 
| 161 | 
            +
                      file_contents = add_semicolons(file_contents)
         | 
| 148 162 |  | 
| 149 | 
            -
             | 
| 163 | 
            +
                      file_contents = compile_new_keyword(file_contents)
         | 
| 150 164 |  | 
| 151 | 
            -
             | 
| 165 | 
            +
                      file_contents = compile_comments(file_contents, comments, temp_file)
         | 
| 152 166 |  | 
| 167 | 
            +
                      file_contents = pretty_print_javascript(file_contents, temp_file,list_of_variables+func_names,options)
         | 
| 153 168 |  | 
| 154 | 
            -
             | 
| 169 | 
            +
                      file_contents = compile_operators(file_contents)
         | 
| 155 170 |  | 
| 156 | 
            -
             | 
| 171 | 
            +
                      file_contents = compile_ruby_math(file_contents)
         | 
| 157 172 |  | 
| 158 | 
            -
             | 
| 173 | 
            +
                      file_contents = file_contents.collect {|element| element.gsub(".enttttttttttt",".end")}
         | 
| 159 174 |  | 
| 160 | 
            -
             | 
| 175 | 
            +
                      if options[:print]
         | 
| 161 176 |  | 
| 162 | 
            -
             | 
| 177 | 
            +
                        puts file_contents.join
         | 
| 163 178 |  | 
| 164 | 
            -
             | 
| 179 | 
            +
                      else
         | 
| 165 180 |  | 
| 166 | 
            -
             | 
| 181 | 
            +
                        output_javascript(file_contents, output_js_file, temp_file)
         | 
| 182 | 
            +
             | 
| 183 | 
            +
                        puts "Compilation is successful!"
         | 
| 167 184 |  | 
| 168 | 
            -
             | 
| 185 | 
            +
                      end
         | 
| 169 186 |  | 
| 170 | 
            -
                     | 
| 171 | 
            -
                    create_mac_executable(file_path)
         | 
| 172 | 
            -
                    FileUtils.mv("#{file_path[0...-3]}", "#{Dir.pwd}/bin/nilac")
         | 
| 173 | 
            -
                    puts "Build Successful!"
         | 
| 187 | 
            +
                    end
         | 
| 174 188 |  | 
| 175 | 
            -
                   | 
| 189 | 
            +
                  else
         | 
| 176 190 |  | 
| 177 | 
            -
                     | 
| 191 | 
            +
                    puts message
         | 
| 192 | 
            +
             | 
| 193 | 
            +
                  end
         | 
| 178 194 |  | 
| 179 | 
            -
                    server_optimized = false
         | 
| 180 195 |  | 
| 181 | 
            -
             | 
| 196 | 
            +
                end
         | 
| 182 197 |  | 
| 183 | 
            -
             | 
| 198 | 
            +
                def start_compile
         | 
| 184 199 |  | 
| 185 | 
            -
             | 
| 200 | 
            +
                  opts = parse_arguments(@input_arguments)
         | 
| 186 201 |  | 
| 187 | 
            -
             | 
| 202 | 
            +
                  options = compose_nilac_options(opts)
         | 
| 188 203 |  | 
| 189 | 
            -
             | 
| 204 | 
            +
                  nilac_version = Nilac::VERSION
         | 
| 190 205 |  | 
| 191 | 
            -
             | 
| 206 | 
            +
                  if opts.values.compact.empty?
         | 
| 192 207 |  | 
| 193 | 
            -
             | 
| 208 | 
            +
                    opts[:help] = "-h"
         | 
| 194 209 |  | 
| 195 | 
            -
             | 
| 210 | 
            +
                  end
         | 
| 196 211 |  | 
| 197 | 
            -
             | 
| 212 | 
            +
                  if opts[:compile] != nil
         | 
| 198 213 |  | 
| 199 214 | 
             
                    if opts[:compile].length == 1
         | 
| 200 215 |  | 
| @@ -204,14 +219,14 @@ module Nilac | |
| 204 219 | 
             
                        current_directory = Dir.pwd
         | 
| 205 220 | 
             
                        input_file = input
         | 
| 206 221 | 
             
                        file_path = current_directory + "/" + input_file
         | 
| 207 | 
            -
                        compile(file_path, | 
| 222 | 
            +
                        compile(file_path,options)
         | 
| 208 223 | 
             
                      elsif File.directory?(input)
         | 
| 209 224 | 
             
                        folder_path = input
         | 
| 210 225 | 
             
                        files = Dir.glob(File.join(folder_path, "*"))
         | 
| 211 226 | 
             
                        files = files.reject { |path| !path.include? ".nila" }
         | 
| 212 227 | 
             
                        files.each do |file|
         | 
| 213 228 | 
             
                          file_path = Dir.pwd + "/" + file
         | 
| 214 | 
            -
                          compile(file_path, | 
| 229 | 
            +
                          compile(file_path,options)
         | 
| 215 230 | 
             
                        end
         | 
| 216 231 | 
             
                      end
         | 
| 217 232 |  | 
| @@ -226,7 +241,7 @@ module Nilac | |
| 226 241 | 
             
                        output_file = output
         | 
| 227 242 | 
             
                        input_file_path = input_file
         | 
| 228 243 | 
             
                        output_file_path = output_file
         | 
| 229 | 
            -
                        compile(input_file_path, | 
| 244 | 
            +
                        compile(input_file_path,options,output_file_path)
         | 
| 230 245 |  | 
| 231 246 | 
             
                      elsif File.directory?(input)
         | 
| 232 247 |  | 
| @@ -243,7 +258,7 @@ module Nilac | |
| 243 258 | 
             
                        files.each do |file|
         | 
| 244 259 | 
             
                          input_file_path = file
         | 
| 245 260 | 
             
                          output_file_path = output_folder_path + "/" + find_file_name(file, ".nila") + ".js"
         | 
| 246 | 
            -
                          compile(input_file_path, | 
| 261 | 
            +
                          compile(input_file_path,options,output_file_path)
         | 
| 247 262 | 
             
                        end
         | 
| 248 263 |  | 
| 249 264 | 
             
                      end
         |