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
| macro forOf { | |
| case (var $name:ident of $array) $body => { | |
| (function(array) { | |
| for (var i = 0, len = array.length; i < len; i++) { | |
| var $name = array[i]; | |
| $body | |
| } | |
| })($array); | |
| } | |
| } |
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
| macro async { | |
| case :{ $rest } => { | |
| $rest | |
| } | |
| case :{ $head $rest ... } => { | |
| $head | |
| async: { $rest ... } | |
| } | |
| case :{ var $x:ident = await($yield:ident, $y ...); $rest ... } => { | |
| (function($yield) { |
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
| macro asmfn { | |
| case $name:ident ($params ...) { $body ... } => { | |
| function $name(asmfn_params($params ...)) { | |
| 'use asm'; | |
| asmfn_convparams($params ...) | |
| $body ... | |
| } | |
| } | |
| // case $name:ident ($params ...): $ret_type { $body ... } => { | |
| // macro ret { |
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
| macro bf { | |
| case ($body ...) => { | |
| eval('var p = 0, b = [], buf = new Buffer(1);'); | |
| _bf($body ...); | |
| } | |
| } | |
| macro _bf { | |
| case (>) => { | |
| eval('p++;'); | |
| } |
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
| macro bf { | |
| case : { $body ... } => { | |
| (function() { | |
| var env = { | |
| p: 0, | |
| b: [], | |
| buf: new Buffer(1) | |
| }; | |
| bf_tokenizer[env]($body ...); | |
| })(); |
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 traverseFn(node, fn) { | |
| var parents = []; | |
| (function f(node) { | |
| fn(node, parents); | |
| parents.push(node); | |
| for (var c in Iterator(node)) { | |
| f(c); | |
| } | |
| parents.pop(); | |
| })(node); |
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 parse(str) { | |
| var ir = Packages.jdk.nashorn.internal.ir; | |
| var runtime = Packages.jdk.nashorn.internal.runtime; | |
| var parser = Packages.jdk.nashorn.internal.parser; | |
| var context = runtime.Context.getContext(); | |
| var source = new runtime.Source('test', str); | |
| var node = new parser.Parser(context.getEnv(), source, new runtime.Context.ThrowErrorManager(), true).parse(); | |
| var lexContext = new ir.LexicalContext(); |
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 express = require('express'); | |
| var app = express(); | |
| app.get('/', function(req, res) { | |
| res.type('text/html'); | |
| res.send('<script>' + | |
| 'new EventSource(\'/event/a\').addEventListener(\'message\',function(event) {' + | |
| 'document.body.appendChild(document.createElement(\'div\')).textContent = event.data;' + | |
| '});' + | |
| '</script>'); |
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
| macro <<EOS { | |
| case { $_ } => { | |
| var comments = #{$_}[0].token.leadingComments; | |
| var text = ''; | |
| if (comments) { | |
| text = comments.map(function(c) { | |
| return c.type === 'Block' ? c.value.replace(/^(\r\n|\n|\r)/, '').replace(/(\r\n|\n|\r)$/, '') : c.value; | |
| }).join('\r\n'); | |
| } | |
| return [makeValue(text, #{here})]; |
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
| import javax.script.ScriptEngine; | |
| import javax.script.ScriptEngineManager; | |
| public class E4X { | |
| public static void main(String[] args) { | |
| System.out.println("E4X: " + System.getProperty("nashorn.lexer.xmlliterals")); | |
| ScriptEngineManager manager = new ScriptEngineManager(); | |
| ScriptEngine engine = manager.getEngineByName("js"); | |
| try { |
OlderNewer