Last active
August 29, 2015 14:01
-
-
Save redraiment/1e953fb1500ac0ede1c2 to your computer and use it in GitHub Desktop.
Embedded JavaScript
This file contains 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 File = function(name) { | |
this.file = new java.io.File(name); | |
}; | |
File.prototype.map = function(fn) { | |
var fin = new java.util.Scanner(this.file); | |
var content = []; | |
while (fin.hasNextLine()) { | |
content.push(fn(fin.nextLine())); | |
} | |
fin.close(); | |
return content; | |
}; | |
var map = function(list, fn) { | |
var rs = []; | |
for (var i = 0; i < list.length; i++) { | |
rs.push(fn(list[i])); | |
} | |
return rs; | |
}; | |
var code = map(arguments, function(name) { | |
var file = new File(name); | |
return file.map(function(line) { | |
if (line.charAt(0) === 37) { | |
return line.substring(1).concat('\n'); | |
} else { | |
return map(line.split("(?=\\[=)|(?<==\\])"), function(e) { | |
if (e.matches('\\[=.*?=\\]')) { | |
return 'print(' + e.replaceAll('^\\[=|=\\]$', '') + ');\n'; | |
} else { | |
return 'print("' + e.replaceAll('"', '\\\\"') + '");\n'; | |
} | |
}).join('') + 'print("\\n");\n'; | |
} | |
}).join(''); | |
}).join('\n'); | |
eval(code); |
This file contains 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
#!/bin/bash | |
exec jrunscript -f "$(cygpath -w "$HOME/lib/js/ejs.js")" $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment