This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compile(source) { // derived from www.typescriptlang.org/Playground/ | |
var result = ''; | |
var outfile = {Write:function(s){ result += s; }, WriteLine:function(s){ result += s + '\n'; }, Close:function(){}}; | |
var compiler = new TypeScript.TypeScriptCompiler(); | |
compiler.setErrorCallback(function(start, len, message) { console.log('error',arguments); }); | |
compiler.parser.errorRecovery = true; | |
compiler.addUnit(source, "input.ts"); | |
compiler.emit(function createFile(fileName) { return outfile; }); | |
return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expr +150 -150 | |
100 => 250 -50 | |
-100 => 50 -250 | |
x => x+150 x-150 | |
x+100 => x+250 x-50 | |
x-100 => x+50 x-250 | |
x*100 => x*100+150 x*100-150 | |
x*-100 => x*100+50 x*100-250 | |
x++ => x++ +150 x++ -150 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getCharPos1: function() { | |
// Get cursor position | |
var charPos = 0; | |
var cursorPos = this.editor.getCursorPosition(); | |
for (var i=0; i<cursorPos.row; i++){ | |
charPos += this.editor.session.$rowLengthCache[i]; // +1 for newline | |
} | |
charPos += cursorPos.column + cursorPos.row; // Add row count to compensate for newlines | |
return charPos; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ordered = pieces.slice(i).sort(function(a,b){ | |
var pa = this.distanceBetween(p,a); | |
var pb = this.distanceBetween(p.b); | |
if (pa < pb) return -1; | |
if (pa > pb) return 1; | |
return 0; | |
}.bind(this)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// requires ZeParser (see repo) | |
// input is a string, your js input with tagliterals | |
function compile(input){ | |
var tree = []; | |
var tokenizer = new Tokenizer(input); | |
tokenizer.tagLiterals = true; // enable tag literals in the engine | |
var parser = new ZeParser(input, tokenizer, tree); | |
parser.parse(); | |
tokenizer.fixValues(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NCA = function(type, version, compiler){ | |
this.type = type; | |
this.version = version; | |
// compiler must have interface method "compile", | |
// which accepts a string as single argument | |
this.compiler = compiler; | |
}; | |
NCA.prototype = { | |
queue: [], | |
fetching: false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parser = ZeParser.createParser(ta.value); | |
parser.tokenizer.fixValues(); | |
var wtree = parser.tokenizer.wtree; | |
ta.className = ''; | |
var ide = wtree.map(function(t){ | |
if (t.name == 14) ta.className = 'error'; | |
return '<span class="t'+t.name+'">'+(t.name==13?'\u29e6':(t.name==14?'\u292c':t.value)).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>')+'</span>'; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var parser = ZeParser.createParser(value); | |
parser.tokenizer.fixValues(); | |
var ide = parser.tokenizer.wtree.map(function(t){ | |
if (t.name == 14) ta.className = 'error'; | |
return '<span class="t'+t.name+'">'+(t.name==13?'\u29e6':(t.name==14?'\u292c':t.value))+'</span>'; | |
}); | |
div.innerHTML = ide.join(''); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the case: | |
// runner.js | |
module.exports = { | |
arr: [], | |
fetch: function(str){ this.arr.push(str); } | |
}; | |
// mod1.js | |
module.exports = function(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Not intended to be fast. | |
var WebVTTCueTextParser = (function(){ // this will return just the WebVTTCueTextParser function and not leak anything else | |
// local scope: | |
var | |
NEWLINE = /\r\n|\r|\n/, | |
SPACE = /[\u0020\t\f]/, | |
NOSPACE = /[^\u0020\t\f]/ |