Skip to content

Commit

Permalink
Version 0.2: Added multi-line statements and README.
Browse files Browse the repository at this point in the history
  • Loading branch information
niutech committed Nov 21, 2012
1 parent cc15146 commit b54d5b9
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 43 deletions.
32 changes: 32 additions & 0 deletions README.md
@@ -0,0 +1,32 @@
TypeScript Interpret
==================

[TypeScript](http://www.typescriptlang.org) is a brand new language which compiles on JavaScript. However, this operation has to be performed manually, using the command-line compiler `tsc` or other tools. But now it can be interpreted straight in your web browser, thanks to TypeScript Interpret!

TypeScript Interpret automatically interprets your TypeScript code typed into a console, using the [jQuery Terminal](https://github.com/jcubic/jquery.terminal) by Jakub Jankiewicz.


Demo
----

[Here is a TypeScript terminal emulator](http://niutech.github.com/typescript-interpret/)


Download
--------

[TypeScript 0.8](https://raw.github.com/niutech/typescript-compile/gh-pages/js/typescript.min.js) (minified JS)

[TypeScript Interpret 0.2](https://raw.github.com/niutech/typescript-interpret/gh-pages/typescript.interpret.min.js) (minified JS)

[jQuery Terminal 0.4.22](https://raw.github.com/jcubic/jquery.terminal/master/js/jquery.terminal-0.4.22.min.js) (minified JS)


Authors & License
----------------

TypeScript is developed by Microsoft Corp. under Apache 2.0 License.

TypeScript Interpret is developed by Jerzy Głowacki under Apache 2.0 License.

jQuery Terminal is developed by Jakub Jankiewicz under GNU GPL 3 License.
101 changes: 58 additions & 43 deletions index.html
@@ -1,69 +1,84 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TypeScript Interpret - Terminal Emulator</title>
<link href="http://terminal.jcubic.pl/css/jquery.terminal.css" rel="stylesheet"/>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<meta charset="utf-8">
<title>TypeScript Interpret - Terminal Emulator</title>
<link rel="stylesheet" href="http://terminal.jcubic.pl/css/jquery.terminal.css">
<style>
html, body, #term {
height: 100%;
margin: 0;
}
#badge {
position: absolute;
top: 0;
right: 0;
z-index: 999;
border: 0;
}
</style>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<a href="https://github.com/niutech/typescript-interpret"><img id="badge" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
<div id="term"></div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://terminal.jcubic.pl/js/jquery.mousewheel-min.js"></script>
<script type="text/javascript" src="http://terminal.jcubic.pl/js/jquery.terminal-0.4.22.min.js"></script>
<script type="text/javascript" src="http://niutech.github.com/typescript-compile/js/typescript.min.js"></script>
<script type="text/javascript" src="typescript.interpret.min.js"></script>
<script type="text/javascript">
jQuery(function($) {

var outfile = {
source: '',
Write: function(s) {
this.source += s;
},
WriteLine: function(s) {
this.source += s + '\n';
},
Clear: function() {
this.source = '';
},
Close: function() {}
var isBalanced = function(cmd) {
var parens = 0;
for(i = 0; i < cmd.length; i++) {
switch(cmd.charAt(i)) {
case '(':
case '{':
case '[':
parens++;
break;
case ')':
case '}':
case ']':
parens--;
}
}
return parens <= 0;
};

var command = '';

var interpret = function(cmd) {
$('#term').terminal(function(cmd, term) {
if(cmd === '') {
return '';
return;
}
outfile.Clear();
var compiler = new TypeScript.TypeScriptCompiler(outfile);
compiler.parser.errorRecovery = true;
compiler.setErrorCallback(function(start, len, message, block) {
throw 'TypeScriptError: ' + message + ', char: ' + start + ', length: ' + len;
});
compiler.addUnit(cmd, '');
//compiler.typeCheck(); //Disabled due to exclusion of lib.d.ts
compiler.emit(false, function createFile(fileName) {
return outfile;
});
}

$('#term').terminal(function(command, term) {
try {
interpret(command);
var result = window.eval(outfile.source);
if(result !== undefined) {
term.echo(new String(result));
command += cmd;
if(isBalanced(command)) {
try {
TypeScriptInterpret.interpret(command);
var result = window.eval(TypeScriptInterpret.outfile.source);
if(result !== undefined) {
term.echo(new String(result));
}
} catch(e) {
term.error(new String(e));
}
} catch(e) {
term.error(new String(e));
command = '';
term.set_prompt('ts> ');
} else {
term.set_prompt('... ');
}
}, {
greetings: 'Welcome to TypeScript Interpret ver. 0.1 by Jerzy Głowacki & Jakub Jankiewicz!',
greetings: 'Welcome to TypeScript Interpret ver. 0.2! Type \'clear\' to clear the terminal.',
name: 'term',
height: 600,
height: $('body').height()-20,
prompt: 'ts> '
});

});
</script>
</body>
Expand Down
31 changes: 31 additions & 0 deletions typescript.interpret.js
@@ -0,0 +1,31 @@
var TypeScriptInterpret = {

outfile: {
source: '',
Write: function(s) {
this.source += s;
},
WriteLine: function(s) {
this.source += s + '\n';
},
Clear: function() {
this.source = '';
},
Close: function() {}
},

interpret: function(cmd) {
this.outfile.Clear();
var compiler = new TypeScript.TypeScriptCompiler(this.outfile);
compiler.parser.errorRecovery = true;
compiler.setErrorCallback(function(start, len, message, block) {
throw 'TypeScriptError: ' + message + ', char: ' + start + ', length: ' + len;
});
compiler.addUnit(cmd, '');
//compiler.typeCheck(); //Disabled due to exclusion of lib.d.ts
compiler.emit(false, function(fileName) {
return this.outfile;
});
}

}
1 change: 1 addition & 0 deletions typescript.interpret.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b54d5b9

Please sign in to comment.