# This is a small REPL for Nila to test out nila code and do bug fixes require 'readline' require 'fs' require 'sys' exec = require('child_process').exec file_name = "#{__dirname}/my_file.nila" output_file_name = "#{__dirname}/my_file.js" stream = fs.createWriteStream(file_name) stream.once 'open', do |fd| stream.write("# REPL Session #{new Date().to_s}\n\n") end rl = readline.createInterface(process.stdin, process.stdout) rl.setPrompt('nila> ') rl.prompt() read = rl.on 'line', do |line| stream.write("puts (#{line})\n\n") exec 'nilac -c my_file.nila', do |error,stdout,stderr| if error != nil sys.print("error: #{error}") end if stdout.strip == "Compilation is successful!" exec output_file_name, do |error,stdout,stderr| if error != nil sys.print(error + "\n") else sys.print(stdout + "\n") end end end end rl.prompt() end read.on 'close', do stream.end() fs.unlink file_name, do |err| puts "Nila file couldn't be deleted!" end fs.unlink output_file_name, do |err| puts "Output js file couldn't be deleted!" end puts "\n\nThanks for trying out Nila!\n" puts "You can learn more about Nila at http://adhithyan15.github.io/nila\n" process.exit(0) end