<commit_before><?php

/*
 * Mustache PHP Compiler
 *
 * (c) July 2011 - <NAME> - <EMAIL>
 */

namespace Mustache;

require_once(dirname(__FILE__).'/Parser.php');
require_once(dirname(__FILE__).'/Generator.php');

class Template {
  protected $data = "";
  protected $compiled = null;
  
  public function __construct($_data) {
    $this->data = $_data;
  }

  public function render($context) {
    if ($this->compiled == null) {
      $code = $this->compile($this->data);
      //      echo "code: ".print_r($code, true)."\n";
      $this->compiled = eval("return function (\$ctx) { $code };");
    }

    $f = $this->compiled;
    return $f($context);
  }

  public function compile($src = null) {
    if ($src == null) {
      $src = $this->data;
    }
    $generator = new Generator();
    $tokens = $this->getTokens($src);
    //    echo "tokens: ".print_r($tokens, true)."\n";
    return $generator->compile($tokens);
  }

  public function getTokens($src = null) {
    if ($src == null) {
      $src = $this->data;
    }
    $parser = new Parser();
    return $parser->compile($src);
  }
};

?><commit_msg>Add debug information to compiler<commit_after><?php

/*
 * Mustache PHP Compiler
 *
 * (c) July 2011 - <NAME> - <EMAIL>
 */

namespace Mustache;

require_once(dirname(__FILE__).'/Parser.php');
require_once(dirname(__FILE__).'/Generator.php');

class Template {
  protected $data = "";
  protected $compiled = null;
  
  public function __construct($_data) {
    $this->data = $_data;
  }

  public function render($context) {
    debug_log("current context ".print_r($context, true), 'COMPILER');
    debug_log("render template ".print_r($this->data, true).", compiled: ".print_r($this->compiled, true), 'COMPILER');
    if ($this->compiled == null) {
      $this->code = $this->compile($this->data);
      debug_log("template code ".print_r($this->code, true), 'COMPILER');
      $this->compiled = eval("return function (\$ctx) { ".$this->code." };");
    }

    $f = $this->compiled;
    $res = $f($context);
    debug_log("template evaluation: ".print_r($res, true), 'COMPILER');
    return $res;
  }

  public function compile($src = null) {
    if ($src == null) {
      $src = $this->data;
    }
    $generator = new Generator();
    $tokens = $this->getTokens($src);
    //    echo "tokens: ".print_r($tokens, true)."\n";
    return $generator->compile($tokens);
  }

  public function getTokens($src = null) {
    if ($src == null) {
      $src = $this->data;
    }
    $parser = new Parser();
    return $parser->compile($src);
  }
};

?>
{'fraction_non_alphanumeric': 0.1967981257321359, 'fraction_numerical': 0.0031237797735259665, 'mean_word_length': 3.0992, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4464253', 'n_tokens_mistral': 871, 'n_tokens_neox': 847, 'n_words': 185}