/**
 * Copyright (C) 2014 Glayzzle (BSD3 License)
 * @authors https://github.com/glayzzle/php-parser/graphs/contributors
 * @url http://glayzzle.com
 */
var extend = require('util')._extend;
var engine = {
  // parsing eval string as '$x = 1;'
  parseEval: function(buffer, options) {
    var lexer = this.lexer;
    var parser = this.parser;
    if (options) {
      if (options.hasOwnProperty('lexer')) {
        lexer = extend(lexer, options.lexer);
      }
      if (options.hasOwnProperty('parser')) {
        parser = extend(parser, options.parser);
      }
      parser.lexer = lexer;
    }
    lexer.mode_eval = true;
    lexer.all_tokens = false;
    return parser.parse(buffer);
  }
  // parse php code with '<?php $x = 1;'
  ,parseCode: function(buffer, options) {
    var lexer = this.lexer;
    var parser = this.parser;
    if (options) {
      if (options.hasOwnProperty('lexer')) {
        lexer = extend(lexer, options.lexer);
      }
      if (options.hasOwnProperty('parser')) {
        parser = extend(parser, options.parser);
      }
      parser.lexer = lexer;
    }
    lexer.mode_eval = false;
    lexer.all_tokens = false;
    return parser.parse(buffer);
  }
  ,parser: null
  // lexer instance
  ,lexer: require('./src/lexer')
  // tokens dictionnary
  ,tokens: require('./src/tokens')
};
// parser instance
engine.parser = require('./src/parser')(engine);
module.exports = engine;

@@ -188,22 +188,980 @@
 nd;%0A
-var engine = %7B
+%0A// helper to clone an object%0Avar deepCopy = function(origin, add) %7B%0A  if (!add %7C%7C typeof add !== 'object') return origin;%0A  var keys = Object.keys(add);%0A  var i = keys.length;%0A  while (i--) %7B%0A    var assign = add%5Bkeys%5Bi%5D%5D;%0A    if (typeof assign === 'object' && !Array.isArray(assign)) %7B%0A      if (!origin.hasOwnProperty(keys%5Bi%5D)) %7B%0A        origin%5Bkeys%5Bi%5D%5D = %7B%7D;%0A      %7D%0A      origin%5Bkeys%5Bi%5D%5D = deepCopy(origin%5Bkeys%5Bi%5D%5D, assign);%0A    %7D else %7B%0A      origin%5Bkeys%5Bi%5D%5D = assign;%0A    %7D%0A  %7D%0A  return origin;%0A%7D;%0A%0A%0Avar engine = %7B%0A%0A  // creates a new instance (for multiple parsing cases)%0A  create: function(options) %7B%0A    var result = deepCopy(%7B%7D, this);%0A    if (options) %7B%0A      if (options.hasOwnProperty('lexer')) %7B%0A        result.lexer = deepCopy(result.lexer, options.lexer);%0A      %7D%0A      if (options.hasOwnProperty('parser')) %7B%0A        result.parser = deepCopy(result.parser, options.parser);%0A      %7D%0A      result.parser.lexer = result.lexer;%0A    %7D%0A    return result;%0A  %7D,%0A
 %0A  /

add a new create helper function to instanciate a new parser context