Permalink
Browse files

Master merge

  • Loading branch information...
2 parents 8c0d173 + 011010d commit fc550b5942990a1d2a78d92a961b2fad57d1f6d8 Mikael Bung committed Apr 23, 2010
Showing with 1,717 additions and 750 deletions.
  1. +128 −33 haskell.hiji.js
  2. +1,006 −715 haskell.parser.js
  3. +1 −0 haskell.primitives.js
  4. +271 −0 haskell.primitives.js~
  5. +2 −1 hiji.css
  6. +3 −1 hiji.html
  7. +152 −0 lib/jquery-1.4.1.min.js
  8. +154 −0 lib/jquery.js
View
@@ -1,12 +1,22 @@
var ENTER = '13';
var UP = '38';
var DOWN = '40';
+var is_module_loaded = false;
+var modules = new Array();
+
+
+var commands = new Array();
+commands[":l"] = "LOAD";
+commands[":load"] = "LOAD";
+commands[":h"] = "HELP";
+commands[":help"] = "HELP";
(function($){
var evaluateHaskell = function(line, env)
{
- ast = haskell.parser.parse(line).ast;
+ var line_ = '{' + line + '}';
+ ast = haskell.parser.parse(line_).ast;
if (ast == undefined){
return "Syntax Error";
}
@@ -23,15 +33,16 @@ var DOWN = '40';
};
var makeInput = function(modules){
- return "<li class='input'>" + makeModules(modules) + "<input type='text' name='inputBox' id='inbox'></li>";
+ return "<li class='input' id='inputTest'>" + makeModules(modules) + "<input type='text' name='inputBox' id='inbox'></li>";
};
var makeOutput = function(output) {
console.log("%o", output);
return $("<li class='output'></li>").text(output.toString());
};
-
+
$.fn.startHiji = function() {
- var modules = new Array();
+
+ //var modules = new Array();
var hist = new Array();
// history
@@ -45,26 +56,9 @@ var DOWN = '40';
var env = new haskell.interpreter.RootEnv();
haskell.primitives.init(env);
- // ladda prelude
-
- $.get('hs/Prelude.hs', function(prelude_data) {
- console.log(prelude_data);
- try {
- var ast = haskell.parser.parse(prelude_data);
- console.log("%o", ast);
- if (ast.ast == undefined) {
- console.log("Syntax Error");
- }
- else {
- haskell.interpreter.prepare(ast.ast, env);
- }
- } catch(e) {
- console.log("%o", e);
- }
- });
+ load_module('hs/Prelude.hs');
modules[0] = "Prelude";
- modules[1] = "Control.Monad";
this.html("<ol>" + makeInput(modules) + "</ol>");
$("input:text:visible:first").focus();
@@ -78,31 +72,132 @@ var DOWN = '40';
if(e.which==DOWN){
input.attr("value", hiss.newer(line));
}
+<<<<<<< HEAD:haskell.hiji.js
if (e.which==ENTER){
+=======
+ if (e.keyCode==ENTER){
+
+>>>>>>> master:haskell.hiji.js
// history
hiss.addHistory(line);
$.cookie("hiss", JSON.stringify(hiss.history_array), {expires: 3 });
input.attr("value","");
- try {
- var newLine = makeEntered(modules, line);
- var output = makeOutput(evaluateHaskell(line, env));
- $('.input', this).after(output).replaceWith(newLine);
- $("ol",this).append(makeInput(modules));
+
+ if(isCommand(line)){
+ runCommand(line, input, line);
+ }else
+ {
+ try {
+ var newLine = makeEntered(modules, line);
+ var output = makeOutput(evaluateHaskell(line, env));
+ $('.input', this).after(output).replaceWith(newLine);
+ $("ol",this).append(makeInput(modules));
+ }
+ catch(e) {
+ console.log("%o", e);
+ };
}
- catch(e) {
- console.log("%o", e);
- };
+
//set focus
$("input:text:visible:first").focus();
-
- }else{
- // document.write(e.keyCode);
}
});
+
+ // load a module
+ function load_module(module){
+ is_module_loaded = false;
+ jQuery.ajax({
+ async : false,
+ url : module,
+ success: function(prelude_data){
+ console.log(prelude_data);
+ try {
+ var ast = haskell.parser.parse(prelude_data);
+ console.log("%o", ast);
+ if (ast.ast == undefined) {
+ console.log("Syntax Error");
+ }
+ else {
+ haskell.interpreter.prepare(ast.ast, env);
+ is_module_loaded = true;
+ }
+ } catch(e) {
+ console.log("%o", e);
+ }
+ }
+ });
+ }
+
+ function isCommand(l){
+ var line = trim(l);
+ if(line.charAt(0) == ':')
+ return true
+ else
+ return false
+ }
+
+ function runCommand(i, input2, line){
+ var input = trim(i);
+ var command = input.indexOf(" ") != -1 ? input.substr(0, input.indexOf(" ")) : input;
+ // load module
+ if(commands[command] == "LOAD"){
+ var arg = trim(input.substr(command.length));
+ var module_name = arg.substr(0, arg.lastIndexOf('.'));
+ load_module(arg);
+ if(is_module_loaded){
+ var module_already_in_modules = false;
+ for(x in modules){
+ if(modules[x] == module_name)
+ module_already_in_modules = true;
+ }
+ if(module_already_in_modules == false){
+ var newLine = makeEntered(modules, line);
+ var output = makeOutput("Module " + module_name +" loaded");
+ $('.input').after(output).replaceWith(newLine);
+ modules.push(module_name);
+ $("ol").append(makeInput(modules));
+ }else{
+ var newLine = makeEntered(modules, line);
+ var output = makeOutput("Module " + module_name + " already loaded");
+ $('.input').after(output).replaceWith(newLine);
+ $("ol").append(makeInput(modules));
+ }
+ }else{
+ var newLine = makeEntered(modules, line);
+ var output = makeOutput("Module " + module_name + " not found");
+ $('.input').after(output).replaceWith(newLine);
+ $("ol").append(makeInput(modules));
+ }
+ }else if(commands[command] == "HELP"){
+ var newLine = makeEntered(modules, line);
+ var output_row = new Array();
+ output_row.push(makeOutput("Help"));
+ output_row.push(makeOutput(" "));
+ output_row.push(makeOutput("Commands:"));
+ output_row.push(makeOutput(":l [Module] ... load a module"));
+ var str = "$('.input')";
+ for (var i = output_row.length-1; i>=0; i--){
+ str += ".after(" + output_row[i] + ")";
+ // $('.input').after(output_row[i]).after(output).replaceWith(newLine);
+ }
+ str += ".replaceWith(newLine);";
+ alert(str);
+ eval(str);
+ // var output = makeOutput("HELP HELP HELP" + "<br>" + "asdas");
+ // $('.input').after(output1).after(output).replaceWith(newLine);
+ // $('.input').after(output).replaceWith(newLine);
+ // $('.input').after(output).replaceWith(newLine);
+ $("ol").append(makeInput(modules));
+ }
+ }
};
+
})(jQuery);
+function trim(str){
+ return str.replace(/^\s+|\s+$/g,"");
+}
// historry-class with nice name
// !!!WARNING!!! NICE NAME. conflict with javascript
Oops, something went wrong.

0 comments on commit fc550b5

Please sign in to comment.