fleau.js
function(input) {
  var code = 'var $_parsers = {\n';
  var parsernames = Object.keys(parsers);
  for (var i = 0; i < parsernames.length; i++) {
    code += '  ' + JSON.stringify(parsernames[i]) + ': ' +
      parsers[parsernames[i]].toString() + ',\n';
  };
  code += '}\n';
  code += compile(input) + '\nif (typeof $_end === "function") {$_end();}';
  var script = new vm.Script(code, {timeout: 4 * 60 * 1000});
  var runner = function(scope) {
    var output = '';
    var pipeOpen = false;
    var ended = false;
    var stream = new Readable({
      encoding: 'utf8',
      read: function() {
        pipeOpen = true;
        if (ended && output === '') {
          pipeOpen = this.push(null);
        } else if (output !== '') {
          pipeOpen = this.push(output);
          output = '';
        }
      },
    });
    scope.$_scope = scope;
    scope.$_write = function(data) {
      output += '' + data;
      if (pipeOpen && output !== '') {
        pipeOpen = stream.push(output);
        output = '';
      }
    };
    scope.$_end = function() {
      ended = true;
      if (pipeOpen) { stream.push(null); }
    };
    script.runInNewContext(scope)
    return stream;
  };
  runner.code = code;
  return runner;
}
function(input) {
  var code = 'var $_parsers = {\n';
  var parsernames = Object.keys(parsers);
  for (var i = 0; i < parsernames.length; i++) {
    code += '  ' + JSON.stringify(parsernames[i]) + ': ' +
      parsers[parsernames[i]].toString() + ',\n';
  };
  code += '}\n';
  code += compile(input) + '\nif (typeof $_end === "function") {$_end();}';
  var script = new vm.Script(code, {timeout: 4 * 60 * 1000});
  var runner = function(scope) {
    var output = '';
    var pipeOpen = false;
    var ended = false;
    var stream = new Readable({
      encoding: 'utf8',
      read: function() {
        pipeOpen = true;
        if (ended && output === '') {
          pipeOpen = this.push(null);
        } else if (output !== '') {
          pipeOpen = this.push(output);
          output = '';
        }
      },
    });
    scope.$_scope = scope;
    scope.$_write = function(data) {
      output += '' + data;
      if (pipeOpen && output !== '') {
        pipeOpen = stream.push(output);
        output = '';
      }
    };
    scope.$_end = function() {
      ended = true;
      if (pipeOpen) { stream.push(null); }
    };
    script.runInNewContext(scope)
    return stream;
  };
  runner.code = code;
  return runner;
}
function ( input ) { var code = 'var $_parsers = {\n' ; var parsernames = Object . keys ( parsers ) ; for ( var i = 0 ; i < parsernames . length ; i ++ ) { code += '  ' + JSON . stringify ( parsernames [ i ] ) + ': ' + parsers [ parsernames [ i ] ] . toString ( ) + ',\n' ; } ; code += '}\n' ; code += compile ( input ) + '\nif (typeof $_end === "function") {$_end();}' ; var script = new vm . Script ( code , { timeout : 4 * 60 * 1000 } ) ; var runner = function ( scope ) { var output = '' ; var pipeOpen = false ; var ended = false ; var stream = new Readable ( { encoding : 'utf8' , read : function ( ) { pipeOpen = true ; if ( ended && output === '' ) { pipeOpen = this . push ( null ) ; } else if ( output !== '' ) { pipeOpen = this . push ( output ) ; output = '' ; } } , } ) ; scope . $_scope = scope ; scope . $_write = function ( data ) { output += '' + data ; if ( pipeOpen && output !== '' ) { pipeOpen = stream . push ( output ) ; output = '' ; } } ; scope . $_end = function ( ) { ended = true ; if ( pipeOpen ) { stream . push ( null ) ; } } ; script . runInNewContext ( scope ) return stream ; } ; runner . code = code ; return runner ; }
string is a template. Return a function that takes a scope and returns a readable stream.
string is a template . Return a function that takes a scope and returns a readable stream .